View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl.collect.bf;
20  
21  import java.util.*;
22  
23  import org.eclipse.aether.artifact.DefaultArtifact;
24  import org.eclipse.aether.collection.CollectRequest;
25  import org.eclipse.aether.collection.CollectResult;
26  import org.eclipse.aether.collection.DependencyCollectionException;
27  import org.eclipse.aether.graph.Dependency;
28  import org.eclipse.aether.graph.Exclusion;
29  import org.eclipse.aether.impl.ArtifactDescriptorReader;
30  import org.eclipse.aether.internal.impl.StubRemoteRepositoryManager;
31  import org.eclipse.aether.internal.impl.StubVersionRangeResolver;
32  import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegate;
33  import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegateTestSupport;
34  import org.eclipse.aether.internal.test.util.DependencyGraphParser;
35  import org.eclipse.aether.util.graph.manager.TransitiveDependencyManager;
36  import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
37  import org.junit.jupiter.api.Test;
38  
39  import static org.junit.jupiter.api.Assertions.assertEquals;
40  
41  /**
42   * UT for {@link BfDependencyCollector}.
43   */
44  public class BfWithSkipperDependencyCollectorTest extends DependencyCollectorDelegateTestSupport {
45      @Override
46      protected DependencyCollectorDelegate setupCollector(ArtifactDescriptorReader artifactDescriptorReader) {
47          session.setConfigProperty(BfDependencyCollector.CONFIG_PROP_SKIPPER, true);
48  
49          return new BfDependencyCollector(
50                  new StubRemoteRepositoryManager(),
51                  artifactDescriptorReader,
52                  new StubVersionRangeResolver(),
53                  Collections.emptyMap());
54      }
55  
56      @Override
57      protected String getTransitiveDepsUseRangesDirtyTreeResource() {
58          return "transitiveDepsUseRangesDirtyTreeResult_BF.txt";
59      }
60  
61      @Override
62      protected String getTransitiveDepsUseRangesAndRelocationDirtyTreeResource() {
63          return "transitiveDepsUseRangesAndRelocationDirtyTreeResult_BF.txt";
64      }
65  
66      private Dependency newDep(String coords, String scope, Collection<Exclusion> exclusions) {
67          Dependency d = new Dependency(new DefaultArtifact(coords), scope);
68          return d.setExclusions(exclusions);
69      }
70  
71      @Test
72      void testSkipperWithDifferentExclusion() throws DependencyCollectionException {
73          collector = setupCollector(newReader("managed/"));
74          parser = new DependencyGraphParser("artifact-descriptions/managed/");
75          session.setDependencyManager(new TransitiveDependencyManager(null));
76  
77          ExclusionDependencySelector exclSel1 = new ExclusionDependencySelector();
78          session.setDependencySelector(exclSel1);
79  
80          Dependency root1 = newDep(
81                  "gid:root:ext:ver", "compile", Collections.singleton(new Exclusion("gid", "transitive-1", "", "ext")));
82          Dependency root2 = newDep(
83                  "gid:root:ext:ver", "compile", Collections.singleton(new Exclusion("gid", "transitive-2", "", "ext")));
84          List<Dependency> dependencies = Arrays.asList(root1, root2);
85  
86          CollectRequest request = new CollectRequest(dependencies, null, Collections.singletonList(repository));
87          request.addManagedDependency(newDep("gid:direct:ext:managed-by-dominant-request"));
88          request.addManagedDependency(newDep("gid:transitive-1:ext:managed-by-root"));
89  
90          CollectResult result = collector.collectDependencies(session, request);
91          assertEquals(0, result.getExceptions().size());
92          assertEquals(2, result.getRoot().getChildren().size());
93          assertEquals(root1, dep(result.getRoot(), 0));
94          assertEquals(root2, dep(result.getRoot(), 1));
95          // the winner has transitive-1 excluded
96          assertEquals(1, path(result.getRoot(), 0).getChildren().size());
97          assertEquals(0, path(result.getRoot(), 0, 0).getChildren().size());
98          // skipped
99          assertEquals(0, path(result.getRoot(), 1).getChildren().size());
100     }
101 }