diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java new file mode 100644 index 0000000..de01dfe --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java @@ -0,0 +1,83 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.plugin; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.util.List; + +/** + * Wrapper for {@link org.twdata.maven.mojoexecutor.MojoExecutor}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public final class DefaultPluginExecutor implements PluginExecutor { + + @Override + public MojoExecutor.Element element(final String key, final String value) { + return MojoExecutor.element(key, value); + } + + @Override + public Xpp3Dom configuration(final MojoExecutor.Element... elements) { + return MojoExecutor.configuration(elements); + } + + @Override + public MojoExecutor.ExecutionEnvironment executionEnvironment( + final MavenProject mavenProject, final MavenSession mavenSession, final BuildPluginManager pluginManager + ) { + return MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); + } + + @Override + public void executeMojo( + final Plugin plugin, final String goal, final Xpp3Dom configuration, + final MojoExecutor.ExecutionEnvironment env + ) throws MojoExecutionException { + MojoExecutor.executeMojo(plugin, goal, configuration, env); + } + + @Override + public Dependency dependency(final String groupid, final String artifactid, final String version) { + return MojoExecutor.dependency(groupid, artifactid, version); + } + + @Override + public List dependencies(final Dependency... dependencies) { + return MojoExecutor.dependencies(dependencies); + } + + @Override + public Plugin plugin( + final String groupid, final String artifactid, final String version, final List dependencies + ) { + return MojoExecutor.plugin(groupid, artifactid, version, dependencies); + } +} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java new file mode 100644 index 0000000..1747f3f --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java @@ -0,0 +1,121 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.plugin; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.util.List; + +/** + * Interface for wrapping calls to static methods on {@link org.twdata.maven.mojoexecutor.MojoExecutor}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public interface PluginExecutor { + + /** + * Constructs the element with a textual body. + * + * @param name The element name + * @param value The element text value + * + * @return The element object + */ + MojoExecutor.Element element(String name, String value); + + /** + * Builds the configuration for the goal using Elements. + * + * @param elements A list of elements for the configuration section + * + * @return The elements transformed into the Maven-native XML format + */ + Xpp3Dom configuration(MojoExecutor.Element... elements); + + /** + * Constructs the {@link MojoExecutor.ExecutionEnvironment} instance fluently. + * + * @param mavenProject The current Maven project + * @param mavenSession The current Maven session + * @param pluginManager The Build plugin manager + * + * @return The execution environment + */ + MojoExecutor.ExecutionEnvironment executionEnvironment( + MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager + ); + + /** + * Entry point for executing a mojo. + * + * @param plugin The plugin to execute + * @param goal The goal to execute + * @param configuration The execution configuration + * @param env The execution environment + * + * @throws MojoExecutionException If there are any exceptions locating or executing the mojo + */ + void executeMojo( + Plugin plugin, String goal, Xpp3Dom configuration, MojoExecutor.ExecutionEnvironment env + ) throws MojoExecutionException; + + /** + * Defines a dependency. + * + * @param groupId The group id + * @param artifactId The artifact id + * @param version The plugin version + * + * @return the dependency instance + */ + Dependency dependency(String groupId, String artifactId, String version); + + /** + * Creates a list of dependencies. + * + * @param dependencies the dependencies + * + * @return A list of dependencies + */ + List dependencies(Dependency... dependencies); + + /** + * Defines a plugin. + * + * @param groupId The group id + * @param artifactId The artifact id + * @param version The plugin version + * @param dependencies The plugin dependencies + * + * @return The plugin instance + */ + Plugin plugin( + String groupId, String artifactId, String version, List dependencies + ); +}