Search in sources :

Example 6 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class IvyArtifactReport method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    if (tofile == null) {
        throw new BuildException("no destination file name: please provide it through parameter 'tofile'");
    }
    pattern = getProperty(pattern, getSettings(), "ivy.retrieve.pattern");
    try {
        String[] confs = splitToArray(getConf());
        ModuleDescriptor md = null;
        if (getResolveId() == null) {
            md = getResolvedDescriptor(getOrganisation(), getModule(), false);
        } else {
            md = getResolvedDescriptor(getResolveId());
        }
        IvyNode[] dependencies = getIvyInstance().getResolveEngine().getDependencies(md, ((ResolveOptions) new ResolveOptions().setLog(getLog())).setConfs(confs).setResolveId(getResolveId()).setValidate(doValidate(getSettings())), null);
        Map<ArtifactDownloadReport, Set<String>> artifactsToCopy = getIvyInstance().getRetrieveEngine().determineArtifactsToCopy(ModuleRevisionId.newInstance(getOrganisation(), getModule(), getRevision()), pattern, ((RetrieveOptions) new RetrieveOptions().setLog(getLog())).setConfs(confs).setResolveId(getResolveId()));
        Map<ModuleRevisionId, Set<ArtifactDownloadReport>> moduleRevToArtifactsMap = new HashMap<>();
        for (ArtifactDownloadReport artifact : artifactsToCopy.keySet()) {
            Set<ArtifactDownloadReport> moduleRevArtifacts = moduleRevToArtifactsMap.get(artifact.getArtifact().getModuleRevisionId());
            if (moduleRevArtifacts == null) {
                moduleRevArtifacts = new HashSet<>();
                moduleRevToArtifactsMap.put(artifact.getArtifact().getModuleRevisionId(), moduleRevArtifacts);
            }
            moduleRevArtifacts.add(artifact);
        }
        generateXml(dependencies, moduleRevToArtifactsMap, artifactsToCopy);
    } catch (ParseException e) {
        log(e.getMessage(), Project.MSG_ERR);
        throw new BuildException("syntax errors in ivy file: " + e, e);
    } catch (IOException e) {
        throw new BuildException("impossible to generate report: " + e, e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) RetrieveOptions(org.apache.ivy.core.retrieve.RetrieveOptions) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IOException(java.io.IOException) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 7 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class LatestCompatibleConflictManager method resolveConflicts.

@Override
public Collection<IvyNode> resolveConflicts(IvyNode parent, Collection<IvyNode> conflicts) {
    if (conflicts.size() < 2) {
        return conflicts;
    }
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();
    Iterator<IvyNode> iter = conflicts.iterator();
    IvyNode node = iter.next();
    ModuleRevisionId mrid = node.getResolvedId();
    if (versionMatcher.isDynamic(mrid)) {
        while (iter.hasNext()) {
            IvyNode other = iter.next();
            if (versionMatcher.isDynamic(other.getResolvedId()) || !versionMatcher.accept(mrid, other.getResolvedId()) && !handleIncompatibleConflict(parent, conflicts, node, other)) {
                // or incompatibility found
                return null;
            }
        }
        // no incompatibility nor dynamic version found, let's return the latest static version
        if (conflicts.size() == 2) {
            // very common special case of only two modules in conflict,
            // let's return the second one (static)
            Iterator<IvyNode> it = conflicts.iterator();
            it.next();
            return Collections.singleton(it.next());
        }
        Collection<IvyNode> newConflicts = new LinkedHashSet<>(conflicts);
        newConflicts.remove(node);
        return super.resolveConflicts(parent, newConflicts);
    } else {
        // the first node is a static revision, let's see if all other versions match
        while (iter.hasNext()) {
            IvyNode other = iter.next();
            if (!versionMatcher.accept(other.getResolvedId(), mrid) && !handleIncompatibleConflict(parent, conflicts, node, other)) {
                // incompatibility found
                return null;
            }
        }
        // no incompatibility found, let's return this static version
        return Collections.singleton(node);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 8 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class LatestCompatibleConflictManager method blackListIncompatibleCallerAndRestartResolveIfPossible.

private void blackListIncompatibleCallerAndRestartResolveIfPossible(IvySettings settings, IvyNode parent, IvyNode selected, IvyNode evicted) {
    Stack<IvyNode> callerStack = new Stack<>();
    callerStack.push(evicted);
    Collection<IvyNodeBlacklist> toBlacklist = blackListIncompatibleCaller(settings.getVersionMatcher(), parent, selected, evicted, callerStack);
    if (toBlacklist != null) {
        final StringBuilder blacklisted = new StringBuilder();
        for (IvyNodeBlacklist blacklist : toBlacklist) {
            if (blacklisted.length() > 0) {
                blacklisted.append(" ");
            }
            IvyNode blacklistedNode = blacklist.getBlacklistedNode();
            blacklistedNode.blacklist(blacklist);
            blacklisted.append(blacklistedNode);
        }
        String rootModuleConf = parent.getData().getReport().getConfiguration();
        evicted.markEvicted(new EvictionData(rootModuleConf, parent, this, Collections.singleton(selected), "with blacklisting of " + blacklisted));
        if (settings.debugConflictResolution()) {
            Message.debug("evicting " + evicted + " by " + evicted.getEvictedData(rootModuleConf));
        }
        throw new RestartResolveProcess("trying to handle incompatibilities between " + selected + " and " + evicted);
    }
}
Also used : RestartResolveProcess(org.apache.ivy.core.resolve.RestartResolveProcess) IvyNodeBlacklist(org.apache.ivy.core.resolve.IvyNodeBlacklist) EvictionData(org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData) IvyNode(org.apache.ivy.core.resolve.IvyNode) Stack(java.util.Stack)

Example 9 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class LatestCompatibleConflictManager method handleAllBlacklistedRevisions.

@Override
public void handleAllBlacklistedRevisions(DependencyDescriptor dd, Collection<ModuleRevisionId> foundBlacklisted) {
    ResolveData resolveData = IvyContext.getContext().getResolveData();
    Collection<IvyNode> blacklisted = new HashSet<>();
    for (ModuleRevisionId mrid : foundBlacklisted) {
        blacklisted.add(resolveData.getNode(mrid));
    }
    for (IvyNode node : blacklisted) {
        IvyNodeBlacklist bdata = node.getBlacklistData(resolveData.getReport().getConfiguration());
        handleUnsolvableConflict(bdata.getConflictParent(), Arrays.asList(bdata.getEvictedNode(), bdata.getSelectedNode()), bdata.getEvictedNode(), bdata.getSelectedNode());
    }
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) IvyNodeBlacklist(org.apache.ivy.core.resolve.IvyNodeBlacklist) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IvyNode(org.apache.ivy.core.resolve.IvyNode) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 10 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class StrictConflictManager method resolveConflicts.

public Collection<IvyNode> resolveConflicts(IvyNode parent, Collection<IvyNode> conflicts) {
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();
    IvyNode lastNode = null;
    for (IvyNode node : conflicts) {
        if (versionMatcher.isDynamic(node.getResolvedId())) {
            // dynamic revision, not enough information to resolve conflict
            return null;
        }
        if (lastNode != null && !lastNode.equals(node)) {
            throw new StrictConflictException(lastNode, node);
        }
        lastNode = node;
    }
    return Collections.singleton(lastNode);
}
Also used : VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Aggregations

IvyNode (org.apache.ivy.core.resolve.IvyNode)26 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)12 ArrayList (java.util.ArrayList)7 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)5 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)4 EvictionData (org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData)4 HashSet (java.util.HashSet)3 ResolveReport (org.apache.ivy.core.report.ResolveReport)3 IvyNodeBlacklist (org.apache.ivy.core.resolve.IvyNodeBlacklist)3 VersionMatcher (org.apache.ivy.plugins.version.VersionMatcher)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 Configuration (org.apache.ivy.core.module.descriptor.Configuration)2 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)2