Search in sources :

Example 1 with ExcludeRule

use of org.gradle.api.artifacts.ExcludeRule in project gradle by gradle.

the class DefaultExcludeRuleContainerTest method assertExcludeRuleContainerHasCorrectExcludeRules.

private void assertExcludeRuleContainerHasCorrectExcludeRules(Set<ExcludeRule> excludeRules, Map... excludeRuleArgs) {
    List<Map> foundRules = new ArrayList<Map>();
    for (ExcludeRule excludeRule : excludeRules) {
        for (Map excludeRuleArg : excludeRuleArgs) {
            if (matchingExcludeRule(excludeRule, excludeRuleArg)) {
                foundRules.add(excludeRuleArg);
                continue;
            }
        }
    }
    assertThat(new HashSet<Map>(Arrays.asList(excludeRuleArgs)), equalTo(new HashSet<Map>(foundRules)));
}
Also used : ExcludeRule(org.gradle.api.artifacts.ExcludeRule)

Example 2 with ExcludeRule

use of org.gradle.api.artifacts.ExcludeRule in project gradle by gradle.

the class DefaultConfiguration method createCopy.

private DefaultConfiguration createCopy(Set<Dependency> dependencies, boolean recursive) {
    DetachedConfigurationsProvider configurationsProvider = new DetachedConfigurationsProvider();
    String newName = name + "Copy";
    Path newIdentityPath = identityPath.getParent().child(newName);
    Path newPath = path.getParent().child(newName);
    Factory<ResolutionStrategyInternal> childResolutionStrategy = resolutionStrategy != null ? Factories.constant(resolutionStrategy.copy()) : resolutionStrategyFactory;
    DefaultConfiguration copiedConfiguration = instantiator.newInstance(DefaultConfiguration.class, newIdentityPath, newPath, newName, configurationsProvider, resolver, listenerManager, metaDataProvider, childResolutionStrategy, projectAccessListener, projectFinder, configurationComponentMetaDataBuilder, fileCollectionFactory, componentIdentifierFactory, buildOperationExecutor, instantiator, artifactNotationParser, attributesFactory, moduleIdentifierFactory);
    configurationsProvider.setTheOnlyConfiguration(copiedConfiguration);
    // state, cachedResolvedConfiguration, and extendsFrom intentionally not copied - must re-resolve copy
    // copying extendsFrom could mess up dependencies when copy was re-resolved
    copiedConfiguration.visible = visible;
    copiedConfiguration.transitive = transitive;
    copiedConfiguration.description = description;
    copiedConfiguration.defaultDependencyActions = defaultDependencyActions;
    copiedConfiguration.canBeConsumed = canBeConsumed;
    copiedConfiguration.canBeResolved = canBeResolved;
    copiedConfiguration.getArtifacts().addAll(getAllArtifacts());
    if (!configurationAttributes.isEmpty()) {
        for (Attribute<?> attribute : configurationAttributes.keySet()) {
            Object value = configurationAttributes.getAttribute(attribute);
            copiedConfiguration.getAttributes().attribute(Cast.<Attribute<Object>>uncheckedCast(attribute), value);
        }
    }
    // todo An ExcludeRule is a value object but we don't enforce immutability for DefaultExcludeRule as strong as we
    // should (we expose the Map). We should provide a better API for ExcludeRule (I don't want to use unmodifiable Map).
    // As soon as DefaultExcludeRule is truly immutable, we don't need to create a new instance of DefaultExcludeRule.
    Set<Configuration> excludeRuleSources = new LinkedHashSet<Configuration>();
    excludeRuleSources.add(this);
    if (recursive) {
        excludeRuleSources.addAll(getHierarchy());
    }
    for (Configuration excludeRuleSource : excludeRuleSources) {
        for (ExcludeRule excludeRule : excludeRuleSource.getExcludeRules()) {
            copiedConfiguration.excludeRules.add(new DefaultExcludeRule(excludeRule.getGroup(), excludeRule.getModule()));
        }
    }
    DomainObjectSet<Dependency> copiedDependencies = copiedConfiguration.getDependencies();
    for (Dependency dependency : dependencies) {
        copiedDependencies.add(dependency.copy());
    }
    return copiedConfiguration;
}
Also used : Path(org.gradle.util.Path) LinkedHashSet(java.util.LinkedHashSet) ResolvedProjectConfiguration(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) TaskDependency(org.gradle.api.tasks.TaskDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) AbstractTaskDependency(org.gradle.api.internal.tasks.AbstractTaskDependency) Dependency(org.gradle.api.artifacts.Dependency) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) ExcludeRule(org.gradle.api.artifacts.ExcludeRule) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule)

