From 4b354066bfed0adb821d5158054e9770e94db400 Mon Sep 17 00:00:00 2001 From: dtruckenmiller Date: Wed, 3 Dec 2014 08:00:23 -0600 Subject: [PATCH 1/4] fix for Allow initialization once per run (with multiple modules) #53 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a new optional configuration parameter ‘runOnlyOnce’ --- pom.xml | 5 +++ .../project13/maven/git/GitCommitIdMojo.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/pom.xml b/pom.xml index d1d4ca8a..870908bd 100644 --- a/pom.xml +++ b/pom.xml @@ -88,6 +88,11 @@ maven-plugin-api ${maven-plugin-api.version} + + org.apache.maven + maven-core + ${maven-plugin-api.version} + org.apache.maven maven-project diff --git a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java index b7787690..26959824 100644 --- a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java +++ b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java @@ -25,6 +25,7 @@ import com.google.common.collect.Lists; import com.google.common.io.Closeables; import com.google.common.io.Files; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; @@ -256,6 +257,19 @@ public class GitCommitIdMojo extends AbstractMojo { @SuppressWarnings("UnusedDeclaration") private boolean skip = false; + /** + * In a multi-module build, only run once. This probably won't "do the right thing" if your project has more than + * one git repository. It you use this with the option 'generateGitPropertiesFile', it will only generate (or update) + * the file in the directory where you started your build. + * + * The git.* parameters are available in all modules. + * + * @parameter default-value="false" + * @since 2.1.12 + */ + @SuppressWarnings("UnusedDeclaration") + private boolean runOnlyOnce = false; + /** * Can be used to exclude certain properties from being emited into the resulting file. * May be useful when you want to hide {@code git.remote.origin.url} (maybe because it contains your repo password?), @@ -272,6 +286,16 @@ public class GitCommitIdMojo extends AbstractMojo { @SuppressWarnings("UnusedDeclaration") private List excludeProperties = Collections.emptyList(); + /** + * The Maven Session Object + * + * @parameter expression="${session}" + * @required + * @readonly + */ + @SuppressWarnings("UnusedDeclaration") + protected MavenSession session; + /** * The properties we store our data in and then expose them */ @@ -291,6 +315,13 @@ public void execute() throws MojoExecutionException { return; } + if (runOnlyOnce) { + if (!session.getExecutionRootDirectory().equals(session.getCurrentProject().getBasedir().getAbsolutePath())) { + log("already run once, return"); + return; + } + } + if (isPomProject(project) && skipPoms) { log("isPomProject is true and skipPoms is true, return"); return; From 581f72c716b438709f966539b5906b50b8d2402b Mon Sep 17 00:00:00 2001 From: dtruckenmiller Date: Wed, 3 Dec 2014 08:03:45 -0600 Subject: [PATCH 2/4] fixed typos in comment --- src/main/java/pl/project13/maven/git/GitCommitIdMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java index 26959824..0cbd4dec 100644 --- a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java +++ b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java @@ -259,10 +259,10 @@ public class GitCommitIdMojo extends AbstractMojo { /** * In a multi-module build, only run once. This probably won't "do the right thing" if your project has more than - * one git repository. It you use this with the option 'generateGitPropertiesFile', it will only generate (or update) + * one git repository. If you use this with the option 'generateGitPropertiesFile', it will only generate (or update) * the file in the directory where you started your build. * - * The git.* parameters are available in all modules. + * The git.* variables are available in all modules. * * @parameter default-value="false" * @since 2.1.12 From cdb1e7755b21314cb9b2efb24af6380b44559032 Mon Sep 17 00:00:00 2001 From: dtruckenmiller Date: Wed, 3 Dec 2014 20:47:12 -0600 Subject: [PATCH 3/4] Reword javadoc --- src/main/java/pl/project13/maven/git/GitCommitIdMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java index 0cbd4dec..81f8d918 100644 --- a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java +++ b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java @@ -262,7 +262,7 @@ public class GitCommitIdMojo extends AbstractMojo { * one git repository. If you use this with the option 'generateGitPropertiesFile', it will only generate (or update) * the file in the directory where you started your build. * - * The git.* variables are available in all modules. + * The git.* maven properties are available in all modules. * * @parameter default-value="false" * @since 2.1.12 From dfdff8dd5061e6f16ee31669e1dc7fb36c9ba155 Mon Sep 17 00:00:00 2001 From: dtruckenmiller Date: Thu, 4 Dec 2014 07:24:43 -0600 Subject: [PATCH 4/4] Added to readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 90e8b3ab..5797d0bf 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,16 @@ It's really simple to setup this plugin; below is a sample pom that you may base --> false + + + false +