use of org.eclipse.ceylon.launcher.ClassLoaderSetupException in project ceylon by eclipse.
the class SourceModules method getModules.
// TODO filters by module name, supported backends (transitive)
public Set<Module> getModules() {
if (this.dir == null) {
this.dir = getProject().resolveFile(Constants.DEFAULT_SOURCE_DIR);
}
FileSet fs = new FileSet();
fs.setDir(this.dir);
// TODO Handle default module
fs.setIncludes("**/" + Constants.MODULE_DESCRIPTOR);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] files = ds.getIncludedFiles();
log("<sourcemodules> found files " + Arrays.toString(files), Project.MSG_VERBOSE);
URI base = dir.toURI();
LinkedHashSet<Module> result = new LinkedHashSet<Module>();
try {
CeylonClassLoader loader = Util.getCeylonClassLoaderCachedInProject(getProject());
for (String file : files) {
URI uri = new File(this.dir, file).getParentFile().toURI();
log("<sourcemodules> file " + file + "=> uri " + uri, Project.MSG_VERBOSE);
String moduleName = base.relativize(uri).getPath().replace('/', '.');
if (moduleName.endsWith(".")) {
moduleName = moduleName.substring(0, moduleName.length() - 1);
}
log("<sourcemodules> file " + file + "=> moduleName " + moduleName, Project.MSG_VERBOSE);
Module mav = new Module();
mav.setName(moduleName);
String version;
try {
version = new ModuleDescriptorReader(loader, mav.getName(), dir).getModuleVersion();
} catch (NoSuchModuleException e) {
log("<sourcemodules> file " + file + "=> module cannot be read: " + moduleName, Project.MSG_VERBOSE);
// skip it
continue;
}
log("<sourcemodules> file " + file + "=> module " + moduleName + "/" + version, Project.MSG_VERBOSE);
mav.setVersion(version);
result.add(mav);
}
} catch (ClassLoaderSetupException x) {
log("failed to set up Ceylon classloader: could not load module set", Project.MSG_VERBOSE);
}
return result;
}
use of org.eclipse.ceylon.launcher.ClassLoaderSetupException in project ceylon by eclipse.
the class Util method getCeylonClassLoaderCachedInProject.
public static CeylonClassLoader getCeylonClassLoaderCachedInProject(final Project project) throws ClassLoaderSetupException {
Object classLoader = project.getReference(CEYLON_CLASSLOADER_REFERENCE);
if (classLoader != null) {
CeylonClassLoader oldLoader = (CeylonClassLoader) classLoader;
// make sure it's still valid
try {
List<File> classPath = CeylonClassLoader.getClassPath();
if (oldLoader.hasSignature(CeylonClassLoader.getClassPathSignature(classPath))) {
// compatible
return oldLoader;
} else {
project.log("Needs a new class loader: cp changed!", Project.MSG_VERBOSE);
CeylonClassLoader loader = CeylonClassLoader.newInstance(classPath);
project.addReference(CEYLON_CLASSLOADER_REFERENCE, loader);
return loader;
}
} catch (FileNotFoundException x) {
throw new ClassLoaderSetupException(x);
} catch (URISyntaxException x) {
throw new ClassLoaderSetupException(x);
} catch (MalformedURLException x) {
throw new ClassLoaderSetupException(x);
}
}
CeylonClassLoader loader = Launcher.getClassLoader();
project.addReference(CEYLON_CLASSLOADER_REFERENCE, loader);
// only add the build listed once, even if we change the class loader later
project.addBuildListener(new BuildListener() {
@Override
public void buildFinished(BuildEvent arg0) {
project.log("Build done, cleaning up Ceylon class loader", Project.MSG_VERBOSE);
// make sure we get the latest one
Object reference = project.getReference(CEYLON_CLASSLOADER_REFERENCE);
project.getReferences().remove(CEYLON_CLASSLOADER_REFERENCE);
if (reference instanceof CeylonClassLoader) {
try {
((CeylonClassLoader) reference).close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@Override
public void buildStarted(BuildEvent arg0) {
}
@Override
public void messageLogged(BuildEvent arg0) {
}
@Override
public void targetFinished(BuildEvent arg0) {
}
@Override
public void targetStarted(BuildEvent arg0) {
}
@Override
public void taskFinished(BuildEvent arg0) {
}
@Override
public void taskStarted(BuildEvent arg0) {
}
});
return loader;
}
use of org.eclipse.ceylon.launcher.ClassLoaderSetupException in project ceylon by eclipse.
the class LazyHelper method inferModule.
private Module inferModule(File file) {
if (file.exists()) {
for (File src : task.getSrc()) {
if (Util.isChildOfOrEquals(src, file)) {
while (!file.equals(src)) {
File moduleDescriptor = file.isDirectory() ? new File(file, Constants.MODULE_DESCRIPTOR) : file;
if (moduleDescriptor.exists() && moduleDescriptor.getName().equals(Constants.MODULE_DESCRIPTOR)) {
String moduleName = moduleDescriptor.getParentFile().getAbsolutePath().substring(src.getAbsolutePath().length() + 1).replace(File.separator, ".");
try {
ModuleDescriptorReader mdr = new ModuleDescriptorReader(task.getClassLoader(), moduleName, src);
return new Module(mdr.getModuleName(), mdr.getModuleVersion());
} catch (NoSuchModuleException e) {
continue;
} catch (ClassLoaderSetupException e) {
// not like we can try again
return null;
}
}
file = file.getParentFile();
}
}
}
}
return null;
}
use of org.eclipse.ceylon.launcher.ClassLoaderSetupException in project ceylon by eclipse.
the class CeylonModuleDescriptorTask method execute.
/**
* Executes the task.
* @exception BuildException if an error occurs
*/
@Override
public void execute() throws BuildException {
Java7Checker.check();
ModuleDescriptorReader reader;
try {
CeylonClassLoader loader = Util.getCeylonClassLoaderCachedInProject(getProject());
try {
reader = new ModuleDescriptorReader(loader, module.getName(), getSrc());
} catch (NoSuchModuleException e) {
throw new BuildException("Failed to load module", e);
}
} catch (ClassLoaderSetupException x) {
throw new BuildException("Failed to set up Ceylon class loader", x);
}
if (versionProperty != null) {
setProjectProperty(versionProperty, reader.getModuleVersion());
}
if (nameProperty != null) {
setProjectProperty(nameProperty, reader.getModuleName());
}
if (licenseProperty != null) {
setProjectProperty(licenseProperty, reader.getModuleLicense());
}
}
Aggregations