mirror of https://github.com/apache/maven.git
[MNG-4041] embedder returns stale maven project state
Submitted by: Igor Fedorenko o Committed additional patch with bugfixes including minor modifications: - used LinkedHashSet instead of HashSet/TreeSet - added missing license headers git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@786882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c25bddb3ab
commit
12fbba751a
|
@ -21,7 +21,9 @@ package org.apache.maven.artifact.resolver.filter;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
|
@ -34,7 +36,7 @@ import org.apache.maven.artifact.Artifact;
|
|||
public class AndArtifactFilter
|
||||
implements ArtifactFilter
|
||||
{
|
||||
private List<ArtifactFilter> filters;
|
||||
private Set<ArtifactFilter> filters;
|
||||
|
||||
public AndArtifactFilter()
|
||||
{
|
||||
|
@ -42,7 +44,7 @@ public class AndArtifactFilter
|
|||
|
||||
public AndArtifactFilter( List<ArtifactFilter> filters )
|
||||
{
|
||||
this.filters = filters;
|
||||
this.filters = new LinkedHashSet<ArtifactFilter>( filters );
|
||||
}
|
||||
|
||||
public boolean include( Artifact artifact )
|
||||
|
@ -63,9 +65,40 @@ public class AndArtifactFilter
|
|||
{
|
||||
if ( filters == null )
|
||||
{
|
||||
filters = new ArrayList<ArtifactFilter>();
|
||||
filters = new LinkedHashSet<ArtifactFilter>();
|
||||
}
|
||||
|
||||
filters.add( artifactFilter );
|
||||
}
|
||||
|
||||
public List<ArtifactFilter> getFilters()
|
||||
{
|
||||
return new ArrayList<ArtifactFilter>( filters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + filters.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( obj instanceof AndArtifactFilter ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AndArtifactFilter other = (AndArtifactFilter) obj;
|
||||
|
||||
return filters.equals( other.filters );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.maven.artifact.resolver.filter;
|
|||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
@ -36,7 +36,7 @@ public class ExclusionSetFilter
|
|||
|
||||
public ExclusionSetFilter( String[] excludes )
|
||||
{
|
||||
this.excludes = new HashSet<String>( Arrays.asList( excludes ) );
|
||||
this.excludes = new LinkedHashSet<String>( Arrays.asList( excludes ) );
|
||||
}
|
||||
|
||||
public ExclusionSetFilter( Set<String> excludes )
|
||||
|
@ -46,6 +46,32 @@ public class ExclusionSetFilter
|
|||
|
||||
public boolean include( Artifact artifact )
|
||||
{
|
||||
return !excludes.contains(artifact.getArtifactId());
|
||||
return !excludes.contains( artifact.getArtifactId() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + excludes.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( obj instanceof ExclusionSetFilter ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ExclusionSetFilter other = (ExclusionSetFilter) obj;
|
||||
|
||||
return excludes.equals( other.excludes );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,11 @@ package org.apache.maven.artifact.resolver.filter;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
|
@ -33,11 +36,11 @@ import org.apache.maven.artifact.Artifact;
|
|||
public class IncludesArtifactFilter
|
||||
implements ArtifactFilter
|
||||
{
|
||||
private final List<String> patterns;
|
||||
private final Set<String> patterns;
|
||||
|
||||
public IncludesArtifactFilter( List<String> patterns )
|
||||
{
|
||||
this.patterns = patterns;
|
||||
this.patterns = new LinkedHashSet<String>( patterns );
|
||||
}
|
||||
|
||||
public boolean include( Artifact artifact )
|
||||
|
@ -55,9 +58,37 @@ public class IncludesArtifactFilter
|
|||
}
|
||||
return matched;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getPatterns()
|
||||
{
|
||||
return patterns;
|
||||
return new ArrayList<String>( patterns );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + patterns.hashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// make sure IncludesArtifactFilter is not equal ExcludesArtifactFilter!
|
||||
if ( obj == null || getClass() != obj.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IncludesArtifactFilter other = (IncludesArtifactFilter) obj;
|
||||
|
||||
return patterns.equals( other.patterns );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,4 +35,31 @@ public class InversionArtifactFilter
|
|||
{
|
||||
return !toInvert.include( artifact );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + toInvert.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( obj instanceof InversionArtifactFilter ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
InversionArtifactFilter other = (InversionArtifactFilter) obj;
|
||||
|
||||
return toInvert.equals( other.toInvert );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,9 @@ package org.apache.maven.artifact.resolver.filter;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
|
@ -33,7 +34,7 @@ public class OrArtifactFilter
|
|||
implements ArtifactFilter
|
||||
{
|
||||
|
||||
private Collection<ArtifactFilter> filters;
|
||||
private Set<ArtifactFilter> filters;
|
||||
|
||||
public OrArtifactFilter()
|
||||
{
|
||||
|
@ -41,7 +42,7 @@ public class OrArtifactFilter
|
|||
|
||||
public OrArtifactFilter( Collection<ArtifactFilter> filters )
|
||||
{
|
||||
this.filters = filters;
|
||||
this.filters = new LinkedHashSet<ArtifactFilter>( filters );
|
||||
}
|
||||
|
||||
public boolean include( Artifact artifact )
|
||||
|
@ -64,10 +65,36 @@ public class OrArtifactFilter
|
|||
{
|
||||
if ( filters == null )
|
||||
{
|
||||
filters = new ArrayList<ArtifactFilter>();
|
||||
filters = new LinkedHashSet<ArtifactFilter>();
|
||||
}
|
||||
|
||||
filters.add( artifactFilter );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + filters.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( obj instanceof OrArtifactFilter ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OrArtifactFilter other = (OrArtifactFilter) obj;
|
||||
|
||||
return filters.equals( other.filters );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -120,4 +120,47 @@ public class ScopeArtifactFilter
|
|||
{
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + ( compileScope ? 1 : 0 );
|
||||
hash = hash * 31 + ( runtimeScope ? 1 : 0 );
|
||||
hash = hash * 31 + ( testScope ? 1 : 0 );
|
||||
hash = hash * 31 + ( providedScope ? 1 : 0 );
|
||||
hash = hash * 31 + ( systemScope ? 1 : 0 );
|
||||
|
||||
hash = hash * 31 + ( scope != null ? scope.hashCode() : 0);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( obj instanceof ScopeArtifactFilter ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ScopeArtifactFilter other = (ScopeArtifactFilter) obj;
|
||||
|
||||
return compileScope == other.compileScope
|
||||
&& runtimeScope == other.runtimeScope
|
||||
&& testScope == other.testScope
|
||||
&& providedScope == other.providedScope
|
||||
&& systemScope == other.systemScope
|
||||
&& equals( scope, other.scope );
|
||||
}
|
||||
|
||||
private static boolean equals( String str1, String str2 )
|
||||
{
|
||||
return str1 != null ? str1.equals( str2 ) : str2 == null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,31 @@ public class TypeArtifactFilter
|
|||
{
|
||||
return type.equals( artifact.getType() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + type.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( obj instanceof TypeArtifactFilter ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TypeArtifactFilter other = (TypeArtifactFilter) obj;
|
||||
|
||||
return type.equals( other.type );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package org.apache.maven.artifact.resolver.filter;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Igor Fedorenko
|
||||
*/
|
||||
public class FilterHashEqualsTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testIncludesExcludesArtifactFilter()
|
||||
{
|
||||
List<String> patterns = Arrays.asList( "c", "d", "e" );
|
||||
|
||||
IncludesArtifactFilter f1 = new IncludesArtifactFilter( patterns );
|
||||
|
||||
IncludesArtifactFilter f2 = new IncludesArtifactFilter( patterns );
|
||||
|
||||
assertTrue( f1.equals(f2) );
|
||||
assertTrue( f2.equals(f1) );
|
||||
assertTrue( f1.hashCode() == f2.hashCode() );
|
||||
|
||||
IncludesArtifactFilter f3 = new IncludesArtifactFilter( Arrays.asList( "d", "c", "e" ) );
|
||||
assertTrue( f1.equals( f3 ) );
|
||||
assertTrue( f1.hashCode() == f3.hashCode() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.apache.maven.project.artifact;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
|
||||
import org.apache.maven.project.artifact.DefaultMavenMetadataCache.CacheKey;
|
||||
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
||||
/**
|
||||
* @author Igor Fedorenko
|
||||
*/
|
||||
public class DefaultMavenMetadataCacheTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
private RepositorySystem repositorySystem;
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
repositorySystem = lookup( RepositorySystem.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
repositorySystem = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testCacheKey()
|
||||
throws Exception
|
||||
{
|
||||
Artifact a1 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
|
||||
ArtifactRepository lr1 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
|
||||
ArtifactRepository rr1 = repositorySystem.createDefaultRemoteRepository();
|
||||
a1.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
|
||||
|
||||
Artifact a2 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
|
||||
ArtifactRepository lr2 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
|
||||
ArtifactRepository rr2 = repositorySystem.createDefaultRemoteRepository();
|
||||
a2.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
|
||||
|
||||
// sanity checks
|
||||
assertNotSame( a1, a2 );
|
||||
assertNotSame( lr1, lr2 );
|
||||
assertNotSame( rr1, rr2 );
|
||||
|
||||
CacheKey k1 = new CacheKey( a1, lr1, Collections.singletonList( rr1 ) );
|
||||
CacheKey k2 = new CacheKey( a2, lr2, Collections.singletonList( rr2 ) );
|
||||
|
||||
assertEquals(k1.hashCode(), k2.hashCode());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue