Search in sources :

Example 1 with DefaultExcludeRule

use of org.apache.ivy.core.module.descriptor.DefaultExcludeRule 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 DefaultExcludeRule

use of org.apache.ivy.core.module.descriptor.DefaultExcludeRule 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 3 with DefaultExcludeRule

use of org.apache.ivy.core.module.descriptor.DefaultExcludeRule in project walkmod-core by walkmod.

the class IvyConfigurationProvider method addArtifact.

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

Example 4 with DefaultExcludeRule

use of org.apache.ivy.core.module.descriptor.DefaultExcludeRule in project ant-ivy by apache.

the class BundleInfoAdapter method toModuleDescriptor.

/**
 * @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;
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) ExtraInfoHolder(org.apache.ivy.core.module.descriptor.ExtraInfoHolder) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) URI(java.net.URI) Date(java.util.Date) DefaultExcludeRule(org.apache.ivy.core.module.descriptor.DefaultExcludeRule) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) HashSet(java.util.HashSet)

Example 5 with DefaultExcludeRule

use of org.apache.ivy.core.module.descriptor.DefaultExcludeRule in project ant-ivy by apache.

the class IvyDependency method asDependencyDescriptor.

DependencyDescriptor asDependencyDescriptor(ModuleDescriptor md, String masterConf, IvySettings settings) {
    if (org == null) {
        throw new BuildException("'org' is required on ");
    }
    if (name == null) {
        throw new BuildException("'name' is required when using inline mode");
    }
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(org, name, branch, rev);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, force, changing, transitive);
    if (conf != null) {
        dd.addDependencyConfiguration(masterConf, conf);
    } else {
        dd.addDependencyConfiguration(masterConf, "*");
    }
    for (IvyDependencyConf c : confs) {
        c.addConf(dd, masterConf);
    }
    for (IvyDependencyArtifact artifact : artifacts) {
        artifact.addArtifact(dd, masterConf);
    }
    for (IvyDependencyExclude exclude : excludes) {
        DefaultExcludeRule rule = exclude.asRule(settings);
        dd.addExcludeRule(masterConf, rule);
    }
    for (IvyDependencyInclude include : includes) {
        DefaultIncludeRule rule = include.asRule(settings);
        dd.addIncludeRule(masterConf, rule);
    }
    return dd;
}
Also used : DefaultExcludeRule(org.apache.ivy.core.module.descriptor.DefaultExcludeRule) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildException(org.apache.tools.ant.BuildException) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultIncludeRule(org.apache.ivy.core.module.descriptor.DefaultIncludeRule)

Aggregations

DefaultExcludeRule (org.apache.ivy.core.module.descriptor.DefaultExcludeRule)7 ArtifactId (org.apache.ivy.core.module.id.ArtifactId)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)4 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)4 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)3 HashMap (java.util.HashMap)2 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)2 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)2 BuildException (org.apache.tools.ant.BuildException)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Ivy (org.apache.ivy.Ivy)1 Configuration (org.apache.ivy.core.module.descriptor.Configuration)1 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)1 DefaultDependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor)1