-
Notifications
You must be signed in to change notification settings - Fork 154
Enh: Allow validator factory to abstain #2008
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
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9de30f
Enh: Allow validator factory to abstain
cstamas c7626b0
Introduce new validator method.
cstamas e5b25d7
Merge remote-tracking branch 'upstream/master' into issue-2007
cstamas 819997e
Add PR review changes
cstamas 3baceec
Update maven-resolver-impl/src/main/java/org/eclipse/aether/internal/…
cstamas e1ef2b0
PR comments
cstamas 52d819d
Tidy up UT
cstamas ddd50e0
Lower case
cstamas 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
289 changes: 162 additions & 127 deletions
289
...impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemValidator.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
158 changes: 158 additions & 0 deletions
158
.../src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemValidatorTest.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,158 @@ | ||
| /* | ||
| * 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.eclipse.aether.internal.impl; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import org.eclipse.aether.DefaultRepositoryCache; | ||
| import org.eclipse.aether.DefaultRepositorySystemSession; | ||
| import org.eclipse.aether.artifact.Artifact; | ||
| import org.eclipse.aether.artifact.DefaultArtifact; | ||
| import org.eclipse.aether.collection.CollectRequest; | ||
| import org.eclipse.aether.graph.Dependency; | ||
| import org.eclipse.aether.internal.test.util.TestUtils; | ||
| import org.eclipse.aether.resolution.ArtifactDescriptorRequest; | ||
| import org.eclipse.aether.spi.validator.Validator; | ||
| import org.eclipse.aether.spi.validator.ValidatorFactory; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class DefaultRepositorySystemValidatorTest { | ||
| @Test | ||
| void abstain() { | ||
| DefaultRepositorySystemValidator validator = new DefaultRepositorySystemValidator( | ||
| Collections.singletonMap("abstain", session -> ValidatorFactory.NOOP)); | ||
| ArtifactDescriptorRequest request = | ||
| new ArtifactDescriptorRequest(new DefaultArtifact("foo:bar:1.0"), Collections.emptyList(), "test"); | ||
| assertDoesNotThrow(() -> validator.validateArtifactDescriptorRequest(TestUtils.newSession(), request)); | ||
| } | ||
|
|
||
| @Test | ||
| void fail() { | ||
| DefaultRepositorySystemValidator validator = | ||
| new DefaultRepositorySystemValidator(Collections.singletonMap("abstain", session -> new Validator() { | ||
| @Override | ||
| public void validateArtifact(Artifact artifact) throws IllegalArgumentException { | ||
| throw new IllegalArgumentException("Artifact validation failed"); | ||
| } | ||
| })); | ||
| ArtifactDescriptorRequest request = | ||
| new ArtifactDescriptorRequest(new DefaultArtifact("foo:bar:1.0"), Collections.emptyList(), "test"); | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> validator.validateArtifactDescriptorRequest(TestUtils.newSession(), request)); | ||
| } | ||
|
|
||
| @Test | ||
| void withCaching() { | ||
| final ConcurrentHashMap<Integer, AtomicInteger> instanceCounter = new ConcurrentHashMap<>(); | ||
| DefaultRepositorySystemValidator validator = | ||
| new DefaultRepositorySystemValidator(Collections.singletonMap("counter", session -> new Validator() { | ||
| @Override | ||
| public void validateArtifact(Artifact artifact) throws IllegalArgumentException { | ||
| instanceCounter | ||
| .computeIfAbsent(System.identityHashCode(this), k -> new AtomicInteger(0)) | ||
| .incrementAndGet(); | ||
| } | ||
| })); | ||
| DefaultRepositorySystemSession sameSession = TestUtils.newSession(); | ||
| sameSession.setCache(new DefaultRepositoryCache()); // with cache | ||
| assertDoesNotThrow(() -> validator.validateArtifactDescriptorRequest( | ||
| sameSession, | ||
| new ArtifactDescriptorRequest(new DefaultArtifact("foo:bar:1.0"), Collections.emptyList(), "test"))); | ||
| assertDoesNotThrow(() -> validator.validateArtifactDescriptorRequest( | ||
| sameSession, | ||
| new ArtifactDescriptorRequest(new DefaultArtifact("baz:foo:1.0"), Collections.emptyList(), "test"))); | ||
| // one instance is | ||
| assertEquals(1, instanceCounter.size()); | ||
| // used twice | ||
| assertEquals( | ||
| 2, | ||
| instanceCounter | ||
| .get(instanceCounter.keySet().stream().iterator().next()) | ||
| .get()); | ||
| } | ||
|
|
||
| @Test | ||
| void withoutCaching() { | ||
| final ConcurrentHashMap<Integer, AtomicInteger> instanceCounter = new ConcurrentHashMap<>(); | ||
| DefaultRepositorySystemValidator validator = | ||
| new DefaultRepositorySystemValidator(Collections.singletonMap("counter", session -> new Validator() { | ||
| @Override | ||
| public void validateArtifact(Artifact artifact) throws IllegalArgumentException { | ||
| instanceCounter | ||
| .computeIfAbsent(System.identityHashCode(this), k -> new AtomicInteger(0)) | ||
| .incrementAndGet(); | ||
| } | ||
| })); | ||
| DefaultRepositorySystemSession sameSession = TestUtils.newSession(); | ||
| sameSession.setCache(null); // without cache | ||
| assertDoesNotThrow(() -> validator.validateArtifactDescriptorRequest( | ||
| sameSession, | ||
| new ArtifactDescriptorRequest(new DefaultArtifact("foo:bar:1.0"), Collections.emptyList(), "test"))); | ||
| assertDoesNotThrow(() -> validator.validateArtifactDescriptorRequest( | ||
| sameSession, | ||
| new ArtifactDescriptorRequest(new DefaultArtifact("baz:foo:1.0"), Collections.emptyList(), "test"))); | ||
| // two instances | ||
| assertEquals(2, instanceCounter.size()); | ||
| for (AtomicInteger counter : instanceCounter.values()) { | ||
| // each used once | ||
| assertEquals(1, counter.get()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void dependencies() { | ||
| final List<Dependency> dependencies = | ||
| Collections.singletonList(new Dependency(new DefaultArtifact("foo:bar:1.0"), "compile")); | ||
| final List<Dependency> managedDependencies = | ||
| Collections.singletonList(new Dependency(new DefaultArtifact("baz:foo:1.0"), "compile")); | ||
|
|
||
| final AtomicInteger validateDependencies = new AtomicInteger(0); | ||
| final AtomicInteger validateManagedDependencies = new AtomicInteger(0); | ||
| DefaultRepositorySystemValidator validator = new DefaultRepositorySystemValidator(Collections.singletonMap( | ||
| "dependencies", session -> new Validator() { | ||
| @Override | ||
| public void validateDependency(Dependency dependency) throws IllegalArgumentException { | ||
| if (dependency.getArtifact().getArtifactId().equals("bar")) { | ||
| validateDependencies.incrementAndGet(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void validateManagedDependency(Dependency managedDependency) | ||
| throws IllegalArgumentException { | ||
| if (managedDependency.getArtifact().getArtifactId().equals("foo")) { | ||
| validateManagedDependencies.incrementAndGet(); | ||
| } | ||
| } | ||
| })); | ||
| assertDoesNotThrow(() -> validator.validateCollectRequest( | ||
| TestUtils.newSession(), | ||
| new CollectRequest(dependencies, managedDependencies, Collections.emptyList()))); | ||
| assertEquals(1, validateDependencies.get()); | ||
| assertEquals(1, validateManagedDependencies.get()); | ||
| } | ||
| } |
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
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
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
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
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.
nit: begin with lower case the
no periods at end
per Oracle guidelines
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.
While I agree with this sentiment, this javadoc method is not the single one in this PR not following that, and in this codebase this is not the single one either (in fact, whole codebase follows this style). I'd leave this change to some time, and IMO the change should be done consistently across whole codebase.
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.
Hm, was wrong: lowercase stands but not the "no period at end"?