|
| 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.supplier; |
| 20 | + |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
| 23 | +import java.util.Collection; |
| 24 | +import java.util.Collections; |
| 25 | +import java.util.stream.Collectors; |
| 26 | + |
| 27 | +import org.eclipse.aether.artifact.ArtifactProperties; |
| 28 | +import org.eclipse.aether.impl.scope.BuildScopeMatrixSource; |
| 29 | +import org.eclipse.aether.impl.scope.BuildScopeSource; |
| 30 | +import org.eclipse.aether.impl.scope.CommonBuilds; |
| 31 | +import org.eclipse.aether.impl.scope.InternalScopeManager; |
| 32 | +import org.eclipse.aether.impl.scope.ScopeManagerConfiguration; |
| 33 | +import org.eclipse.aether.internal.impl.scope.ScopeManagerDump; |
| 34 | +import org.eclipse.aether.scope.DependencyScope; |
| 35 | +import org.eclipse.aether.scope.ResolutionScope; |
| 36 | + |
| 37 | +import static org.eclipse.aether.impl.scope.BuildScopeQuery.all; |
| 38 | +import static org.eclipse.aether.impl.scope.BuildScopeQuery.byBuildPath; |
| 39 | +import static org.eclipse.aether.impl.scope.BuildScopeQuery.byProjectPath; |
| 40 | +import static org.eclipse.aether.impl.scope.BuildScopeQuery.select; |
| 41 | +import static org.eclipse.aether.impl.scope.BuildScopeQuery.singleton; |
| 42 | +import static org.eclipse.aether.impl.scope.BuildScopeQuery.union; |
| 43 | + |
| 44 | +/** |
| 45 | + * Maven3 scope configurations. Configures scope manager to support Maven3 scopes. |
| 46 | + * |
| 47 | + * @since 2.0.11 |
| 48 | + */ |
| 49 | +public final class Maven3ScopeManagerConfiguration implements ScopeManagerConfiguration { |
| 50 | + public static final Maven3ScopeManagerConfiguration INSTANCE = new Maven3ScopeManagerConfiguration(); |
| 51 | + public static final String DS_COMPILE = "compile"; |
| 52 | + public static final String DS_RUNTIME = "runtime"; |
| 53 | + public static final String DS_PROVIDED = "provided"; |
| 54 | + public static final String DS_SYSTEM = "system"; |
| 55 | + public static final String DS_TEST = "test"; |
| 56 | + public static final String RS_NONE = "none"; |
| 57 | + public static final String RS_MAIN_COMPILE = "main-compile"; |
| 58 | + public static final String RS_MAIN_COMPILE_PLUS_RUNTIME = "main-compilePlusRuntime"; |
| 59 | + public static final String RS_MAIN_RUNTIME = "main-runtime"; |
| 60 | + public static final String RS_MAIN_RUNTIME_PLUS_SYSTEM = "main-runtimePlusSystem"; |
| 61 | + public static final String RS_TEST_COMPILE = "test-compile"; |
| 62 | + public static final String RS_TEST_RUNTIME = "test-runtime"; |
| 63 | + |
| 64 | + private Maven3ScopeManagerConfiguration() {} |
| 65 | + |
| 66 | + @Override |
| 67 | + public String getId() { |
| 68 | + return "Maven3"; |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public boolean isStrictDependencyScopes() { |
| 73 | + return false; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public boolean isStrictResolutionScopes() { |
| 78 | + return false; |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public BuildScopeSource getBuildScopeSource() { |
| 83 | + return new BuildScopeMatrixSource( |
| 84 | + Collections.singletonList(CommonBuilds.PROJECT_PATH_MAIN), |
| 85 | + Arrays.asList(CommonBuilds.BUILD_PATH_COMPILE, CommonBuilds.BUILD_PATH_RUNTIME), |
| 86 | + CommonBuilds.MAVEN_TEST_BUILD_SCOPE); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public Collection<DependencyScope> buildDependencyScopes(InternalScopeManager internalScopeManager) { |
| 91 | + ArrayList<DependencyScope> result = new ArrayList<>(); |
| 92 | + result.add(internalScopeManager.createDependencyScope(DS_COMPILE, true, all())); |
| 93 | + result.add(internalScopeManager.createDependencyScope( |
| 94 | + DS_RUNTIME, true, byBuildPath(CommonBuilds.BUILD_PATH_RUNTIME))); |
| 95 | + result.add(internalScopeManager.createDependencyScope( |
| 96 | + DS_PROVIDED, |
| 97 | + false, |
| 98 | + union( |
| 99 | + byBuildPath(CommonBuilds.BUILD_PATH_COMPILE), |
| 100 | + select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME)))); |
| 101 | + result.add(internalScopeManager.createDependencyScope( |
| 102 | + DS_TEST, false, byProjectPath(CommonBuilds.PROJECT_PATH_TEST))); |
| 103 | + result.add(internalScopeManager.createSystemDependencyScope( |
| 104 | + DS_SYSTEM, false, all(), ArtifactProperties.LOCAL_PATH)); |
| 105 | + return result; |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public Collection<ResolutionScope> buildResolutionScopes(InternalScopeManager internalScopeManager) { |
| 110 | + Collection<DependencyScope> allDependencyScopes = internalScopeManager.getDependencyScopeUniverse(); |
| 111 | + Collection<DependencyScope> nonTransitiveDependencyScopes = |
| 112 | + allDependencyScopes.stream().filter(s -> !s.isTransitive()).collect(Collectors.toSet()); |
| 113 | + DependencyScope system = |
| 114 | + internalScopeManager.getDependencyScope(DS_SYSTEM).orElse(null); |
| 115 | + |
| 116 | + ArrayList<ResolutionScope> result = new ArrayList<>(); |
| 117 | + result.add(internalScopeManager.createResolutionScope( |
| 118 | + RS_NONE, |
| 119 | + InternalScopeManager.Mode.REMOVE, |
| 120 | + Collections.emptySet(), |
| 121 | + Collections.emptySet(), |
| 122 | + allDependencyScopes)); |
| 123 | + result.add(internalScopeManager.createResolutionScope( |
| 124 | + RS_MAIN_COMPILE, |
| 125 | + InternalScopeManager.Mode.ELIMINATE, |
| 126 | + singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_COMPILE), |
| 127 | + Collections.singletonList(system), |
| 128 | + nonTransitiveDependencyScopes)); |
| 129 | + result.add(internalScopeManager.createResolutionScope( |
| 130 | + RS_MAIN_COMPILE_PLUS_RUNTIME, |
| 131 | + InternalScopeManager.Mode.ELIMINATE, |
| 132 | + byProjectPath(CommonBuilds.PROJECT_PATH_MAIN), |
| 133 | + Collections.singletonList(system), |
| 134 | + nonTransitiveDependencyScopes)); |
| 135 | + result.add(internalScopeManager.createResolutionScope( |
| 136 | + RS_MAIN_RUNTIME, |
| 137 | + InternalScopeManager.Mode.ELIMINATE, |
| 138 | + singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME), |
| 139 | + Collections.emptySet(), |
| 140 | + nonTransitiveDependencyScopes)); |
| 141 | + result.add(internalScopeManager.createResolutionScope( |
| 142 | + RS_MAIN_RUNTIME_PLUS_SYSTEM, |
| 143 | + InternalScopeManager.Mode.ELIMINATE, |
| 144 | + singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME), |
| 145 | + Collections.singletonList(system), |
| 146 | + nonTransitiveDependencyScopes)); |
| 147 | + result.add(internalScopeManager.createResolutionScope( |
| 148 | + RS_TEST_COMPILE, |
| 149 | + InternalScopeManager.Mode.ELIMINATE, |
| 150 | + select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_COMPILE), |
| 151 | + Collections.singletonList(system), |
| 152 | + nonTransitiveDependencyScopes)); |
| 153 | + result.add(internalScopeManager.createResolutionScope( |
| 154 | + RS_TEST_RUNTIME, |
| 155 | + InternalScopeManager.Mode.ELIMINATE, |
| 156 | + select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME), |
| 157 | + Collections.singletonList(system), |
| 158 | + nonTransitiveDependencyScopes)); |
| 159 | + return result; |
| 160 | + } |
| 161 | + |
| 162 | + // === |
| 163 | + |
| 164 | + public static void main(String... args) { |
| 165 | + ScopeManagerDump.dump(Maven3ScopeManagerConfiguration.INSTANCE); |
| 166 | + } |
| 167 | +} |
0 commit comments