|
| 1 | +package org.apache.maven.shared.dependency.graph; |
| 2 | + |
| 3 | +/* |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | + * or more contributor license agreements. See the NOTICE file |
| 6 | + * distributed with this work for additional information |
| 7 | + * regarding copyright ownership. The ASF licenses this file |
| 8 | + * to you under the Apache License, Version 2.0 (the |
| 9 | + * "License"); you may not use this file except in compliance |
| 10 | + * with the License. You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, |
| 15 | + * software distributed under the License is distributed on an |
| 16 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | + * KIND, either express or implied. See the License for the |
| 18 | + * specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + */ |
| 21 | + |
| 22 | +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; |
| 23 | +import org.apache.maven.project.ProjectBuildingRequest; |
| 24 | +import org.apache.maven.shared.dependency.graph.internal.DirectScopeDependencySelector; |
| 25 | +import org.apache.maven.shared.dependency.graph.internal.VerboseJavaScopeSelector; |
| 26 | +import org.eclipse.aether.collection.DependencyGraphTransformer; |
| 27 | +import org.eclipse.aether.collection.DependencySelector; |
| 28 | +import org.eclipse.aether.util.artifact.JavaScopes; |
| 29 | +import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; |
| 30 | +import org.eclipse.aether.util.graph.selector.AndDependencySelector; |
| 31 | +import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector; |
| 32 | +import org.eclipse.aether.util.graph.selector.OptionalDependencySelector; |
| 33 | +import org.eclipse.aether.util.graph.transformer.ConflictResolver; |
| 34 | +import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver; |
| 35 | +import org.eclipse.aether.util.graph.transformer.NearestVersionSelector; |
| 36 | +import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector; |
| 37 | + |
| 38 | +import java.util.HashMap; |
| 39 | +import java.util.Map; |
| 40 | +import java.util.Objects; |
| 41 | + |
| 42 | +/** |
| 43 | + * <div> |
| 44 | + * This class will carry various options used by |
| 45 | + * {@link DependencyCollectorBuilder#collectDependencyGraph(DependencyCollectorRequest)} |
| 46 | + * </div> |
| 47 | + * <div> |
| 48 | + * There is a set of default values such: |
| 49 | + * </div> |
| 50 | + * <div> |
| 51 | + * DependencySelector |
| 52 | + * <pre> |
| 53 | + * new AndDependencySelector( |
| 54 | + * new DirectScopeDependencySelector( JavaScopes.TEST ), |
| 55 | + * new DirectScopeDependencySelector( JavaScopes.PROVIDED ), |
| 56 | + * new OptionalDependencySelector(), |
| 57 | + * new ExclusionDependencySelector() ); |
| 58 | + * </pre> |
| 59 | + * </div> |
| 60 | + * <div> |
| 61 | + * DependencyGraphTransformer |
| 62 | + * <pre> |
| 63 | + * new ConflictResolver( |
| 64 | + * new NearestVersionSelector(), |
| 65 | + * new VerboseJavaScopeSelector(), |
| 66 | + * new SimpleOptionalitySelector(), |
| 67 | + * new JavaScopeDeriver() ); |
| 68 | + * </pre> |
| 69 | + * </div> |
| 70 | + * <div> |
| 71 | + * configProperties have 2 default values |
| 72 | + * <pre> |
| 73 | + * ConflictResolver.CONFIG_PROP_VERBOSE, true |
| 74 | + * DependencyManagerUtils.CONFIG_PROP_VERBOSE, true |
| 75 | + * </pre> |
| 76 | + * <a href="https://maven.apache.org/resolver/configuration.html">Move Resolver configuration properties</a>. |
| 77 | + * </div> |
| 78 | + * @since 3.2.1 |
| 79 | + */ |
| 80 | +public class DependencyCollectorRequest |
| 81 | +{ |
| 82 | + |
| 83 | + private final ProjectBuildingRequest buildingRequest; |
| 84 | + |
| 85 | + private ArtifactFilter filter; |
| 86 | + |
| 87 | + private Map<String, Object> configProperties = new HashMap<>(); |
| 88 | + |
| 89 | + private DependencySelector dependencySelector = new AndDependencySelector( |
| 90 | + new DirectScopeDependencySelector( JavaScopes.TEST ), |
| 91 | + new DirectScopeDependencySelector( JavaScopes.PROVIDED ), |
| 92 | + new OptionalDependencySelector(), |
| 93 | + new ExclusionDependencySelector() ); |
| 94 | + |
| 95 | + private DependencyGraphTransformer dependencyGraphTransformer = new ConflictResolver( |
| 96 | + new NearestVersionSelector(), |
| 97 | + new VerboseJavaScopeSelector(), |
| 98 | + new SimpleOptionalitySelector(), |
| 99 | + new JavaScopeDeriver() ); |
| 100 | + |
| 101 | + public DependencyCollectorRequest( ProjectBuildingRequest buildingRequest ) |
| 102 | + { |
| 103 | + this( buildingRequest, null ); |
| 104 | + } |
| 105 | + |
| 106 | + public DependencyCollectorRequest( ProjectBuildingRequest buildingRequest, ArtifactFilter filter ) |
| 107 | + { |
| 108 | + Objects.requireNonNull( buildingRequest, "ProjectBuildingRequest cannot be null" ); |
| 109 | + this.buildingRequest = buildingRequest; |
| 110 | + this.filter = filter; |
| 111 | + configProperties.put( ConflictResolver.CONFIG_PROP_VERBOSE, true ); |
| 112 | + configProperties.put( DependencyManagerUtils.CONFIG_PROP_VERBOSE, true ); |
| 113 | + } |
| 114 | + |
| 115 | + public ProjectBuildingRequest getBuildingRequest() |
| 116 | + { |
| 117 | + return buildingRequest; |
| 118 | + } |
| 119 | + |
| 120 | + public ArtifactFilter getFilter() |
| 121 | + { |
| 122 | + return filter; |
| 123 | + } |
| 124 | + |
| 125 | + public DependencySelector getDependencySelector() |
| 126 | + { |
| 127 | + return dependencySelector; |
| 128 | + } |
| 129 | + |
| 130 | + public DependencyCollectorRequest dependencySelector( DependencySelector dependencySelector ) |
| 131 | + { |
| 132 | + this.dependencySelector = dependencySelector; |
| 133 | + return this; |
| 134 | + } |
| 135 | + |
| 136 | + public DependencyGraphTransformer getDependencyGraphTransformer() |
| 137 | + { |
| 138 | + return dependencyGraphTransformer; |
| 139 | + } |
| 140 | + |
| 141 | + public DependencyCollectorRequest dependencyGraphTransformer( |
| 142 | + DependencyGraphTransformer dependencyGraphTransformer ) |
| 143 | + { |
| 144 | + this.dependencyGraphTransformer = dependencyGraphTransformer; |
| 145 | + return this; |
| 146 | + } |
| 147 | + |
| 148 | + public Map<String, Object> getConfigProperties() |
| 149 | + { |
| 150 | + return this.configProperties; |
| 151 | + } |
| 152 | + |
| 153 | + public void addConfigProperty( String key, Object value ) |
| 154 | + { |
| 155 | + this.configProperties.put( key, value ); |
| 156 | + } |
| 157 | + |
| 158 | + public void removeConfigProperty( String key ) |
| 159 | + { |
| 160 | + this.configProperties.remove( key ); |
| 161 | + } |
| 162 | +} |
0 commit comments