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      @Parameterized.Parameter
56      public boolean useSkipper;
57  
58      @Override
59      protected void setupCollector() {
60          session.setConfigProperty(BfDependencyCollector.CONFIG_PROP_SKIPPER, useSkipper);
61  
62          collector = new BfDependencyCollector(
63                  new StubRemoteRepositoryManager(), newReader(""), new StubVersionRangeResolver());
64      }
65  
66      @Override
67      protected String getTransitiveDepsUseRangesDirtyTreeResource() {
68          return "transitiveDepsUseRangesDirtyTreeResult_BF.txt";
69      }
70  
71      private Dependency newDep(String coords, String scope, Collection<Exclusion> exclusions) {
72          Dependency d = new Dependency(new DefaultArtifact(coords), scope);
73          return d.setExclusions(exclusions);
74      }
75  
76      @Test
77      public void testSkipperWithDifferentExclusion() throws DependencyCollectionException {
78          Assume.assumeTrue(useSkipper);
79          collector.setArtifactDescriptorReader(newReader("managed/"));
80          parser = new DependencyGraphParser("artifact-descriptions/managed/");
81          session.setDependencyManager(new TransitiveDependencyManager());
82  
83          ExclusionDependencySelector exclSel1 = new ExclusionDependencySelector();
84          session.setDependencySelector(exclSel1);
85  
86          Dependency root1 = newDep(
87                  "gid:root:ext:ver", "compile", Collections.singleton(new Exclusion("gid", "transitive-1", "", "ext")));
88          Dependency root2 = newDep(
89                  "gid:root:ext:ver", "compile", Collections.singleton(new Exclusion("gid", "transitive-2", "", "ext")));
90          List<Dependency> dependencies = Arrays.asList(root1, root2);
91  
92          CollectRequest request = new CollectRequest(dependencies, null, Arrays.asList(repository));
93          request.addManagedDependency(newDep("gid:direct:ext:managed-by-dominant-request"));
94          request.addManagedDependency(newDep("gid:transitive-1:ext:managed-by-root"));
95  
96          CollectResult result = collector.collectDependencies(session, request);
97          assertEquals(0, result.getExceptions().size());
98          assertEquals(2, result.getRoot().getChildren().size());
99          assertEquals(root1, dep(result.getRoot(), 0));
100         assertEquals(root2, dep(result.getRoot(), 1));
101         // the winner has transitive-1 excluded
102         assertEquals(1, path(result.getRoot(), 0).getChildren().size());
103         assertEquals(0, path(result.getRoot(), 0, 0).getChildren().size());
104         // skipped
105         assertEquals(0, path(result.getRoot(), 1).getChildren().size());
106     }
107 }