Java Code Examples for org.apache.maven.model.Dependency#getClassifier()

The following examples show how to use org.apache.maven.model.Dependency#getClassifier() . 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: ArtifactUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void mergeDependencyWithDefaults(Dependency dep, Dependency def) {
	if (dep.getScope() == null && def.getScope() != null) {
		dep.setScope(def.getScope());
		dep.setSystemPath(def.getSystemPath());
	}

	if (dep.getVersion() == null && def.getVersion() != null) {
		dep.setVersion(def.getVersion());
	}

	if (dep.getClassifier() == null && def.getClassifier() != null) {
		dep.setClassifier(def.getClassifier());
	}

	if (dep.getType() == null && def.getType() != null) {
		dep.setType(def.getType());
	}

	@SuppressWarnings("rawtypes")
	List exclusions = dep.getExclusions();
	if (exclusions == null || exclusions.isEmpty()) {
		dep.setExclusions(def.getExclusions());
	}
}
 
Example 2
Source File: ProjectManifestCustomizer.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * utility method to return {@link Dependency} as G:V:A:C maven coordinates
 *
 * @param dependency - the maven {@link Dependency} whose coordinates need to be computed
 * @return - the {@link Dependency} info as G:V:A:C string
 */
private static String asCoordinates(Dependency dependency) {
    StringBuilder dependencyCoordinates = new StringBuilder().
        append(dependency.getGroupId())
        .append(":")
        .append(dependency.getArtifactId())
        .append(":")
        .append(dependency.getVersion());

    if (dependency.getClassifier() != null) {
        dependencyCoordinates.append(":").append(dependency.getClassifier());
    }

    return dependencyCoordinates.toString();
}
 
Example 3
Source File: RESTCollector.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
/**
 * Translate a given set of pvr:dependencies into ArtifactRefs.
 * @param session the ManipulationSession
 * @param deps Set of ArtifactRef to store the results in.
 * @param dependencies dependencies to examine
 */
private static void recordDependencies( ManipulationSession session, Set<ArtifactRef> deps,
                                        Map<ArtifactRef, Dependency> dependencies )
{
    final VersioningState vs = session.getState( VersioningState.class );
    final RESTState state = session.getState( RESTState.class );

    for ( ArtifactRef pvr : dependencies.keySet() )
    {
        Dependency d = dependencies.get( pvr );

        SimpleScopedArtifactRef sa = new SimpleScopedArtifactRef(
                        new SimpleProjectVersionRef( pvr.asProjectRef(), handlePotentialSnapshotVersion( vs, pvr.getVersionString() ) ),
                        new SimpleTypeAndClassifier( d.getType(), d.getClassifier() ),
                        d.getScope() );

        boolean validate = true;

        // Don't bother adding an artifact with a property that couldn't be resolved.
        if (sa.getVersionString().contains( "$" ))
        {
            validate = false;
        }
        // If we are not (re)aligning suffixed dependencies then ignore them.
        // Null check to avoid problems with some tests where state is not instantiated.
        if ( state != null && !state.isRestSuffixAlign() &&
                        ( sa.getVersionString().contains( vs.getRebuildSuffix() ) ||
                                        vs.getSuffixAlternatives().stream().anyMatch( s -> sa.getVersionString().contains( s ) ) ) )
        {
            validate = false;
        }
        if (validate)
        {
            deps.add( sa );
        }
    }
}
 
Example 4
Source File: SimpleScopedArtifactRef.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
public SimpleScopedArtifactRef( final Dependency dependency )
{
    super( dependency.getGroupId(), dependency.getArtifactId(),
           isEmpty( dependency.getVersion() ) ? "*" : dependency.getVersion(),
           dependency.getType(), dependency.getClassifier());
    this.scope = dependency.getScope();
}
 
Example 5
Source File: DisplayDependencyUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of dependencies where the dependencies which are defined in the dependency management section have
 * been filtered out.
 *
 * @param dependencies The set of dependencies.
 * @param dependencyManagement The set of dependencies from the dependency management section.
 * @return A new set of dependencies which are from the set of dependencies but not from the set of dependency
 *         management dependencies.
 * @since 1.0-beta-1
 */
