Walkmod is a Java tool, so you must have (≥ 1.7) installed in order to proceed.
WALKMOD_HOME
environment variable,
whose value must be the instalation directory.
WALKMOD_HOME/bin
environment variable to
your PATH
.
walkmod --version
. It
should print out your installed version of walkmod, for example:
Walkmod version "3.0" Java version: 1.8.0_101 Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre OS: Mac OS X, Version: 10.12.2
WalkMod started as a framework to write code transformations. However, most of the users look for quick fixes for existing static code analysis tools. Here appear the commands to get the results.
walkmod apply -DconfigurationFile=rulesets/java/basic.xml pmd
walkmod apply checkstyle
walkmod apply -DauthToken="THIS_IS_MY_TOKEN" -DsonarHost="https://sonarqube.com" sonar
If you are you interested to selectively apply the required changes incrementally, you need to use WalkModHub.
Otherwise, if you want to learn how to use more complex code transformations through a fixed configuration (walkmod.xml
), read the Basic Usage.
pom.xml
. This example, shows you how to apply quick fixes for PMD using Maven.
<plugin> <groupId>org.walkmod.maven.plugins</groupId> <artifactId>walkmod-maven-plugin</artifactId> <version>1.0.3</version> <executions> <execution> <goals> <goal>apply</goal> </goals> <configuration> <chains>pmd</chains> <properties>rulesets/java/basic.xml</properties> </configuration> </execution> </executions> </plugin>And run
mvn package
build.gradle
. This example, shows you how to apply quick fixes for PMD using Gradle.
buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'org.walkmod:gradle-walkmod-plugin:0.0.1' } } apply plugin: 'walkmod' walkmod { chains = [ 'pmd' ] }And run
gradle walkmodApply
Let's see how to use walkmod with a simple Java project. With this aim, we have prepared this tutorial, which executes walkmod to clean unused imports in a simple project. Please, before continuing with this tutorial, verify that you have installed and .
Now, follow the next instructions.
git clone https://github.com/walkmod/quickstart.git
It downloads the source code of our example.
cd quickstart
It enters to the root project folder. This project, as many maven projects, contains the sources in the src/main/java
directory.
Please, check that the file src/main/java/org/walkmod/quickstart/model/Tweet.java
contains an unused import for java.util.Calendar
.
walkmod add imports-cleaner
It creates, if it is missing, a walkmod.xml
file and adds the imports-cleaner plugin in the configuration.
walkmod apply
It executes walkmod in the project and voila! it has removed an unused import in the class org.walkmod.quickstart.model.Tweet
.
INFO [main] - ** STARTING TRANSFORMATIONS CHAINS ** ----------------------------------------------------------- INFO [main] - >>org.walkmod.quickstart.model.Tweet ------------------------------------------------------------ INFO [main] - TRANSFORMATION CHAIN SUCCESS ------------------------------------------------------------ INFO [main] - Total time : 0,96 seconds INFO [main] - Finished at : Mon, 28 Dec 2015 10:04:06 INFO [main] - Final memory : 65 M/ 88 M INFO [main] - Total modified files : 1
git diff
to check the differences. mvn package
to check if it compiles.
Code formatters specify the appearance of the code: indentation, when to use or avoid parenthesis or brackets, etc, but never about the contents of the code.
For many organizations, having code conventions about the code format is really important, because otherwise, people usually reformat the code created by other people continuously, and thus, becomes impossible understand the changes history.
One of the most well-known formatter tools is the Eclipse formatter. If you want to use this, run the following command:
walkmod set-writer -DconfigFile="myformatter.xml" java-formatter
With Walkmod you apply quick fixes by means of code transformations. In fact, the list of plugins allows you publishing and applying quick fixes for your favorite static code analysis tool (e.g PMD, SonarQube, CheckStule) in any project. In order to discover which plugin you need, follow the next instructions:
walkmod plugins
to print the list of available Walkmod plugins.... │ │ │ │ ├───────────────────┼─────┼──────────────────────────────────────────────────┤ │ checkstyle │ │ Walkmod plugin to automatically fix the reported │ │ │ │ problems by Checkstyle. │ │ │ │ │ │ │ │ URL:https://github.com/walkmod/walkmod-checkstyl │ │ │ │ e-plugin │ ├───────────────────┼─────┼──────────────────────────────────────────────────┤ │ pmd │ │ Walkmod plugin to automatically fix the reported │ │ │ │ problems by PMD. │ │ │ │ │ │ │ │ URL:https://github.com/walkmod/walkmod-pmd-plugi │ │ │ │ n │ ├───────────────────┼─────┼──────────────────────────────────────────────────┤ ...
walkmod inspect $plugin-id
to discover the transformations of an specific plugin. For example:
walkmod inspect pmdAnd the contents are as follows:
┌─────────────────────────────────────────────┬────────────────┬──────────────────────────────┬─────────────┐ │ TYPE NAME (ID) │ CATEGORY │ PROPERTIES │ DESCRIPTION │ ├─────────────────────────────────────────────┼────────────────┼──────────────────────────────┼─────────────┤ │ pmd │ transformation │ configurationFile:String │ unavailable │ └─────────────────────────────────────────────┴────────────────┴──────────────────────────────┴─────────────┘These identifiers (ID) are the parameters used in the
walkmod add $ID
command. Properties, such as configurationFile
,
needs to be passed as a dynamic argument.
walkmod add -DonfigurationFile=XXXXX pmd
"bin;lib/guava.jar;lib/log4j.jar"
):
walkmod add -Dclasspath="bin;lib/guava.jar;lib/log4j.jar" rawclasspath