Search in sources :

Example 16 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class ConfigurationResolveReport method getModuleIds.

/**
 * gives all the modules ids concerned by this report, from the most dependent to the least one
 *
 * @return a list of ModuleId
 */
public List<ModuleId> getModuleIds() {
    if (modulesIds == null) {
        List<IvyNode> sortedDependencies = resolveEngine.getSortEngine().sortNodes(getDependencies(), SortOptions.SILENT);
        Collections.reverse(sortedDependencies);
        for (IvyNode dependency : sortedDependencies) {
            ModuleId mid = dependency.getResolvedId().getModuleId();
            Collection<IvyNode> deps = modulesIdsMap.get(mid);
            if (deps == null) {
                deps = new LinkedHashSet<>();
                modulesIdsMap.put(mid, deps);
            }
            deps.add(dependency);
        }
        modulesIds = new ArrayList<>(modulesIdsMap.keySet());
    }
    return Collections.unmodifiableList(modulesIds);
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 17 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyNodeCallers method addCaller.

/**
 * @param rootModuleConf ditto
 * @param callerNode IvyNode
 * @param callerConf ditto
 * @param requestedConf ditto
 * @param dependencyConfs
 *            '*' must have been resolved
 * @param dd
 *            the dependency revision id asked by the caller
 */
public void addCaller(String rootModuleConf, IvyNode callerNode, String callerConf, String requestedConf, String[] dependencyConfs, DependencyDescriptor dd) {
    ModuleDescriptor md = callerNode.getDescriptor();
    ModuleRevisionId mrid = callerNode.getResolvedId();
    if (mrid.getModuleId().equals(node.getId().getModuleId())) {
        throw new IllegalArgumentException("a module is not authorized to depend on itself: " + node.getId());
    }
    Map<ModuleRevisionId, Caller> callers = callersByRootConf.get(rootModuleConf);
    if (callers == null) {
        callers = new HashMap<>();
        callersByRootConf.put(rootModuleConf, callers);
    }
    Caller caller = callers.get(mrid);
    if (caller == null) {
        caller = new Caller(md, mrid, dd, callerNode.canExclude(rootModuleConf));
        callers.put(mrid, caller);
    }
    caller.addConfiguration(requestedConf, dependencyConfs);
    IvyNode parent = callerNode.getRealNode();
    for (ModuleId mid : parent.getAllCallersModuleIds()) {
        allCallers.put(mid, parent);
    }
    allCallers.put(mrid.getModuleId(), callerNode);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId)

Example 18 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyNodeEviction method isEvicted.

public boolean isEvicted(String rootModuleConf) {
    cleanEvicted();
    if (node.isRoot()) {
        return false;
    }
    EvictionData evictedData = getEvictedData(rootModuleConf);
    if (evictedData == null) {
        return false;
    }
    IvyNode root = node.getRoot();
    ModuleId moduleId = node.getId().getModuleId();
    Collection<ModuleRevisionId> resolvedRevisions = root.getResolvedRevisions(moduleId, rootModuleConf);
    return !resolvedRevisions.contains(node.getResolvedId()) || evictedData.isTransitivelyEvicted();
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId)

Example 19 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class RetrieveEngine method determineArtifactsToCopy.

public Map<ArtifactDownloadReport, Set<String>> determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) throws ParseException, IOException {
    ModuleId moduleId = mrid.getModuleId();
    if (options.getResolveId() == null) {
        options.setResolveId(ResolveOptions.getDefaultResolveId(moduleId));
    }
    ResolutionCacheManager cacheManager = getCache();
    String[] confs = getConfs(mrid, options);
    String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), settings.getVariables());
    // find what we must retrieve where
    // ArtifactDownloadReport source -> Set (String copyDestAbsolutePath)
    final Map<ArtifactDownloadReport, Set<String>> artifactsToCopy = new HashMap<>();
    // String copyDestAbsolutePath -> Set (ArtifactRevisionId source)
    final Map<String, Set<ArtifactRevisionId>> conflictsMap = new HashMap<>();
    // String copyDestAbsolutePath -> Set (ArtifactDownloadReport source)
    final Map<String, Set<ArtifactDownloadReport>> conflictsReportsMap = new HashMap<>();
    // String copyDestAbsolutePath -> Set (String conf)
    final Map<String, Set<String>> conflictsConfMap = new HashMap<>();
    XmlReportParser parser = new XmlReportParser();
    for (final String conf : confs) {
        File report = cacheManager.getConfigurationResolveReportInCache(options.getResolveId(), conf);
        parser.parse(report);
        Collection<ArtifactDownloadReport> artifacts = new ArrayList<>(Arrays.asList(parser.getArtifactReports()));
        if (destIvyPattern != null) {
            for (ModuleRevisionId rmrid : parser.getRealDependencyRevisionIds()) {
                artifacts.add(parser.getMetadataArtifactReport(rmrid));
            }
        }
        final PackagingManager packagingManager = new PackagingManager();
        packagingManager.setSettings(IvyContext.getContext().getSettings());
        for (final ArtifactDownloadReport adr : artifacts) {
            final Artifact artifact = adr.getArtifact();
            final String ext;
            if (adr.getUnpackedLocalFile() == null) {
                ext = artifact.getExt();
            } else {
                final Artifact unpackedArtifact;
                // check if the download report is aware of the unpacked artifact
                if (adr.getUnpackedArtifact() != null) {
                    unpackedArtifact = adr.getUnpackedArtifact();
                } else {
                    // use the packaging manager to get hold of the unpacked artifact
                    unpackedArtifact = packagingManager.getUnpackedArtifact(artifact);
                }
                if (unpackedArtifact == null) {
                    throw new RuntimeException("Could not determine unpacked artifact for " + artifact + " while determining artifacts to copy for module " + mrid);
                }
                ext = unpackedArtifact.getExt();
            }
            String destPattern = "ivy".equals(adr.getType()) ? destIvyPattern : destFilePattern;
            if (!"ivy".equals(adr.getType()) && !options.getArtifactFilter().accept(adr.getArtifact())) {
                // skip this artifact, the filter didn't accept it!
                continue;
            }
            ModuleRevisionId aMrid = artifact.getModuleRevisionId();
            String destFileName = IvyPatternHelper.substitute(destPattern, aMrid.getOrganisation(), aMrid.getName(), aMrid.getBranch(), aMrid.getRevision(), artifact.getName(), artifact.getType(), ext, conf, adr.getArtifactOrigin(), aMrid.getQualifiedExtraAttributes(), artifact.getQualifiedExtraAttributes());
            Set<String> dest = artifactsToCopy.get(adr);
            if (dest == null) {
                dest = new HashSet<>();
                artifactsToCopy.put(adr, dest);
            }
            String copyDest = settings.resolveFile(destFileName).getAbsolutePath();
            String[] destinations = new String[] { copyDest };
            if (options.getMapper() != null) {
                destinations = options.getMapper().mapFileName(copyDest);
            }
            for (String destination : destinations) {
                dest.add(destination);
                Set<ArtifactRevisionId> conflicts = conflictsMap.get(destination);
                Set<ArtifactDownloadReport> conflictsReports = conflictsReportsMap.get(destination);
                Set<String> conflictsConf = conflictsConfMap.get(destination);
                if (conflicts == null) {
                    conflicts = new HashSet<>();
                    conflictsMap.put(destination, conflicts);
                }
                if (conflictsReports == null) {
                    conflictsReports = new HashSet<>();
                    conflictsReportsMap.put(destination, conflictsReports);
                }
                if (conflictsConf == null) {
                    conflictsConf = new HashSet<>();
                    conflictsConfMap.put(destination, conflictsConf);
                }
                if (conflicts.add(artifact.getId())) {
                    conflictsReports.add(adr);
                    conflictsConf.add(conf);
                }
            }
        }
    }
    // resolve conflicts if any
    for (Map.Entry<String, Set<ArtifactRevisionId>> entry : conflictsMap.entrySet()) {
        String copyDest = entry.getKey();
        Set<ArtifactRevisionId> artifacts = entry.getValue();
        Set<String> conflictsConfs = conflictsConfMap.get(copyDest);
        if (artifacts.size() > 1) {
            List<ArtifactDownloadReport> artifactsList = new ArrayList<>(conflictsReportsMap.get(copyDest));
            // conflicts battle is resolved by a sort using a conflict resolving policy
            // comparator which consider as greater a winning artifact
            Collections.sort(artifactsList, getConflictResolvingPolicy());
            // after the sort, the winning artifact is the greatest one, i.e. the last one
            // we fail if different artifacts of the same module are mapped to the same file
            ArtifactDownloadReport winner = artifactsList.get(artifactsList.size() - 1);
            ModuleRevisionId winnerMD = winner.getArtifact().getModuleRevisionId();
            for (int i = artifactsList.size() - 2; i >= 0; i--) {
                ArtifactDownloadReport current = artifactsList.get(i);
                if (winnerMD.equals(current.getArtifact().getModuleRevisionId())) {
                    throw new RuntimeException("Multiple artifacts of the module " + winnerMD + " are retrieved to the same file! Update the retrieve pattern " + " to fix this error.");
                }
            }
            Message.info("\tconflict on " + copyDest + " in " + conflictsConfs + ": " + winnerMD.getRevision() + " won");
            // and going backward to the least artifact
            for (int i = artifactsList.size() - 2; i >= 0; i--) {
                ArtifactDownloadReport looser = artifactsList.get(i);
                Message.verbose("\t\tremoving conflict looser artifact: " + looser.getArtifact());
                // for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy
                // map
                Set<String> dest = artifactsToCopy.get(looser);
                dest.remove(copyDest);
                if (dest.isEmpty()) {
                    artifactsToCopy.remove(looser);
                }
            }
        }
    }
    return artifactsToCopy;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ArrayList(java.util.ArrayList) ModuleId(org.apache.ivy.core.module.id.ModuleId) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Artifact(org.apache.ivy.core.module.descriptor.Artifact) XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) PackagingManager(org.apache.ivy.core.pack.PackagingManager) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) ArtifactRevisionId(org.apache.ivy.core.module.id.ArtifactRevisionId)

