use of org.eclipse.ceylon.common.ModuleDescriptorReader.NoSuchModuleException 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.common.ModuleDescriptorReader.NoSuchModuleException 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.common.ModuleDescriptorReader.NoSuchModuleException in project ceylon by eclipse.
the class ModuleDescriptorReader method visitModule.
private void visitModule(VFS vfs, PhasedUnits pus, List<String> name, File srcDir, VirtualFile virtualSourceDirectory, ModuleSourceMapper moduleSourceMapper) throws NoSuchModuleException {
for (String part : name) {
File child = new File(srcDir, part);
if (child.exists() && child.isDirectory()) {
moduleSourceMapper.push(part);
srcDir = child;
} else {
throw new NoSuchModuleException("Failed to find module name part " + part + " of " + name + " in " + srcDir);
}
}
File moduleFile = new File(srcDir, ModuleManager.MODULE_FILE);
if (moduleFile.exists()) {
moduleSourceMapper.visitModuleFile();
pus.parseUnit(vfs.getFromFile(moduleFile), virtualSourceDirectory);
} else {
throw new NoSuchModuleException("No module file in " + srcDir);
}
}
use of org.eclipse.ceylon.common.ModuleDescriptorReader.NoSuchModuleException 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