Skip to content
Merged
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
37 changes: 23 additions & 14 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,17 @@ public void error(String msg, Throwable t) {
commitIdPropertiesOutputFormat = CommitIdPropertiesOutputFormat.PROPERTIES;
}

Properties properties = null;
// check if properties have already been injected
Properties contextProperties = getContextProperties(project);
boolean alreadyInjected = injectAllReactorProjects && contextProperties != null;
if (alreadyInjected) {
log.info(
"injectAllReactorProjects is enabled - attempting to use the already computed values");
// makes sure the existing context properties are not mutated
properties = new Properties(contextProperties);
}

final GitCommitIdPlugin.Callback cb =
new GitCommitIdPlugin.Callback() {
@Override
Expand Down Expand Up @@ -1339,7 +1350,7 @@ public boolean shouldGenerateGitPropertiesFile() {

@Override
public void performPublishToAllSystemEnvironments(Properties properties) {
publishToAllSystemEnvironments(getLogInterface(), properties);
publishToAllSystemEnvironments(getLogInterface(), properties, contextProperties);
}

@Override
Expand Down Expand Up @@ -1393,29 +1404,27 @@ public boolean shouldPropertiesEscapeUnicode() {
}
};

Properties properties = null;
// check if properties have already been injected
Properties contextProperties = getContextProperties(project);
boolean alreadyInjected = injectAllReactorProjects && contextProperties != null;
if (alreadyInjected) {
log.info(
"injectAllReactorProjects is enabled - attempting to use the already computed values");
properties = contextProperties;
}

GitCommitIdPlugin.runPlugin(cb, properties);
} catch (GitCommitIdExecutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}

private void publishToAllSystemEnvironments(LogInterface log, Properties propertiesToPublish) {
private void publishToAllSystemEnvironments(LogInterface log, Properties propertiesToPublish, Properties contextProperties) {
publishPropertiesInto(propertiesToPublish, project.getProperties());
// some plugins rely on the user properties (e.g. flatten-maven-plugin)
publishPropertiesInto(propertiesToPublish, session.getUserProperties());

if (injectAllReactorProjects) {
appendPropertiesToReactorProjects(log, propertiesToPublish);
Properties diffPropertiesToPublish = new Properties();
propertiesToPublish.forEach((k, v) -> {
if (!contextProperties.contains(k)) {
diffPropertiesToPublish.setProperty(k.toString(), v.toString());
}
});
if(!diffPropertiesToPublish.isEmpty()) {
appendPropertiesToReactorProjects(log, diffPropertiesToPublish);
}
}

if (injectIntoSysProperties) {
Expand Down Expand Up @@ -1479,7 +1488,7 @@ private void publishPropertiesInto(Properties propertiesToPublish, Properties pr
private void appendPropertiesToReactorProjects(LogInterface log, Properties propertiesToPublish) {
for (MavenProject mavenProject : reactorProjects) {
log.debug("Adding properties to project: '" + mavenProject.getName() + "'");

if(mavenProject.equals(project)) continue;
publishPropertiesInto(propertiesToPublish, mavenProject.getProperties());
mavenProject.setContextValue(CONTEXT_KEY, propertiesToPublish);
}
Expand Down