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

The following examples show how to use org.apache.maven.model.Dependency#getType() . 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: 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 3
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 4
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 5
Source File: BomGeneratorMojo.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
private String comparisonKey(Dependency dependency) {
    return dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + (dependency.getType() != null ? dependency.getType() : "jar");
}
 
Example 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: MavenUtils.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
private static String getDependencyString(Dependency dependency) {
	String ds=dependency.getGroupId()+":"+dependency.getArtifactId()+":"+dependency.getVersion()+":"+dependency.getType()+":";
	return ds;
}
 
Example 14
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 );
                }
            }
        }
    }
}