Skip to content

Commit a30bd84

Browse files
committed
Switch develop to 3.4.1-SNAPSHOT and add thread safety features to config an initialise goals.
1 parent 8c89f2a commit a30bd84

File tree

13 files changed

+36
-20
lines changed

13 files changed

+36
-20
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.rudikershaw.gitbuildhook</groupId>
77
<artifactId>git-build-hook-maven-plugin</artifactId>
8-
<version>3.5.0-SNAPSHOT</version>
8+
<version>3.4.1-SNAPSHOT</version>
99
<packaging>maven-plugin</packaging>
1010

1111
<name>Git Build Hook Maven Plugin</name>

src/main/java/com/rudikershaw/gitbuildhook/GitConfigMojo.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.util.Map;
55

6+
import com.rudikershaw.gitbuildhook.threadsafety.ClassLock;
67
import org.apache.maven.plugin.MojoFailureException;
78
import org.apache.maven.plugins.annotations.LifecyclePhase;
89
import org.apache.maven.plugins.annotations.Mojo;
@@ -37,21 +38,23 @@ public void execute() throws MojoFailureException {
3738
if (repoBuilder.getGitDir().getAbsolutePath().contains(".git/worktrees/")) {
3839
getLog().warn(
3940
"The plugin appears to be running in a Git worktree. "
40-
+ "Worktree configuration is not currently supported. No configuration changes made."
41+
+ "No configuration changes made."
4142
);
4243
return;
4344
}
4445

45-
try (Git git = Git.open(repoBuilder.getGitDir())) {
46-
final StoredConfig config = git.getRepository().getConfig();
47-
for (final Map.Entry<String, String> entry : gitConfig.entrySet()) {
48-
final String[] conf = stringToConfigArray(entry.getKey());
49-
config.setString(conf[0], conf[1], conf[2], entry.getValue());
50-
getLog().info("Git config '" + entry.getKey() + "' set to - " + entry.getValue());
46+
synchronized (ClassLock.class) {
47+
try (Git git = Git.open(repoBuilder.getGitDir())) {
48+
final StoredConfig config = git.getRepository().getConfig();
49+
for (final Map.Entry<String, String> entry : gitConfig.entrySet()) {
50+
final String[] conf = stringToConfigArray(entry.getKey());
51+
config.setString(conf[0], conf[1], conf[2], entry.getValue());
52+
getLog().info("Git config '" + entry.getKey() + "' set to - " + entry.getValue());
53+
}
54+
config.save();
55+
} catch (final IOException ioe) {
56+
failBuildBecauseRepoCouldNotBeFound(ioe);
5157
}
52-
config.save();
53-
} catch (final IOException ioe) {
54-
failBuildBecauseRepoCouldNotBeFound(ioe);
5558
}
5659
}
5760

src/main/java/com/rudikershaw/gitbuildhook/InitialiseMojo.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.rudikershaw.gitbuildhook;
22

3+
import com.rudikershaw.gitbuildhook.threadsafety.ClassLock;
34
import org.apache.maven.plugin.AbstractMojo;
45
import org.apache.maven.plugin.MojoFailureException;
56
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -44,7 +45,9 @@ private boolean isGitRepoInitialised() {
4445
*/
4546
private void initialiseGitRepository() throws MojoFailureException {
4647
try {
47-
Git.init().setDirectory(project.getBasedir()).call();
48+
synchronized (ClassLock.class) {
49+
Git.init().setDirectory(project.getBasedir()).call();
50+
}
4851
} catch (final GitAPIException e) {
4952
if (!isGitRepoInitialised()) {
5053
throw new MojoFailureException("Could not initialise a local git repository.", e);

src/main/java/com/rudikershaw/gitbuildhook/InstallMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void installGitHook(final String hookName, final String filePath, final
7272
}
7373

7474
/**
75-
* Copies the specified file from the file system into the the default hooks directory.
75+
* Copies the specified file from the file system into the default hooks directory.
7676
*
7777
* @param filePath path to the file to use as the hook.
7878
* @param gitHookPathStr the location to move the file to.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.rudikershaw.gitbuildhook.threadsafety;
2+
3+
/**
4+
* Class to act as a universal lock for non-thread safe operations of the plugin.
5+
*/
6+
public class ClassLock {
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** Package containing classes for aiding in the thread safety of the plugin. */
2+
package com.rudikershaw.gitbuildhook.threadsafety;

src/test/resources/default-test-project/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<plugin>
1616
<groupId>com.rudikershaw.gitbuildhook</groupId>
1717
<artifactId>git-build-hook-maven-plugin</artifactId>
18-
<version>3.5.0-SNAPSHOT</version>
18+
<version>3.4.1-SNAPSHOT</version>
1919
</plugin>
2020
</plugins>
2121
</build>

src/test/resources/test-project-configure/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<plugin>
1616
<groupId>com.rudikershaw.gitbuildhook</groupId>
1717
<artifactId>git-build-hook-maven-plugin</artifactId>
18-
<version>3.5.0-SNAPSHOT</version>
18+
<version>3.4.1-SNAPSHOT</version>
1919
<configuration>
2020
<gitConfig>
2121
<core.hooksPath>hooks-path/</core.hooksPath>

src/test/resources/test-project-initialise/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<plugin>
1616
<groupId>com.rudikershaw.gitbuildhook</groupId>
1717
<artifactId>git-build-hook-maven-plugin</artifactId>
18-
<version>3.5.0-SNAPSHOT</version>
18+
<version>3.4.1-SNAPSHOT</version>
1919
<executions>
2020
<execution>
2121
<goals>

src/test/resources/test-project-install-hooks/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<plugin>
1616
<groupId>com.rudikershaw.gitbuildhook</groupId>
1717
<artifactId>git-build-hook-maven-plugin</artifactId>
18-
<version>3.5.0-SNAPSHOT</version>
18+
<version>3.4.1-SNAPSHOT</version>
1919
<configuration>
2020
<installHooks>
2121
<pre-commit>hook-to-install.sh</pre-commit>

src/test/resources/test-project-invalid-hook/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<plugin>
1616
<groupId>com.rudikershaw.gitbuildhook</groupId>
1717
<artifactId>git-build-hook-maven-plugin</artifactId>
18-
<version>3.5.0-SNAPSHOT</version>
18+
<version>3.4.1-SNAPSHOT</version>
1919
<configuration>
2020
<installHooks>
2121
<pre-commit-oops>hook-to-install.sh</pre-commit-oops>

src/test/resources/test-project-reinstall-hooks/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<plugin>
1616
<groupId>com.rudikershaw.gitbuildhook</groupId>
1717
<artifactId>git-build-hook-maven-plugin</artifactId>
18-
<version>3.5.0-SNAPSHOT</version>
18+
<version>3.4.1-SNAPSHOT</version>
1919
<configuration>
2020
<installHooks>
2121
<pre-commit>hook-to-install.sh</pre-commit>

src/test/resources/test-project-reinstall-hooks/pom2.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<plugin>
1616
<groupId>com.rudikershaw.gitbuildhook</groupId>
1717
<artifactId>git-build-hook-maven-plugin</artifactId>
18-
<version>3.5.0-SNAPSHOT</version>
18+
<version>3.4.1-SNAPSHOT</version>
1919
<configuration>
2020
<installHooks>
2121
<pre-commit>hook-to-reinstall.sh</pre-commit>

0 commit comments

Comments
 (0)