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
Fix #326 Migrate to using Maven 3 APIs and Aether for dependency resolution #327
Conversation
c985d30
to
363900f
Compare
Set required Maven version to 3.5.4, as that is the version used by CI. |
+1 |
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.
There are some questions and suggestions inline.
Besides, could you please reword to Fix #326 ...
?
* Set repo session in the components that need it. | ||
* @param session The repository system session | ||
*/ | ||
public void setAetherRepoSession( RepositorySystemSession session ) |
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.
Why is this setter needed? I do not see it called from anywhere.
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.
Maven calls it when injecting the RepositorySystemSession. The idea was to have this setter initialize the fields in the other classes. I couldn't find a way to get the DI framework to inject it.
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.
Replaced with MavenSession injection
* Set repo session in the components that need it. | ||
* @param session The repository system session | ||
*/ | ||
public void setAetherRepoSession( RepositorySystemSession session ) |
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.
Why is this setter needed? I do not see it called from anywhere.
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.
Replaced with MavenSession injection
* Set repo session in the components that need it. | ||
* @param session The repository system session | ||
*/ | ||
public void setAetherRepoSession( RepositorySystemSession session ) |
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.
Why is this setter needed? I do not see it called from anywhere.
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.
Replaced with MavenSession injection
String type, String classifier, ArtifactRepository localRepository, List<ArtifactRepository> repositories ) | ||
throws ArtifactResolutionException, IOException, ArtifactNotFoundException | ||
String type, String classifier, List<RemoteRepository> remoteRepositories ) | ||
throws ArtifactResolutionException | ||
{ | ||
// TODO: this is a bit crude - proper type, or proper handling as metadata rather than an artifact in 2.1? |
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.
Shouldn't this comment be removed? It does not seem to make any sense anymore.
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.
Maybe? I understood the comment to say that handling the third party descriptor as an artifact was crude, but I'm not sure what the intended alternative was. I'll remove the comment.
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.
Removed the comment
@Override | ||
public void setAetherRepoSession( RepositorySystemSession aetherRepoSession ) | ||
{ | ||
this.aetherRepoSession = aetherRepoSession; |
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.
Making aetherRepoSession mutable in this way does not feel good. If there is no way to persuade plexus to inject it, I vote for removing the aetherRepoSession field and pass it via method parameter.
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.
I agree, it is not nice. I couldn't find a way to inject it. I'll move it to method parameters.
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.
Replaced with MavenSession injection
*/ | ||
Properties props = new Properties(); | ||
props.putAll( System.getProperties() ); | ||
ProjectBuildingRequest req = new DefaultProjectBuildingRequest() |
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.
Do we need a new instance of ProjectBuildingRequest for each iteration of the enclosing for loop?
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.
The parameters don't change, so probably not. I'll change it to reuse the request.
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.
I think it is better here. Constructing the request shouldn't take any real time, and moving it outside the for loop puts a lot of distance between the declaration and use of the request.
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.
Constructing the request shouldn't take any real time
It very much depends on how many iterations the loop has and also on how many sys props are set.
puts a lot of distance
Sounds like a readability/aesthetics concern? - those are important, but here, I'd favor performance, unless proven that pulling the req out of the loop is technically impossible.
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.
Sure, but the system properties aren't being copied anymore, since the session change.
It's just a readability concern.
I'll move it out of the loop.
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.
Done
* Some POMs may refer to e.g. java.home or java.version, | ||
* so we need to ensure common system properties are set when parsing POMs. | ||
* Using the current system properties seems like a decent solution. | ||
*/ |
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.
I wonder if it wasn't safer to derive the ProjectBuildingRequest from the currently running request. Something like https://github.com/blackducksoftware/hub-maven-plugin/blob/master/src/main/java/com/blackducksoftware/integration/maven/MavenDependencyExtractor.java#L73
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.
That looks better, wasn't aware of MavenSession. Will try it out.
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.
Using MavenSession
|
||
public void setAetherRepoSession( RepositorySystemSession aetherRepoSession ) | ||
{ | ||
this.aetherRepoSession = aetherRepoSession; |
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.
Making aetherRepoSession mutable in this way does not feel good. If there is no way to persuade plexus to inject it, I vote for removing the aetherRepoSession field and pass it via method parameter.
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.
Replaced with MavenSession injection
@@ -216,4 +231,8 @@ public void loadProjectDependencies( ResolvedProjectDependencies artifacts, | |||
} | |||
// CHECKSTYLE_ON: MethodLength | |||
|
|||
public void setAetherRepoSession( RepositorySystemSession aetherRepoSession ) | |||
{ | |||
this.aetherRepoSession = aetherRepoSession; |
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.
Making aetherRepoSession mutable in this way does not feel good. If there is no way to persuade plexus to inject it, I vote for removing the aetherRepoSession field and pass it via method parameter.
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.
Replaced with MavenSession injection
Addressed comments, and reworded commit message. The MavenSession has a getter for the RepositorySystemSession, and can be injected with |
The test failure is a timeout.
|
Thanks, looks very good. |
Yes, done. |
Ouch, an editorconfig violation. Otherwise looks mergeable. Thanks! |
…ncy resolution
Great work, thanks a lot, @srdo ! |
Based on #324, please look at that one first.
This migrates the plugin to Maven 3 dependencies, and also replaces the old ArtifactResolver with maven-resolver.
The version requirement here is at least 3.5.0, as maven-resolver-provider is not present in prior versions. For now I've set the plugin to need 3.6.1, as that was what I tested with.