Search in sources :

Example 1 with ArtifactId

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);
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultExcludeRule(org.apache.ivy.core.module.descriptor.DefaultExcludeRule) ArtifactId(org.apache.ivy.core.module.id.ArtifactId)

Example 2 with ArtifactId

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);
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) DefaultIncludeRule(org.apache.ivy.core.module.descriptor.DefaultIncludeRule)

Example 3 with ArtifactId

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);
    }
}
Also used : ArtifactId(org.apache.ivy.core.module.id.ArtifactId) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultDependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor) ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultExcludeRule(org.apache.ivy.core.module.descriptor.DefaultExcludeRule) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)

Example 4 with ArtifactId

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());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultIncludeRule(org.apache.ivy.core.module.descriptor.DefaultIncludeRule) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 5 with ArtifactId

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()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IncludeRule(org.apache.ivy.core.module.descriptor.IncludeRule) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) MDArtifact(org.apache.ivy.core.module.descriptor.MDArtifact) DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ArtifactId (org.apache.ivy.core.module.id.ArtifactId)9 DefaultExcludeRule (org.apache.ivy.core.module.descriptor.DefaultExcludeRule)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)5 HashMap (java.util.HashMap)3 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)3 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)3 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 DefaultIncludeRule (org.apache.ivy.core.module.descriptor.DefaultIncludeRule)2 URI (java.net.URI)1 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Configuration (org.apache.ivy.core.module.descriptor.Configuration)1 DefaultDependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor)1 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)1 DependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor)1 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)1