mirror of https://github.com/apache/maven.git
PR: MNG-1039
Submitted by: Matthew Inger Reviewed by: Brett Porter filter based on dependency type git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@292392 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
94468725f6
commit
04de595b24
|
@ -24,8 +24,10 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.TypeArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Repository;
|
||||
|
@ -63,6 +65,8 @@ public class DependenciesTask
|
|||
|
||||
private String useScope;
|
||||
|
||||
private String type;
|
||||
|
||||
private boolean verbose;
|
||||
|
||||
/**
|
||||
|
@ -145,7 +149,26 @@ public class DependenciesTask
|
|||
// TODO: managed dependencies
|
||||
Map managedDependencies = Collections.EMPTY_MAP;
|
||||
|
||||
ArtifactFilter filter = useScope != null ? new ScopeArtifactFilter( useScope ) : null;
|
||||
ArtifactFilter filter = null;
|
||||
if ( useScope != null )
|
||||
{
|
||||
filter = new ScopeArtifactFilter( useScope );
|
||||
}
|
||||
if ( type != null )
|
||||
{
|
||||
TypeArtifactFilter typeArtifactFilter = new TypeArtifactFilter( type );
|
||||
if ( filter != null )
|
||||
{
|
||||
AndArtifactFilter andFilter = new AndArtifactFilter();
|
||||
andFilter.add( filter );
|
||||
andFilter.add( typeArtifactFilter );
|
||||
filter = andFilter;
|
||||
}
|
||||
else
|
||||
{
|
||||
filter = typeArtifactFilter;
|
||||
}
|
||||
}
|
||||
|
||||
result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
|
||||
remoteArtifactRepositories, metadataSource, filter, listeners );
|
||||
|
@ -181,12 +204,12 @@ public class DependenciesTask
|
|||
{
|
||||
Artifact artifact = (Artifact) i.next();
|
||||
String filename = localRepo.pathOf( artifact );
|
||||
|
||||
|
||||
FileList.FileName file = new FileList.FileName();
|
||||
file.setName( filename );
|
||||
|
||||
|
||||
fileList.addConfiguredFile( file );
|
||||
|
||||
|
||||
fileSet.createInclude().setName( filename );
|
||||
}
|
||||
}
|
||||
|
@ -263,4 +286,11 @@ public class DependenciesTask
|
|||
{
|
||||
this.useScope = useScope;
|
||||
}
|
||||
|
||||
public void setType( String type )
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package org.apache.maven.artifact.resolver.filter;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
/**
|
||||
* Artifact Filter which filters on artifact type
|
||||
*/
|
||||
public class TypeArtifactFilter
|
||||
implements ArtifactFilter
|
||||
{
|
||||
private String type = "jar";
|
||||
|
||||
public TypeArtifactFilter( String type )
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean include( Artifact artifact )
|
||||
{
|
||||
return type.equals( artifact.getType() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue