Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line option -o does not produce output with -g option #6934

Closed
Fernal73 opened this issue Aug 1, 2019 · 14 comments

Comments

@Fernal73
Copy link

commented Aug 1, 2019

https://checkstyle.org/cmdline.html#Command_line_usage

-g,--generate-xpath-suppression - generate to output a suppression.xml to use to suppress all violations from user's config.

java -cp {classpath/jarfile}\
 com.puppycrawl.tools.checkstyle.Main\
 -g\
 -c {config file}\
 -p {properties file}\
 -o cs.errors\
 {list of java sources} 

Detected:

Suppressions xpath xml output is generated if checkstyle rules under Tree Walker module are violated.
Argument '-o cs.errors' is ignored, by design, but it would be better to respect -o.


Expected:
Error file as specified in option -o must be output of -g.


Versions run against : 8.22, 8.23.

@romani romani added the approved label Aug 4, 2019

strkkk added a commit to strkkk/checkstyle that referenced this issue Aug 10, 2019
strkkk added a commit to strkkk/checkstyle that referenced this issue Aug 10, 2019
romani added a commit that referenced this issue Aug 11, 2019

@romani romani added the bug label Aug 11, 2019

@romani romani added this to the 8.24 milestone Aug 11, 2019

@romani

This comment has been minimized.

Copy link
Member

commented Aug 11, 2019

Fix is merged

@romani romani closed this Aug 11, 2019

@romani

This comment has been minimized.

Copy link
Member

commented Aug 11, 2019

@strkkk , please update xdoc, it has

-g,--generate-xpath-suppression - generate to output a suppression.xml to use to suppress all violations from user's config.

@romani romani reopened this Aug 11, 2019

@strkkk

This comment has been minimized.

Copy link
Collaborator

commented Aug 12, 2019

@romani what is wrong with it?

@Fernal73

This comment has been minimized.

Copy link
Author

commented Aug 12, 2019

The output also includes a line that informs the user of the number of errors found. That should not be part of the xml output. That will help while redirecting the xml to a file via say a 'tee' command. As it stands, that additional line forms part of the xml output.

@strkkk

This comment has been minimized.

Copy link
Collaborator

commented Aug 12, 2019

The output also includes a line that informs the user of the number of errors found. That should not be part of the xml output

I think you can create new issue for it

@Fernal73

This comment has been minimized.

Copy link
Author

commented Aug 12, 2019

I'm unaware if it has been fixed with the above. If not, yes, a new issue will have to be raised.
There's no need to display the message when the -o option is used in conjunction with -g.

What about when it's not i.e. , should any message be displayed when only -g is in effect? Note that suppressions are generated only for TreeWalker modules. There may be violations in the parent module, Checker, for which suppressions are never generated. There is no xml document generated when there are no violations under module TreeWalker. "Checkstyle ends with # errors" is displayed if other violations exist. This is output to stdout instead of stderr, unlike the log messages.

My understanding is that the -g option is used for generating the suppression document specifically. No other stdout output should be provided. Kindly comment.

@romani

This comment has been minimized.

Copy link
Member

commented Aug 12, 2019

what is wrong with it?

In doc:

suppression.xml

Should be:
suppression xml as we will generate file with name defined by -o, so we do not know name, it is not hatdcoded anymore

@romani

This comment has been minimized.

Copy link
Member

commented Aug 12, 2019

doc fix is merged.

@romani romani closed this Aug 12, 2019

@Fernal73

This comment has been minimized.

Copy link
Author

commented Aug 17, 2019

The documentation could also be updated as to how to run Checkstyle as an ant java task and set the -g parameter since the existing Ant task for Checkstyle doesn't allow that option to be set.

@romani

This comment has been minimized.

Copy link
Member

commented Aug 17, 2019

ow to run Checkstyle as an ant java task and set the -g parameter

it is not for ANT, such option will never be in ANT.

@Fernal73

This comment has been minimized.

Copy link
Author

commented Aug 17, 2019

OExactly. But it can be run as an Ant Java task if the user wishes to with all the command line parameters. I'm not referring to the Checkstyle ant task. That's separate.

To support the -g option, the current Checkstyle task has to be rewritten or a fresh Ant task has to be created.

https://checkstyle.sourceforge.io/anttask.html

I don't want to write up a feature request for it as it's still experimental. Do you?

@romani

This comment has been minimized.

Copy link
Member

commented Aug 17, 2019

let postpone request creation, ant task is heavily underused, user use maven/gradle more then ANT.

@Fernal73

This comment has been minimized.

Copy link
Author

commented Aug 18, 2019

That's fine with me. I can always run my batch file through Ant if needed.

@Fernal73

This comment has been minimized.

Copy link
Author

commented Aug 18, 2019

EDITED:

 <target name="checkstyleg">
    <fileset dir="${basedir}"
             id="javasrcs">
      <include name="**/*.java" />
    </fileset>
    <pathconvert property="sources"
                 refid="javasrcs"
                 pathsep=" " />
            <java classname="${cs.main.class}" 
              logError="true">
      <arg line="-c ${cs.config} -p ${cs.properties} -o  ${ant.project.name}-xpath.xml -g ${sources}" />
      <classpath>
        <pathelement path="{checkstyle classpath} " />
        <pathelement path="${java.class.path}" />
      </classpath>
    </java>
  </target>

cs.main.class -> com.puppycrawl.tools.checkstyle.Main
cs.properties -> properties file

https://checkstyle.sourceforge.io/cmdline.html

This may help with the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.