Skip to content

Commit

Permalink
Allows git hook to run maven with thread count option (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
reda-alaoui authored Feb 2, 2024
1 parent 9a116f2 commit 1732e8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions core/src/main/java/com/cosium/code/format/InstallHooksMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public class InstallHooksMojo extends AbstractMavenGitCodeFormatMojo {
@Parameter(property = "gcf.preCommitHookPipeline", defaultValue = "")
private String preCommitHookPipeline;

/**
* If present, this value will be passed to '-T, --threads Thread count, for instance 2.0C where C
* is core multiplied'
*/
@Parameter(property = "gcf.hookMavenThreadCount")
private String hookMavenThreadCount;

public void execute() throws MojoExecutionException {
if (!isExecutionRoot()) {
getLog().debug("Not in execution root. Do not execute.");
Expand Down Expand Up @@ -143,11 +150,14 @@ private String mavenCliArguments() {
.filter(prop -> System.getProperty(prop) != null)
.map(prop -> "-D" + prop + "=" + System.getProperty(prop));

Stream<String> properties = Stream.concat(propagatedProperties, Stream.of(propertiesToAdd));
Stream<String> arguments = Stream.concat(propagatedProperties, Stream.of(propertiesToAdd));
if (preCommitHookPipeline != null && !preCommitHookPipeline.isEmpty()) {
properties = Stream.concat(properties, Stream.of(preCommitHookPipeline));
arguments = Stream.concat(arguments, Stream.of(preCommitHookPipeline));
}
if (hookMavenThreadCount != null && !hookMavenThreadCount.isEmpty()) {
arguments = Stream.concat(arguments, Stream.of("-T " + hookMavenThreadCount));
}
return properties.collect(Collectors.joining(" "));
return arguments.collect(Collectors.joining(" "));
}

private Path prepareHooksDirectory() {
Expand Down
1 change: 1 addition & 0 deletions core/src/test/projects/non-root-module/module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</dependency>
</dependencies>
<configuration>
<hookMavenThreadCount>1C</hookMavenThreadCount>
<propertiesToAdd>
<prop>-X</prop>
</propertiesToAdd>
Expand Down

0 comments on commit 1732e8e

Please sign in to comment.