Search in sources :

Example 1 with NoSuchModuleException

use of com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException in project ceylon-compiler by ceylon.

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileSet(org.apache.tools.ant.types.FileSet) CeylonClassLoader(com.redhat.ceylon.launcher.CeylonClassLoader) ClassLoaderSetupException(com.redhat.ceylon.launcher.ClassLoaderSetupException) URI(java.net.URI) ModuleDescriptorReader(com.redhat.ceylon.common.ModuleDescriptorReader) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) NoSuchModuleException(com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException) File(java.io.File)

Example 2 with NoSuchModuleException

use of com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException in project ceylon-compiler by ceylon.

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());
    }
}
Also used : ModuleDescriptorReader(com.redhat.ceylon.common.ModuleDescriptorReader) CeylonClassLoader(com.redhat.ceylon.launcher.CeylonClassLoader) NoSuchModuleException(com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException) BuildException(org.apache.tools.ant.BuildException) ClassLoaderSetupException(com.redhat.ceylon.launcher.ClassLoaderSetupException)

Example 3 with NoSuchModuleException

use of com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException in project ceylon-compiler by ceylon.

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);
    }
}
Also used : NoSuchModuleException(com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException) VirtualFile(com.redhat.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 4 with NoSuchModuleException

use of com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException in project ceylon-compiler by ceylon.

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;
}
Also used : ModuleDescriptorReader(com.redhat.ceylon.common.ModuleDescriptorReader) NoSuchModuleException(com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException) ClassLoaderSetupException(com.redhat.ceylon.launcher.ClassLoaderSetupException) File(java.io.File)

Aggregations

NoSuchModuleException (com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException)4 ModuleDescriptorReader (com.redhat.ceylon.common.ModuleDescriptorReader)3 ClassLoaderSetupException (com.redhat.ceylon.launcher.ClassLoaderSetupException)3 File (java.io.File)3 CeylonClassLoader (com.redhat.ceylon.launcher.CeylonClassLoader)2 VirtualFile (com.redhat.ceylon.compiler.typechecker.io.VirtualFile)1 URI (java.net.URI)1 LinkedHashSet (java.util.LinkedHashSet)1 BuildException (org.apache.tools.ant.BuildException)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 FileSet (org.apache.tools.ant.types.FileSet)1