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