//
ClassLoader serviceCL = baseCL;
//
DiskFileSystem sourcePath = null;
try {
// As first attempt we tried to use the classpath since eclipse would copy the template to this location
// but that could a chicken egg problem as a template is coped in the classpath only if the compilation
// is successfull and sometimes a controller references a template literal that is generated from the
// template source
ClassLoader cl = env.getClass().getClassLoader();
Class eclipseImplClass = cl.loadClass("org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl");
if (eclipseImplClass.isInstance(env)) {
Method getJavaProject = eclipseImplClass.getMethod("getJavaProject");
Object javaProject = getJavaProject.invoke(env);
Class aptConfigClass = cl.loadClass("org.eclipse.jdt.apt.core.util.AptConfig");
Class javaProjectClass = cl.loadClass("org.eclipse.jdt.core.IJavaProject");
Method getProcessorOptionsMethod = aptConfigClass.getMethod("getProcessorOptions", javaProjectClass);
Map<String, String> options = (Map<String, String>)getProcessorOptionsMethod.invoke(null, javaProject);
log.info("Retrieved options " + options);
//
String sp = options.get("-sourcepath");
log.info("Found sourcepath " + sp);
if (sp != null) {
// We take the first value
Spliterator split = new Spliterator(sp, PATH_SEPARATOR_CHAR);
if (split.hasNext()) {
File root = new File(split.next());
if (root.isDirectory()) {
sourcePath = new DiskFileSystem(root);
}
}
}
// Building service class loader, this works better in eclipse specially with m2e and