Search in sources :

Example 6 with ModuleInfo

use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.

the class MavenUtils method getDependencies.

public static ModuleInfo getDependencies(InputStream stream, String name, String version) throws IOException {
    Document doc;
    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(stream);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    }
    doc.getDocumentElement().normalize();
    Element root = doc.getDocumentElement();
    String modGroupId = getText(root, "groupId");
    // can be null, inherited from parent
    if (modGroupId == null) {
        Element parent = getFirstElement(root, "parent");
        if (parent != null)
            modGroupId = getText(parent, "groupId");
    }
    String modArtifactId = getText(root, "artifactId");
    String classifier = getText(root, "classifier");
    String modVersion = getText(root, "version");
    // can be null, inherited from parent
    if (modVersion == null) {
        Element parent = getFirstElement(root, "parent");
        if (parent != null)
            modVersion = getText(parent, "version");
    }
    String modName = modGroupId + ":" + modArtifactId;
    if (name != null && !name.equals(modName))
        return null;
    if (version != null && !version.equals(modVersion))
        return null;
    Element deps = getFirstElement(root, "dependencies");
    Set<ModuleDependencyInfo> ret = new HashSet<>();
    if (deps != null) {
        NodeList depList = deps.getElementsByTagName("dependency");
        if (depList != null) {
            for (int i = 0; i < depList.getLength(); i++) {
                Element dep = (Element) depList.item(i);
                String depGroupId = getText(dep, "groupId");
                String depArtifactId = getText(dep, "artifactId");
                String depClassifier = getText(dep, "classifier");
                String depVersion = getText(dep, "version");
                String depScope = getText(dep, "scope");
                String depOptional = getText(dep, "optional");
                ModuleScope scope;
                // keep compile, runtime, provided
                if (depScope != null && (depScope.equals("system") || depScope.equals("test")))
                    continue;
                if ("provided".equals(depScope))
                    scope = ModuleScope.PROVIDED;
                else if ("runtime".equals(depScope))
                    scope = ModuleScope.RUNTIME;
                else
                    scope = ModuleScope.COMPILE;
                ret.add(new ModuleDependencyInfo(MavenRepository.NAMESPACE, moduleName(depGroupId, depArtifactId, depClassifier), depVersion, "true".equals(depOptional), false, Backends.JAVA, scope));
            }
        }
    }
    return new ModuleInfo(MavenRepository.NAMESPACE, modName, modVersion, modGroupId, modArtifactId, classifier, null, ret);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ModuleScope(org.eclipse.ceylon.model.cmr.ModuleScope) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet)

Example 7 with ModuleInfo

use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.

the class ResolverTestCase method testMavenDependecyResolver.

@Test
public void testMavenDependecyResolver() throws Exception {
    final MavenDependencyResolver resolver = new MavenDependencyResolver();
    doTest(new Tester() {

        public void run(CmrRepository repository, final File artifact) {
            ModuleInfo infos = resolver.resolve(new TestArtifactResult(repository, "org.apache.camel:camel-core", "2.9.2", artifact), null);
            Assert.assertNotNull(infos);
            Assert.assertEquals(String.valueOf(infos), 3, infos.getDependencies().size());
        }
    });
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) MavenDependencyResolver(org.eclipse.ceylon.cmr.maven.MavenDependencyResolver) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) Test(org.junit.Test)

Example 8 with ModuleInfo

use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.

the class NpmUtils method getModuleInfo.

private ModuleInfo getModuleInfo(Object obj, String moduleName, String version, Overrides overrides) {
    if (obj == null) {
        return new ModuleInfo(NpmRepository.NAMESPACE, moduleName, version, null, null, null, null, NO_DEPS);
    }
    if (!(obj instanceof Map)) {
        throw new RuntimeException("Expected an Object");
    }
    @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj;
    Set<ModuleDependencyInfo> deps = new HashSet<ModuleDependencyInfo>();
    for (String depName : map.keySet()) {
        String depVersion = asString(map.get(depName));
        deps.add(new ModuleDependencyInfo(NpmRepository.NAMESPACE, depName, depVersion, false, false, Backends.JS));
    }
    ModuleInfo result = new ModuleInfo(NpmRepository.NAMESPACE, moduleName, version, null, null, null, null, deps);
    if (overrides != null)
        result = overrides.applyOverrides(moduleName, version, result);
    return result;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with ModuleInfo

use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.

the class JarUtils method getDependencies.

private static ModuleInfo getDependencies(File moduleArchive, String name, String version, Overrides overrides) {
    // FIXME: also look inside the dependencies for descriptors
    File xml = new File(moduleArchive.getParentFile(), "module.xml");
    ModuleInfo result = getDependenciesFromFile(xml, name, version, overrides);
    if (result != null) {
        return result;
    }
    File props = new File(moduleArchive.getParentFile(), "module.properties");
    return getDependenciesFromFile(props, name, version, overrides);
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 10 with ModuleInfo

use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.

the class PropertiesDependencyResolver method resolveFromInputStream.

@Override
public ModuleInfo resolveFromInputStream(InputStream stream, String moduleName, String moduleVersion, Overrides overrides) {
    try {
        final Properties properties = new Properties();
        properties.load(stream);
        Set<ModuleDependencyInfo> infos = new LinkedHashSet<>();
        for (Map.Entry<?, ?> entry : properties.entrySet()) {
            String depUri = entry.getKey().toString();
            String version = entry.getValue().toString();
            boolean optional = false;
            boolean shared = false;
            if (depUri.startsWith("+")) {
                depUri = depUri.substring(1);
                shared = true;
            }
            if (depUri.endsWith("?")) {
                depUri = depUri.substring(0, depUri.length() - 1);
                optional = true;
            }
            String namespace = ModuleUtil.getNamespaceFromUri(depUri);
            String modName = ModuleUtil.getModuleNameFromUri(depUri);
            infos.add(new ModuleDependencyInfo(namespace, modName, version, optional, shared, Backends.JAVA));
        }
        ModuleInfo ret = new ModuleInfo(null, moduleName, moduleVersion, // FIXME: store this
        ModuleUtil.getMavenGroupIdIfMavenModule(moduleName), ModuleUtil.getMavenArtifactIdIfMavenModule(moduleName), ModuleUtil.getMavenClassifierIfMavenModule(moduleName), null, infos);
        if (overrides != null)
            ret = overrides.applyOverrides(moduleName, moduleVersion, ret);
        return ret;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Properties(java.util.Properties) Map(java.util.Map)

Aggregations

ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)20 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)12 HashSet (java.util.HashSet)9 File (java.io.File)4 IOException (java.io.IOException)3 Map (java.util.Map)3 ZipEntry (java.util.zip.ZipEntry)3 ZipFile (java.util.zip.ZipFile)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 JarFile (java.util.jar.JarFile)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)2 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)2 MavenDependencyResolver (org.eclipse.ceylon.cmr.maven.MavenDependencyResolver)2 Backends (org.eclipse.ceylon.common.Backends)2 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)2 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)2 Test (org.junit.Test)2