Java Code Examples for org.apache.maven.model.Exclusion#setArtifactId()

The following examples show how to use org.apache.maven.model.Exclusion#setArtifactId() . 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: MavenPomFileGenerator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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(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);
}
 
Example 2
Source File: MavenPomFileGenerator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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(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);
}
 
Example 3
Source File: ExternalBomResolver.java    From sundrio with Apache License 2.0 6 votes vote down vote up
private Dependency toMavenDependency(org.eclipse.aether.graph.Dependency from) {
    org.eclipse.aether.artifact.Artifact fromArt = from.getArtifact();

    Dependency dependency = new Dependency();
    dependency.setGroupId(fromArt.getGroupId());
    dependency.setArtifactId(fromArt.getArtifactId());
    dependency.setVersion(fromArt.getVersion());
    dependency.setType(fromArt.getExtension());
    dependency.setScope(Artifact.SCOPE_COMPILE.equals(from.getScope()) ? null : from.getScope());
    dependency.setClassifier(fromArt.getClassifier());
    dependency.setOptional(dependency.isOptional());

    if (from.getExclusions() != null && from.getExclusions().size() > 0) {
        List<Exclusion> exclusions = new LinkedList<Exclusion>();
        for (org.eclipse.aether.graph.Exclusion fromEx : from.getExclusions()) {
            Exclusion ex = new Exclusion();
            ex.setGroupId(fromEx.getGroupId());
            ex.setArtifactId(fromEx.getArtifactId());
            exclusions.add(ex);
        }
        dependency.setExclusions(exclusions);
    }

    return dependency;
}
 
Example 4
Source File: DetectExtension.java    From os-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static void interpolate(Map<String, String> dict, Iterable<Dependency> dependencies) {
    if (dependencies == null) {
        return;
    }

    for (Dependency d: dependencies) {
        d.setGroupId(interpolate(dict, d.getGroupId()));
        d.setArtifactId(interpolate(dict, d.getArtifactId()));
        d.setVersion(interpolate(dict, d.getVersion()));
        d.setClassifier(interpolate(dict, d.getClassifier()));
        d.setSystemPath(interpolate(dict, d.getSystemPath()));
        for (Exclusion e: d.getExclusions()) {
            e.setGroupId(interpolate(dict, e.getGroupId()));
            e.setArtifactId(interpolate(dict, e.getArtifactId()));
        }
    }
}
 
Example 5
Source File: StackResolutionTest.java    From vertx-stack with Apache License 2.0 6 votes vote down vote up
@Test
public void testConflictManagementUsingExclusions() {
  Dependency dependency = new Dependency("io.vertx", "vertx-core", "3.1.0");
  Exclusion exclusion1 = new Exclusion();
  exclusion1.setGroupId("com.fasterxml.jackson.core");
  exclusion1.setArtifactId("jackson-databind");
  Exclusion exclusion2 = new Exclusion();
  exclusion2.setGroupId("com.fasterxml.jackson.core");
  exclusion2.setArtifactId("jackson-core");
  dependency.addExclusion(exclusion1);
  dependency.addExclusion(exclusion2);
  Stack stack = new Stack()
      .addDependency(dependency)
      // Not the version used by vert.x
      .addDependency(new Dependency("com.fasterxml.jackson.core", "jackson-databind", "2.4.1.3"));
  StackResolution resolution = new StackResolution(stack, root, STRICT);
  resolution.resolve();
  Map<String, File> map = resolution.resolve();
  assertThat(map).containsKey("io.vertx:vertx-core:jar:3.1.0");
  assertThat(map).containsKey("com.fasterxml.jackson.core:jackson-databind:jar:2.4.1.3");
}
 
