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.manager; 020 021import java.util.Collection; 022import java.util.Map; 023 024import org.eclipse.aether.collection.DependencyCollectionContext; 025import org.eclipse.aether.collection.DependencyManager; 026import org.eclipse.aether.graph.Exclusion; 027import org.eclipse.aether.scope.ScopeManager; 028import org.eclipse.aether.scope.SystemDependencyScope; 029 030/** 031 * A dependency manager that mimics the way Maven 2.x works. This manager was used throughout all Maven 3.x versions. 032 * <p> 033 * This manager has {@code deriveUntil=2} and {@code applyFrom=2}. 034 * <p> 035 * Note regarding transitivity: it is broken, and should not be used. 036 */ 037public final class ClassicDependencyManager extends AbstractDependencyManager { 038 /** 039 * Creates a new dependency manager without any management information. 040 * 041 * @deprecated Use constructor that provides consumer application specific predicate. 042 */ 043 @Deprecated 044 public ClassicDependencyManager() { 045 this(null); 046 } 047 048 public ClassicDependencyManager(ScopeManager scopeManager) { 049 this(false, scopeManager); 050 } 051 052 /** 053 * Creates a new dependency manager without any management information. 054 * 055 * @param transitive If true, this manager will collect (derive) until last node on graph. If false, 056 * it will work as original Maven 3 "classic" dependency manager, collect only up to 057 * depth of 2. 058 * 059 * @since 2.0.0 060 */ 061 public ClassicDependencyManager(boolean transitive, ScopeManager scopeManager) { 062 super(transitive ? Integer.MAX_VALUE : 2, 2, scopeManager); 063 } 064 065 @SuppressWarnings("checkstyle:ParameterNumber") 066 private ClassicDependencyManager( 067 int depth, 068 int deriveUntil, 069 int applyFrom, 070 Map<Object, Holder<String>> managedVersions, 071 Map<Object, Holder<String>> managedScopes, 072 Map<Object, Holder<Boolean>> managedOptionals, 073 Map<Object, Holder<String>> managedLocalPaths, 074 Map<Object, Collection<Holder<Collection<Exclusion>>>> managedExclusions, 075 SystemDependencyScope systemDependencyScope) { 076 super( 077 depth, 078 deriveUntil, 079 applyFrom, 080 managedVersions, 081 managedScopes, 082 managedOptionals, 083 managedLocalPaths, 084 managedExclusions, 085 systemDependencyScope); 086 } 087 088 @Override 089 public DependencyManager deriveChildManager(DependencyCollectionContext context) { 090 // MNG-4720: Maven2 backward compatibility 091 // Removing this IF makes one IT fail here (read comment above): 092 // https://github.com/apache/maven-integration-testing/blob/b4e8fd52b99a058336f9c7c5ec44fdbc1427759c/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4720DependencyManagementExclusionMergeTest.java#L67 093 if (depth == 1) { 094 return newInstance(managedVersions, managedScopes, managedOptionals, managedLocalPaths, managedExclusions); 095 } 096 return super.deriveChildManager(context); 097 } 098 099 @Override 100 protected DependencyManager newInstance( 101 Map<Object, Holder<String>> managedVersions, 102 Map<Object, Holder<String>> managedScopes, 103 Map<Object, Holder<Boolean>> managedOptionals, 104 Map<Object, Holder<String>> managedLocalPaths, 105 Map<Object, Collection<Holder<Collection<Exclusion>>>> managedExclusions) { 106 return new ClassicDependencyManager( 107 depth + 1, 108 deriveUntil, 109 applyFrom, 110 managedVersions, 111 managedScopes, 112 managedOptionals, 113 managedLocalPaths, 114 managedExclusions, 115 systemDependencyScope); 116 } 117}