-
Notifications
You must be signed in to change notification settings - Fork 158
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
[MENFORCER-466] Apply the all levels scope and optional selectors on RequireUpperBoundDeps #254
Merged
slawekjaranowski
merged 2 commits into
apache:master
from
andrzejj0:MENFORCER-466-provided-optional
Mar 17, 2023
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -22,21 +22,21 @@ | |
import javax.inject.Named; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.enforcer.rule.api.EnforcerRuleException; | ||
import org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule; | ||
import org.apache.maven.enforcer.rules.dependency.selector.AllLevelsOptionalDependencySelector; | ||
import org.apache.maven.enforcer.rules.dependency.selector.AllLevelsScopeDependencySelector; | ||
import org.apache.maven.enforcer.rules.utils.ArtifactUtils; | ||
import org.eclipse.aether.collection.DependencyCollectionContext; | ||
import org.eclipse.aether.collection.DependencySelector; | ||
import org.eclipse.aether.graph.Dependency; | ||
import org.eclipse.aether.graph.DependencyNode; | ||
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector; | ||
|
||
import static org.apache.maven.artifact.Artifact.SCOPE_PROVIDED; | ||
import static org.apache.maven.artifact.Artifact.SCOPE_TEST; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Rex Hoffman</a> | ||
*/ | ||
|
@@ -49,8 +49,6 @@ public final class DependencyConvergence extends AbstractStandardEnforcerRule { | |
|
||
private List<String> excludes; | ||
|
||
private List<String> scopes = Arrays.asList(Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_SYSTEM); | ||
|
||
private DependencyVersionMap dependencyVersionMap; | ||
|
||
private final ResolveUtil resolveUtil; | ||
|
@@ -64,23 +62,8 @@ public DependencyConvergence(ResolveUtil resolveUtil) { | |
public void execute() throws EnforcerRuleException { | ||
|
||
DependencyNode node = resolveUtil.resolveTransitiveDependenciesVerbose( | ||
// TODO: use a modified version of ExclusionDependencySelector to process excludes and includes | ||
new DependencySelector() { | ||
@Override | ||
public boolean selectDependency(Dependency dependency) { | ||
// regular OptionalDependencySelector only discriminates optional dependencies at level 2+ | ||
return !dependency.isOptional() | ||
// regular scope selectors only discard transitive dependencies | ||
// and always allow direct dependencies | ||
&& scopes.contains(dependency.getScope()); | ||
} | ||
|
||
@Override | ||
public DependencySelector deriveChildSelector(DependencyCollectionContext context) { | ||
return this; | ||
} | ||
}, | ||
// process dependency exclusions | ||
new AllLevelsOptionalDependencySelector(), | ||
new AllLevelsScopeDependencySelector(SCOPE_TEST, SCOPE_PROVIDED), | ||
new ExclusionDependencySelector()); | ||
dependencyVersionMap = new DependencyVersionMap().setUniqueVersions(uniqueVersions); | ||
node.accept(dependencyVersionMap); | ||
|
@@ -142,7 +125,7 @@ private String buildConvergenceErrorMsg(List<DependencyNode> nodeList) { | |
@Override | ||
public String toString() { | ||
return String.format( | ||
"DependencyConvergence[includes=%s, excludes=%s, uniqueVersions=%b, scopes=%s]", | ||
includes, excludes, uniqueVersions, String.join(",", scopes)); | ||
"DependencyConvergence[includes=%s, excludes=%s, uniqueVersions=%b]", | ||
includes, excludes, uniqueVersions); | ||
} | ||
} |
This file contains 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
40 changes: 40 additions & 0 deletions
40
.../apache/maven/enforcer/rules/dependency/selector/AllLevelsOptionalDependencySelector.java
This file contains 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,40 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.maven.enforcer.rules.dependency.selector; | ||
|
||
import org.eclipse.aether.collection.DependencyCollectionContext; | ||
import org.eclipse.aether.collection.DependencySelector; | ||
import org.eclipse.aether.graph.Dependency; | ||
|
||
/** | ||
* Dependency selector discarding {@code optional} dependencies on all levels. | ||
* The standard {@link org.eclipse.aether.util.graph.selector.OptionalDependencySelector} | ||
* does not discard direct dependencies. | ||
*/ | ||
public class AllLevelsOptionalDependencySelector implements DependencySelector { | ||
@Override | ||
public boolean selectDependency(Dependency dependency) { | ||
return !dependency.isOptional(); | ||
} | ||
|
||
@Override | ||
public DependencySelector deriveChildSelector(DependencyCollectionContext context) { | ||
return this; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...org/apache/maven/enforcer/rules/dependency/selector/AllLevelsScopeDependencySelector.java
This file contains 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,50 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.maven.enforcer.rules.dependency.selector; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.eclipse.aether.collection.DependencyCollectionContext; | ||
import org.eclipse.aether.collection.DependencySelector; | ||
import org.eclipse.aether.graph.Dependency; | ||
|
||
/** | ||
* Dependency selector discarding dependencies with the given scope on all levels. | ||
* The standard {@link org.eclipse.aether.util.graph.selector.ScopeDependencySelector} | ||
* does not discard direct dependencies. | ||
*/ | ||
public class AllLevelsScopeDependencySelector implements DependencySelector { | ||
private final Collection<String> excluded; | ||
|
||
public AllLevelsScopeDependencySelector(String... excluded) { | ||
this.excluded = excluded != null ? Arrays.asList(excluded) : Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public boolean selectDependency(Dependency dependency) { | ||
return !excluded.contains(dependency.getScope()); | ||
} | ||
|
||
@Override | ||
public DependencySelector deriveChildSelector(DependencyCollectionContext context) { | ||
return this; | ||
} | ||
} |
This file contains 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
34 changes: 34 additions & 0 deletions
34
maven-enforcer-plugin/src/it/mrm/repository/menforcer466_requires_api150-1.0.pom
This file contains 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,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
* 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. | ||
* | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.apache.maven.plugins.enforcer.its</groupId> | ||
<artifactId>menforcer466_requires_api150</artifactId> | ||
<version>1.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins.enforcer.its</groupId> | ||
<artifactId>menforcer128_api</artifactId> | ||
<version>1.5.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
maven-enforcer-plugin/src/it/mrm/repository/menforcer466_requires_utils30-1.0.pom
This file contains 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,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
* 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. | ||
* | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.apache.maven.plugins.enforcer.its</groupId> | ||
<artifactId>menforcer466_requires_utils30</artifactId> | ||
<version>1.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins.enforcer.its</groupId> | ||
<artifactId>menforcer138_utils</artifactId> | ||
<version>3.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains 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
18 changes: 0 additions & 18 deletions
18
maven-enforcer-plugin/src/it/projects/require-upper-bound-deps-provided/invoker.properties
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a new parameter according to: MENFORCER-470
But ok - I will restore it as
exludesScopes