Example 6
Source File: StackResolutionTest.java    From vertx-stack with Apache License 2.0 6 votes vote down vote up
@Test
public void testTheResolutionWhenATransitiveDependencyIsMissingButExcluded() {
  File local = new File("target/test-repos/incomplete");
  new LocalRepoBuilder(local).addArtifact(new LocalArtifact("org.acme", "acme", "1.0").generateMainArtifact()
      .addDependency(new LocalDependency("org.acme", "acme-missing", "1.0"))).build();

  Exclusion exclusion = new Exclusion();
  exclusion.setArtifactId("acme-missing");
  exclusion.setGroupId("org.acme");

  Dependency dependency = new Dependency("org.acme", "acme", "1.0", "txt");
  dependency.addExclusion(exclusion);

  Stack stack = new Stack()
      .addDependency(new Dependency("io.vertx", "vertx-core", "3.1.0"))
      .addDependency(dependency);
  StackResolutionOptions options = new StackResolutionOptions().setFailOnConflicts(true)
      .setLocalRepository(local.getAbsolutePath());
  StackResolution resolution = new StackResolution(stack, root, options);
  Map<String, File> map = resolution.resolve();
  assertThat(map).containsKey("io.vertx:vertx-core:jar:3.1.0");
  assertThat(map).containsKey("org.acme:acme:txt:1.0");
}
 
Example 7
Source File: StackResolutionTest.java    From vertx-stack with Apache License 2.0 6 votes vote down vote up
@Test
public void testTheResolutionWhenATransitiveDependencyIsMissingButOptional() {
  File local = new File("target/test-repos/incomplete");
  new LocalRepoBuilder(local).addArtifact(new LocalArtifact("org.acme", "acme", "1.0").generateMainArtifact()
      .addDependency(new LocalDependency("org.acme", "acme-missing", "1.0").optional(true))).build();

  Exclusion exclusion = new Exclusion();
  exclusion.setArtifactId("acme-missing");
  exclusion.setGroupId("org.acme");

  Dependency dependency = new Dependency("org.acme", "acme", "1.0", "txt");
  Stack stack = new Stack()
      .addDependency(new Dependency("io.vertx", "vertx-core", "3.1.0"))
      .addDependency(dependency);
  StackResolutionOptions options = new StackResolutionOptions().setFailOnConflicts(true)
      .setLocalRepository(local.getAbsolutePath());
  StackResolution resolution = new StackResolution(stack, root, options);
  Map<String, File> map = resolution.resolve();
  assertThat(map).containsKey("io.vertx:vertx-core:jar:3.1.0");
  assertThat(map).containsKey("org.acme:acme:txt:1.0");
}
 
Example 8
Source File: DefaultExcludeRuleConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Exclusion convert(ExcludeRule excludeRule) {
    if (isConvertable(excludeRule)) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId(excludeRule.getGroup());
        exclusion.setArtifactId(excludeRule.getModule());
        return exclusion;
    }
    return null;
}
 
Example 9
Source File: DefaultExcludeRuleConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Exclusion convert(ExcludeRule excludeRule) {
    if (isConvertable(excludeRule)) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId(excludeRule.getGroup());
        exclusion.setArtifactId(excludeRule.getModule());
        return exclusion;
    }
    return null;
}
 
Example 10
Source File: MavenCoordinatesResolver.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
static Dependency createDependencyFromCoordinates(String coordinatesString, boolean excludeTransitive) {
    final String[] coordinates = coordinatesString.split(":");
    int amountOfCoordinates = coordinates.length;
    if (amountOfCoordinates < 2) {
        throw new IllegalArgumentException(
            "Coordinates of the specified strategy [" + coordinatesString + "] doesn't have the correct format.");
    }
    final Dependency dependency = new Dependency();
    dependency.setGroupId(coordinates[0]);
    dependency.setArtifactId(coordinates[1]);
    if (amountOfCoordinates == 3) {
        dependency.setVersion(coordinates[2]);
    } else if (amountOfCoordinates >= 4) {
        dependency.setType(coordinates[2].isEmpty() ? "jar" : coordinates[2]);
        dependency.setClassifier(coordinates[3]);
    }
    if (amountOfCoordinates >= 5) {
        dependency.setVersion(coordinates[4]);
    }
    if (amountOfCoordinates == 6) {
        dependency.setScope(coordinates[5]);
    }
    if (dependency.getVersion() == null || dependency.getVersion().isEmpty()) {
        dependency.setVersion(ExtensionVersion.version().toString());
    }
    if (excludeTransitive) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId("*");
        exclusion.setArtifactId("*");
        dependency.setExclusions(Arrays.asList(exclusion));
    }
    return dependency;
}
 
