You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2021/08/26 10:10:12 UTC
[camel] 02/02: Provide a lock to support concurrent generation
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 91bf5351b0e293b18a610db4f904c957bd16a2f7
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Aug 26 12:09:36 2021 +0200
Provide a lock to support concurrent generation
---
.../org/apache/camel/maven/packaging/ComponentDslMojo.java | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java
index d6cab7e..28491c7 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java
@@ -28,6 +28,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -100,6 +103,8 @@ public class ComponentDslMojo extends AbstractGeneratorMojo {
DynamicClassLoader projectClassLoader;
+ private static final Map<Path, Lock> locks = new ConcurrentHashMap<>();
+
@Override
public void execute(MavenProject project, MavenProjectHelper projectHelper, BuildContext buildContext)
throws MojoFailureException, MojoExecutionException {
@@ -145,7 +150,13 @@ public class ComponentDslMojo extends AbstractGeneratorMojo {
throw new RuntimeException(e.getMessage(), e);
}
- executeComponent(files);
+ Lock lock = locks.computeIfAbsent(root, d -> new ReentrantLock());
+ lock.lock();
+ try {
+ executeComponent(files);
+ } finally {
+ lock.unlock();
+ }
}
private void executeComponent(Map<File, Supplier<String>> jsonFiles) throws MojoExecutionException, MojoFailureException {