use of com.sun.tools.javac.file.JavacFileManager in project ceylon-compiler by ceylon.
the class CeylonDocToolTests method compileJavaModule.
private void compileJavaModule(String pathname, String... fileNames) throws Exception {
CeyloncTool compiler = new CeyloncTool();
List<String> options = Arrays.asList("-src", pathname, "-out", "build/ceylon-cars", "-cp", CompilerTests.getClassPathAsPath());
JavacFileManager fileManager = compiler.getStandardFileManager(null, null, null);
List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
for (String name : fileNames) {
qualifiedNames.add(pathname + File.separator + name);
}
Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
JavacTask task = compiler.getTask(null, null, null, options, null, fileObjects);
Boolean ret = task.call();
Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
}
use of com.sun.tools.javac.file.JavacFileManager in project ceylon-compiler by ceylon.
the class T7021650 method run.
/**
* Perform a compilation with custom factories registered in the context,
* and verify that corresponding objects are created in each round.
*/
void run() throws Exception {
Counter demoCounter = new Counter();
Counter myAttrCounter = new Counter();
Context context = new Context();
// Use a custom file manager which creates classloaders for annotation
// processors with a sensible delegation parent, so that all instances
// of test classes come from the same class loader. This is important
// because the test performs class checks on the instances of classes
// found in the context for each round or processing.
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
public JavaFileManager make(Context c) {
return new JavacFileManager(c, true, null) {
@Override
protected ClassLoader getClassLoader(URL[] urls) {
return new URLClassLoader(urls, T7021650.class.getClassLoader());
}
};
}
});
Demo.preRegister(context, demoCounter);
MyAttr.preRegister(context, myAttrCounter);
String[] args = { "-d", ".", "-processor", T7021650.class.getName(), "-XprintRounds", new File(testSrc, T7021650.class.getName() + ".java").getPath() };
compile(context, args);
// Expect to create Demo for initial round, then MAX_ROUNDS in which
// GenX files are generated, then standard final round of processing.
checkEqual("demoCounter", demoCounter.count, MAX_ROUNDS + 2);
// Expect to create MyAttr for same processing rounds as for Demo,
// plus additional context for final compilation.
checkEqual("myAttrCounter", myAttrCounter.count, MAX_ROUNDS + 3);
}
use of com.sun.tools.javac.file.JavacFileManager in project ceylon-compiler by ceylon.
the class LanguageCompiler method findModuleDescriptorForFile.
private JavaFileObject findModuleDescriptorForFile(File file) {
JavacFileManager dfm = (JavacFileManager) fileManager;
File dir = file.getParentFile();
while (dir != null) {
try {
String name = dir.getPath() + "/module";
JavaFileObject fo = dfm.getJavaFileForInput(StandardLocation.SOURCE_PATH, name, Kind.SOURCE);
if (fo != null) {
return fo;
}
} catch (IOException e) {
// Ignore
}
dir = dir.getParentFile();
}
return null;
}
use of com.sun.tools.javac.file.JavacFileManager in project ceylon-compiler by ceylon.
the class LanguageCompiler method isResource.
private boolean isResource(JavaFileObject fo) {
// make sure we get a proper normalized abslute path
String fileName = FileUtil.absoluteFile(new File(fo.toUri().getPath())).getPath();
// now see if it's in any of the resource paths
JavacFileManager dfm = (JavacFileManager) fileManager;
for (File dir : dfm.getLocation(CeylonLocation.RESOURCE_PATH)) {
String prefix = FileUtil.absoluteFile(dir).getPath();
if (fileName.startsWith(prefix)) {
return true;
}
}
return false;
}
use of com.sun.tools.javac.file.JavacFileManager in project ceylon-compiler by ceylon.
the class LanguageCompiler method addModuleDescriptors.
// This is a bit of a hack, but if we got passed a list of resources
// without any accompaning source files we'll not be able to determine
// the module to which the resource files belong. So to try to fix that
// we see if a module file exists in the source folders and add it to
// the list of source files
private List<JavaFileObject> addModuleDescriptors(List<JavaFileObject> sourceFiles, List<JavaFileObject> resourceFiles) {
List<JavaFileObject> result = sourceFiles;
JavacFileManager dfm = (JavacFileManager) fileManager;
for (JavaFileObject fo : resourceFiles) {
String resName = JarUtils.toPlatformIndependentPath(dfm.getLocation(CeylonLocation.RESOURCE_PATH), fo.getName());
JavaFileObject moduleFile = findModuleDescriptorForFile(new File(resName));
if (moduleFile != null && !result.contains(moduleFile)) {
result = result.append(moduleFile);
}
}
return result;
}
Aggregations