Search in sources :

Example 1 with DependencyDescriptor

use of org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor 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 2 with DependencyDescriptor

use of org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor 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 3 with DependencyDescriptor

use of org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor in project ceylon by eclipse.

the class AetherUtils method fetchDependencies.

private ArtifactResult fetchDependencies(RepositoryManager manager, CmrRepository repository, String groupId, String artifactId, String classifier, String version, boolean fetchSingleArtifact, String repositoryDisplayString) {
    Overrides overrides = repository.getRoot().getService(Overrides.class);
    ArtifactOverrides ao = null;
    log.debug("Overrides for " + canonicalForm(groupId, artifactId, classifier, version) + " in " + overrides.getSource());
    ArtifactContext context = getArtifactContext(groupId, artifactId, classifier, version);
    if (overrides != null) {
        ao = overrides.getArtifactOverrides(context);
        log.debug(ao != null ? "-> found overrides" : "-> no overrides");
    }
    // entire replacement
    ArtifactContext replacementContext = null;
    if (ao != null && ao.getReplace() != null) {
        replacementContext = ao.getReplace().getArtifactContext();
    } else if (overrides != null) {
        replacementContext = overrides.replace(context);
    }
    if (replacementContext != null) {
        log.debug(String.format("[Maven-Overrides] Replacing %s with %s.", context, replacementContext));
        // replace fetched dependency
        String[] nameToGroupArtifactIds = nameToGroupArtifactIds(replacementContext.getName());
        if (nameToGroupArtifactIds != null) {
            groupId = nameToGroupArtifactIds[0];
            artifactId = nameToGroupArtifactIds[1];
            classifier = nameToGroupArtifactIds[2];
            version = replacementContext.getVersion();
            // new AO
            context = getArtifactContext(groupId, artifactId, classifier, version);
            ao = overrides.getArtifactOverrides(context);
        }
    }
    // version replacement
    if (overrides != null && overrides.isVersionOverridden(context)) {
        version = overrides.getVersionOverride(context);
        context.setVersion(version);
    }
    if (ao != null && ao.hasVersion()) {
        version = ao.getVersion();
        context.setVersion(version);
        log.debug("Using version " + version);
    }
    // classifier replacement
    if (ao != null && ao.hasClassifier()) {
        classifier = ao.getClassifier();
        log.debug("Using classifier " + classifier);
    }
    final String name = MavenUtils.moduleName(groupId, artifactId, classifier);
    // only used for messages
    final String coordinates = canonicalForm(groupId, artifactId, classifier, version);
    try {
        DependencyDescriptor info = impl.getDependencies(groupId, artifactId, version, classifier, null, fetchSingleArtifact);
        if (info == null) {
            log.debug("No artifact found: " + coordinates);
            return null;
        }
        final SingleArtifactResult result;
        if (fetchSingleArtifact) {
            result = new SingleArtifactResult(repository, name, version, groupId, artifactId, classifier, info.getFile(), repositoryDisplayString);
        } else {
            final List<ArtifactResult> dependencies = new ArrayList<>();
            for (DependencyDescriptor dep : info.getDependencies()) {
                String dGroupId = dep.getGroupId();
                String dArtifactId = dep.getArtifactId();
                String dClassifier = dep.getClassifier();
                String dVersion = dep.getVersion();
                boolean export = false;
                boolean optional = dep.isOptional();
                boolean isCeylon = false;
                ModuleScope scope = toModuleScope(dep);
                ArtifactContext dContext = null;
                if (overrides != null)
                    dContext = getArtifactContext(dGroupId, dArtifactId, dClassifier, dVersion);
                if (overrides != null) {
                    if (overrides.isRemoved(dContext) || (ao != null && ao.isRemoved(dContext))) {
                        log.debug(String.format("[Maven-Overrides] Removing %s from %s.", dep, context));
                        // skip dependency
                        continue;
                    }
                    if (ao != null && ao.isAddedOrUpdated(dContext)) {
                        log.debug(String.format("[Maven-Overrides] Replacing %s from %s.", dep, context));
                        // skip dependency
                        continue;
                    }
                    ArtifactContext replace = overrides.replace(dContext);
                    if (replace != null) {
                        dContext = replace;
                        String[] groupArtifactIds = nameToGroupArtifactIds(replace.getName());
                        if (groupArtifactIds == null) {
                            isCeylon = true;
                        } else {
                            dGroupId = groupArtifactIds[0];
                            dArtifactId = groupArtifactIds[1];
                            dClassifier = groupArtifactIds[2];
                        }
                        dVersion = replace.getVersion();
                    }
                    if (ao != null) {
                        if (ao.isShareOverridden(dContext))
                            export = ao.isShared(dContext);
                        if (ao.isOptionalOverridden(dContext))
                            optional = ao.isOptional(dContext);
                    }
                }
                // do we have a version update?
                if (overrides != null && overrides.isVersionOverridden(dContext)) {
                    dVersion = overrides.getVersionOverride(dContext);
                }
                ArtifactResult dr;
                if (isCeylon)
                    dr = createArtifactResult(manager, dContext.getNamespace(), dContext.getName(), dVersion, export, optional, scope, repositoryDisplayString);
                else
                    dr = createArtifactResult(manager, repository, dGroupId, dArtifactId, dClassifier, dVersion, export, optional, scope, repositoryDisplayString, dep.getExclusions());
                dependencies.add(dr);
            }
            if (ao != null) {
                for (DependencyOverride addon : ao.getAdd()) {
                    ArtifactContext dContext = addon.getArtifactContext();
                    String dVersion = overrides.getVersionOverride(dContext);
                    dependencies.add(createArtifactResult(manager, repository, dContext, dVersion, addon.isShared(), addon.isOptional(), ModuleScope.COMPILE, repositoryDisplayString, null));
                    log.debug(String.format("[Maven-Overrides] Added %s to %s.", addon.getArtifactContext(), context));
                }
            }
            result = new AetherArtifactResult(repository, name, version, groupId, artifactId, classifier, info.getFile(), dependencies, repositoryDisplayString);
        }
        if (ao != null && ao.getFilter() != null) {
            result.setFilter(PathFilterParser.parse(ao.getFilter()));
        }
        return result;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } catch (AetherException e) {
        log.debug("Could not resolve artifact [" + coordinates + "] : " + e);
        return null;
    }
}
Also used : ArtifactOverrides(org.eclipse.ceylon.cmr.api.ArtifactOverrides) DependencyDescriptor(org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor) ArrayList(java.util.ArrayList) ModuleScope(org.eclipse.ceylon.model.cmr.ModuleScope) MavenArtifactContext(org.eclipse.ceylon.cmr.api.MavenArtifactContext) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) LazyArtifactResult(org.eclipse.ceylon.cmr.impl.LazyArtifactResult) AbstractArtifactResult(org.eclipse.ceylon.cmr.impl.AbstractArtifactResult) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ArtifactOverrides(org.eclipse.ceylon.cmr.api.ArtifactOverrides) Overrides(org.eclipse.ceylon.cmr.api.Overrides) DependencyOverride(org.eclipse.ceylon.cmr.api.DependencyOverride) AetherException(org.eclipse.ceylon.cmr.resolver.aether.AetherException)

Aggregations

DependencyDescriptor (org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor)3 HashSet (java.util.HashSet)2 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)2 ArtifactOverrides (org.eclipse.ceylon.cmr.api.ArtifactOverrides)2 DependencyOverride (org.eclipse.ceylon.cmr.api.DependencyOverride)2 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)2 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)1 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)1 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)1 Overrides (org.eclipse.ceylon.cmr.api.Overrides)1 AbstractArtifactResult (org.eclipse.ceylon.cmr.impl.AbstractArtifactResult)1 LazyArtifactResult (org.eclipse.ceylon.cmr.impl.LazyArtifactResult)1 AetherException (org.eclipse.ceylon.cmr.resolver.aether.AetherException)1 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)1 ModuleScope (org.eclipse.ceylon.model.cmr.ModuleScope)1