private static Set<Dependency> removeDependencyManagment( Set<Dependency> dependencies, Set<Dependency> dependencyManagement )
{
    Set<Dependency> result = new TreeSet<>( new DependencyComparator() );
    for ( Iterator<Dependency> i = dependencies.iterator(); i.hasNext(); )
    {
        Dependency c = i.next();
        boolean matched = false;
        Iterator<Dependency> j = dependencyManagement.iterator();
        while ( !matched && j.hasNext() )
        {
            Dependency t =j.next();
            if ( StringUtils.equals( t.getGroupId(), c.getGroupId() )
                && StringUtils.equals( t.getArtifactId(), c.getArtifactId() )
                && ( t.getScope() == null || StringUtils.equals( t.getScope(), c.getScope() ) )
                && ( t.getClassifier() == null || StringUtils.equals( t.getClassifier(), c.getClassifier() ) )
                && ( c.getVersion() == null || t.getVersion() == null
                    || StringUtils.equals( t.getVersion(), c.getVersion() ) ) )
            {
                matched = true;
                break;
            }
        }
        if ( !matched )
        {
            result.add( c );
        }
    }
    return result;
}
 
Example 6
Source File: AbstractVersionsDependencyUpdaterMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
protected String toString( Dependency d )
{
    StringBuilder buf = new StringBuilder();
    buf.append( d.getGroupId() );
    buf.append( ':' );
    buf.append( d.getArtifactId() );
    if ( d.getType() != null && d.getType().length() > 0 )
    {
        buf.append( ':' );
        buf.append( d.getType() );
    }
    else
    {
        buf.append( ":jar" );
    }
    if ( d.getClassifier() != null && d.getClassifier().length() > 0 )
    {
        buf.append( ':' );
        buf.append( d.getClassifier() );
    }
    if ( d.getVersion() != null && d.getVersion().length() > 0 )
    {
        buf.append( ":" );
        buf.append( d.getVersion() );
    }
    return buf.toString();
}
 
Example 7
Source File: DependencyUpdatesReport.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of dependencies where the dependencies which are defined in the dependency management section have
 * been filtered out.
 *
 * @param dependencies The set of dependencies.
 * @param dependencyManagement The set of dependencies from the dependency management section.
 * @return A new set of dependencies which are from the set of dependencies but not from the set of dependency
 *         management dependencies.
 * @since 1.0-beta-1
 */
private static Set<Dependency> removeDependencyManagment( Set<Dependency> dependencies, Set<Dependency> dependencyManagement )
{
    Set<Dependency> result = new TreeSet<>( new DependencyComparator() );
    for ( Dependency c : dependencies )
    {
        boolean matched = false;
        Iterator<Dependency> j = dependencyManagement.iterator();
        while ( !matched && j.hasNext() )
        {
            Dependency t = j.next();
            if ( StringUtils.equals( t.getGroupId(), c.getGroupId() )
                && StringUtils.equals( t.getArtifactId(), c.getArtifactId() )
                && ( t.getScope() == null || StringUtils.equals( t.getScope(), c.getScope() ) )
                && ( t.getClassifier() == null || StringUtils.equals( t.getClassifier(), c.getClassifier() ) )
                && ( c.getVersion() == null || t.getVersion() == null
                    || StringUtils.equals( t.getVersion(), c.getVersion() ) ) )
            {
                matched = true;
                break;
            }
        }
        if ( !matched )
        {
            result.add( c );
        }
    }
    return result;
}
 
Example 8
Source File: ProjectManifestCustomizer.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * utility method to return {@link Dependency} as G:V:A:C maven coordinates
 *
 * @param dependency - the maven {@link Dependency} whose coordinates need to be computed
 * @return - the {@link Dependency} info as G:V:A:C string
 */
private static String asCoordinates(Dependency dependency) {
    StringBuilder dependencyCoordinates = new StringBuilder().
        append(dependency.getGroupId())
        .append(":")
        .append(dependency.getArtifactId())
        .append(":")
        .append(dependency.getVersion());

    if (dependency.getClassifier() != null) {
        dependencyCoordinates.append(":").append(dependency.getClassifier());
    }

    return dependencyCoordinates.toString();
}
 
