Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-1828

Better java package name detection

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: checkstyle-plugin
    • Labels:
      None
    • Environment:
      Platform: All, OS: All
    • Similar Issues:

      Description

      Hi, the java package name detection algorithm in hudson.plugins.check​
      style.util.JavaPacka​geDetetcor.detectPackageName()does not support all the
      syntax options for package definitions.

      Specifically:

      • having a tab character after the word "package"
      • having more than one white space character after the word "package"
      • having leading white space before the word "package"
      • having trailing white space or a "//" comment after the ';'
      • not having the package name on the line same line as the word "package"
      • having comments (either // style, or /* ... */) anywhere in the package
        definition

      Whilst these constructs are unusual (and some of the are probably bad
      practice), they should not break the checkstyle plugin.

      A good start would be to read the whole file in, rather than using the
      LineIterator class. You could then use a regular expression with the DOTALL
      flag enabled, and use the '\s' contruct to match whitespace including line
      terminators. This solves the white space issues and not having the package name
      on the same line as the word "package".

      To solve the comment issue, I suggest something like:

      1. Read the whole file.
      2. Strip out all comments.
      3. Look for the package definition in the amended data.

        Attachments

          Activity

          Hide
          drulli Ulli Hafner added a comment -

          Started.

          Show
          drulli Ulli Hafner added a comment - Started.
          Hide
          drulli Ulli Hafner added a comment -

          Added testcase checkComplicatedPackageName() and fix.

          Do you know an existing Java parser engine? Parsing on my own seems to be a bit
          out of scope...

          If this enhanced version is still not sufficient for you please reopen.

          Show
          drulli Ulli Hafner added a comment - Added testcase checkComplicatedPackageName() and fix. Do you know an existing Java parser engine? Parsing on my own seems to be a bit out of scope... If this enhanced version is still not sufficient for you please reopen.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in hudson
          User: : drulli
          Path:
          trunk/hudson/plugins/checkstyle/src/main/java/hudson/plugins/checkstyle/util/AbstractPackageDetector.java
          trunk/hudson/plugins/checkstyle/src/main/java/hudson/plugins/checkstyle/util/JavaPackageDetector.java
          trunk/hudson/plugins/checkstyle/src/main/resources/tabview/main.jelly
          trunk/hudson/plugins/checkstyle/src/test/java/hudson/plugins/checkstyle/util/CsharpNamespaceDetectorTest.java
          trunk/hudson/plugins/checkstyle/src/test/java/hudson/plugins/checkstyle/util/JavaPackageDetectorTest.java
          trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/ActionBinding-Original-Formatting.cs
          trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/ActionBinding.cs
          trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/MavenJavaTest.txt
          trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/complicated-package-declaration.txt
          http://fisheye4.cenqua.com/changelog/hudson/?cs=10208
          Log:
          [Fixed JENKINS-1828]: use a better regexp for java package parsing.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in hudson User: : drulli Path: trunk/hudson/plugins/checkstyle/src/main/java/hudson/plugins/checkstyle/util/AbstractPackageDetector.java trunk/hudson/plugins/checkstyle/src/main/java/hudson/plugins/checkstyle/util/JavaPackageDetector.java trunk/hudson/plugins/checkstyle/src/main/resources/tabview/main.jelly trunk/hudson/plugins/checkstyle/src/test/java/hudson/plugins/checkstyle/util/CsharpNamespaceDetectorTest.java trunk/hudson/plugins/checkstyle/src/test/java/hudson/plugins/checkstyle/util/JavaPackageDetectorTest.java trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/ActionBinding-Original-Formatting.cs trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/ActionBinding.cs trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/MavenJavaTest.txt trunk/hudson/plugins/checkstyle/src/test/resources/hudson/plugins/checkstyle/util/complicated-package-declaration.txt http://fisheye4.cenqua.com/changelog/hudson/?cs=10208 Log: [Fixed JENKINS-1828] : use a better regexp for java package parsing.

            People

            • Assignee:
              drulli Ulli Hafner
              Reporter:
              srbrown1 srbrown1
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: