Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<artifactId>maven-core</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<version>0.0.7</version>
</dependency>
<!-- dependencies to annotations -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.sonatype.plexus.build.incremental.BuildContext;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -322,6 +324,12 @@ public class GitCommitIdMojo extends AbstractMojo {
*/
@Parameter(defaultValue = "30000")
long nativeGitTimeoutInMs;

/**
* Injected {@link BuildContext} to recognize incremental builds.
*/
@Component
private BuildContext buildContext;

/**
* The properties we store our data in and then expose them.
Expand All @@ -348,6 +356,14 @@ public void execute() throws MojoExecutionException {
// Set the verbose setting: now it should be correctly loaded from maven.
log.setVerbose(verbose);

// Skip mojo execution on incremental builds.
if (buildContext != null && buildContext.isIncremental()) {
// Except if properties file is missing at all
if (!generateGitPropertiesFile || craftPropertiesOutputFile(project.getBasedir(), generateGitPropertiesFilename).exists()) {
return;
}
}

// read source encoding from project properties for those who still doesn't use UTF-8
String sourceEncoding = project.getProperties().getProperty("project.build.sourceEncoding");
if (null != sourceEncoding) {
Expand Down Expand Up @@ -582,6 +598,11 @@ private void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, Fi
} catch (final IOException ex) {
throw new RuntimeException("Cannot create custom git properties file: " + gitPropsFile, ex);
}

if (buildContext != null) {
buildContext.refresh(gitPropsFile);
}

} else {
log.info("Properties file [{}] is up-to-date (for module {})...", gitPropsFile.getAbsolutePath(), project.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>false</runOnConfiguration>
</execute>
</action>
Expand Down