Skip to content
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

Convert AbstractEclipseTestMojo to use Aether API #4294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@
import java.util.StringJoiner;
import java.util.concurrent.ExecutionException;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
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.model.Dependency;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.surefire.api.booter.ProviderParameterNames;
import org.apache.maven.surefire.api.util.ScanResult;
import org.apache.maven.surefire.booter.BooterConstants;
import org.apache.maven.surefire.booter.PropertiesWrapper;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
Expand Down Expand Up @@ -325,9 +325,6 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo {
@Component
protected RepositorySystem repositorySystem;

@Component
private ResolutionErrorHandler resolutionErrorHandler;

@Component(role = TychoProject.class)
private Map<String, TychoProject> projectTypes;

Expand Down Expand Up @@ -1208,23 +1205,28 @@ private List<File> getFrameworkExtensions() throws MojoExecutionException {

if (frameworkExtensions != null) {
for (Dependency frameworkExtension : frameworkExtensions) {
Artifact artifact = repositorySystem.createDependencyArtifact(frameworkExtension);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setResolveRoot(true).setResolveTransitively(false);
request.setLocalRepository(session.getLocalRepository());
// XXX wrong repositories -- these are user artifacts, not plugin artifacts
request.setRemoteRepositories(project.getPluginArtifactRepositories());
request.setOffline(session.isOffline());
request.setForceUpdate(session.getRequest().isUpdateSnapshots());
ArtifactResolutionResult result = repositorySystem.resolve(request);
org.eclipse.aether.artifact.Artifact artifact = new org.eclipse.aether.artifact.DefaultArtifact(
frameworkExtension.getGroupId(), frameworkExtension.getArtifactId(),
frameworkExtension.getType(), frameworkExtension.getVersion());
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.setRepositories(RepositoryUtils.toRepos(project.getRemoteArtifactRepositories()));
ArtifactResult artifactResult;
try {
resolutionErrorHandler.throwErrors(request, result);
artifactResult = repositorySystem.resolveArtifact(session.getRepositorySession(), artifactRequest);
if (artifactResult.isResolved()) {
files.add(artifactResult.getArtifact().getFile());
} else {
MojoExecutionException exception = new MojoExecutionException(
"Failed to resolve framework extension " + frameworkExtension.getManagementKey());
artifactResult.getExceptions().forEach(exception::addSuppressed);
throw exception;
}
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException(
"Failed to resolve framework extension " + frameworkExtension.getManagementKey(), e);
}
files.add(artifact.getFile());

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -50,8 +51,8 @@
* harness bundles. The bundles are resolved from the target platform of the project. Note that the
* test runtime does typically <em>not</em> contain the entire target platform. If there are
* implicitly required bundles (e.g. <code>org.apache.felix.scr</code> to make declarative services
* work), they need to be added manually through an <code>extraRequirements</code> configuration on the
* <code>target-platform-configuration</code> plugin.
* work), they need to be added manually through an <code>extraRequirements</code> configuration on
* the <code>target-platform-configuration</code> plugin.
* </p>
* <p>
* This goal adopts the maven-failsafe paradigm, that works in the following way:
Expand Down Expand Up @@ -99,6 +100,9 @@ public class TychoIntegrationTestMojo extends AbstractEclipseTestMojo {
@Parameter(defaultValue = "${localRepository}", required = true, readonly = true)
private ArtifactRepository localRepository;

@Component
protected org.apache.maven.repository.RepositorySystem oldRepositorySystem;

/**
* Configures the packaging type where this mojos applies
*/
Expand Down Expand Up @@ -201,7 +205,7 @@ protected boolean useMetadataDirectory(ReactorProject otherProject) {
}

private ArtifactResolutionResult resolveDependency(final Dependency dependency) {
final var artifact = repositorySystem.createDependencyArtifact(dependency);
final var artifact = oldRepositorySystem.createDependencyArtifact(dependency);
final var remoteRepositories = new ArrayList<ArtifactRepository>(32);
remoteRepositories.addAll(pluginRemoteRepositories);
remoteRepositories.addAll(projectRemoteRepositories);
Expand All @@ -213,7 +217,7 @@ private ArtifactResolutionResult resolveDependency(final Dependency dependency)
.setResolveTransitively(true)//
.setCollectionFilter(new ProviderDependencyArtifactFilter())//
.setRemoteRepositories(remoteRepositories);
return repositorySystem.resolve(request);
return oldRepositorySystem.resolve(request);
}

private static final class ProviderDependencyArtifactFilter implements ArtifactFilter {
Expand Down
Loading