Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to take additional classpaths in plugin configuration #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import static java.nio.file.Files.readAllBytes;

public abstract class BaseVertxMojo extends AbstractMojo {

private Pattern CLASSPATH_DELIMITER = Pattern.compile(":");

@Component
protected MavenProject project;

Expand All @@ -60,6 +63,22 @@ public abstract class BaseVertxMojo extends AbstractMojo {
@Parameter
protected File configFile = null;

/**
* <p>
* The extra classpath for this verticle.
* </p>
* <p>
* If the path is relative (does not start with / or a drive letter like
* C:), the path is relative to the directory containing the POM.
* </p>
* <p>
* An example value would be src/main/resources/:src/test/resources/
* </p>
*/

@Parameter
protected String classpath = null;

/**
* The number of instances of the verticle to instantiate in the vert.x
* server. The default is 1.
Expand All @@ -73,6 +92,8 @@ public abstract class BaseVertxMojo extends AbstractMojo {
@Parameter(defaultValue = "target/mods")
protected File modsDir;



protected JsonObject getConf() {
JsonObject config = null;
final String confContent = readConfigFile(configFile);
Expand Down Expand Up @@ -106,6 +127,7 @@ protected ClassLoader createClassLoader() throws Exception {
List<URL> urls = new ArrayList<>();
addURLs(urls, "src/main/platform_lib");
addURLs(urls, "src/main/resources/platform_lib");
addClasspathResources(urls);

return new LoadFirstClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
}
Expand Down Expand Up @@ -134,6 +156,20 @@ private void addURLs(List<URL> urls, String dirName) throws IOException {
}
}

private void addClasspathResources(final List<URL> urls) throws IOException{
if(classpath != null){
String[] paths = CLASSPATH_DELIMITER.split(classpath);
if(paths != null){
for(String path: paths){
File dir = new File(path);
if(dir.exists()){
urls.add(dir.getCanonicalFile().toURI().toURL());
}
}
}
}
}

private static class LoadFirstClassLoader extends URLClassLoader {

private final ClassLoader parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public void execute() throws MojoExecutionException {
if (createFatJar) {
System.setProperty("vertx.mods", modsDir.getAbsolutePath());
final PlatformManager pm = factory.createPlatformManager();

final CountDownLatch latch = new CountDownLatch(1);
pm.makeFatJar(moduleName, "target",
pm.makeFatJar(moduleName, project.getBuild().getDirectory(),
new Handler<AsyncResult<Void>>() {
@Override
public void handle(final AsyncResult<Void> event) {
Expand Down