use of org.apache.ivy.core.module.id.ArtifactId in project ant-ivy by apache.
the class IvyDependencyExclude method asRule.
DefaultExcludeRule asRule(IvySettings settings) {
String matcherName = (matcher == null) ? PatternMatcher.EXACT : matcher;
String orgPattern = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
String modulePattern = (module == null) ? PatternMatcher.ANY_EXPRESSION : module;
String namePattern = (name == null) ? PatternMatcher.ANY_EXPRESSION : name;
String typePattern = (type == null) ? PatternMatcher.ANY_EXPRESSION : type;
String extPattern = (ext == null) ? typePattern : ext;
ArtifactId aid = new ArtifactId(new ModuleId(orgPattern, modulePattern), namePattern, typePattern, extPattern);
return new DefaultExcludeRule(aid, settings.getMatcher(matcherName), null);
}
use of org.apache.ivy.core.module.id.ArtifactId in project ant-ivy by apache.
the class IvyDependencyInclude method asRule.
DefaultIncludeRule asRule(IvySettings settings) {
String matcherName = matcher == null ? PatternMatcher.EXACT : matcher;
String namePattern = name == null ? PatternMatcher.ANY_EXPRESSION : name;
String typePattern = type == null ? PatternMatcher.ANY_EXPRESSION : type;
String extPattern = ext == null ? typePattern : ext;
ArtifactId aid = new ArtifactId(new ModuleId(PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION), namePattern, typePattern, extPattern);
return new DefaultIncludeRule(aid, settings.getMatcher(matcherName), null);
}
use of org.apache.ivy.core.module.id.ArtifactId in project ant-ivy by apache.
the class PomModuleDescriptorBuilder method addDependency.
public void addDependency(Resource res, PomDependencyData dep) {
String scope = dep.getScope();
if (!isNullOrEmpty(scope) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
// unknown scope, defaulting to 'compile'
scope = "compile";
}
String version = dep.getVersion();
if (isNullOrEmpty(version)) {
version = getDefaultVersion(dep);
}
ModuleRevisionId moduleRevId = ModuleRevisionId.newInstance(dep.getGroupId(), dep.getArtifactId(), version);
// Some POMs depend on themselves; Ivy doesn't allow this. Don't add this dependency!
// Example: https://repo1.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
if (mRevId != null && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
return;
}
// experimentation shows the following, excluded modules are
// inherited from parent POMs if either of the following is true:
// the <exclusions> element is missing or the <exclusions> element
// is present, but empty.
List<ModuleId> excluded = dep.getExcludedModules();
if (excluded.isEmpty()) {
excluded = getDependencyMgtExclusions(ivyModuleDescriptor, dep.getGroupId(), dep.getArtifactId());
}
final boolean excludeAllTransitiveDeps = shouldExcludeAllTransitiveDeps(excluded);
// the same dependency mrid could appear twice in the module descriptor,
// so we check if we already have created a dependency descriptor for the dependency mrid
final DependencyDescriptor existing = this.ivyModuleDescriptor.depDescriptors.get(moduleRevId);
final DefaultDependencyDescriptor dd = (existing != null && existing instanceof DefaultDependencyDescriptor) ? (DefaultDependencyDescriptor) existing : new PomDependencyDescriptor(dep, ivyModuleDescriptor, moduleRevId, !excludeAllTransitiveDeps);
if (isNullOrEmpty(scope)) {
scope = getDefaultScope(dep);
}
ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
mapping.addMappingConfs(dd, dep.isOptional());
Map<String, String> extraAtt = new HashMap<>();
if (dep.getClassifier() != null || dep.getType() != null && !"jar".equals(dep.getType())) {
String type = "jar";
if (dep.getType() != null) {
type = dep.getType();
}
String ext = type;
// Cfr. http://maven.apache.org/guides/mini/guide-attached-tests.html
if ("test-jar".equals(type)) {
ext = "jar";
extraAtt.put("m:classifier", "tests");
} else if (JAR_PACKAGINGS.contains(type)) {
ext = "jar";
}
// dependency to assume such an artifact is published
if (dep.getClassifier() != null) {
extraAtt.put("m:classifier", dep.getClassifier());
}
DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(dd, dd.getDependencyId().getName(), type, ext, null, extraAtt);
// here we have to assume a type and ext for the artifact, so this is a limitation
// compared to how m2 behave with classifiers
String optionalizedScope = dep.isOptional() ? "optional" : scope;
dd.addDependencyArtifact(optionalizedScope, depArtifact);
}
for (ModuleId excludedModule : excluded) {
// in account while defining the DefaultDependencyDescriptor itself
if ("*".equals(excludedModule.getOrganisation()) && "*".equals(excludedModule.getName())) {
continue;
}
for (String conf : dd.getModuleConfigurations()) {
dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(excludedModule, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, null));
}
}
// intentional identity check to make sure we don't re-add the same dependency
if (existing != dd) {
ivyModuleDescriptor.addDependency(dd);
}
}
use of org.apache.ivy.core.module.id.ArtifactId in project ant-ivy by apache.
the class BintrayResolverTest method testBintrayArtifacts.
@Test
public void testBintrayArtifacts() throws Exception {
BintrayResolver resolver = new BintrayResolver();
resolver.setName("test");
resolver.setSettings(settings);
assertEquals("test", resolver.getName());
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ant", "ant-antunit", "1.2");
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false);
dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "javadoc", "jar"), ExactPatternMatcher.INSTANCE, null));
dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "sources", "jar"), ExactPatternMatcher.INSTANCE, null));
ResolvedModuleRevision rmr = resolver.getDependency(dd, data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "javadoc", "jar");
DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "sources", "jar");
DownloadReport report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
assertNotNull(report);
assertEquals(2, report.getArtifactsReports().length);
ArtifactDownloadReport ar = report.getArtifactReport(profiler);
assertNotNull(ar);
assertEquals(profiler, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
ar = report.getArtifactReport(trace);
assertNotNull(ar);
assertEquals(trace, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
// test to ask to download again, should use cache
report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
assertNotNull(report);
assertEquals(2, report.getArtifactsReports().length);
ar = report.getArtifactReport(profiler);
assertNotNull(ar);
assertEquals(profiler, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
ar = report.getArtifactReport(trace);
assertNotNull(ar);
assertEquals(trace, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
use of org.apache.ivy.core.module.id.ArtifactId in project ant-ivy by apache.
the class IvyNode method getArtifacts.
/**
* Returns the artifacts of this dependency required in the configurations themselves required
* in the given root module configuration
*
* @param rootModuleConf String
* @return array of {@link Artifact}s
*/
public Artifact[] getArtifacts(String rootModuleConf) {
// first we look for the dependency configurations required
// in the given root module configuration
String[] confs = getConfigurations(rootModuleConf);
if (confs == null || confs.length == 0) {
// no configuration required => no artifact required
return new Artifact[0];
}
if (md == null) {
throw new IllegalStateException("impossible to get artifacts when data has not been loaded. IvyNode = " + this);
}
// the set we fill before returning
Set<Artifact> artifacts = new HashSet<>();
// we check if we have dependencyArtifacts includes description for this rootModuleConf
Set<DependencyArtifactDescriptor> dependencyArtifacts = usage.getDependencyArtifactsSet(rootModuleConf);
if (md.isDefault() && dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) {
addArtifactsFromOwnUsage(artifacts, dependencyArtifacts);
addArtifactsFromMergedUsage(rootModuleConf, artifacts);
} else {
Set<IncludeRule> includes = new LinkedHashSet<>();
addAllIfNotNull(includes, usage.getDependencyIncludesSet(rootModuleConf));
for (IvyNodeUsage usage : mergedUsages.values()) {
addAllIfNotNull(includes, usage.getDependencyIncludesSet(rootModuleConf));
}
if ((dependencyArtifacts == null || dependencyArtifacts.isEmpty()) && includes.isEmpty()) {
// no artifacts / includes: we get all artifacts as defined by the descriptor
for (String conf : confs) {
artifacts.addAll(Arrays.asList(md.getArtifacts(conf)));
}
} else {
// we have to get only artifacts listed as "includes";
// first we get all artifacts as defined by the module descriptor
// and classify them by artifact id
Map<ArtifactId, Artifact> allArtifacts = new HashMap<>();
for (String conf : confs) {
for (Artifact art : md.getArtifacts(conf)) {
allArtifacts.put(art.getId().getArtifactId(), art);
}
}
// now we add caller defined ones
if (dependencyArtifacts != null) {
addArtifactsFromOwnUsage(artifacts, dependencyArtifacts);
}
addArtifactsFromMergedUsage(rootModuleConf, artifacts);
// and now we filter according to include rules
Iterator<IncludeRule> it = includes.iterator();
while (it.hasNext()) {
IncludeRule dad = it.next();
Collection<Artifact> arts = findArtifactsMatching(dad, allArtifacts);
if (arts.isEmpty()) {
Message.error("a required artifact is not listed by module descriptor: " + dad.getId());
// we remove it from required list to prevent message to be displayed more
// than once
it.remove();
} else {
Message.debug(this + " in " + rootModuleConf + ": including " + arts);
artifacts.addAll(arts);
}
}
}
}
// now exclude artifacts that aren't accepted by any caller
Iterator<Artifact> iter = artifacts.iterator();
while (iter.hasNext()) {
Artifact artifact = iter.next();
boolean excluded = callers.doesCallersExclude(rootModuleConf, artifact);
if (excluded) {
Message.debug(this + " in " + rootModuleConf + ": excluding " + artifact);
iter.remove();
}
}
return artifacts.toArray(new Artifact[artifacts.size()]);
}
Aggregations