-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MENFORCER-466: Apply the all levels (so, including direct) scope and …
…optional selectors on RequireUpperBoundDeps
- Loading branch information
Showing
9 changed files
with
215 additions
and
61 deletions.
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.resolveTransitiveDependencies( | ||
// 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; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...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,51 @@ | ||
/* | ||
* 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 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 String[] excluded; | ||
|
||
public AllLevelsScopeDependencySelector(String... excluded) { | ||
this.excluded = excluded; | ||
} | ||
|
||
@Override | ||
public boolean selectDependency(Dependency dependency) { | ||
return Arrays.stream(excluded) | ||
.map(scope -> !scope.equals(dependency.getScope())) | ||
.reduce(Boolean::logicalAnd) | ||
.orElse(true); | ||
} | ||
|
||
@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.