Skip to content

Commit 15f9901

Browse files
author
TheSnoozer
committed
Merge remote-tracking branch 'origin/master' into 674
2 parents 339d132 + 77f800f commit 15f9901

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,17 @@ public void error(String msg, Throwable t) {
12431243
commitIdPropertiesOutputFormat = CommitIdPropertiesOutputFormat.PROPERTIES;
12441244
}
12451245

1246+
Properties properties = null;
1247+
// check if properties have already been injected
1248+
Properties contextProperties = getContextProperties(project);
1249+
boolean alreadyInjected = injectAllReactorProjects && contextProperties != null;
1250+
if (alreadyInjected) {
1251+
log.info(
1252+
"injectAllReactorProjects is enabled - attempting to use the already computed values");
1253+
// makes sure the existing context properties are not mutated
1254+
properties = new Properties(contextProperties);
1255+
}
1256+
12461257
final GitCommitIdPlugin.Callback cb =
12471258
new GitCommitIdPlugin.Callback() {
12481259
@Override
@@ -1348,7 +1359,7 @@ public boolean shouldGenerateGitPropertiesFile() {
13481359

13491360
@Override
13501361
public void performPublishToAllSystemEnvironments(Properties properties) {
1351-
publishToAllSystemEnvironments(getLogInterface(), properties);
1362+
publishToAllSystemEnvironments(getLogInterface(), properties, contextProperties);
13521363
}
13531364

13541365
@Override
@@ -1402,29 +1413,30 @@ public boolean shouldPropertiesEscapeUnicode() {
14021413
}
14031414
};
14041415

1405-
Properties properties = null;
1406-
// check if properties have already been injected
1407-
Properties contextProperties = getContextProperties(project);
1408-
boolean alreadyInjected = injectAllReactorProjects && contextProperties != null;
1409-
if (alreadyInjected) {
1410-
log.info(
1411-
"injectAllReactorProjects is enabled - attempting to use the already computed values");
1412-
properties = contextProperties;
1413-
}
1414-
14151416
GitCommitIdPlugin.runPlugin(cb, properties);
14161417
} catch (GitCommitIdExecutionException e) {
14171418
throw new MojoExecutionException(e.getMessage(), e);
14181419
}
14191420
}
14201421

1421-
private void publishToAllSystemEnvironments(LogInterface log, Properties propertiesToPublish) {
1422+
private void publishToAllSystemEnvironments(
1423+
LogInterface log,
1424+
Properties propertiesToPublish,
1425+
Properties contextProperties) {
14221426
publishPropertiesInto(propertiesToPublish, project.getProperties());
14231427
// some plugins rely on the user properties (e.g. flatten-maven-plugin)
14241428
publishPropertiesInto(propertiesToPublish, session.getUserProperties());
14251429

14261430
if (injectAllReactorProjects) {
1427-
appendPropertiesToReactorProjects(log, propertiesToPublish);
1431+
Properties diffPropertiesToPublish = new Properties();
1432+
propertiesToPublish.forEach((k, v) -> {
1433+
if (!contextProperties.contains(k)) {
1434+
diffPropertiesToPublish.setProperty(k.toString(), v.toString());
1435+
}
1436+
});
1437+
if (!diffPropertiesToPublish.isEmpty()) {
1438+
appendPropertiesToReactorProjects(log, diffPropertiesToPublish);
1439+
}
14281440
}
14291441

14301442
if (injectIntoSysProperties) {
@@ -1482,7 +1494,9 @@ private void publishPropertiesInto(Properties propertiesToPublish, Properties pr
14821494
private void appendPropertiesToReactorProjects(LogInterface log, Properties propertiesToPublish) {
14831495
for (MavenProject mavenProject : reactorProjects) {
14841496
log.debug("Adding properties to project: '" + mavenProject.getName() + "'");
1485-
1497+
if (mavenProject.equals(project)) {
1498+
continue;
1499+
}
14861500
publishPropertiesInto(propertiesToPublish, mavenProject.getProperties());
14871501
mavenProject.setContextValue(CONTEXT_KEY, propertiesToPublish);
14881502
}

0 commit comments

Comments
 (0)