walkmod / walkmod-core

walkmod: an open source tool to fix coding style issues
http://www.walkmod.com
GNU Lesser General Public License v3.0
153 stars 23 forks source link

Transformation chain fails with maven & checkstyle #75

Closed surli closed 6 years ago

surli commented 7 years ago

Hi,

I'm trying to use walkmod for fixing checkstyle on the following maven project: https://github.com/INRIA/spoon . More specifically, as a test, I'm trying to fix checkstyle issue I had on this commit: https://github.com/INRIA/spoon/pull/1499/commits/0d2d0af2c758223562ee82b206cadf64ffb89f2e (it had wrong indent, and a problem with spaces somewhere in the file).

I installed last version on a macos, using homebrew:

193-51-236-54:Github urli$ walkmod -v
 INFO [main] - Java version: 1.8.0_111
 INFO [main] - Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre
 INFO [main] - OS: Mac OS X, Vesion: 10.12.6
--------------------------------------------------------------------------------
                     _    _       _ _   ___  ___          _                     
                    | |  | |     | | |  |  \/  |         | |                    
                    | |  | | __ _| | | _| .  . | ___   __| |                    
                    | |/\| |/ _` | | |/ / |\/| |/ _ \ / _` |                    
                    \  /\  / (_| | |   <| |  | | (_) | (_| |                    
                     \/  \/ \__,_|_|_|\_\_|  |_/\___/ \__,_|                    
--------------------------------------------------------------------------------
An open source tool to apply code conventions
version 3.0 - February 2017 -
--------------------------------------------------------------------------------
Walkmod version "3.0"
Java version: 1.8.0_111
Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre
OS: Mac OS X, Version: 10.12.6

So looking on the usage I first tried to call walkmod apply checkstyle on my specific commit, it ended up with the following stacktrace:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.407 s
[INFO] Finished at: 2017-08-11T14:06:21+02:00
[INFO] Final Memory: 51M/771M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:checkstyle (default) on project spoon-core: An error has occurred in Checkstyle report generation. Failed during checkstyle execution: There are 79 errors reported by Checkstyle 6.11.2 with checkstyle.xml ruleset. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
 INFO [main] - TRANSFORMATION CHAIN FAILS

--------------------------------------------------------------------------------
 INFO [main] - Total time: 21,256 seconds
 INFO [main] - Finished at: Fri, 11 Aug 2017 14:06:22
 INFO [main] - Final memory: 173 M/ 193 M
--------------------------------------------------------------------------------
 INFO [main] - Please, see the walkmod log file for details
ERROR [main] - TRANSFORMATION CHAIN (checkstyle) FAILS
An exeception has been produced during the null transformation - org.walkmod.util.location.LocationImpl@4215838f
    at org.walkmod.maven.providers.MavenProject.build(MavenProject.java:252)
    at org.walkmod.maven.providers.MavenProject.resolveClassLoader(MavenProject.java:368)
    at org.walkmod.maven.providers.ClassLoaderConfigurationProvider.load(ClassLoaderConfigurationProvider.java:85)
    at org.walkmod.javalang.walkers.DefaultClasspathEvaluator.runClassLoaderInitializers(DefaultClasspathEvaluator.java:59)
    at org.walkmod.javalang.walkers.DefaultClasspathEvaluator.evaluate(DefaultClasspathEvaluator.java:21)
    at org.walkmod.javalang.walkers.DefaultJavaWalker.calculateClasspath(DefaultJavaWalker.java:147)
    at org.walkmod.javalang.walkers.DefaultJavaWalker.execute(DefaultJavaWalker.java:161)
    at org.walkmod.impl.DefaultChainWalkerInvocation.invoke(DefaultChainWalkerInvocation.java:41)
    at org.walkmod.impl.DefaultChainInvocation.invoke(DefaultChainInvocation.java:38)
    at org.walkmod.impl.DefaultChainAdapter.execute(DefaultChainAdapter.java:166)
    at org.walkmod.conf.entities.impl.ConfigurationImpl.executeChain(ConfigurationImpl.java:731)
    at org.walkmod.conf.entities.impl.ConfigurationImpl.execute(ConfigurationImpl.java:825)
    at org.walkmod.WalkModFacade.run(WalkModFacade.java:284)
    at org.walkmod.WalkModFacade.apply(WalkModFacade.java:142)
    at org.walkmod.commands.ApplyCommand.execute(ApplyCommand.java:42)
    at org.walkmod.WalkModDispatcher.execute(WalkModDispatcher.java:172)
    at org.walkmod.WalkModDispatcher.main(WalkModDispatcher.java:197)
Caused by: org.walkmod.conf.ConfigurationException: Error executing: mvn clean install -DskipTests -DskipWalkmod in /Users/urli/Github/spoon
    ... 17 more
Caused by: java.lang.Exception: Error executing: mvn clean install -DskipTests -DskipWalkmod in /Users/urli/Github/spoon
    ... 17 more

Please note that in our project, a mvn install -DskipTests=true on this specific commit would fail because of the checkstyle errors in this commit.

Then I tried with the following walkmod.xml config file:

<!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD" "http://www.walkmod.com/dtd/walkmod-1.1.dtd">
<walkmod>
    <conf-providers>
        <conf-provider type="maven"/>
    </conf-providers>
    <chain name="default">
        <transformation type="checkstyle"/>
    </chain>

</walkmod>

and then I obtained the following error:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.740 s
[INFO] Finished at: 2017-08-11T14:12:03+02:00
[INFO] Final Memory: 51M/775M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:checkstyle (default) on project spoon-core: An error has occurred in Checkstyle report generation. Failed during checkstyle execution: There are 79 errors reported by Checkstyle 6.11.2 with checkstyle.xml ruleset. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
ERROR [main] - Invalid configuration
org.walkmod.conf.ConfigurationException: Error executing: mvn clean install -DskipTests -DskipWalkmod in /Users/urli/Github/spoon
    at org.walkmod.maven.providers.MavenProject.build(MavenProject.java:252)
    at org.walkmod.maven.providers.MavenProject.resolveClassLoader(MavenProject.java:368)
    at org.walkmod.maven.providers.ClassLoaderConfigurationProvider.load(ClassLoaderConfigurationProvider.java:85)
    at org.walkmod.impl.DefaultConfigurationAdapter.prepare(DefaultConfigurationAdapter.java:56)
    at org.walkmod.conf.ConfigurationManager.addProviders(ConfigurationManager.java:64)
    at org.walkmod.conf.ConfigurationManager.<init>(ConfigurationManager.java:75)
    at org.walkmod.conf.ConfigurationManager.<init>(ConfigurationManager.java:79)
    at org.walkmod.WalkModFacade.readConfig(WalkModFacade.java:181)
    at org.walkmod.WalkModFacade.run(WalkModFacade.java:256)
    at org.walkmod.WalkModFacade.apply(WalkModFacade.java:142)
    at org.walkmod.commands.ApplyCommand.execute(ApplyCommand.java:40)
    at org.walkmod.WalkModDispatcher.execute(WalkModDispatcher.java:172)
    at org.walkmod.WalkModDispatcher.main(WalkModDispatcher.java:197)
Caused by: java.lang.Exception: Error executing: mvn clean install -DskipTests -DskipWalkmod in /Users/urli/Github/spoon
    ... 13 more
ERROR [main] - Invalid configuration
java.lang.NullPointerException
    at org.walkmod.WalkModFacade.run(WalkModFacade.java:264)
    at org.walkmod.WalkModFacade.apply(WalkModFacade.java:142)
    at org.walkmod.commands.ApplyCommand.execute(ApplyCommand.java:40)
    at org.walkmod.WalkModDispatcher.execute(WalkModDispatcher.java:172)
    at org.walkmod.WalkModDispatcher.main(WalkModDispatcher.java:197)
Exception in thread "main" java.lang.NullPointerException
    at org.walkmod.WalkModFacade.run(WalkModFacade.java:284)
    at org.walkmod.WalkModFacade.apply(WalkModFacade.java:142)
    at org.walkmod.commands.ApplyCommand.execute(ApplyCommand.java:40)
    at org.walkmod.WalkModDispatcher.execute(WalkModDispatcher.java:172)
    at org.walkmod.WalkModDispatcher.main(WalkModDispatcher.java:197)

So any hint how to use walkmod in my case?

surli commented 7 years ago

Ping @walkmod

rpau commented 6 years ago

Sorry for the delay. Checking.

surli commented 6 years ago

Note that in order to replicate easily my bugs I created a dedicated branch to reproduce the problem: https://github.com/surli/failingProject/tree/checkstyle-error

rpau commented 6 years ago

@surli In the PR I have sent to you, is using a new version of the walkmod-maven-plugin and the workflow is a little bit different than the one that it is explained in the web site. It is something that I decided to change recently.

The problem you experienced with the command is due to:

Notice that my PR is not applying changes into the code. It is because code mutation is not an accepted practice because commits needs to be idempotent, and more importantly, the tests should be executed according a commit, not for a mutated codebase.

I am planning to add this information to the website.

surli commented 6 years ago

Great! Thanks for your information. I'm currently working on a tool to automate the creation of patches (see: https://github.com/Spirals-Team/repairnator). I'll certainly come back to you as I'll try to put walkmod in it :)