org.apache.ivy.core.module.id.ArtifactId Java Examples

The following examples show how to use org.apache.ivy.core.module.id.ArtifactId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IvyConfigurationProvider.java    From walkmod-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addArtifact(String groupId, String artifactId, String version) throws Exception {

		artifacts.add(groupId+":"+artifactId+":"+version);

		String[] dep = null;
		dep = new String[] { groupId, artifactId, version };
		if (md == null) {
			md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller",
					"working"));
		}
		DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0],
				dep[1], dep[2]), false, false, true);
		md.addDependency(dd);
		ExcludeRule er = new DefaultExcludeRule(new ArtifactId(new ModuleId("org.walkmod", "walkmod-core"),
				PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
				ExactPatternMatcher.INSTANCE, null);
		dd.addExcludeRule(null, er);
	}
 
Example #2
Source File: IvyConfigurationProvider.java    From walkmod-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addArtifact(String groupId, String artifactId, String version) throws Exception {

		artifacts.add(groupId+":"+artifactId+":"+version);

		String[] dep = null;
		dep = new String[] { groupId, artifactId, version };
		if (md == null) {
			md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller",
					"working"));
		}
		DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0],
				dep[1], dep[2]), false, false, true);
		md.addDependency(dd);
		ExcludeRule er = new DefaultExcludeRule(new ArtifactId(new ModuleId("org.walkmod", "walkmod-core"),
				PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
				ExactPatternMatcher.INSTANCE, null);
		dd.addExcludeRule(null, er);
	}
 
Example #3
Source File: IvyTranslations.java    From jeka with Apache License 2.0 6 votes vote down vote up
private static DefaultExcludeRule toExcludeRule(JkDepExclude depExclude, Iterable<String> allRootConfs) {
    final String type = depExclude.getType() == null ? PatternMatcher.ANY_EXPRESSION : depExclude
            .getType();
    final String ext = depExclude.getExt() == null ? PatternMatcher.ANY_EXPRESSION : depExclude
            .getExt();
    final ArtifactId artifactId = new ArtifactId(toModuleId(depExclude.getModuleId()), "*", type,
            ext);
    final DefaultExcludeRule result = new DefaultExcludeRule(artifactId,
            ExactPatternMatcher.INSTANCE, null);
    for (final JkScope scope : depExclude.getScopes()) {
        result.addConfiguration(scope.getName());
    }
    if (depExclude.getScopes().isEmpty()) {
        for (final String conf : allRootConfs) {
            result.addConfiguration(conf);
        }

    }
    return result;
}
 
Example #4
Source File: DefaultExcludeRuleConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #5
Source File: NameSpaceHelper.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public static ArtifactId transform(ArtifactId artifactId, NamespaceTransformer t) {
    if (t.isIdentity()) {
        return artifactId;
    }
    ModuleId mid = transform(artifactId.getModuleId(), t);
    if (mid.equals(artifactId.getModuleId())) {
        return artifactId;
    }
    return new ArtifactId(mid, artifactId.getName(), artifactId.getType(), artifactId.getExt());
}
 
Example #6
Source File: AbstractIncludeExcludeRule.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public AbstractIncludeExcludeRule(ArtifactId aid, PatternMatcher matcher,
                                  Map<String, String> extraAttributes) {
    super(null, extraAttributes);
    id = aid;
    patternMatcher = matcher;
    initStandardAttributes();
}
 
Example #7
Source File: DefaultModuleDescriptor.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Only works when namespace is properly set. The behaviour is not specified if namespace is
 * not set.
 *
 * @param moduleConfigurations String[]
 * @param artifactId ditto
 * @return boolean
 */
public boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId) {
    if (namespace != null) {
        artifactId = NameSpaceHelper
                .transform(artifactId, namespace.getFromSystemTransformer());
    }
    for (ExcludeRule rule : getExcludeRules(moduleConfigurations)) {
        if (MatcherHelper.matches(rule.getMatcher(), rule.getId(), artifactId)) {
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: DefaultDependencyDescriptor.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * only works when namespace is properly set. The behaviour is not specified if namespace is not
 * set.
 *
 * @param moduleConfigurations String[]
 * @param artifactId ditto
 * @return boolean
 */
public boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId) {
    if (namespace != null) {
        artifactId = NameSpaceHelper
                .transform(artifactId, namespace.getFromSystemTransformer());
    }
    for (ExcludeRule rule : getExcludeRules(moduleConfigurations)) {
        if (MatcherHelper.matches(rule.getMatcher(), rule.getId(), artifactId)) {
            return true;
        }
    }
    return false;
}
 
Example #9
Source File: IvyNode.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static Collection<Artifact> findArtifactsMatching(IncludeRule rule,
        Map<ArtifactId, Artifact> allArtifacts) {
    Collection<Artifact> ret = new ArrayList<>();
    for (Map.Entry<ArtifactId, Artifact> entry : allArtifacts.entrySet()) {
        if (MatcherHelper.matches(rule.getMatcher(), rule.getId(), entry.getKey())) {
            ret.add(entry.getValue());
        }
    }
    return ret;
}
 
Example #10
Source File: IvyNodeUsage.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static IncludeRule includeAllArtifacts() {
    final ArtifactId aid = new ArtifactId(
            new ModuleId(PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
            PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION);
    return new DefaultIncludeRule(aid, ExactPatternMatcher.INSTANCE, null);
}
 
Example #11
Source File: IvyExclude.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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 artifactPattern = (artifact == null) ? PatternMatcher.ANY_EXPRESSION : artifact;
    String typePattern = (type == null) ? PatternMatcher.ANY_EXPRESSION : type;
    String extPattern = (ext == null) ? typePattern : ext;
    ArtifactId aid = new ArtifactId(new ModuleId(orgPattern, modulePattern), artifactPattern,
            typePattern, extPattern);
    return new DefaultExcludeRule(aid, settings.getMatcher(matcherName), null);
}
 
Example #12
Source File: IvyDependencyExclude.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #13
Source File: DefaultExcludeRuleConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #14
Source File: DefaultExcludeRuleConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #15
Source File: DefaultExcludeRuleConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #16
Source File: IvyDependencyInclude.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: DefaultIncludeRule.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public DefaultIncludeRule(ArtifactId aid, PatternMatcher matcher, Map<String, String> extraAttributes) {
    super(aid, matcher, extraAttributes);
}
 
Example #18
Source File: GradlePomModuleDescriptorBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.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;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = determineExtension(type);
        handleSpecialTypes(type, extraAtt);

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put(EXTRA_ATTRIBUTE_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);
    }

    // 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(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #19
Source File: GradlePomModuleDescriptorBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.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;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = type;

        // if type is 'test-jar', the extension is 'jar' and the classifier is 'tests'
        // 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";
        }

        // we deal with classifiers by setting an extra attribute and forcing the
        // 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);
    }

    // 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(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #20
Source File: BintrayResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example #21
Source File: MatcherHelper.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public static boolean matches(PatternMatcher m, ArtifactId exp, ArtifactId aid) {
    return matches(m, exp.getModuleId(), aid.getModuleId())
            && matches(m, exp.getName(), aid.getName())
            && matches(m, exp.getExt(), aid.getExt())
            && matches(m, exp.getType(), aid.getType());
}
 
Example #22
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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;

        // if type is 'test-jar', the extension is 'jar' and the classifier is 'tests'
        // 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";
        }

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put("m:classifier", dep.getClassifier());
        }
        final 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
        final String optionalizedScope = dep.isOptional() ? "optional" : scope;
        depArtifact.addConfiguration(optionalizedScope);
        dd.addDependencyArtifact(optionalizedScope, depArtifact);
    }

    for (ModuleId excludedModule : excluded) {
        // This represents exclude all transitive dependencies, which we have already taken
        // 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);
    }
}
 
Example #23
Source File: DefaultExcludeRule.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public DefaultExcludeRule(ArtifactId aid, PatternMatcher matcher, Map<String, String> extraAttributes) {
    super(aid, matcher, extraAttributes);
}
 
Example #24
Source File: AbstractIncludeExcludeRule.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ArtifactId getId() {
    return id;
}
 
Example #25
Source File: GradlePomModuleDescriptorBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.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;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = determineExtension(type);
        handleSpecialTypes(type, extraAtt);

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put(EXTRA_ATTRIBUTE_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);
    }

    // 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(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #26
Source File: GradlePomModuleDescriptorBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.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;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = type;

        // if type is 'test-jar', the extension is 'jar' and the classifier is 'tests'
        // 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";
        }

        // we deal with classifiers by setting an extra attribute and forcing the
        // 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);
    }

    // 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(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #27
Source File: BundleInfoAdapter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * @param parser ModuleDescriptorParser
 * @param baseUri
 *            uri to help build the absolute url if the bundle info has a relative uri.
 * @param bundle BundleInfo
 * @param manifest Manifest
 * @param profileProvider ExecutionEnvironmentProfileProvider
 * @return DefaultModuleDescriptor ditto
 * @throws ProfileNotFoundException if descriptor is not found
 */
