Skip to content

Instantly share code, notes, and snippets.

@vietj
Created November 30, 2011 08:42
Show Gist options
  • Save vietj/1408448 to your computer and use it in GitHub Desktop.
Save vietj/1408448 to your computer and use it in GitHub Desktop.
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.log("Retrieved options " + options);
String sp = options.get("-sourcepath");
log.log("Found sourcepath " + sp);
if (sp != null)
{
// We take the first value
Spliterator split = new Spliterator(sp, ':');
if (split.hasNext())
{
File root = new File(split.next());
if (root.isDirectory())
{
sourcePath = new DiskFileSystem(root);
}
}
}
}
}
catch (Exception ignore)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment