String path = file.getPath();
sourcePathElements.add(path);
}
}
} catch (Exception e) {
throw new InvalidPluginDescriptorException(
"Failed to get source files from " + srcRoot, e);
}
List<String> argsList = new ArrayList<String>();
argsList.add("-nocompile");
argsList.add("-cp");
StringBuilder cp = new StringBuilder();
//Add the compile classpath
List<String> compileClasspathElements;
try {
compileClasspathElements = project.getCompileClasspathElements();
} catch (DependencyResolutionRequiredException e) {
throw new InvalidPluginDescriptorException(
"Failed to get compileClasspathElements.", e);
}
for (String ccpe : compileClasspathElements) {
appendToPath(cp, ccpe);
}
//Add the current CL classptah
URL[] urls = ((URLClassLoader) getClass().getClassLoader()).getURLs();
for (URL url : urls) {
String path;
try {
path = url.getPath();
} catch (Exception e) {
throw new InvalidPluginDescriptorException(
"Failed to get classpath files from " + url, e);
}
appendToPath(cp, path);
}
String classpath = cp.toString();
debug("cl=" + classpath);
argsList.add(classpath);
argsList.addAll(sourcePathElements);
String[] args = argsList.toArray(new String[argsList.size()]);
List<MojoDescriptor> descriptors = new ArrayList<MojoDescriptor>();
MojoDescriptorTls.setDescriptors(descriptors);
try {
Main.process(new MojoApf(pluginDescriptor), new PrintWriter(System.out), args);
} catch (Throwable t) {
//TODO: [by yl] This is never caught - apt swallows the exception.
//Use the TLS to hold thrown exception
throw new InvalidPluginDescriptorException(
"Failed to extract plugin descriptor.", t);
}
return MojoDescriptorTls.getDescriptors();
}