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.util.graph.selector;
20  
21  import org.eclipse.aether.collection.DependencyCollectionContext;
22  import org.eclipse.aether.collection.DependencySelector;
23  import org.eclipse.aether.graph.Dependency;
24  
25  import static java.util.Objects.requireNonNull;
26  
27  /**
28   * A dependency selector that excludes optional dependencies which occur beyond level one of the dependency graph.
29   *
30   * @see Dependency#isOptional()
31   * @deprecated This class is deprecated. Use same named class from impl module instead.
32   */
33  @Deprecated
34  public final class OptionalDependencySelector implements DependencySelector {
35  
36      private final int depth;
37  
38      /**
39       * Creates a new selector to exclude optional transitive dependencies.
40       */
41      public OptionalDependencySelector() {
42          depth = 0;
43      }
44  
45      private OptionalDependencySelector(int depth) {
46          this.depth = depth;
47      }
48  
49      public boolean selectDependency(Dependency dependency) {
50          requireNonNull(dependency, "dependency cannot be null");
51          return depth < 2 || !dependency.isOptional();
52      }
53  
54      public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
55          requireNonNull(context, "context cannot be null");
56          if (depth >= 2) {
57              return this;
58          }
59  
60          return new OptionalDependencySelector(depth + 1);
61      }
62  
63      @Override
64      public boolean equals(Object obj) {
65          if (this == obj) {
66              return true;
67          } else if (null == obj || !getClass().equals(obj.getClass())) {
68              return false;
69          }
70  
71          OptionalDependencySelector that = (OptionalDependencySelector) obj;
72          return depth == that.depth;
73      }
74  
75      @Override
76      public int hashCode() {
77          int hash = getClass().hashCode();
78          hash = hash * 31 + depth;
79          return hash;
80      }
81  
82      @Override
83      public String toString() {
84          return String.format("%s(depth: %d)", this.getClass().getSimpleName(), this.depth);
85      }
86  }