-
Notifications
You must be signed in to change notification settings - Fork 28
[MSHARED-1158] make DependencyCollectorBuilder more configurable #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
olamy
merged 2 commits into
master
from
MSHARED-1158-DefaultDependencyCollectorBuilder-configurable
Nov 11, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/main/java/org/apache/maven/shared/dependency/graph/DependencyCollectorRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package org.apache.maven.shared.dependency.graph; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; | ||
import org.apache.maven.project.ProjectBuildingRequest; | ||
import org.apache.maven.shared.dependency.graph.internal.DirectScopeDependencySelector; | ||
import org.apache.maven.shared.dependency.graph.internal.VerboseJavaScopeSelector; | ||
import org.eclipse.aether.collection.DependencyGraphTransformer; | ||
import org.eclipse.aether.collection.DependencySelector; | ||
import org.eclipse.aether.util.artifact.JavaScopes; | ||
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; | ||
import org.eclipse.aether.util.graph.selector.AndDependencySelector; | ||
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector; | ||
import org.eclipse.aether.util.graph.selector.OptionalDependencySelector; | ||
import org.eclipse.aether.util.graph.transformer.ConflictResolver; | ||
import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver; | ||
import org.eclipse.aether.util.graph.transformer.NearestVersionSelector; | ||
import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* <div> | ||
* This class will carry various options used by | ||
* {@link DependencyCollectorBuilder#collectDependencyGraph(DependencyCollectorRequest)} | ||
* </div> | ||
* <div> | ||
* There is a set of default values such: | ||
* </div> | ||
* <div> | ||
* DependencySelector | ||
* <pre> | ||
* new AndDependencySelector( | ||
* new DirectScopeDependencySelector( JavaScopes.TEST ), | ||
* new DirectScopeDependencySelector( JavaScopes.PROVIDED ), | ||
* new OptionalDependencySelector(), | ||
* new ExclusionDependencySelector() ); | ||
* </pre> | ||
* </div> | ||
* <div> | ||
* DependencyGraphTransformer | ||
* <pre> | ||
* new ConflictResolver( | ||
* new NearestVersionSelector(), | ||
* new VerboseJavaScopeSelector(), | ||
* new SimpleOptionalitySelector(), | ||
* new JavaScopeDeriver() ); | ||
* </pre> | ||
* </div> | ||
* <div> | ||
* configProperties have 2 default values | ||
* <pre> | ||
* ConflictResolver.CONFIG_PROP_VERBOSE, true | ||
* DependencyManagerUtils.CONFIG_PROP_VERBOSE, true | ||
* </pre> | ||
* <a href="https://maven.apache.org/resolver/configuration.html">Move Resolver configuration properties</a>. | ||
* </div> | ||
* @since 3.2.1 | ||
*/ | ||
public class DependencyCollectorRequest | ||
{ | ||
|
||
private final ProjectBuildingRequest buildingRequest; | ||
|
||
private ArtifactFilter filter; | ||
|
||
private Map<String, Object> configProperties = new HashMap<>(); | ||
|
||
private DependencySelector dependencySelector = new AndDependencySelector( | ||
new DirectScopeDependencySelector( JavaScopes.TEST ), | ||
new DirectScopeDependencySelector( JavaScopes.PROVIDED ), | ||
new OptionalDependencySelector(), | ||
new ExclusionDependencySelector() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well TBH this empty ExclusionDependencySelector doesn't have any effect. we could simply remove it and the code not will not pass tru to do nothing :) |
||
|
||
private DependencyGraphTransformer dependencyGraphTransformer = new ConflictResolver( | ||
new NearestVersionSelector(), | ||
new VerboseJavaScopeSelector(), | ||
new SimpleOptionalitySelector(), | ||
new JavaScopeDeriver() ); | ||
|
||
public DependencyCollectorRequest( ProjectBuildingRequest buildingRequest ) | ||
{ | ||
this( buildingRequest, null ); | ||
} | ||
|
||
public DependencyCollectorRequest( ProjectBuildingRequest buildingRequest, ArtifactFilter filter ) | ||
{ | ||
Objects.requireNonNull( buildingRequest, "ProjectBuildingRequest cannot be null" ); | ||
this.buildingRequest = buildingRequest; | ||
this.filter = filter; | ||
configProperties.put( ConflictResolver.CONFIG_PROP_VERBOSE, true ); | ||
configProperties.put( DependencyManagerUtils.CONFIG_PROP_VERBOSE, true ); | ||
} | ||
|
||
public ProjectBuildingRequest getBuildingRequest() | ||
{ | ||
return buildingRequest; | ||
} | ||
|
||
public ArtifactFilter getFilter() | ||
{ | ||
return filter; | ||
} | ||
|
||
public DependencySelector getDependencySelector() | ||
{ | ||
return dependencySelector; | ||
} | ||
|
||
public DependencyCollectorRequest dependencySelector( DependencySelector dependencySelector ) | ||
{ | ||
this.dependencySelector = dependencySelector; | ||
return this; | ||
} | ||
|
||
public DependencyGraphTransformer getDependencyGraphTransformer() | ||
{ | ||
return dependencyGraphTransformer; | ||
} | ||
|
||
public DependencyCollectorRequest dependencyGraphTransformer( | ||
DependencyGraphTransformer dependencyGraphTransformer ) | ||
{ | ||
this.dependencyGraphTransformer = dependencyGraphTransformer; | ||
return this; | ||
} | ||
|
||
public Map<String, Object> getConfigProperties() | ||
{ | ||
return this.configProperties; | ||
} | ||
|
||
public void addConfigProperty( String key, Object value ) | ||
{ | ||
this.configProperties.put( key, value ); | ||
} | ||
|
||
public void removeConfigProperty( String key ) | ||
{ | ||
this.configProperties.remove( key ); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.