Skip to content

Commit

Permalink
[MSHARED-1300] Order of dependencies is not always retained when filt…
Browse files Browse the repository at this point in the history
…ering (#33)
  • Loading branch information
kjarosh authored Sep 12, 2023
1 parent c3b2940 commit bbcf213
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ private Set<Artifact> filterIncludes( Set<Artifact> artifacts, List<String> theI
{
Set<Artifact> result = new LinkedHashSet<>();

for ( String include : theIncludes )
for ( Artifact artifact : artifacts )
{
for ( Artifact artifact : artifacts )
for ( String include : theIncludes )
{
// if the classifier or type of the artifact
// matches the feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.testing.ArtifactStubFactory;
Expand Down Expand Up @@ -92,4 +97,26 @@ public void testFiltering3()
Set<Artifact> result = filter.filter( artifacts );
assertEquals( 5, result.size() );
}

@Test
public void testFilteringOrder()
throws IOException
{
TypeFilter filter = new TypeFilter( "war,jar", "zip" );
Set<Artifact> artifacts = new LinkedHashSet<>();

ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
artifacts.add( factory.createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) );
artifacts.add( factory.createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) );
artifacts.add( factory.createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "war", null ) );

Set<Artifact> result = filter.filter( artifacts );

assertEquals( 2, result.size() );

List<Artifact> resultList = new ArrayList<>( result );

assertEquals( "a", resultList.get(0).getArtifactId() );
assertEquals( "c", resultList.get(1).getArtifactId() );
}
}

0 comments on commit bbcf213

Please sign in to comment.