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

Better java package name detection

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • checkstyle-plugin
    • None
    • Platform: All, OS: All

    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

          People

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

            Dates

              Created:
              Updated:
              Resolved: