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

Better java package name detection


    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • checkstyle-plugin
    • None
    • Platform: All, OS: All

      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.


      • 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

      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.

            drulli Ulli Hafner
            srbrown1 srbrown1
            0 Vote for this issue
            0 Start watching this issue