001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.util.graph.selector; 020 021import org.eclipse.aether.collection.DependencyCollectionContext; 022import org.eclipse.aether.collection.DependencySelector; 023import org.eclipse.aether.graph.Dependency; 024 025import static java.util.Objects.requireNonNull; 026 027/** 028 * A dependency selector that excludes optional dependencies which occur beyond level one of the dependency graph. 029 * 030 * @see Dependency#isOptional() 031 * @deprecated This class is deprecated. Use same named class from impl module instead. 032 */ 033@Deprecated 034public final class OptionalDependencySelector implements DependencySelector { 035 036 private final int depth; 037 038 /** 039 * Creates a new selector to exclude optional transitive dependencies. 040 */ 041 public OptionalDependencySelector() { 042 depth = 0; 043 } 044 045 private OptionalDependencySelector(int depth) { 046 this.depth = depth; 047 } 048 049 public boolean selectDependency(Dependency dependency) { 050 requireNonNull(dependency, "dependency cannot be null"); 051 return depth < 2 || !dependency.isOptional(); 052 } 053 054 public DependencySelector deriveChildSelector(DependencyCollectionContext context) { 055 requireNonNull(context, "context cannot be null"); 056 if (depth >= 2) { 057 return this; 058 } 059 060 return new OptionalDependencySelector(depth + 1); 061 } 062 063 @Override 064 public boolean equals(Object obj) { 065 if (this == obj) { 066 return true; 067 } else if (null == obj || !getClass().equals(obj.getClass())) { 068 return false; 069 } 070 071 OptionalDependencySelector that = (OptionalDependencySelector) obj; 072 return depth == that.depth; 073 } 074 075 @Override 076 public int hashCode() { 077 int hash = getClass().hashCode(); 078 hash = hash * 31 + depth; 079 return hash; 080 } 081 082 @Override 083 public String toString() { 084 return String.format("%s(depth: %d)", this.getClass().getSimpleName(), this.depth); 085 } 086}