/gradle-walkmod-plugin

A Gradle plugin to easily integrate Walkmod on your projects

Primary LanguageGroovyApache License 2.0Apache-2.0

Walkmod Gradle Plugin

Build Status Coverage Status Semantic Versioning

The Walkmod Gradle Plugin is the first tool to provide Walkmod integration with Gradle. This plugin adds two new tasks to allow checking and applying walkmod changes to your projects.

Warning
this is a preliminary version and still some work must be done.

Installation

As long as this is a preliminary version, no fixed repository exisists. If you wish to test the tool, you’ll need to install it locally from sources. A install task is provided to simplify the installation in maven local. Use the following snippet inside a Gradle build file:

build.gradle
buildscript {
    repositories {
        mavenLocal()
    }

    dependencies {
        classpath 'org.walkmod:gradle-walkmod-plugin:0.0.1'
    }
}

apply plugin: 'walkmod'

Usage

The plugin adds a two new tasks:

  1. walkmodCheck: checks for possible changes. Same as using walkmod check in the command tool.

  2. walkmodApply: applies changes. Same as using walkmod apply in the command tool.

Properties

Each tasks provides the following properties for its configuration:

chains

chain names to check or apply. Type: List<String>. Default: empty (all chains).

offline

true to resolve dependencies (uses Ivy), false to resolve locally. Type: boolean. Default: false.

verbose

true to show extra information. Type: boolean. Default: false.

showErrors

true to get full details when something goes wrong. Type: boolean. Default: true.

configFile

walkmod configuration file. Type: File. Default: walkmod.xml.

Methods

None right now (this may change in the future).

Using plugins

Due to some unresolved classpath issues, currently, external plugins must be added as runtime dependencies.

For instance, if you include walkmod-imports-cleaner-plugin

walkmod.xml
<!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD"  "http://www.walkmod.com/dtd/walkmod-1.0.dtd" >
<walkmod>
 <plugins>
  <plugin groupId="org.walkmod" artifactId="walkmod-imports-cleaner-plugin" version="2.0" />
  </plugins>
  <chain name="example-chain" >
    <transformation type="walkmod:commons:import-cleaner" />
  </chain>
</walkmod>

you’ll need to add the plugin’s jar in your dependencies block.

build.gradle
dependencies {
	runtime 'org.walkmod:walkmod-imports-cleaner-plugin:2.0'

	testCompile group: 'junit', name: 'junit', version: '4.+'
}

Using scripts

Due to some unresolved classpath issues, currently, walkmod scripts require org.walkmod:javalang to be added as dependency.

So, if you include the following script

script.groovy
import org.walkmod.javalang.ast.body.ModifierSet;
import org.walkmod.javalang.ast.body.FieldDeclaration;
import java.lang.reflect.Modifier;

for(type in node.types){
  def fields = type.members.findAll({it instanceof FieldDeclaration});
  for (field in fields){
    int modifiers = ModifierSet.addModifier(field.modifiers, Modifier.PRIVATE);
    modifiers = ModifierSet.removeModifier(modifiers, Modifier.PROTECTED);
    modifiers = ModifierSet.removeModifier(modifiers, Modifier.PUBLIC);
    field.setModifiers(modifiers);
  }
}

you’ll need to add org.walkmod:javalang in your dependencies block as follows:

dependencies {
	compile 'org.walkmod:javalang:3.0.0'

	testCompile group: 'junit', name: 'junit', version: '4.+'
}

Compatibility with previous releases

Configuration

Warning
This is work in progress and this option is not recommended

This plugin uses walkmod-core:2.2.0 by default, however you can change this by defining a value on the walkmod extension, like so

build.gradle
walkmod {
    version = '1.0.7-SNAPSHOT'
}

Do not forget to add an entry to the repositories block pointint to Maven local if you’d like to run a local version of any walkmod artifact (walkmod-core, walkmod-cmd, etc.). Here there’s an example:

build.gradle
repositories {
    mavenLocal()   // (1)
    mavenCentral() // (2)
}

walkmod {
    version = '1.0.7-SNAPSHOT'
}
  1. resolves artifacts in your local Maven repository

  2. resolves artifacts in Maven Central

Contributing

In the spirit of free and open software, everyone is encouraged to help improve this project. If you discover errors or omissions in the source code, documentation, please don’t hesitate to submit an issue or open a pull request with a fix. New contributors are always welcome!

Here are some ways you can contribute:

  • by using prerelease (alpha, beta or preview) versions

  • by reporting bugs

  • by suggesting new features

  • by writing or editing documentation

  • by writing specifications

  • by writing code — No patch is too small.

    • fix typos

    • add comments

    • clean up inconsistent whitespace

    • write tests!

  • by refactoring code

  • by fixing {uri-issues}[issues]

  • by reviewing patches

Special thanks

  • To the Walkmod team for such a tool.

  • To @aalmiray’s {asciidoctor-gradle-plugin-url}[asciidoctor-gradle-plugin] which served as foundation for this one.