diff --git a/.gitignore b/.gitignore index 2d513a0..c164804 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ /.idea/ /target/ +/.settings/ +.project +.classpath +.factorypath diff --git a/README.md b/README.md index 3691d9b..b993b67 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,29 @@ Add the plugin execution to your `pom.xml`: -``` +```xml org.jpeek jpeek-maven-plugin - 0.0.1-SNAPSHOT + 1.0-SNAPSHOT - jpeek-analysis + + analyze + + + ${project.build.outputDirectory} + ${project.build.directory}/jpeek/ + -``` \ No newline at end of file +``` + +Or run it from the command-line: + +``` +mvn org.jpeek:jpeek-maven-plugin:1.0-SNAPSHOT:analyze +``` diff --git a/pom.xml b/pom.xml index 2cf3d1d..7117c95 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,7 @@ SOFTWARE. https://github.com/yegor256/jpeek-maven-plugin 2020 + UTF-8 1.8 1.8 @@ -72,7 +73,32 @@ SOFTWARE. 3.6.0 provided + + org.jpeek + jpeek + 0.30.24 + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.6.0 + + + mojo-descriptor + process-classes + + descriptor + + + + + + + qulice diff --git a/src/main/java/org/jpeek/plugin/JpeekMojo.java b/src/main/java/org/jpeek/plugin/JpeekMojo.java index 87e7a4b..f1b415a 100644 --- a/src/main/java/org/jpeek/plugin/JpeekMojo.java +++ b/src/main/java/org/jpeek/plugin/JpeekMojo.java @@ -23,25 +23,62 @@ */ package org.jpeek.plugin; +import java.io.File; +import java.io.IOException; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.jpeek.App; /** * {@link org.apache.maven.plugin.AbstractMojo} implementation for jPeek. * * @since 0.1 - * @todo #1:30min Implement jpeek plugin execution - * JpeekMojo must execute jpeek and analyze project files upon build. - * Use the jpeek jar from manve repository to execute it with in the - * project. + * @todo #3:30min Add some tests for this Mojo using AbstractMojoTestCase + * from maven-plugin-testing-harness. A good resource for examples is + * maven-checkstyle-plugin. It has been verified that it works from the + * command line (see README). + * @todo #3:30min Add support for analyzing classes in the test directory. + * This should output an analysis most certainly in a different directory + * from the main classes. */ -@Mojo(name = "jpeek-analysis", defaultPhase = LifecyclePhase.TEST) -public class JpeekMojo extends AbstractMojo { +@Mojo(name = "analyze", defaultPhase = LifecyclePhase.VERIFY) +public final class JpeekMojo extends AbstractMojo { + + /** + * Specifies the path where to find classes analyzed by jPeek. + * @checkstyle MemberNameCheck (3 lines) + */ + @Parameter(property = "jpeek.input", defaultValue = "${project.build.outputDirectory}") + private File inputDirectory; + + /** + * Specifies the path to save the jPeek output. + * @checkstyle MemberNameCheck (3 lines) + */ + @Parameter(property = "jpeek.output", defaultValue = "${project.build.directory}/jpeek/") + private File outputDirectory; + + /** + * Skip analyze. + */ + @Parameter(property = "jpeek.skip", defaultValue = "false") + private boolean skip; + @Override public void execute() throws MojoExecutionException, MojoFailureException { - //method body + if (!this.skip) { + try { + new App( + this.inputDirectory.toPath(), + this.outputDirectory.toPath() + ).analyze(); + } catch (final IOException ex) { + throw new MojoExecutionException("Couldn't analyze", ex); + } + } } }