move artifact filters to maven-artifact

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-13 04:29:25 +00:00
parent 4dae786c59
commit 55d33da355
4 changed files with 154 additions and 67 deletions

View File

@ -0,0 +1,54 @@
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;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Apply multiple filters.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class AndArtifactFilter
implements ArtifactFilter
{
private final List filters = new ArrayList();
public boolean include( Artifact artifact )
{
boolean include = true;
for ( Iterator i = filters.iterator(); i.hasNext() && include; )
{
ArtifactFilter filter = (ArtifactFilter) i.next();
if ( !filter.include( artifact ) )
{
include = false;
}
}
return include;
}
public void add( ArtifactFilter artifactFilter )
{
filters.add( artifactFilter );
}
}

View File

@ -0,0 +1,42 @@
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;
import java.util.List;
/**
* Filter to exclude from a list of artifact patterns.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
* @todo I think this is equiv. to exclusion set filter in maven-core
*/
public class ExcludesArtifactFilter
extends IncludesArtifactFilter
{
public ExcludesArtifactFilter( List patterns )
{
super( patterns );
}
public boolean include( Artifact artifact )
{
return !super.include( artifact );
}
}

View File

@ -0,0 +1,55 @@
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;
import java.util.Iterator;
import java.util.List;
/**
* Filter to include from a list of artifact patterns.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class IncludesArtifactFilter
implements ArtifactFilter
{
private final List patterns;
public IncludesArtifactFilter( List patterns )
{
this.patterns = patterns;
}
public boolean include( Artifact artifact )
{
String id = artifact.getGroupId() + ":" + artifact.getArtifactId();
boolean matched = false;
for ( Iterator i = patterns.iterator(); i.hasNext() & !matched; )
{
// TODO: what about wildcards? Just specifying groups? versions?
if ( id.equals( i.next() ) )
{
matched = true;
}
}
return matched;
}
}

View File

@ -17,7 +17,9 @@ package org.apache.maven.plugin.assembly;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionException;
@ -326,70 +328,4 @@ public class AssemblyMojo
return defaultExcludes;
}
// TODO: move to maven-artifact - generally useful
private static class AndArtifactFilter
implements ArtifactFilter
{
private final List filters = new ArrayList();
public boolean include( Artifact artifact )
{
boolean include = true;
for ( Iterator i = filters.iterator(); i.hasNext() && include; )
{
ArtifactFilter filter = (ArtifactFilter) i.next();
if ( !filter.include( artifact ) )
{
include = false;
}
}
return include;
}
public void add( ArtifactFilter artifactFilter )
{
filters.add( artifactFilter );
}
}
private static class IncludesArtifactFilter
implements ArtifactFilter
{
private final List patterns;
public IncludesArtifactFilter( List patterns )
{
this.patterns = patterns;
}
public boolean include( Artifact artifact )
{
String id = artifact.getGroupId() + ":" + artifact.getArtifactId();
boolean matched = false;
for ( Iterator i = patterns.iterator(); i.hasNext() & !matched; )
{
// TODO: what about wildcards? Just specifying groups? versions?
if ( id.equals( i.next() ) )
{
matched = true;
}
}
return matched;
}
}
private static class ExcludesArtifactFilter
extends IncludesArtifactFilter
{
public ExcludesArtifactFilter( List patterns )
{
super( patterns );
}
public boolean include( Artifact artifact )
{
return !super.include( artifact );
}
}
}