[MNG-6415] Project Artifacts Cache does not retain the order of classpath entries.

This commit is contained in:
rfscholte 2018-09-24 19:50:39 +02:00
parent 421164ef2b
commit 7c1e7129b1
2 changed files with 75 additions and 2 deletions
maven-core/src
main/java/org/apache/maven/project/artifact
test/java/org/apache/maven/project/artifact

View File

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -86,7 +87,7 @@ public class DefaultProjectArtifactsCache
artifactId = project.getArtifactId();
version = project.getVersion();
Set<String> deps = new HashSet<>();
Set<String> deps = new LinkedHashSet<>();
if ( project.getDependencyArtifacts() != null )
{
for ( Artifact dep: project.getDependencyArtifacts() )
@ -203,7 +204,7 @@ public class DefaultProjectArtifactsCache
assertUniqueKey( key );
CacheRecord record =
new CacheRecord( Collections.unmodifiableSet( new HashSet<>( projectArtifacts ) ) );
new CacheRecord( Collections.unmodifiableSet( new LinkedHashSet<>( projectArtifacts ) ) );
cache.put( key, record );

View File

@ -0,0 +1,72 @@
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 static org.junit.Assert.assertArrayEquals;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.codehaus.plexus.PlexusTestCase;
public class DefaultProjectArtifactsCacheTest extends PlexusTestCase
{
private ProjectArtifactsCache cache;
@Override
protected void setUp()
throws Exception
{
super.setUp();
cache = lookup( ProjectArtifactsCache.class );
}
public void testProjectDependencyOrder() throws Exception
{
ProjectArtifactsCache.Key project1 = new ProjectArtifactsCache.Key(){};
Set<Artifact> artifacts = new LinkedHashSet<>( 4 );
artifacts.add( new DefaultArtifact( "g", "a1", "v", "compile", "jar", "", null ) );
artifacts.add( new DefaultArtifact( "g", "a2", "v", "compile", "jar", "", null ) );
artifacts.add( new DefaultArtifact( "g", "a3", "v", "compile", "jar", "", null ) );
artifacts.add( new DefaultArtifact( "g", "a4", "v", "compile", "jar", "", null ) );
cache.put( project1, artifacts );
assertArrayEquals( artifacts.toArray( new Artifact[0] ),
cache.get( project1 ).getArtifacts().toArray( new Artifact[0] ) );
ProjectArtifactsCache.Key project2 = new ProjectArtifactsCache.Key(){};
Set<Artifact> reversedArtifacts = new LinkedHashSet<>( 4 );
artifacts.add( new DefaultArtifact( "g", "a4", "v", "compile", "jar", "", null ) );
artifacts.add( new DefaultArtifact( "g", "a3", "v", "compile", "jar", "", null ) );
artifacts.add( new DefaultArtifact( "g", "a2", "v", "compile", "jar", "", null ) );
artifacts.add( new DefaultArtifact( "g", "a1", "v", "compile", "jar", "", null ) );
cache.put( project2, reversedArtifacts );
assertArrayEquals( reversedArtifacts.toArray( new Artifact[0] ),
cache.get( project2 ).getArtifacts().toArray( new Artifact[0] ) );
}
}