Search in sources :

Example 11 with ModuleDependencyInfo

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

the class AetherUtils method addSearchResult.

private void addSearchResult(String groupId, String artifactId, String version, ModuleVersionResult result, Overrides overrides, String repositoryDisplayString) throws AetherException {
    ArtifactOverrides artifactOverrides = null;
    String classifier = null;
    if (overrides != null) {
        ArtifactContext ctx = new ArtifactContext(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version);
        // see if this artifact is replaced
        ArtifactContext replaceContext = overrides.replace(ctx);
        if (replaceContext != null) {
            String[] groupArtifactIds = nameToGroupArtifactIds(replaceContext.getName());
            if (groupArtifactIds == null)
                // abort
                return;
            groupId = groupArtifactIds[0];
            artifactId = groupArtifactIds[1];
            classifier = groupArtifactIds[2];
            version = replaceContext.getVersion();
            ctx = replaceContext;
        } else if (overrides.isVersionOverridden(ctx)) {
            // perhaps its version is overridden?
            version = overrides.getVersionOverride(ctx);
            ctx.setVersion(version);
        }
        artifactOverrides = overrides.getArtifactOverrides(ctx);
    }
    DependencyDescriptor info = impl.getDependencies(groupId, artifactId, version, classifier, "pom", false);
    if (info != null) {
        StringBuilder description = new StringBuilder();
        StringBuilder licenseBuilder = new StringBuilder();
        collectInfo(info, description, licenseBuilder);
        Set<ModuleDependencyInfo> dependencies = new HashSet<>();
        Set<ModuleVersionArtifact> artifactTypes = new HashSet<>();
        artifactTypes.add(new ModuleVersionArtifact(".jar", null, null));
        Set<String> authors = new HashSet<>();
        for (DependencyDescriptor dep : info.getDependencies()) {
            String namespace = MavenRepository.NAMESPACE;
            String depName = MavenUtils.moduleName(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier());
            String depVersion = dep.getVersion();
            boolean export = false;
            boolean optional = dep.isOptional();
            if (overrides != null) {
                ArtifactContext depCtx = new ArtifactContext(namespace, depName, dep.getVersion());
                if (overrides.isRemoved(depCtx) || (artifactOverrides != null && (artifactOverrides.isRemoved(depCtx) || artifactOverrides.isAddedOrUpdated(depCtx))))
                    continue;
                ArtifactContext replaceCtx = overrides.replace(depCtx);
                if (replaceCtx != null) {
                    depCtx = replaceCtx;
                    namespace = replaceCtx.getNamespace();
                    depName = replaceCtx.getName();
                }
                if (overrides.isVersionOverridden(depCtx))
                    depVersion = overrides.getVersionOverride(depCtx);
                if (artifactOverrides != null) {
                    if (artifactOverrides.isShareOverridden(depCtx))
                        export = artifactOverrides.isShared(depCtx);
                    if (artifactOverrides.isOptionalOverridden(depCtx))
                        optional = artifactOverrides.isOptional(depCtx);
                }
            }
            ModuleDependencyInfo moduleDependencyInfo = new ModuleDependencyInfo(namespace, depName, depVersion, optional, export, Backends.JAVA, toModuleScope(dep));
            dependencies.add(moduleDependencyInfo);
        }
        if (artifactOverrides != null) {
            for (DependencyOverride add : artifactOverrides.getAdd()) {
                ArtifactContext ac = add.getArtifactContext();
                ModuleDependencyInfo moduleDependencyInfo = new ModuleDependencyInfo(ac.getNamespace(), ac.getName(), ac.getVersion(), add.isOptional(), add.isShared(), Backends.JAVA, ModuleScope.COMPILE);
                dependencies.add(moduleDependencyInfo);
            }
        }
        ModuleVersionDetails moduleVersionDetails = new ModuleVersionDetails(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version, groupId, artifactId, null, description.length() > 0 ? description.toString() : null, licenseBuilder.length() > 0 ? licenseBuilder.toString() : null, authors, dependencies, artifactTypes, true, repositoryDisplayString);
        result.addVersion(moduleVersionDetails);
    }
}
Also used : ArtifactOverrides(org.eclipse.ceylon.cmr.api.ArtifactOverrides) DependencyDescriptor(org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) MavenArtifactContext(org.eclipse.ceylon.cmr.api.MavenArtifactContext) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) DependencyOverride(org.eclipse.ceylon.cmr.api.DependencyOverride) HashSet(java.util.HashSet)

Example 12 with ModuleDependencyInfo

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

the class MavenDependencyResolver method toModuleInfo.

private static ModuleInfo toModuleInfo(DependencyDescriptor descriptor, String name, String version, Overrides overrides) {
    Set<ModuleDependencyInfo> infos = new HashSet<>();
    for (DependencyDescriptor dep : descriptor.getDependencies()) {
        String depName = MavenUtils.moduleName(dep.getGroupId(), dep.getArtifactId(), null);
        infos.add(new ModuleDependencyInfo(MavenRepository.NAMESPACE, depName, dep.getVersion(), dep.isOptional(), false, Backends.JAVA, AetherUtils.toModuleScope(dep)));
    }
    String descrName = MavenUtils.moduleName(descriptor.getGroupId(), descriptor.getArtifactId(), null);
    // if it's not the descriptor we wanted, let's not return it
    if (name != null && !name.equals(descrName))
        return null;
    if (version != null && !version.equals(descriptor.getVersion()))
        return null;
    ModuleInfo ret = new ModuleInfo(MavenRepository.NAMESPACE, descrName, descriptor.getVersion(), descriptor.getGroupId(), descriptor.getArtifactId(), null, null, infos);
    if (overrides != null)
        ret = overrides.applyOverrides(descrName, descriptor.getVersion(), ret);
    return ret;
}
Also used : DependencyDescriptor(org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) HashSet(java.util.HashSet)

Example 13 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo 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 14 with ModuleDependencyInfo

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

the class AetherTestCase method testListVersionsAether.

@Test
public void testListVersionsAether() throws Exception {
    CmrRepository repository = createAetherRepository();
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    ModuleVersionQuery lookup = new ModuleVersionQuery("com.sparkjava:spark-core", "1.", Type.JAR);
    ModuleVersionResult result = manager.completeVersions(lookup);
    Assert.assertEquals(3, result.getVersions().size());
    Assert.assertNotNull(result.getVersions().get("1.0"));
    Assert.assertNotNull(result.getVersions().get("1.1"));
    Assert.assertNotNull(result.getVersions().get("1.1.1"));
    for (ModuleVersionDetails res : result.getVersions().values()) {
        Assert.assertEquals("Spark\nA Sinatra inspired java web framework\nhttp://www.sparkjava.com", res.getDoc());
        Assert.assertEquals("The Apache Software License, Version 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0.txt", res.getLicense());
        NavigableSet<ModuleDependencyInfo> deps = res.getDependencies();
        List<ModuleDependencyInfo> compileDeps = new ArrayList<>(deps.size());
        for (ModuleDependencyInfo dep : res.getDependencies()) {
            if (dep.getModuleScope() == ModuleScope.COMPILE || dep.getModuleScope() == ModuleScope.PROVIDED)
                compileDeps.add(dep);
        }
        Assert.assertEquals(4, compileDeps.size());
    }
    lookup = new ModuleVersionQuery("com.sparkjava:spark-core", null, Type.JAR);
    result = manager.completeVersions(lookup);
    // Count the version up to 2.3
    int cnt = 0;
    for (ModuleVersionDetails mvd : result.getVersions().values()) {
        cnt++;
        if ("2.3".equals(mvd.getVersion())) {
            break;
        }
    }
    Assert.assertEquals(7, cnt);
    // now check that we only downloaded the POMs for that, and not the jars
    File repo = new File("build/test-classes/maven-settings/repository");
    File folder = new File(repo, "com/sparkjava/spark-core/1.0");
    Assert.assertTrue(new File(folder, "spark-core-1.0.pom").exists());
    Assert.assertFalse(new File(folder, "spark-core-1.0.jar").exists());
    Assert.assertFalse(new File(repo, "org/eclipse/jetty/jetty-server/9.0.2.v20130417/jetty-server-9.0.2.v20130417.jar").exists());
    // this one has a conflict if we do resolve it non-lazily
    lookup = new ModuleVersionQuery("org.hibernate:hibernate-validator", "3.", Type.JAR);
    result = manager.completeVersions(lookup);
    Assert.assertEquals(4, result.getVersions().size());
}
Also used : ModuleVersionResult(org.eclipse.ceylon.cmr.api.ModuleVersionResult) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ArrayList(java.util.ArrayList) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionQuery(org.eclipse.ceylon.cmr.api.ModuleVersionQuery) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) Test(org.junit.Test)

Example 15 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo 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)

Aggregations

ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)29 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)12 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)10 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)5 IOException (java.io.IOException)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)3 Backends (org.eclipse.ceylon.common.Backends)3 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 File (java.io.File)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 TreeSet (java.util.TreeSet)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 DependencyDescriptor (org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor)2 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)2