Example 20 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class MessageBasedNonMatchingVersionReporter method reportNonMatchingVersion.

public void reportNonMatchingVersion(DependencyDescriptor descriptor, ModuleDescriptor md) {
    ModuleRevisionId dependencyRevisionId = descriptor.getDependencyRevisionId();
    ModuleRevisionId parentRevisionId = descriptor.getParentRevisionId();
    if (parentRevisionId == null) {
        // There are some rare case where DependencyDescriptor have no parent.
        // This is should not be used in the SortEngine, but if it is, we
        // show a decent trace.
        reportMessage("Non matching revision detected when sorting.  Dependency " + dependencyRevisionId + " doesn't match " + md.getModuleRevisionId());
    } else {
        ModuleId parentModuleId = parentRevisionId.getModuleId();
        reportMessage("Non matching revision detected when sorting.  " + parentModuleId + " depends on " + dependencyRevisionId + ", doesn't match " + md.getModuleRevisionId());
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId)

Aggregations

ModuleId (org.apache.ivy.core.module.id.ModuleId)49 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)19 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)13 File (java.io.File)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Date (java.util.Date)6 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)6 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)6 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)6 BuildException (org.apache.tools.ant.BuildException)6 Ivy (org.apache.ivy.Ivy)5 ArtifactId (org.apache.ivy.core.module.id.ArtifactId)5 ResolveReport (org.apache.ivy.core.report.ResolveReport)5 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)5 IvySettings (org.apache.ivy.core.settings.IvySettings)5 IOException (java.io.IOException)4 Map (java.util.Map)4 Configuration (org.apache.ivy.core.module.descriptor.Configuration)4