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.Arrays;
22  import java.util.Collection;
23  import java.util.Collections;
24  import java.util.List;
25  
26  import org.eclipse.aether.artifact.DefaultArtifact;
27  import org.eclipse.aether.collection.CollectRequest;
28  import org.eclipse.aether.collection.CollectResult;
29  import org.eclipse.aether.collection.DependencyCollectionException;
30  import org.eclipse.aether.graph.Dependency;
31  import org.eclipse.aether.graph.Exclusion;
32  import org.eclipse.aether.internal.impl.StubRemoteRepositoryManager;
33  import org.eclipse.aether.internal.impl.StubVersionRangeResolver;
34  import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegateTestSupport;
35  import org.eclipse.aether.internal.test.util.DependencyGraphParser;
36  import org.eclipse.aether.util.graph.manager.TransitiveDependencyManager;
37  import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
38  import org.junit.Assume;
39  import org.junit.Test;
40  import org.junit.runner.RunWith;
41  import org.junit.runners.Parameterized;
42  
43  import static org.junit.Assert.assertEquals;
44  
45  /**
46   * UT for {@link BfDependencyCollector}.
47   */
48  @RunWith(Parameterized.class)
49  public class BfDependencyCollectorTest extends DependencyCollectorDelegateTestSupport {
50      @Parameterized.Parameters
51      public static List<Boolean> parameters() {
52          return Arrays.asList(Boolean.TRUE, Boolean.FALSE);
53      }
54  
55      @SuppressWarnings("checkstyle:VisibilityModifier")
56      @Parameterized.Parameter
57      public boolean useSkipper;
58  
59      @Override
60      protected void setupCollector() {
61          session.setConfigProperty(BfDependencyCollector.CONFIG_PROP_SKIPPER, useSkipper);
62  
63          collector = new BfDependencyCollector(
64                  new StubRemoteRepositoryManager(), newReader(""), new StubVersionRangeResolver());
65      }
66  
67      @Override
68      protected String getTransitiveDepsUseRangesDirtyTreeResource() {
69          return "transitiveDepsUseRangesDirtyTreeResult_BF.txt";
70      }
71  
72      @Override
73      protected String getTransitiveDepsUseRangesAndRelocationDirtyTreeResource() {
74          return "transitiveDepsUseRangesAndRelocationDirtyTreeResult_BF.txt";
75      }
76  
77      private Dependency newDep(String coords, String scope, Collection<Exclusion> exclusions) {
78          Dependency d = new Dependency(new DefaultArtifact(coords), scope);
79          return d.setExclusions(exclusions);
80      }
81  
82      @Test
83      public void testSkipperWithDifferentExclusion() throws DependencyCollectionException {
84          Assume.assumeTrue(useSkipper);
85          collector.setArtifactDescriptorReader(newReader("managed/"));
86          parser = new DependencyGraphParser("artifact-descriptions/managed/");
87          session.setDependencyManager(new TransitiveDependencyManager());
88  
89          ExclusionDependencySelector exclSel1 = new ExclusionDependencySelector();
90          session.setDependencySelector(exclSel1);
91  
92          Dependency root1 = newDep(
93                  "gid:root:ext:ver", "compile", Collections.singleton(new Exclusion("gid", "transitive-1", "", "ext")));
94          Dependency root2 = newDep(
95                  "gid:root:ext:ver", "compile", Collections.singleton(new Exclusion("gid", "transitive-2", "", "ext")));
96          List<Dependency> dependencies = Arrays.asList(root1, root2);
97  
98          CollectRequest request = new CollectRequest(dependencies, null, Arrays.asList(repository));
99          request.addManagedDependency(newDep("gid:direct:ext:managed-by-dominant-request"));
100         request.addManagedDependency(newDep("gid:transitive-1:ext:managed-by-root"));
101 
102         CollectResult result = collector.collectDependencies(session, request);
103         assertEquals(0, result.getExceptions().size());
104         assertEquals(2, result.getRoot().getChildren().size());
105         assertEquals(root1, dep(result.getRoot(), 0));
106         assertEquals(root2, dep(result.getRoot(), 1));
107         // the winner has transitive-1 excluded
108         assertEquals(1, path(result.getRoot(), 0).getChildren().size());
109         assertEquals(0, path(result.getRoot(), 0, 0).getChildren().size());
110         // skipped
111         assertEquals(0, path(result.getRoot(), 1).getChildren().size());
112     }
113 }