-
Notifications
You must be signed in to change notification settings - Fork 169
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
Move away from legacy maven-compat #151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,14 +40,8 @@ | |
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.artifact.DefaultArtifact; | ||
import org.apache.maven.artifact.handler.ArtifactHandler; | ||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; | ||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; | ||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; | ||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler; | ||
import org.apache.maven.artifact.versioning.VersionRange; | ||
import org.apache.maven.execution.MavenExecutionRequest; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
|
@@ -56,7 +50,6 @@ | |
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.project.MavenProject; | ||
import org.apache.maven.repository.RepositorySystem; | ||
import org.apache.maven.shared.incremental.IncrementalBuildHelper; | ||
import org.apache.maven.shared.incremental.IncrementalBuildHelperRequest; | ||
import org.apache.maven.shared.utils.ReaderFactory; | ||
|
@@ -85,6 +78,16 @@ | |
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; | ||
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor; | ||
import org.codehaus.plexus.languages.java.version.JavaVersion; | ||
import org.eclipse.aether.RepositorySystem; | ||
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.resolution.ArtifactResolutionException; | ||
import org.eclipse.aether.resolution.ArtifactResult; | ||
import org.eclipse.aether.resolution.DependencyRequest; | ||
import org.eclipse.aether.resolution.DependencyResult; | ||
import org.eclipse.aether.util.artifact.JavaScopes; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
|
||
|
@@ -583,12 +586,6 @@ public abstract class AbstractCompilerMojo | |
@Component | ||
private ArtifactHandlerManager artifactHandlerManager; | ||
|
||
/** | ||
* Throws an exception on artifact resolution errors. | ||
*/ | ||
@Component | ||
private ResolutionErrorHandler resolutionErrorHandler; | ||
|
||
protected abstract SourceInclusionScanner getSourceInclusionScanner( int staleMillis ); | ||
|
||
protected abstract SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding ); | ||
|
@@ -1847,29 +1844,36 @@ private List<String> resolveProcessorPathEntries() | |
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( coord.getType() ); | ||
|
||
Artifact artifact = new DefaultArtifact( | ||
coord.getGroupId(), | ||
coord.getArtifactId(), | ||
VersionRange.createFromVersionSpec( coord.getVersion() ), | ||
Artifact.SCOPE_RUNTIME, | ||
coord.getType(), | ||
coord.getClassifier(), | ||
handler, | ||
false ); | ||
|
||
ArtifactResolutionRequest request = new ArtifactResolutionRequest() | ||
.setArtifact( artifact ) | ||
.setResolveRoot( true ) | ||
.setResolveTransitively( true ) | ||
.setLocalRepository( session.getLocalRepository() ) | ||
.setRemoteRepositories( project.getRemoteArtifactRepositories() ); | ||
|
||
ArtifactResolutionResult resolutionResult = repositorySystem.resolve( request ); | ||
|
||
resolutionErrorHandler.throwErrors( request, resolutionResult ); | ||
|
||
for ( Artifact resolved : resolutionResult.getArtifacts() ) | ||
coord.getGroupId(), | ||
coord.getArtifactId(), | ||
coord.getClassifier(), | ||
handler.getExtension(), | ||
coord.getVersion() | ||
); | ||
|
||
CollectRequest collectRequest = new CollectRequest( new Dependency( artifact, JavaScopes.RUNTIME ), | ||
project.getRemoteProjectRepositories() ); | ||
DependencyRequest dependencyRequest = new DependencyRequest(); | ||
dependencyRequest.setCollectRequest( collectRequest ); | ||
DependencyResult dependencyResult = repositorySystem.resolveDependencies( | ||
session.getRepositorySession(), dependencyRequest ); | ||
|
||
ArrayList<ArtifactResult> failed = new ArrayList<>(); | ||
for ( ArtifactResult resolved : dependencyResult.getArtifactResults() ) | ||
{ | ||
if ( resolved.getArtifact() != null && resolved.getArtifact().getFile() != null ) | ||
{ | ||
elements.add( resolved.getArtifact().getFile().getAbsolutePath() ); | ||
} | ||
else | ||
{ | ||
failed.add( resolved ); | ||
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. Can this actually happen or would this not just throw a 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. I believe you are right. If the one the dependencies cannot be resolved,
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. Correct. In addition, result.getExceptions() will contain the list of all gathered exceptions (if there are more than one). |
||
} | ||
} | ||
if ( !failed.isEmpty() ) | ||
{ | ||
elements.add( resolved.getFile().getAbsolutePath() ); | ||
throw new MojoExecutionException( "Error resolving processor path entries", | ||
new ArtifactResolutionException( failed ) ); | ||
} | ||
} | ||
return new ArrayList<>( elements ); | ||
|
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 found that if you don not need to Inject parameters into the Mojo and thus do not test the Mojos run method, one can also go with PlexusTestcase see:
https://github.com/eclipse-tycho/tycho/blob/fdda7227e6cd714c2e120f70dd624cde2cca4ce1/tycho-p2/tycho-p2-facade/src/test/java/org/eclipse/tycho/p2/facade/test/MetadataSerializableImplTest.java
Still, I think this is a bit of a "blind-spot" that there is not a JUnit5 / Non-Compat replacement for a MojoTestCase.