Search in sources :

Example 1 with ClassLoaderSetupException

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

Example 2 with ClassLoaderSetupException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) CeylonClassLoader(org.eclipse.ceylon.launcher.CeylonClassLoader) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ClassLoaderSetupException(org.eclipse.ceylon.launcher.ClassLoaderSetupException) BuildListener(org.apache.tools.ant.BuildListener) BuildEvent(org.apache.tools.ant.BuildEvent) File(java.io.File)

Example 3 with ClassLoaderSetupException

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

Example 4 with ClassLoaderSetupException

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

Aggregations

ClassLoaderSetupException (org.eclipse.ceylon.launcher.ClassLoaderSetupException)4 File (java.io.File)3 ModuleDescriptorReader (org.eclipse.ceylon.common.ModuleDescriptorReader)3 NoSuchModuleException (org.eclipse.ceylon.common.ModuleDescriptorReader.NoSuchModuleException)3 CeylonClassLoader (org.eclipse.ceylon.launcher.CeylonClassLoader)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashSet (java.util.LinkedHashSet)1 BuildEvent (org.apache.tools.ant.BuildEvent)1 BuildException (org.apache.tools.ant.BuildException)1 BuildListener (org.apache.tools.ant.BuildListener)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 FileSet (org.apache.tools.ant.types.FileSet)1