Example 3 with ExcludeRule

use of org.gradle.api.artifacts.ExcludeRule in project gradle by gradle.

the class MavenPomFileGenerator method addDependency.

private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) {
    Dependency mavenDependency = new Dependency();
    mavenDependency.setGroupId(dependency.getGroupId());
    mavenDependency.setArtifactId(artifactId);
    mavenDependency.setVersion(mapToMavenSyntax(dependency.getVersion()));
    mavenDependency.setType(type);
    mavenDependency.setScope(scope);
    mavenDependency.setClassifier(classifier);
    for (ExcludeRule excludeRule : dependency.getExcludeRules()) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*"));
        exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*"));
        mavenDependency.addExclusion(exclusion);
    }
    getModel().addDependency(mavenDependency);
}
Also used : Exclusion(org.apache.maven.model.Exclusion) Dependency(org.apache.maven.model.Dependency) ExcludeRule(org.gradle.api.artifacts.ExcludeRule)

Example 4 with ExcludeRule

use of org.gradle.api.artifacts.ExcludeRule in project gradle by gradle.

the class IvyDescriptorFileGenerator method writeDependencies.

private void writeDependencies(OptionalAttributeXmlWriter xmlWriter) throws IOException {
    xmlWriter.startElement("dependencies");
    for (IvyDependencyInternal dependency : dependencies) {
        xmlWriter.startElement("dependency").attribute("org", dependency.getOrganisation()).attribute("name", dependency.getModule()).attribute("rev", dependency.getRevision()).attribute("conf", dependency.getConfMapping());
        if (!dependency.isTransitive()) {
            xmlWriter.attribute("transitive", "false");
        }
        for (DependencyArtifact dependencyArtifact : dependency.getArtifacts()) {
            printDependencyArtifact(dependencyArtifact, xmlWriter);
        }
        for (ExcludeRule excludeRule : dependency.getExcludeRules()) {
            writeDependencyExclude(excludeRule, xmlWriter);
        }
        xmlWriter.endElement();
    }
    xmlWriter.endElement();
}
Also used : IvyDependencyInternal(org.gradle.api.publish.ivy.internal.dependency.IvyDependencyInternal) DependencyArtifact(org.gradle.api.artifacts.DependencyArtifact) ExcludeRule(org.gradle.api.artifacts.ExcludeRule)

Aggregations

ExcludeRule (org.gradle.api.artifacts.ExcludeRule)4 LinkedHashSet (java.util.LinkedHashSet)1 Dependency (org.apache.maven.model.Dependency)1 Exclusion (org.apache.maven.model.Exclusion)1 Configuration (org.gradle.api.artifacts.Configuration)1 Dependency (org.gradle.api.artifacts.Dependency)1 DependencyArtifact (org.gradle.api.artifacts.DependencyArtifact)1 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)1 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)1 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)1 ResolvedProjectConfiguration (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration)1 AbstractTaskDependency (org.gradle.api.internal.tasks.AbstractTaskDependency)1 IvyDependencyInternal (org.gradle.api.publish.ivy.internal.dependency.IvyDependencyInternal)1 TaskDependency (org.gradle.api.tasks.TaskDependency)1 Path (org.gradle.util.Path)1