Skip to content

Commit ee43e57

Browse files
committed
only injects properties into every reactor project once
Enabling `injectAllReactorProjects` in large and old reactor projects allows to avoid repeatedly parsing the git history to retrieve the information. In the apache/james-project enabling this property allowed to lower the time spent in git-commit-id from 39s[1] to 2s[2]. However, looking at the verbose logs one can see that the plugin keeps injecting the properties into every reactor project for every project where the plugin runs. This commit aims to avoid reinjecting keys which have already been set in the context. [1] https://ge.apache.org/s/xumcl7ztpkmhw/timeline?collapse-all&outcome=success,failed&view=by-type [2] https://ge.apache.org/s/gpnevfknmdv5a/timeline?collapse-all&hide-timeline&outcome=success,failed&view=by-type
1 parent e7ec732 commit ee43e57

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,17 @@ public void error(String msg, Throwable t) {
12341234
commitIdPropertiesOutputFormat = CommitIdPropertiesOutputFormat.PROPERTIES;
12351235
}
12361236

1237+
Properties properties = null;
1238+
// check if properties have already been injected
1239+
Properties contextProperties = getContextProperties(project);
1240+
boolean alreadyInjected = injectAllReactorProjects && contextProperties != null;
1241+
if (alreadyInjected) {
1242+
log.info(
1243+
"injectAllReactorProjects is enabled - attempting to use the already computed values");
1244+
// makes sure the existing context properties are not mutated
1245+
properties = new Properties(contextProperties);
1246+
}
1247+
12371248
final GitCommitIdPlugin.Callback cb =
12381249
new GitCommitIdPlugin.Callback() {
12391250
@Override
@@ -1339,7 +1350,7 @@ public boolean shouldGenerateGitPropertiesFile() {
13391350

13401351
@Override
13411352
public void performPublishToAllSystemEnvironments(Properties properties) {
1342-
publishToAllSystemEnvironments(getLogInterface(), properties);
1353+
publishToAllSystemEnvironments(getLogInterface(), properties, contextProperties);
13431354
}
13441355

13451356
@Override
@@ -1393,29 +1404,27 @@ public boolean shouldPropertiesEscapeUnicode() {
13931404
}
13941405
};
13951406

1396-
Properties properties = null;
1397-
// check if properties have already been injected
1398-
Properties contextProperties = getContextProperties(project);
1399-
boolean alreadyInjected = injectAllReactorProjects && contextProperties != null;
1400-
if (alreadyInjected) {
1401-
log.info(
1402-
"injectAllReactorProjects is enabled - attempting to use the already computed values");
1403-
properties = contextProperties;
1404-
}
1405-
14061407
GitCommitIdPlugin.runPlugin(cb, properties);
14071408
} catch (GitCommitIdExecutionException e) {
14081409
throw new MojoExecutionException(e.getMessage(), e);
14091410
}
14101411
}
14111412

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

14171418
if (injectAllReactorProjects) {
1418-
appendPropertiesToReactorProjects(log, propertiesToPublish);
1419+
Properties diffPropertiesToPublish = new Properties();
1420+
propertiesToPublish.forEach((k, v) -> {
1421+
if (!contextProperties.contains(k)) {
1422+
diffPropertiesToPublish.setProperty(k.toString(), v.toString());
1423+
}
1424+
});
1425+
if(!diffPropertiesToPublish.isEmpty()) {
1426+
appendPropertiesToReactorProjects(log, diffPropertiesToPublish);
1427+
}
14191428
}
14201429

14211430
if (injectIntoSysProperties) {
@@ -1479,7 +1488,7 @@ private void publishPropertiesInto(Properties propertiesToPublish, Properties pr
14791488
private void appendPropertiesToReactorProjects(LogInterface log, Properties propertiesToPublish) {
14801489
for (MavenProject mavenProject : reactorProjects) {
14811490
log.debug("Adding properties to project: '" + mavenProject.getName() + "'");
1482-
1491+
if(mavenProject.equals(project)) continue;
14831492
publishPropertiesInto(propertiesToPublish, mavenProject.getProperties());
14841493
mavenProject.setContextValue(CONTEXT_KEY, propertiesToPublish);
14851494
}

0 commit comments

Comments
 (0)