diff --git a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxFatJarMojo.java b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxFatJarMojo.java index 73f56b3..7d99fde 100644 --- a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxFatJarMojo.java +++ b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxFatJarMojo.java @@ -32,39 +32,43 @@ import static org.vertx.java.platform.PlatformLocator.factory; @Mojo(name = "fatJar", requiresProject = true, threadSafe = false, requiresDependencyResolution = - COMPILE_PLUS_RUNTIME) + COMPILE_PLUS_RUNTIME) public class VertxFatJarMojo extends BaseVertxMojo { - @Parameter(property = "vertx.createFatJar", defaultValue = "false") - protected Boolean createFatJar; + @Parameter(property = "vertx.createFatJar", defaultValue = "false") + protected Boolean createFatJar; - @Override - public void execute() throws MojoExecutionException { - try { - if (createFatJar) { - System.setProperty("vertx.mods", modsDir.getAbsolutePath()); - final PlatformManager pm = factory.createPlatformManager(); + private static final Object lock = new Object(); - final CountDownLatch latch = new CountDownLatch(1); - pm.makeFatJar(moduleName, project.getBasedir().getAbsolutePath() + "/target", - new Handler>() { - @Override - public void handle(final AsyncResult event) { - if (event.succeeded()) { - latch.countDown(); - } else { - if (!event.succeeded()) { - getLog().error(event.cause()); - } - latch.countDown(); - } - } - }); - latch.await(MAX_VALUE, MILLISECONDS); - } - } catch (final Exception e) { - throw new MojoExecutionException(e.getMessage()); - } - } + @Override + public void execute() throws MojoExecutionException { + synchronized (lock) { + try { + if (createFatJar) { + System.setProperty("vertx.mods", modsDir.getAbsolutePath()); + final PlatformManager pm = factory.createPlatformManager(); + + final CountDownLatch latch = new CountDownLatch(1); + pm.makeFatJar(moduleName, project.getBasedir().getAbsolutePath() + "/target", + new Handler>() { + @Override + public void handle(final AsyncResult event) { + if (event.succeeded()) { + latch.countDown(); + } else { + if (!event.succeeded()) { + getLog().error(event.cause()); + } + latch.countDown(); + } + } + }); + latch.await(MAX_VALUE, MILLISECONDS); + } + } catch (final Exception e) { + throw new MojoExecutionException(e.getMessage()); + } + } + } } diff --git a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxInitMojo.java b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxInitMojo.java index 87e622a..be81ae6 100644 --- a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxInitMojo.java +++ b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxInitMojo.java @@ -38,39 +38,42 @@ @Mojo(name = "init", requiresProject = true, threadSafe = false, requiresDependencyResolution = COMPILE_PLUS_RUNTIME) public class VertxInitMojo extends BaseVertxMojo { - @Override - public void execute() throws MojoExecutionException { + private static final Object lock = new Object(); - try { - setVertxMods(); + @Override + public void execute() throws MojoExecutionException { + synchronized (lock) { + try { + setVertxMods(); - File cpFile = new File("vertx_classpath.txt"); - if (!cpFile.exists()) { - cpFile.createNewFile(); - String defaultCp = "src/main/resources\r\n" + - "target/classes\r\n" + - "target/dependencies\r\n" + - "bin\r\n"; - try (FileWriter writer = new FileWriter(cpFile)) { - writer.write(defaultCp); - } - } + File cpFile = new File("vertx_classpath.txt"); + if (!cpFile.exists()) { + cpFile.createNewFile(); + String defaultCp = "src/main/resources\r\n" + + "target/classes\r\n" + + "target/dependencies\r\n" + + "bin\r\n"; + try (FileWriter writer = new FileWriter(cpFile)) { + writer.write(defaultCp); + } + } - final PlatformManager pm = factory.createPlatformManager(); + final PlatformManager pm = factory.createPlatformManager(); - final CountDownLatch latch = new CountDownLatch(1); - pm.createModuleLink(moduleName, new Handler>() { - @Override - public void handle(AsyncResult asyncResult) { - if (!asyncResult.succeeded()) { - getLog().info(asyncResult.cause().getMessage()); - } - latch.countDown(); - } - }); - latch.await(MAX_VALUE, MILLISECONDS); - } catch (final Exception e) { - throw new MojoExecutionException(e.getMessage(), e); - } - } + final CountDownLatch latch = new CountDownLatch(1); + pm.createModuleLink(moduleName, new Handler>() { + @Override + public void handle(AsyncResult asyncResult) { + if (!asyncResult.succeeded()) { + getLog().info(asyncResult.cause().getMessage()); + } + latch.countDown(); + } + }); + latch.await(MAX_VALUE, MILLISECONDS); + } catch (final Exception e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } + } } diff --git a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxPullInDepsMojo.java b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxPullInDepsMojo.java index b7c73f6..c8a1815 100644 --- a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxPullInDepsMojo.java +++ b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxPullInDepsMojo.java @@ -15,39 +15,43 @@ import static org.vertx.java.platform.PlatformLocator.factory; @Mojo(name = "pullInDeps", requiresProject = true, threadSafe = false, requiresDependencyResolution = - COMPILE_PLUS_RUNTIME) + COMPILE_PLUS_RUNTIME) public class VertxPullInDepsMojo extends BaseVertxMojo { - @Parameter(property = "vertx.pullInDeps", defaultValue = "false") - protected Boolean pullInDeps; - - @Override - public void execute() throws MojoExecutionException { - if (pullInDeps) { - ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader(); - try { - setVertxMods(); - Thread.currentThread().setContextClassLoader(createClassLoader()); - PlatformManager pm = factory.createPlatformManager(); - - final CountDownLatch latch = new CountDownLatch(1); - pm.pullInDependencies(moduleName, - new Handler>() { - @Override - public void handle(final AsyncResult event) { - if (!event.succeeded()) { - getLog().error(event.cause()); - } - latch.countDown(); - } - }); - latch.await(MAX_VALUE, MILLISECONDS); - - } catch (final Exception e) { - throw new MojoExecutionException(e.getMessage()); - } finally { - Thread.currentThread().setContextClassLoader(oldTCCL); - } - } - } + private static final Object lock = new Object(); + + @Parameter(property = "vertx.pullInDeps", defaultValue = "false") + protected Boolean pullInDeps; + + @Override + public void execute() throws MojoExecutionException { + synchronized (lock) { + if (pullInDeps) { + ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader(); + try { + setVertxMods(); + Thread.currentThread().setContextClassLoader(createClassLoader()); + PlatformManager pm = factory.createPlatformManager(); + + final CountDownLatch latch = new CountDownLatch(1); + pm.pullInDependencies(moduleName, + new Handler>() { + @Override + public void handle(final AsyncResult event) { + if (!event.succeeded()) { + getLog().error(event.cause()); + } + latch.countDown(); + } + }); + latch.await(MAX_VALUE, MILLISECONDS); + + } catch (final Exception e) { + throw new MojoExecutionException(e.getMessage()); + } finally { + Thread.currentThread().setContextClassLoader(oldTCCL); + } + } + } + } } diff --git a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxRunModMojo.java b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxRunModMojo.java index 5b8747e..3300f00 100644 --- a/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxRunModMojo.java +++ b/plugin/src/main/java/org/vertx/maven/plugin/mojo/VertxRunModMojo.java @@ -2,10 +2,13 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.vertx.java.core.AsyncResult; import org.vertx.java.core.Handler; import org.vertx.java.platform.PlatformManager; +import java.util.Collections; +import java.util.Map; import java.util.concurrent.CountDownLatch; import static java.lang.Long.MAX_VALUE; @@ -36,11 +39,21 @@ @Mojo(name = "runMod", requiresProject = true, threadSafe = false, requiresDependencyResolution = COMPILE_PLUS_RUNTIME) public class VertxRunModMojo extends BaseVertxMojo { + /** + * List of system properties to set when running a module. + */ + @Parameter + protected Map systemPropertyVariables = Collections.emptyMap(); + @Override public void execute() throws MojoExecutionException { ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader(); try { + for (final Map.Entry entry : systemPropertyVariables.entrySet()) { + System.setProperty(entry.getKey(), entry.getValue()); + } + setVertxMods(); Thread.currentThread().setContextClassLoader(createClassLoader());