Example 9
Source File: GenerateMetadataMojo.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private Artifact toArtifact(final Dependency dependency) {
    final ArtifactTypeRegistry registry = session.getArtifactTypeRegistry();
    final ArtifactType type = registry.get(dependency.getType());

    return new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(),
        type.getExtension(), dependency.getVersion(), type);
}
 
Example 10
Source File: Dependencies.java    From flatten-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * @param dependency is the {@link Dependency} to {@link Map#put(Object, Object) put} or {@link Map#get(Object) get}
 *            .
 * @return the {@link java.util.Map.Entry#getKey() key} for the {@link Dependency}.
 */
protected String getKey( Dependency dependency )
{

    return dependency.getManagementKey() + ":" + dependency.getClassifier();
}
 
Example 11
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void writeDependency(Dependency dependency, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();
    if (dependency.getGroupId() != null) {
        writeValue(serializer, "groupId", dependency.getGroupId(), dependency);
    }
    if (dependency.getArtifactId() != null) {
        writeValue(serializer, "artifactId", dependency.getArtifactId(), dependency);
    }
    if (dependency.getVersion() != null) {
        writeValue(serializer, "version", dependency.getVersion(), dependency);
    }
    if ((dependency.getType() != null) && !dependency.getType().equals("jar")) {
        writeValue(serializer, "type", dependency.getType(), dependency);
    }
    if (dependency.getClassifier() != null) {
        writeValue(serializer, "classifier", dependency.getClassifier(), dependency);
    }
    if (dependency.getScope() != null) {
        writeValue(serializer, "scope", dependency.getScope(), dependency);
    }
    if (dependency.getSystemPath() != null) {
        writeValue(serializer, "systemPath", dependency.getSystemPath(), dependency);
    }
    if ((dependency.getExclusions() != null) && (dependency.getExclusions().size() > 0)) {
        serializer.startTag(NAMESPACE, "exclusions");
        for (Iterator<Exclusion> iter = dependency.getExclusions().iterator(); iter.hasNext();) {
            Exclusion o = iter.next();
            writeExclusion(o, "exclusion", serializer);
        }
        serializer.endTag(NAMESPACE, "exclusions");
    }
    if (dependency.getOptional() != null) {
        writeValue(serializer, "optional", dependency.getOptional(), dependency);
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(dependency, "", start, b.length());
}
 
Example 12
Source File: AddDependencyPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private NBVersionInfo convert2VInfo(Dependency dep) {
    return new NBVersionInfo(null, dep.getGroupId(), dep.getArtifactId(),
            dep.getVersion(), dep.getType(), null, null, null, dep.getClassifier());
}
 
Example 13
Source File: CombinedQuarkusPlatformDescriptor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
DepKey(Dependency dep) {
    this(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier(), dep.getType());
}
 
Example 14
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 4 votes vote down vote up
private Artifact toArtifact(Dependency dependency) {
    return new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType(), dependency.getClassifier(),
            getArtifactHandler());
}
 
Example 15
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 4 votes vote down vote up
private static String dependencyKey(Dependency dependency) {
    return dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getType() + ":" + dependency.getClassifier();
}
 
Example 16
Source File: Extensions.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public static AppArtifactCoords toCoords(final Dependency d) {
    return new AppArtifactCoords(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion());
}
 
Example 17
Source File: Project.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
private void resolveDeps( MavenSessionHandler session, List<Dependency> deps, boolean includeManagedDependencies,
                          Map<ArtifactRef, Dependency> resolvedDependencies )
                throws ManipulationException
{
    ListIterator<Dependency> iterator = deps.listIterator( deps.size() );

    // Iterate in reverse order so later deps take precedence
    while ( iterator.hasPrevious() )
    {
        Dependency d = iterator.previous();

        if ( session.getExcludedScopes().contains( d.getScope() ) )
        {
            logger.debug( "Ignoring dependency {} as scope matched {}", d, session.getExcludedScopes());
            continue;
        }

        String g = PropertyResolver.resolveInheritedProperties( session, this, "${project.groupId}".equals( d.getGroupId() ) ?
                        getGroupId() :
                        d.getGroupId() );
        String a = PropertyResolver.resolveInheritedProperties( session, this, "${project.artifactId}".equals( d.getArtifactId() ) ?
                        getArtifactId() :
                        d.getArtifactId() );
        String v = PropertyResolver.resolveInheritedProperties( session, this, d.getVersion() );

        if ( includeManagedDependencies && isEmpty( v ) )
        {
            v = "*";
        }
        if ( isNotEmpty( g ) && isNotEmpty( a ) && isNotEmpty( v ) )
        {
            SimpleScopedArtifactRef sar = new SimpleScopedArtifactRef( g, a, v, d.getType(), d.getClassifier(), d.getScope() );

            // If the GAVTC already exists within the map it means we have a duplicate entry. While Maven
            // technically allows this it does warn that this leads to unstable models. In PME case this breaks
            // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate.
            if ( resolvedDependencies.containsKey( sar ) )
            {
                logger.error( "Found duplicate entry within dependency list. Key of {} and dependency {}", sar, d );
                iterator.remove();
            }
            else
            {
                Dependency old = resolvedDependencies.put( sar, d );

                if ( old != null )
                {
                    logger.error( "Internal project dependency resolution failure ; replaced {} in store by {}:{}:{}.",
                                  old, g, a, v );
                    throw new ManipulationException(
                                    "Internal project dependency resolution failure ; replaced {} by {}", old, d );
                }
            }
        }
    }
}
 
Example 18
Source File: Extensions.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public static AppArtifactKey toKey(final Dependency dependency) {
    return new AppArtifactKey(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(),
            dependency.getType());
}
 
Example 19
Source File: BomGeneratorMojo.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
private void overwriteDependencyManagement(Document pom, List<Dependency> dependencies) throws Exception {
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile("/project/dependencyManagement/dependencies");

    NodeList nodes = (NodeList) expr.evaluate(pom, XPathConstants.NODESET);
    if (nodes.getLength() == 0) {
        throw new IllegalStateException("No dependencies found in the dependencyManagement section of the current pom");
    }

    Node dependenciesSection = nodes.item(0);
    // cleanup the dependency management section
    while (dependenciesSection.hasChildNodes()) {
        Node child = dependenciesSection.getFirstChild();
        dependenciesSection.removeChild(child);
    }

    for (Dependency dep : dependencies) {

        if ("target".equals(dep.getArtifactId())) {
            // skip invalid artifact that somehow gets included
            continue;
        }

        Element dependencyEl = pom.createElement("dependency");

        Element groupIdEl = pom.createElement("groupId");
        groupIdEl.setTextContent(dep.getGroupId());
        dependencyEl.appendChild(groupIdEl);

        Element artifactIdEl = pom.createElement("artifactId");
        artifactIdEl.setTextContent(dep.getArtifactId());
        dependencyEl.appendChild(artifactIdEl);

        Element versionEl = pom.createElement("version");
        versionEl.setTextContent(dep.getVersion());
        dependencyEl.appendChild(versionEl);

        if (!"jar".equals(dep.getType())) {
            Element typeEl = pom.createElement("type");
            typeEl.setTextContent(dep.getType());
            dependencyEl.appendChild(typeEl);
        }

        if (dep.getClassifier() != null) {
            Element classifierEl = pom.createElement("classifier");
            classifierEl.setTextContent(dep.getClassifier());
            dependencyEl.appendChild(classifierEl);
        }

        if (dep.getScope() != null && !"compile".equals(dep.getScope())) {
            Element scopeEl = pom.createElement("scope");
            scopeEl.setTextContent(dep.getScope());
            dependencyEl.appendChild(scopeEl);
        }

        if (dep.getExclusions() != null && !dep.getExclusions().isEmpty()) {

            Element exclsEl = pom.createElement("exclusions");

            for (Exclusion e : dep.getExclusions()) {
                Element exclEl = pom.createElement("exclusion");

                Element groupIdExEl = pom.createElement("groupId");
                groupIdExEl.setTextContent(e.getGroupId());
                exclEl.appendChild(groupIdExEl);

                Element artifactIdExEl = pom.createElement("artifactId");
                artifactIdExEl.setTextContent(e.getArtifactId());
                exclEl.appendChild(artifactIdExEl);

                exclsEl.appendChild(exclEl);
            }

            dependencyEl.appendChild(exclsEl);
        }


        dependenciesSection.appendChild(dependencyEl);
    }


}