public List<ModuleIdentifier> getExcludedModules() { Element exclusionsElement = getFirstChildElement(depElement, EXCLUSIONS); if (exclusionsElement != null) { NodeList childs = exclusionsElement.getChildNodes(); List<ModuleIdentifier> exclusions = Lists.newArrayList(); for (int i = 0; i < childs.getLength(); i++) { Node node = childs.item(i); if (node instanceof Element && EXCLUSION.equals(node.getNodeName())) { String groupId = getFirstChildText((Element) node, GROUP_ID); String artifactId = getFirstChildText((Element) node, ARTIFACT_ID); if ((groupId != null) && (artifactId != null)) { exclusions.add(DefaultModuleIdentifier.newId(groupId, artifactId)); } } } return exclusions; } return Collections.emptyList(); }
private void listModuleVersionsFromCache(DependencyMetadata dependency, BuildableModuleVersionListingResolveResult result) { ModuleVersionSelector requested = dependency.getRequested(); final ModuleIdentifier moduleId = getCacheKey(requested); ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId); if (cachedModuleVersionList != null) { Set<String> versionList = cachedModuleVersionList.getModuleVersions(); Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList, new Transformer<ModuleVersionIdentifier, String>() { public ModuleVersionIdentifier transform(String original) { return new DefaultModuleVersionIdentifier(moduleId, original); } }); if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) { LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName()); } else { result.listed(versionList); // When age == 0, verified since the start of this build, assume listing hasn't changed result.setAuthoritative(cachedModuleVersionList.getAgeMillis() == 0); } } }
public ComponentModuleMetadataDetails module(final Object sourceModule) { final NotationParser<Object, ModuleIdentifier> parser = parser(); final ModuleIdentifier source = parser.parseNotation(sourceModule); return new ComponentModuleMetadataDetails() { public void replacedBy(final Object targetModule) { ModuleIdentifier target = parser.parseNotation(targetModule); detectCycles(replacements, source, target); replacements.put(source, target); } public ModuleIdentifier getId() { return source; } public ModuleIdentifier getReplacedBy() { return replacements.get(source); } }; }
private static void detectCycles(Map<ModuleIdentifier, ModuleIdentifier> replacements, ModuleIdentifier source, ModuleIdentifier target) { if (source.equals(target)) { throw new InvalidUserDataException(String.format("Cannot declare module replacement that replaces self: %s->%s", source, target)); } ModuleIdentifier m = replacements.get(target); if (m == null) { //target does not exist in the map, there's no cycle for sure return; } Set<ModuleIdentifier> visited = new LinkedHashSet<ModuleIdentifier>(); visited.add(source); visited.add(target); while(m != null) { if (!visited.add(m)) { //module was already visited, there is a cycle throw new InvalidUserDataException( format("Cannot declare module replacement %s->%s because it introduces a cycle: %s", source, target, Joiner.on("->").join(visited) + "->" + source)); } m = replacements.get(m); } }
public VersionPatternVisitor newVisitor(final ModuleIdentifier module, final Collection<String> dest, final ResourceAwareResolveResult result) { return new VersionPatternVisitor() { final Set<ExternalResourceName> searched = new HashSet<ExternalResourceName>(); public void visit(ResourcePattern pattern, IvyArtifactName artifact) throws ResourceException { ExternalResourceName metadataLocation = pattern.toModulePath(module).resolve("maven-metadata.xml"); if (!searched.add(metadataLocation)) { return; } result.attempted(metadataLocation); MavenMetadata mavenMetaData = mavenMetadataLoader.load(metadataLocation.getUri()); for (String version : mavenMetaData.versions) { dest.add(version); } } }; }
private ProjectComponentIdentifier getReplacementFor(ModuleComponentSelector selector) { ModuleIdentifier candidateId = DefaultModuleIdentifier.newId(selector.getGroup(), selector.getModule()); Collection<ProjectComponentIdentifier> providingProjects = replacementMap.get(candidateId); if (providingProjects.isEmpty()) { LOGGER.info("Found no composite build substitute for module '" + candidateId + "'."); return null; } if (providingProjects.size() == 1) { ProjectComponentIdentifier match = providingProjects.iterator().next(); LOGGER.info("Found project '" + match + "' as substitute for module '" + candidateId + "'."); return match; } SortedSet<String> sortedProjects = Sets.newTreeSet(CollectionUtils.collect(providingProjects, new Transformer<String, ProjectComponentIdentifier>() { @Override public String transform(ProjectComponentIdentifier projectComponentIdentifier) { return projectComponentIdentifier.getDisplayName(); } })); String failureMessage = String.format("Module version '%s' is not unique in composite: can be provided by %s.", selector.getDisplayName(), sortedProjects); throw new ModuleVersionResolveException(selector, failureMessage); }
private List createDependencyChildren(RenderableDependency dependency, final Set<Object> visited) { Iterable<? extends RenderableDependency> children = dependency.getChildren(); return CollectionUtils.collect(children, new Transformer<Map, RenderableDependency>() { @Override public Map transform(RenderableDependency childDependency) { boolean alreadyVisited = !visited.add(childDependency.getId()); boolean alreadyRendered = alreadyVisited && !childDependency.getChildren().isEmpty(); String name = replaceArrow(childDependency.getName()); boolean hasConflict = !name.equals(childDependency.getName()); LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(6); ModuleIdentifier moduleIdentifier = getModuleIdentifier(childDependency); map.put("module", moduleIdentifier == null ? null : moduleIdentifier.toString()); map.put("name", name); map.put("resolvable", childDependency.getResolutionState()); map.put("hasConflict", hasConflict); map.put("alreadyRendered", alreadyRendered); map.put("children", Collections.emptyList()); if (!alreadyRendered) { map.put("children", createDependencyChildren(childDependency, visited)); } return map; } }); }
private AtlasDependencyTree toAtlasDependencyTree() { AtlasDependencyTree atlasDependencyTree = new AtlasDependencyTree(mResolvedDependencies); //Setting dependency for (ResolvedDependencyInfo dependencyInfo : mResolvedDependencies) { if (Type.AWB == DependencyConvertUtils.Type.getType(dependencyInfo.getType())) { AwbBundle bundle = DependencyConvertUtils.toBundle(dependencyInfo, project); if (apDependencies != null) { Map<ModuleIdentifier, String> awbDependencies = apDependencies.getAwbDependencies( dependencyInfo.getGroup(), dependencyInfo.getName()); bundle.setBaseAwbDependencies(awbDependencies); } atlasDependencyTree.getAwbBundles().add(bundle); collect(dependencyInfo, bundle); } else { collect(dependencyInfo, atlasDependencyTree.getMainBundle()); } } return atlasDependencyTree; }
private void listModuleVersionsFromCache(DependencyMetaData dependency, BuildableModuleComponentVersionSelectionResolveResult result) { ModuleVersionSelector requested = dependency.getRequested(); final ModuleIdentifier moduleId = getCacheKey(requested); ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId); if (cachedModuleVersionList != null) { ModuleVersionListing versionList = cachedModuleVersionList.getModuleVersions(); Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList.getVersions(), new Transformer<ModuleVersionIdentifier, Versioned>() { public ModuleVersionIdentifier transform(Versioned original) { return new DefaultModuleVersionIdentifier(moduleId, original.getVersion()); } }); if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) { LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName()); } else { result.listed(versionList); // When age == 0, verified since the start of this build, assume listing hasn't changed result.setAuthoritative(cachedModuleVersionList.getAgeMillis() == 0); } } }
/** * Empty String for either group or module name is not allowed. */ protected ModuleIdentifier parseType(String notation) { assert notation != null; String[] split = notation.split(":"); if (split.length != 2) { throw new UnsupportedNotationException(notation); } String group = split[0].trim(); String name = split[1].trim(); if (group.length() == 0 || name.length() == 0) { throw new UnsupportedNotationException(notation); } for (char c : INVALID_SPEC_CHARS) { if (group.indexOf(c) != -1 || name.indexOf(c) != -1) { throw new UnsupportedNotationException(notation); } } return newId(group, name); }
public void localListModuleVersions(DependencyMetaData dependency, BuildableModuleVersionSelectionResolveResult result) { ModuleVersionSelector requested = dependency.getRequested(); final ModuleIdentifier moduleId = moduleExtractor.transform(requested); ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId); if (cachedModuleVersionList != null) { ModuleVersionListing versionList = cachedModuleVersionList.getModuleVersions(); Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList.getVersions(), new Transformer<ModuleVersionIdentifier, Versioned>() { public ModuleVersionIdentifier transform(Versioned original) { return new DefaultModuleVersionIdentifier(moduleId, original.getVersion()); } }); if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) { LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName()); } else { if (cachedModuleVersionList.getAgeMillis() == 0) { // Verified since the start of this build, assume still missing result.listed(versionList); } else { // Was missing last time we checked result.probablyListed(versionList); } } } }
public void listModuleVersions(DependencyMetaData dependency, BuildableModuleVersionSelectionResolveResult result) { ModuleIdentifier module = new DefaultModuleIdentifier(dependency.getRequested().getGroup(), dependency.getRequested().getName()); VersionList versionList = versionLister.getVersionList(module); // List modules based on metadata files ModuleVersionArtifactMetaData metaDataArtifact = getMetaDataArtifactFor(dependency); listVersionsForAllPatterns(getIvyPatterns(), metaDataArtifact, versionList); // List modules with missing metadata files if (isAllownomd()) { for (ModuleVersionArtifactMetaData otherArtifact : getDefaultMetaData(dependency).getArtifacts()) { listVersionsForAllPatterns(getArtifactPatterns(), otherArtifact, versionList); } } DefaultModuleVersionListing moduleVersions = new DefaultModuleVersionListing(); for (VersionList.ListedVersion listedVersion : versionList.getVersions()) { moduleVersions.add(listedVersion.getVersion()); } result.listed(moduleVersions); }
public VersionList getVersionList(final ModuleIdentifier module) { return new DefaultVersionList() { final Set<String> searched = new HashSet<String>(); public void visit(ResourcePattern resourcePattern, ModuleVersionArtifactMetaData artifact) throws ResourceException { String metadataLocation = resourcePattern.toModulePath(module) + "/maven-metadata.xml"; if (!searched.add(metadataLocation)) { return; } MavenMetadata mavenMetaData = mavenMetadataLoader.load(metadataLocation); for (String version : mavenMetaData.versions) { add(new ListedVersion(version, resourcePattern)); } } }; }
public CachedModuleVersionList getCachedModuleResolution(ModuleComponentRepository repository, ModuleIdentifier moduleId) { ModuleVersionsCacheEntry moduleVersionsCacheEntry = getCache().get(createKey(repository, moduleId)); if (moduleVersionsCacheEntry == null) { return null; } return new DefaultCachedModuleVersionList(moduleVersionsCacheEntry, timeProvider); }
public boolean mustRefreshVersionList(final ModuleIdentifier moduleIdentifier, Set<ModuleVersionIdentifier> matchingVersions, long ageMillis) { CachedDependencyResolutionControl dependencyResolutionControl = new CachedDependencyResolutionControl(moduleIdentifier, matchingVersions, ageMillis); for (Action<? super DependencyResolutionControl> rule : dependencyCacheRules) { rule.execute(dependencyResolutionControl); if (dependencyResolutionControl.ruleMatch()) { return dependencyResolutionControl.mustCheck(); } } return false; }
public ModuleForcingResolveRule(Collection<? extends ModuleVersionSelector> forcedModules) { if (!forcedModules.isEmpty()) { this.forcedModules = new HashMap<ModuleIdentifier, String>(); for (ModuleVersionSelector module : forcedModules) { this.forcedModules.put(new DefaultModuleIdentifier(module.getGroup(), module.getName()), module.getVersion()); } } else { this.forcedModules = null; } }
@Override public void execute(DependencySubstitutionInternal details) { if (forcedModules == null) { return; } ModuleIdentifier key = new DefaultModuleIdentifier(details.getOldRequested().getGroup(), details.getOldRequested().getName()); if (forcedModules.containsKey(key) && details.getRequested() instanceof ModuleComponentSelector) { details.useTarget(DefaultModuleComponentSelector.newSelector(key.getGroup(), key.getName(), forcedModules.get(key)), VersionSelectionReasons.FORCED); } }
private SpecRuleAction<? super ComponentSelection> createSpecRuleActionFromId(Object id, RuleAction<? super ComponentSelection> ruleAction) { final ModuleIdentifier moduleIdentifier; try { moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id); } catch (UnsupportedNotationException e) { throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e); } Spec<ComponentSelection> spec = new ComponentSelectionMatchingSpec(moduleIdentifier); return new SpecRuleAction<ComponentSelection>(ruleAction, spec); }
private List<ModuleIdentifier> getDependencyMgtExclusions(PomDependencyData dep) { PomDependencyMgt pomDependencyMgt = findDependencyDefault(dep); if (pomDependencyMgt != null) { return pomDependencyMgt.getExcludedModules(); } return Collections.emptyList(); }
@Override public void listModuleVersions(DependencyMetadata dependency, BuildableModuleVersionListingResolveResult result) { delegate.getRemoteAccess().listModuleVersions(dependency, result); switch (result.getState()) { case Listed: ModuleIdentifier moduleId = getCacheKey(dependency.getRequested()); Set<String> versionList = result.getVersions(); moduleVersionsCache.cacheModuleVersionList(delegate, moduleId, versionList); break; case Failed: break; default: throw new IllegalStateException("Unexpected state on listModuleVersions: " + result.getState()); } }
public boolean excludeModule(ModuleIdentifier element) { for (AbstractModuleExclusion excludeSpec : excludeSpecs) { if (excludeSpec.excludeModule(element)) { return true; } } return false; }
public boolean excludeArtifact(ModuleIdentifier module, IvyArtifactName artifact) { for (AbstractModuleExclusion excludeSpec : excludeSpecs) { if (excludeSpec.excludeArtifact(module, artifact)) { return true; } } return false; }
@Override public boolean excludeArtifact(ModuleIdentifier module, IvyArtifactName artifact) { return matches(moduleId.getGroup(), module.getGroup()) && matches(moduleId.getName(), module.getName()) && matches(ivyArtifactName.getName(), artifact.getName()) && matches(ivyArtifactName.getExtension(), artifact.getExtension()) && matches(ivyArtifactName.getType(), artifact.getType()); }
private static AbstractModuleExclusion forExclude(Exclude rule) { // For custom ivy pattern matchers, don't inspect the rule any more deeply: this prevents us from doing smart merging later if (!PatternMatchers.isExactMatcher(rule.getMatcher())) { return new IvyPatternMatcherExcludeRuleSpec(rule); } ModuleIdentifier moduleId = rule.getModuleId(); IvyArtifactName artifact = rule.getArtifact(); boolean anyOrganisation = isWildcard(moduleId.getGroup()); boolean anyModule = isWildcard(moduleId.getName()); boolean anyArtifact = isWildcard(artifact.getName()) && isWildcard(artifact.getType()) && isWildcard(artifact.getExtension()); // Build a strongly typed (mergeable) exclude spec for each supplied rule if (anyArtifact) { if (!anyOrganisation && !anyModule) { return new ModuleIdExcludeSpec(moduleId.getGroup(), moduleId.getName()); } else if (!anyModule) { return new ModuleNameExcludeSpec(moduleId.getName()); } else if (!anyOrganisation) { return new GroupNameExcludeSpec(moduleId.getGroup()); } else { return EXCLUDE_ALL_MODULES_SPEC; } } else { return new ArtifactExcludeSpec(moduleId, artifact); } }
public boolean excludeArtifact(ModuleIdentifier module, IvyArtifactName artifact) { if (!isArtifactExclude) { return false; } return matches(moduleId.getGroup(), module.getGroup()) && matches(moduleId.getName(), module.getName()) && matches(ivyArtifactName.getName(), artifact.getName()) && matches(ivyArtifactName.getExtension(), artifact.getExtension()) && matches(ivyArtifactName.getType(), artifact.getType()); }
public boolean excludeModule(ModuleIdentifier element) { for (AbstractModuleExclusion spec : filters) { if (!spec.excludeModule(element)) { return false; } } return true; }
public boolean excludeArtifact(ModuleIdentifier module, IvyArtifactName artifact) { for (AbstractModuleExclusion spec : filters) { if (!spec.excludeArtifact(module, artifact)) { return false; } } return true; }
public void execute(final ConflictResolutionResult result) { result.getConflict().withParticipatingModules(new Action<ModuleIdentifier>() { public void execute(ModuleIdentifier moduleIdentifier) { ModuleVersionResolveState selected = result.getSelected(); // Restart each configuration. For the evicted configuration, this means moving incoming dependencies across to the // matching selected configuration. For the select configuration, this mean traversing its dependencies. resolveState.getModule(moduleIdentifier).restart(selected); } }); }
public ModuleResolveState getModule(ModuleIdentifier id) { ModuleResolveState module = modules.get(id); if (module == null) { module = new ModuleResolveState(idGenerator, id, this, metaDataResolver); modules.put(id, module); } return module; }
private boolean isExcluded(ModuleExclusion selector, DependencyMetadata dependency) { if (!resolveState.edgeFilter.isSatisfiedBy(dependency)) { LOGGER.debug("{} is filtered.", dependency); return true; } ModuleIdentifier targetModuleId = DefaultModuleIdentifier.newId(dependency.getRequested().getGroup(), dependency.getRequested().getName()); if (selector.excludeModule(targetModuleId)) { LOGGER.debug("{} is excluded from {}.", targetModuleId, this); return true; } return false; }
static PotentialConflict potentialConflict(final ConflictContainer<ModuleIdentifier, ? extends ComponentResolutionState>.Conflict conflict) { return new PotentialConflict() { public boolean conflictExists() { return conflict != null; } public void withParticipatingModules(Action<ModuleIdentifier> action) { assert conflictExists(); for (ModuleIdentifier participant : conflict.participants) { action.execute(participant); } } }; }
private SpecRuleAction<? super ComponentMetadataDetails> createSpecRuleActionForModule(Object id, RuleAction<? super ComponentMetadataDetails> ruleAction) { ModuleIdentifier moduleIdentifier; try { moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id); } catch (UnsupportedNotationException e) { throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e); } Spec<ComponentMetadataDetails> spec = new ComponentMetadataDetailsMatchingSpec(moduleIdentifier); return new SpecRuleAction<ComponentMetadataDetails>(ruleAction, spec); }
private void doListModuleVersions(DependencyMetadata dependency, BuildableModuleVersionListingResolveResult result) { ModuleIdentifier module = new DefaultModuleIdentifier(dependency.getRequested().getGroup(), dependency.getRequested().getName()); Set<String> versions = new LinkedHashSet<String>(); VersionPatternVisitor visitor = versionLister.newVisitor(module, versions, result); // List modules based on metadata files (artifact version is not considered in listVersionsForAllPatterns()) IvyArtifactName metaDataArtifact = getMetaDataArtifactName(dependency.getRequested().getName()); listVersionsForAllPatterns(ivyPatterns, metaDataArtifact, visitor); // List modules with missing metadata files for (IvyArtifactName otherArtifact : getDependencyArtifactNames(dependency.getRequested().getName(), dependency.getArtifacts())) { listVersionsForAllPatterns(artifactPatterns, otherArtifact, visitor); } result.listed(versions); }
public ExternalResourceName toModulePath(ModuleIdentifier module) { String pattern = getBase().getPath(); if (!pattern.endsWith(MavenPattern.M2_PATTERN)) { throw new UnsupportedOperationException("Cannot locate module for non-maven layout."); } String metaDataPattern = pattern.substring(0, pattern.length() - MavenPattern.M2_PER_MODULE_PATTERN.length() - 1); return getBase().getRoot().resolve(substituteTokens(metaDataPattern, toAttributes(module))); }
/** * Empty String for either group or module name is not allowed. */ protected ModuleIdentifier parseType(String notation) { assert notation != null; String[] split = notation.split(":"); if (split.length != 2) { throw new UnsupportedNotationException(notation); } String group = validate(split[0].trim(), notation); String name = validate(split[1].trim(), notation); return newId(group, name); }
private ModuleIdentifier getModuleIdentifier(RenderableDependency renderableDependency) { if (renderableDependency.getId() instanceof ModuleComponentIdentifier) { ModuleComponentIdentifier id = (ModuleComponentIdentifier) renderableDependency.getId(); return new DefaultModuleIdentifier(id.getGroup(), id.getModule()); } return null; }
private List createModuleInsights(final Configuration configuration) { Iterable<ModuleIdentifier> modules = collectModules(configuration); return CollectionUtils.collect(modules, new Transformer<Object, ModuleIdentifier>() { @Override public Object transform(ModuleIdentifier moduleIdentifier) { return createModuleInsight(moduleIdentifier, configuration); } }); }