protected void mergeDependency_Classifier( Dependency target, Dependency source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getClassifier(); if ( src != null ) { if ( sourceDominant || target.getClassifier() == null ) { target.setClassifier( src ); target.setLocation( "classifier", source.getLocation( "classifier" ) ); } } }
private void validateEffectiveModelAgainstDependency( String prefix, ModelProblemCollector problems, Model m, Dependency d, ModelBuildingRequest request ) { String key = d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion() + ( d.getClassifier() != null ? ":" + d.getClassifier() : "" ); String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion(); if ( key.equals( mKey ) ) { // This means a module which is build has a dependency which has the same // groupId, artifactId, version and classifier coordinates. This is in consequence // a self reference or in other words a circular reference which can not being resolved. addViolation( problems, Severity.FATAL, Version.V31, prefix + " " + key, key, "is referencing itself.", d ); } }
private void validate20RawDependenciesSelfReferencing( ModelProblemCollector problems, Model m, List<Dependency> dependencies, String prefix, ModelBuildingRequest request ) { // We only check for groupId/artifactId/version/classifier cause if there is another // module with the same groupId/artifactId/version/classifier this will fail the build // earlier like "Project '...' is duplicated in the reactor. // So it is sufficient to check only groupId/artifactId/version/classifier and not the // packaging type. for ( Dependency dependency : dependencies ) { String key = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion() + ( dependency.getClassifier() != null ? ":" + dependency.getClassifier() : "" ); String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion(); if ( key.equals( mKey ) ) { // This means a module which is build has a dependency which has the same // groupId, artifactId, version and classifier coordinates. This is in consequence // a self reference or in other words a circular reference which can not being resolved. addViolation( problems, Severity.FATAL, Version.V31, prefix + " " + key, key, "is referencing itself.", dependency ); } } }
private static boolean dependenciesEquals( List<Dependency> a, List<Dependency> b ) { if ( a.size() != b.size() ) { return false; } Iterator<Dependency> aI = a.iterator(); Iterator<Dependency> bI = b.iterator(); while ( aI.hasNext() ) { Dependency aD = aI.next(); Dependency bD = bI.next(); boolean r = Objects.equals( aD.getGroupId(), bD.getGroupId() ) // && Objects.equals( aD.getArtifactId(), bD.getArtifactId() ) // && Objects.equals( aD.getVersion(), bD.getVersion() ) // && Objects.equals( aD.getType(), bD.getType() ) // && Objects.equals( aD.getClassifier(), bD.getClassifier() ) // && Objects.equals( aD.getScope(), bD.getScope() ); r &= exclusionsEquals( aD.getExclusions(), bD.getExclusions() ); if ( !r ) { return false; } } return true; }
public static int pluginHashCode( Plugin plugin ) { int hash = 17; hash = hash * 31 + Objects.hashCode( plugin.getGroupId() ); hash = hash * 31 + Objects.hashCode( plugin.getArtifactId() ); hash = hash * 31 + Objects.hashCode( plugin.getVersion() ); hash = hash * 31 + ( plugin.isExtensions() ? 1 : 0 ); for ( Dependency dependency : plugin.getDependencies() ) { hash = hash * 31 + Objects.hashCode( dependency.getGroupId() ); hash = hash * 31 + Objects.hashCode( dependency.getArtifactId() ); hash = hash * 31 + Objects.hashCode( dependency.getVersion() ); hash = hash * 31 + Objects.hashCode( dependency.getType() ); hash = hash * 31 + Objects.hashCode( dependency.getClassifier() ); hash = hash * 31 + Objects.hashCode( dependency.getScope() ); for ( Exclusion exclusion : dependency.getExclusions() ) { hash = hash * 31 + Objects.hashCode( exclusion.getGroupId() ); hash = hash * 31 + Objects.hashCode( exclusion.getArtifactId() ); } } return hash; }
private 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() ); } List exclusions = dep.getExclusions(); if ( exclusions == null || exclusions.isEmpty() ) { dep.setExclusions( def.getExclusions() ); } }
private static Artifact createDependencyArtifact( ArtifactFactory factory, Dependency dependency, String inheritedScope, ArtifactFilter inheritedFilter ) throws InvalidVersionSpecificationException { String effectiveScope = getEffectiveScope( dependency.getScope(), inheritedScope ); if ( effectiveScope == null ) { return null; } VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); Artifact dependencyArtifact = factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange, dependency.getType(), dependency.getClassifier(), effectiveScope, dependency.isOptional() ); ArtifactFilter dependencyFilter = inheritedFilter; if ( dependencyFilter != null && !dependencyFilter.include( dependencyArtifact ) ) { return null; } if ( Artifact.SCOPE_SYSTEM.equals( effectiveScope ) ) { dependencyArtifact.setFile( new File( dependency.getSystemPath() ) ); } dependencyArtifact.setDependencyFilter( createDependencyFilter( dependency, dependencyFilter ) ); return dependencyArtifact; }
d.getClassifier(), d.getScope(), d.isOptional() );
d.getClassifier(), d.getScope(), d.isOptional() );
public static Dependency toDependency( org.apache.maven.model.Dependency dependency, ArtifactTypeRegistry stereotypes ) { ArtifactType stereotype = stereotypes.get( dependency.getType() ); if ( stereotype == null ) { stereotype = new DefaultArtifactType( dependency.getType() ); } boolean system = dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0; Map<String, String> props = null; if ( system ) { props = Collections.singletonMap( ArtifactProperties.LOCAL_PATH, dependency.getSystemPath() ); } Artifact artifact = new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null, dependency.getVersion(), props, stereotype ); List<Exclusion> exclusions = new ArrayList<>( dependency.getExclusions().size() ); for ( org.apache.maven.model.Exclusion exclusion : dependency.getExclusions() ) { exclusions.add( toExclusion( exclusion ) ); } Dependency result = new Dependency( artifact, dependency.getScope(), dependency.getOptional() != null ? dependency.isOptional() : null, exclusions ); return result; }
private Dependency convert( org.apache.maven.model.Dependency dependency, ArtifactTypeRegistry stereotypes ) { ArtifactType stereotype = stereotypes.get( dependency.getType() ); if ( stereotype == null ) { stereotype = new DefaultArtifactType( dependency.getType() ); } boolean system = dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0; Map<String, String> props = null; if ( system ) { props = Collections.singletonMap( ArtifactProperties.LOCAL_PATH, dependency.getSystemPath() ); } Artifact artifact = new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null, dependency.getVersion(), props, stereotype ); List<Exclusion> exclusions = new ArrayList<>( dependency.getExclusions().size() ); for ( org.apache.maven.model.Exclusion exclusion : dependency.getExclusions() ) { exclusions.add( convert( exclusion ) ); } Dependency result = new Dependency( artifact, dependency.getScope(), dependency.getOptional() != null ? dependency.isOptional() : null, exclusions ); return result; }
versionRange, d.getType(), d.getClassifier(), scope, inheritedScope, d.isOptional() );
/** * Converts the dependency into a dependency node * * @param buildingRequest the Maven building request * @param parent the parent node * @param dependency the dependency to convert * @return the resulting dependency node * @throws ArtifactResolverException thrown if there is an error during * conversion */ private DependencyNode toDependencyNode(ProjectBuildingRequest buildingRequest, DependencyNode parent, org.apache.maven.model.Dependency dependency) throws ArtifactResolverException { final DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); coordinate.setGroupId(dependency.getGroupId()); coordinate.setArtifactId(dependency.getArtifactId()); coordinate.setVersion(dependency.getVersion()); coordinate.setExtension(dependency.getType()); coordinate.setClassifier(dependency.getClassifier()); final Artifact artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact(); artifact.setScope(dependency.getScope()); return new DefaultDependencyNode(parent, artifact, dependency.getVersion(), dependency.getScope(), null); }
"must be 'pom' to import the managed dependencies.", dependency ); else if ( StringUtils.isNotEmpty( dependency.getClassifier() ) )
d.getClassifier(), d.getScope(), d.isOptional() ); if ( getLogger().isDebugEnabled() )
public static Dependency cloneDependency( Dependency src ) { Dependency result = null; if ( src != null ) { result = new Dependency(); result.setArtifactId( src.getArtifactId() ); result.setClassifier( src.getClassifier() ); result.setExclusions( cloneList( src.getExclusions(), DEPENDENCY_EXCLUSION_CLONER ) ); result.setGroupId( src.getGroupId() ); result.setOptional( src.isOptional() ); result.setScope( src.getScope() ); result.setSystemPath( src.getSystemPath() ); result.setType( src.getType() ); result.setVersion( src.getVersion() ); } return result; }
@Test public void getLocalArtifactUrl_shouldAddDependencyToDependenciesTask() { DependencyResolver dependencyResolver = createResolver(); DependencyJar dependencyJar = new DependencyJar("group1", "artifact1", "3", null); dependencyResolver.getLocalArtifactUrl(dependencyJar); List<Dependency> dependencies = dependenciesTask.getDependencies(); assertEquals(1, dependencies.size()); Dependency dependency = dependencies.get(0); assertEquals("group1", dependency.getGroupId()); assertEquals("artifact1", dependency.getArtifactId()); assertEquals("3", dependency.getVersion()); assertEquals("jar", dependency.getType()); assertNull(dependency.getClassifier()); }
+ ": dependencies with import scope must have type 'pom'." ); else if ( d.getClassifier() != null )
if ( dependency.getClassifier() != null ) serializer.startTag( NAMESPACE, "classifier" ).text( dependency.getClassifier() ).endTag( NAMESPACE, "classifier" );
for ( Dependency dependency : project.getDependencies() ) String classifier = dependency.getClassifier(); if ( classifier == null )