Search in sources :

Example 1 with ModuleDescriptorReader

use of com.redhat.ceylon.common.ModuleDescriptorReader 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 ModuleDescriptorReader

use of com.redhat.ceylon.common.ModuleDescriptorReader 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 ModuleDescriptorReader

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

the class ModuleDescriptorReaderTest method testReadDescriptorA.

@Test
public void testReadDescriptorA() throws NoSuchModuleException {
    // We need this property because the ModuleDescriptorReader uses the Ceylon
    // Launcher+CeylonClassLoader that dynamically find and load the necessary
    // jar and car files. But when running from within Eclipse it doesn't know
    // where to look, so we need to give it a hint
    System.setProperty("ceylon.home", "../ceylon-dist/dist");
    ModuleDescriptorReader r = new ModuleDescriptorReader("com.redhat.ceylon.ant.modules.a", new File("test/src"));
    Assert.assertEquals("1.0", r.getModuleVersion());
    Assert.assertEquals("com.redhat.ceylon.ant.modules.a", r.getModuleName());
    Assert.assertEquals("http://example.com/license", r.getModuleLicense());
    List<String> authors = r.getModuleAuthors();
    Assert.assertEquals(2, authors.size());
    Assert.assertEquals("Tom", authors.get(0));
    Assert.assertEquals("and Tom", authors.get(1));
}
Also used : ModuleDescriptorReader(com.redhat.ceylon.common.ModuleDescriptorReader) File(java.io.File) Test(org.junit.Test)

Example 4 with ModuleDescriptorReader

use of com.redhat.ceylon.common.ModuleDescriptorReader 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

ModuleDescriptorReader (com.redhat.ceylon.common.ModuleDescriptorReader)4 NoSuchModuleException (com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException)3 ClassLoaderSetupException (com.redhat.ceylon.launcher.ClassLoaderSetupException)3 File (java.io.File)3 CeylonClassLoader (com.redhat.ceylon.launcher.CeylonClassLoader)2 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 Test (org.junit.Test)1