Example 11
Source File: DefaultExcludeRuleConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Exclusion convert(ExcludeRule excludeRule) {
    if (isConvertable(excludeRule)) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId(excludeRule.getGroup());
        exclusion.setArtifactId(excludeRule.getModule());
        return exclusion;
    }
    return null;
}
 
Example 12
Source File: DefaultExcludeRuleConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Exclusion convert(ExcludeRule excludeRule) {
    if (isConvertable(excludeRule)) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId(excludeRule.getGroup());
        exclusion.setArtifactId(excludeRule.getModule());
        return exclusion;
    }
    return null;
}
 
Example 13
Source File: CommonManipulator.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
/**
 * Apply explicit overrides to a set of dependencies from a project. The explicit overrides come from
 * dependencyExclusion. However they have to be separated out from standard overrides so we can easily
 * ignore any property references (and overwrite them).
 *
 * @param project the current Project
 * @param dependencies dependencies to check
 * @param explicitOverrides a custom map to handle wildcard overrides
 * @param state the CommonState, to retrieve Common Properties
 * @param versionPropertyUpdateMap properties to update
 * @throws ManipulationException if an error occurs
 */
protected void applyExplicitOverrides( final Project project,
                                       final Map<? extends ProjectVersionRef, ? extends InputLocationTracker> dependencies,
                                       final WildcardMap<String> explicitOverrides, final CommonState state,
                                       final Map<Project, Map<String, PropertyMapper>> versionPropertyUpdateMap )
                throws ManipulationException
{
    // Apply matching overrides to dependencies
    for ( final ProjectVersionRef projectVersionRef : dependencies.keySet() )
    {
        final ProjectRef groupIdArtifactId = new SimpleProjectRef( projectVersionRef.getGroupId(), projectVersionRef.getArtifactId() );

        if ( explicitOverrides.containsKey( groupIdArtifactId ) )
        {
            final String overrideVersion = explicitOverrides.get( groupIdArtifactId );
            final DependencyPluginWrapper wrapper = new DependencyPluginWrapper( dependencies.get( projectVersionRef ) );
            final String oldVersion = wrapper.getVersion();

            if ( isEmpty( overrideVersion ) || isEmpty( oldVersion ) )
            {
                if ( isEmpty( oldVersion ) )
                {
                    logger.debug( "Unable to force align as no existing version field to update for " + groupIdArtifactId + "; ignoring" );
                }
                else
                {
                    logger.warn( "Unable to force align as override version is empty for " + groupIdArtifactId
                                                 + "; ignoring" );
                }
            }
            else
            {
                for ( String target : overrideVersion.split( "," ) )
                {
                    if ( target.startsWith( "+" ) )
                    {
                        logger.info( "Adding dependency exclusion {} to dependency {} ", target.substring( 1 ),
                                     projectVersionRef );
                        Exclusion e = new Exclusion();
                        e.setGroupId( target.substring( 1 ).split( ":" )[0] );
                        e.setArtifactId( target.split( ":" )[1] );
                        wrapper.addExclusion( e );
                    }
                    else
                    {
                        logger.info( "Explicit overrides : force aligning {} to {}.", groupIdArtifactId, target );

                        if ( !PropertiesUtils.cacheProperty( project, state, versionPropertyUpdateMap, oldVersion,
                                                             target, projectVersionRef, true ) )
                        {
                            if ( oldVersion.contains( "${" ) )
                            {
                                // This might happen if the property was inherited from an external parent.
                                logger.warn( "Overriding version with {} when old version contained a property {} "
                                                             + "that was not found in the current project",
                                             target, oldVersion );
                            }
                            // Not checking strict version alignment here as explicit overrides take priority.
                            wrapper.setVersion( target );
                        }
                    }
                }
            }
        }
    }
}