public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser,
        URI baseUri, BundleInfo bundle, Manifest manifest,
        ExecutionEnvironmentProfileProvider profileProvider) throws ProfileNotFoundException {
    DefaultModuleDescriptor md = new DefaultModuleDescriptor(parser, null);
    md.addExtraAttributeNamespace("o", Ivy.getIvyHomeURL() + "osgi");
    ModuleRevisionId mrid = asMrid(BundleInfo.BUNDLE_TYPE, bundle.getSymbolicName(),
        bundle.getVersion());
    md.setResolvedPublicationDate(new Date());
    md.setModuleRevisionId(mrid);

    md.addConfiguration(CONF_DEFAULT);
    md.addConfiguration(CONF_OPTIONAL);
    md.addConfiguration(CONF_TRANSITIVE_OPTIONAL);

    Set<String> exportedPkgNames = new HashSet<>(bundle.getExports().size());
    for (ExportPackage exportPackage : bundle.getExports()) {
        md.getExtraInfos().add(
            new ExtraInfoHolder(EXTRA_INFO_EXPORT_PREFIX + exportPackage.getName(),
                    exportPackage.getVersion().toString()));
        exportedPkgNames.add(exportPackage.getName());
        String[] confDependencies = new String[exportPackage.getUses().size() + 1];
        int i = 0;
        for (String use : exportPackage.getUses()) {
            confDependencies[i++] = CONF_USE_PREFIX + use;
        }
        confDependencies[i] = CONF_NAME_DEFAULT;
        md.addConfiguration(new Configuration(CONF_USE_PREFIX + exportPackage.getName(),
                PUBLIC, "Exported package " + exportPackage.getName(),
                confDependencies, true, null));
    }

    requirementAsDependency(md, bundle, exportedPkgNames);

    if (baseUri != null) {
        for (BundleArtifact bundleArtifact : bundle.getArtifacts()) {
            String type = "jar";
            String ext = "jar";
            String packaging = null;
            if (bundle.hasInnerClasspath() && !bundleArtifact.isSource()) {
                packaging = "bundle";
            }
            if ("packed".equals(bundleArtifact.getFormat())) {
                ext = "jar.pack.gz";
                if (packaging != null) {
                    packaging += ",pack200";
                } else {
                    packaging = "pack200";
                }
            }
            if (bundleArtifact.isSource()) {
                type = "source";
            }
            URI uri = bundleArtifact.getUri();
            if (uri != null) {
                DefaultArtifact artifact = buildArtifact(mrid, baseUri, uri, type, ext,
                    packaging);
                md.addArtifact(CONF_NAME_DEFAULT, artifact);
            }
        }
    }

    if (profileProvider != null) {
        for (String env : bundle.getExecutionEnvironments()) {
            ExecutionEnvironmentProfile profile = profileProvider.getProfile(env);
            if (profile == null) {
                throw new ProfileNotFoundException("Execution environment profile " + env
                        + " not found");
            }
            for (String pkg : profile.getPkgNames()) {
                ArtifactId id = new ArtifactId(ModuleId.newInstance(BundleInfo.PACKAGE_TYPE,
                    pkg), PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
                        PatternMatcher.ANY_EXPRESSION);
                DefaultExcludeRule rule = new DefaultExcludeRule(id,
                        ExactOrRegexpPatternMatcher.INSTANCE, null);
                for (String conf : md.getConfigurationsNames()) {
                    rule.addConfiguration(conf);
                }
                md.addExcludeRule(rule);
            }
        }
    }

    if (manifest != null) {
        for (Map.Entry<Object, Object> entries : manifest.getMainAttributes().entrySet()) {
            md.addExtraInfo(new ExtraInfoHolder(entries.getKey().toString(), entries.getValue()
                    .toString()));
        }
    }

    return md;
}
 
Example #28
Source File: IncludeRule.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the id of the described artifact, without revision information
 *
 * @return ArtifactId
 */
ArtifactId getId();
 
Example #29
Source File: ExcludeRule.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the id of the described artifact, without revision information
 *
 * @return ArtifactId
 */
ArtifactId getId();
 
Example #30
Source File: ModuleDescriptor.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * @param moduleConfs String[]
 * @param artifactId ditto
 * @return true if an exclude rule of this module attached to any of the given configurations
 *         matches the given artifact id, and thus exclude it
 */
boolean doesExclude(String[] moduleConfs, ArtifactId artifactId);