Skip to content

Commit bbcf213

Browse files
authored
[MSHARED-1300] Order of dependencies is not always retained when filtering (#33)
1 parent c3b2940 commit bbcf213

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/main/java/org/apache/maven/shared/artifact/filter/collection/AbstractArtifactFeatureFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ private Set<Artifact> filterIncludes( Set<Artifact> artifacts, List<String> theI
9090
{
9191
Set<Artifact> result = new LinkedHashSet<>();
9292

93-
for ( String include : theIncludes )
93+
for ( Artifact artifact : artifacts )
9494
{
95-
for ( Artifact artifact : artifacts )
95+
for ( String include : theIncludes )
9696
{
9797
// if the classifier or type of the artifact
9898
// matches the feature

src/test/java/org/apache/maven/shared/artifact/filter/collection/TestTypeFilter.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
* specific language governing permissions and limitations
1919
* under the License.
2020
*/
21+
import java.io.IOException;
22+
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.LinkedHashSet;
2125
import java.util.List;
2226
import java.util.Set;
27+
import java.util.stream.Collectors;
2328

2429
import org.apache.maven.artifact.Artifact;
2530
import org.apache.maven.plugin.testing.ArtifactStubFactory;
@@ -92,4 +97,26 @@ public void testFiltering3()
9297
Set<Artifact> result = filter.filter( artifacts );
9398
assertEquals( 5, result.size() );
9499
}
100+
101+
@Test
102+
public void testFilteringOrder()
103+
throws IOException
104+
{
105+
TypeFilter filter = new TypeFilter( "war,jar", "zip" );
106+
Set<Artifact> artifacts = new LinkedHashSet<>();
107+
108+
ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
109+
artifacts.add( factory.createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) );
110+
artifacts.add( factory.createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) );
111+
artifacts.add( factory.createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "war", null ) );
112+
113+
Set<Artifact> result = filter.filter( artifacts );
114+
115+
assertEquals( 2, result.size() );
116+
117+
List<Artifact> resultList = new ArrayList<>( result );
118+
119+
assertEquals( "a", resultList.get(0).getArtifactId() );
120+
assertEquals( "c", resultList.get(1).getArtifactId() );
121+
}
95122
}

0 commit comments

Comments
 (0)