use of org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor 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.descriptor.DefaultDependencyArtifactDescriptor in project Saturn by vipshop.
the class IvyGetArtifact method getIvyfile.
private File getIvyfile(String org, String name, String rev, String[] confs, Set<Map<String, Object>> artifacts) throws IOException {
File ivyfile;
ivyfile = File.createTempFile("ivy", ".xml");
ivyfile.deleteOnExit();
DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(org, name + "-caller", "working"));
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(org, name, rev), false, false, true);
if (artifacts != null && !artifacts.isEmpty()) {
for (Map<String, Object> artifact : artifacts) {
String artifactName = (String) artifact.get("name");
String artifactType = (String) artifact.get("type");
String artifactExt = (String) artifact.get("ext");
URL artifactUrl = (URL) artifact.get("url");
Map<?, ?> extraAttributes = (Map<?, ?>) artifact.get("extraAttributes");
DefaultDependencyArtifactDescriptor dad = new DefaultDependencyArtifactDescriptor(dd, artifactName, artifactType, artifactExt, artifactUrl, extraAttributes);
dd.addDependencyArtifact("default", dad);
}
}
for (int i = 0; i < confs.length; i++) {
dd.addDependencyConfiguration("default", confs[i]);
}
md.addDependency(dd);
md.addExtraAttributeNamespace("m", "http://ant.apache.org/ivy/maven");
XmlModuleDescriptorWriter.write(md, ivyfile);
return ivyfile;
}
use of org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor in project ant-ivy by apache.
the class IvyDependencyArtifact method addArtifact.
void addArtifact(DefaultDependencyDescriptor dd, String masterConf) {
String typePattern = type == null ? PatternMatcher.ANY_EXPRESSION : type;
String extPattern = ext == null ? typePattern : ext;
URL u;
try {
u = url == null ? null : new URL(url);
} catch (MalformedURLException e) {
throw new BuildException("Malformed url in the artifact: " + e.getMessage(), e);
}
DefaultDependencyArtifactDescriptor dad = new DefaultDependencyArtifactDescriptor(dd, name, typePattern, extPattern, u, null);
dd.addDependencyArtifact(masterConf, dad);
}
Aggregations