From 829cc5dff696a90766f6c8641b7eaa2363858dec Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 8 Feb 2017 12:30:18 +0000 Subject: [PATCH 1/7] pom.xml: version set to 2.2.0-SNAPSHOT --- builder/pom.xml | 2 +- plugin-sample/pom.xml | 2 +- plugin/pom.xml | 2 +- pom.xml | 2 +- ruleset/pom.xml | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index 2e3fd39..1a07416 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -12,7 +12,7 @@ kemitix-checkstyle-ruleset-builder - 2.1.0 + 2.2.0-SNAPSHOT jar Kemitix Checkstyle Ruleset Builder diff --git a/plugin-sample/pom.xml b/plugin-sample/pom.xml index e8b07bd..f8785db 100644 --- a/plugin-sample/pom.xml +++ b/plugin-sample/pom.xml @@ -8,7 +8,7 @@ net.kemitix kemitix-checkstyle-ruleset-plugin-sample - 2.1.0 + 2.2.0-SNAPSHOT Kemitix Checkstyle Ruleset Plugin Sample Sample usage of the Kemitix Checkstyle Ruleset Plugin diff --git a/plugin/pom.xml b/plugin/pom.xml index e88bef1..93aa2b7 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.1.0 + 2.2.0-SNAPSHOT kemitix-checkstyle-ruleset-maven-plugin diff --git a/pom.xml b/pom.xml index aef2d05..496da4f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.1.0 + 2.2.0-SNAPSHOT pom Kemitix Checkstyle Ruleset (Parent) diff --git a/ruleset/pom.xml b/ruleset/pom.xml index 869cdba..265309e 100644 --- a/ruleset/pom.xml +++ b/ruleset/pom.xml @@ -7,11 +7,11 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.1.0 + 2.2.0-SNAPSHOT kemitix-checkstyle-ruleset - 2.1.0 + 2.2.0-SNAPSHOT jar Kemitix Checkstyle Ruleset From df4c951142fbec091879f854a41f36d32256322d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 8 Feb 2017 19:40:53 +0000 Subject: [PATCH 2/7] builder:CheckstyleWriter: use system's line separator --- .../kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java index c82f1f7..5ce2daa 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java @@ -50,7 +50,7 @@ import java.util.stream.Stream; @RequiredArgsConstructor class CheckstyleWriter implements CommandLineRunner { - private static final String NEWLINE = "\n"; + private static final String NEWLINE = System.getProperty("line.separator"); private final OutputProperties outputProperties; From 4de68a84ce1e3ba3415633ea114c419d16adafa1 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 8 Feb 2017 19:50:54 +0000 Subject: [PATCH 3/7] builder:CheckstyleWriterTest: use system's file separator --- .../checkstyle/ruleset/builder/CheckstyleWriterTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java index 2412652..da7d873 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -30,6 +30,8 @@ public class CheckstyleWriterTest { private static final String TEMPLATE = "C:%s\nTW:%s"; + private static final String FILE_SEPARATOR = System.getProperty("file.separator"); + private CheckstyleWriter checkstyleWriter; private OutputProperties outputProperties; @@ -181,9 +183,11 @@ public class CheckstyleWriterTest { @Test public void throwRteIfErrorWritingFile() throws Exception { //given - outputProperties.setDirectory(Paths.get("/../imaginary")); + final String imaginary = String.join(FILE_SEPARATOR, "", "..", "imaginary"); + outputProperties.setDirectory(Paths.get(imaginary)); exception.expect(RuntimeException.class); - exception.expectMessage("java.nio.file.NoSuchFileException: /../imaginary/checkstyle-LAYOUT.xml"); + exception.expectMessage( + "java.nio.file.NoSuchFileException: " + imaginary + FILE_SEPARATOR + "checkstyle-LAYOUT.xml"); //when checkstyleWriter.run(); } From 64330d01da026624067fa6fb0b92bf7a0aa51e47 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 8 Feb 2017 19:25:07 +0000 Subject: [PATCH 4/7] plugin:pom.xml: remove properties-maven-plugin This was loading the properties from the project that was using the plugin. --- plugin/pom.xml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/plugin/pom.xml b/plugin/pom.xml index 93aa2b7..d3b24d5 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -101,34 +101,6 @@ 1.8 - - org.codehaus.mojo - properties-maven-plugin - ${properties-maven-plugin.version} - - - - set-system-properties - - - - - maven-checkstyle-plugin.version - ${maven-checkstyle-plugin.version} - - - checkstyle.version - ${checkstyle.version} - - - sevntu.version - ${sevntu.version} - - - - - - From cf22d09a60a63186b65f104eb89d00f309cc9210 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 8 Feb 2017 19:26:00 +0000 Subject: [PATCH 5/7] plugin:AbstractCheckMojo: load the version from the plugin's pom file --- .../ruleset/plugin/AbstractCheckMojo.java | 91 +++++++++++++++---- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java index fbb72f1..ae39165 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java @@ -26,7 +26,12 @@ package net.kemitix.checkstyle.ruleset.plugin; import lombok.Setter; import lombok.val; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; @@ -34,14 +39,19 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.twdata.maven.mojoexecutor.MojoExecutor; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + /** * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset. * * @author Paul Campbell (pcampbell@kemitix.net) */ -public abstract class AbstractCheckMojo extends AbstractMojo { +abstract class AbstractCheckMojo extends AbstractMojo { private static final String CHECKSTYLE_GROUPID = "com.puppycrawl.tools"; @@ -73,8 +83,11 @@ public abstract class AbstractCheckMojo extends AbstractMojo { @Parameter(defaultValue = "${session}", readonly = true) private MavenSession mavenSession; + @Parameter(defaultValue = "${localRepository}", readonly = true, required = true) + private ArtifactRepository artifactRepository = null; + @Component - private BuildPluginManager pluginManager; + private BuildPluginManager pluginManager = null; /** * Execute Checkstyle Check. @@ -84,28 +97,66 @@ public abstract class AbstractCheckMojo extends AbstractMojo { * @throws MojoExecutionException on execution error * @throws MojoFailureException on execution failure */ - protected final void performCheck(final String level) throws MojoExecutionException, MojoFailureException { - // load versions from plugin's pom.xml - val properties = System.getProperties(); - val mavenCheckstylePluginVersion = properties.getProperty("maven-checkstyle-plugin.version"); - val checkstyleVersion = properties.getProperty("checkstyle.version"); - val sevntuVersion = properties.getProperty("sevntu.version"); + final void performCheck(final String level) throws MojoExecutionException, MojoFailureException { + val properties = getProperties(); + debug("properties: %s", properties); + // get versions from pom.xml properties + val pluginVersion = getProperty(properties, "maven-checkstyle-plugin.version"); + val checkstyleVersion = getProperty(properties, "checkstyle.version"); + val sevntuVersion = getProperty(properties, "sevntu.version"); + + // configure + val checkstylePlugin = getPlugin(pluginVersion, checkstyleVersion, sevntuVersion); + val configuration = MojoExecutor.configuration( + MojoExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level))); + val environment = MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); + + // run + info("Running Checkstyle %s (sevntu: %s) with ruleset %s (%s)", checkstyleVersion, sevntuVersion, level, + rulesetVersion + ); + MojoExecutor.executeMojo(checkstylePlugin, "check", configuration, environment); + info("Checkstyle complete"); + } + + private String getProperty(final Properties properties, final String key) { + val property = properties.getProperty(key); + debug(key + ": %s", property); + return property; + } + + private Plugin getPlugin(final String pluginVersion, final String checkstyleVersion, final String sevntuVersion) { + // create checkstyle dependencies val checkstyle = MojoExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion); val sevntu = MojoExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion); val ruleset = MojoExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion); - val checkstylePlugin = - MojoExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, mavenCheckstylePluginVersion, - MojoExecutor.dependencies(checkstyle, sevntu, ruleset) - ); - val configLocation = - MojoExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level)); + val dependencies = MojoExecutor.dependencies(checkstyle, sevntu, ruleset); - getLog().info(String.format("Running Checkstyle %s (sevntu: %s) with ruleset %s (%s)", checkstyleVersion, - sevntuVersion, level, rulesetVersion - )); - MojoExecutor.executeMojo(checkstylePlugin, "check", MojoExecutor.configuration(configLocation), - MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager) - ); + return MojoExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies); + } + + private Properties getProperties() throws MojoFailureException { + // load properties from the plugin pom.xml + val pluginArtifactId = KEMITIX_ARTIFACTID + "-maven-plugin"; + val pluginArtifact = new DefaultArtifact(KEMITIX_GROUPID, pluginArtifactId, rulesetVersion, null, "", null, + new DefaultArtifactHandler("pom") + ); + try { + val pomReader = new FileReader(artifactRepository.find(pluginArtifact) + .getFile()); + return new MavenXpp3Reader().read(pomReader) + .getProperties(); + } catch (XmlPullParserException | IOException e) { + throw new MojoFailureException("Can't load properties from plugin's pom.xml", e); + } + } + + private void info(final String format, final Object... args) { + getLog().info(String.format(format, args)); + } + + private void debug(final String format, final Object... args) { + getLog().debug(String.format(format, args)); } } From 718041b0542e98ef96b7a10768471a5ffc0fe028 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 9 Feb 2017 09:24:40 +0000 Subject: [PATCH 6/7] pom.xml: version set to 2.1.1 --- builder/pom.xml | 2 +- plugin-sample/pom.xml | 2 +- plugin/pom.xml | 2 +- pom.xml | 2 +- ruleset/pom.xml | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index 1a07416..fae7ef6 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -12,7 +12,7 @@ kemitix-checkstyle-ruleset-builder - 2.2.0-SNAPSHOT + 2.1.1 jar Kemitix Checkstyle Ruleset Builder diff --git a/plugin-sample/pom.xml b/plugin-sample/pom.xml index f8785db..20eb3fe 100644 --- a/plugin-sample/pom.xml +++ b/plugin-sample/pom.xml @@ -8,7 +8,7 @@ net.kemitix kemitix-checkstyle-ruleset-plugin-sample - 2.2.0-SNAPSHOT + 2.1.1 Kemitix Checkstyle Ruleset Plugin Sample Sample usage of the Kemitix Checkstyle Ruleset Plugin diff --git a/plugin/pom.xml b/plugin/pom.xml index d3b24d5..8208852 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.2.0-SNAPSHOT + 2.1.1 kemitix-checkstyle-ruleset-maven-plugin diff --git a/pom.xml b/pom.xml index 496da4f..ad63965 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.2.0-SNAPSHOT + 2.1.1 pom Kemitix Checkstyle Ruleset (Parent) diff --git a/ruleset/pom.xml b/ruleset/pom.xml index 265309e..5e42e90 100644 --- a/ruleset/pom.xml +++ b/ruleset/pom.xml @@ -7,11 +7,11 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.2.0-SNAPSHOT + 2.1.1 kemitix-checkstyle-ruleset - 2.2.0-SNAPSHOT + 2.1.1 jar Kemitix Checkstyle Ruleset From 1bc5e9b0babbf8898034b510b321e0dfb76ce648 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 9 Feb 2017 09:26:08 +0000 Subject: [PATCH 7/7] CHANGELOG --- CHANGELOG | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 4b7a42a..4876cc4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,12 @@ CHANGELOG ========= +2.1.1 +----- + +* Load plugin dependency versions from the plugin's own pom +* Cross-platform build + 2.1.0 -----