Skip to content

Commit

Permalink
Fixed Maven artifact resolver initialization in QuarkusProjectMojoBase
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Sep 11, 2024
1 parent e1577e6 commit 30a96b1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.maven;

import static io.quarkus.devtools.project.CodestartResourceLoadersBuilder.getCodestartResourceLoaders;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -18,24 +16,23 @@
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.repository.RemoteRepository;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.CodestartResourceLoadersBuilder;
import io.quarkus.devtools.project.JavaVersion;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.buildfile.MavenProjectBuildFile;
import io.quarkus.maven.components.QuarkusWorkspaceProvider;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.utilities.MojoUtils;
import io.quarkus.platform.descriptor.loader.json.ResourceLoader;
import io.quarkus.platform.tools.ToolsConstants;
import io.quarkus.platform.tools.ToolsUtils;
Expand All @@ -56,9 +53,6 @@ public abstract class QuarkusProjectMojoBase extends AbstractMojo {
@Parameter(defaultValue = "${session}", readonly = true)
MavenSession session;

@Component
protected RepositorySystem repoSystem;

@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
protected RepositorySystemSession repoSession;

Expand All @@ -75,7 +69,7 @@ public abstract class QuarkusProjectMojoBase extends AbstractMojo {
private String bomVersion;

@Component
RemoteRepositoryManager remoteRepositoryManager;
QuarkusWorkspaceProvider workspaceProvider;

private List<ArtifactCoords> importedPlatforms;

Expand Down Expand Up @@ -108,8 +102,13 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException("Failed to initialize Quarkus Maven extension manager", e);
}
} else {
final List<ResourceLoader> codestartsResourceLoader = getCodestartResourceLoaders(resolveExtensionCatalog());
quarkusProject = QuarkusProject.of(baseDir(), resolveExtensionCatalog(),
final ExtensionCatalog extensionCatalog = resolveExtensionCatalog();
final List<ResourceLoader> codestartsResourceLoader = CodestartResourceLoadersBuilder
.codestartLoadersBuilder()
.artifactResolver(artifactResolver())
.catalog(extensionCatalog)
.build();
quarkusProject = QuarkusProject.of(baseDir(), extensionCatalog,
codestartsResourceLoader,
log, buildTool, JavaVersion.NA);
}
Expand Down Expand Up @@ -180,25 +179,19 @@ protected List<ArtifactCoords> getImportedPlatforms() throws MojoExecutionExcept
}

protected MavenArtifactResolver catalogArtifactResolver() throws MojoExecutionException {
return artifactResolver;
return artifactResolver();
}

protected MavenArtifactResolver artifactResolver() throws MojoExecutionException {
return artifactResolver == null ? artifactResolver = initArtifactResolver() : artifactResolver;
}

protected MavenArtifactResolver initArtifactResolver() throws MojoExecutionException {
try {
return MavenArtifactResolver.builder()
.setRepositorySystem(repoSystem)
.setRepositorySystemSession(
getLog().isDebugEnabled() ? repoSession : MojoUtils.muteTransferListener(repoSession))
.setRemoteRepositories(repos)
.setRemoteRepositoryManager(remoteRepositoryManager)
.build();
} catch (BootstrapMavenException e) {
throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e);
}
return workspaceProvider.createArtifactResolver(
BootstrapMavenContext.config()
.setArtifactTransferLogging(getLog().isDebugEnabled())
.setRepositorySystem(workspaceProvider.getRepositorySystem())
.setRemoteRepositoryManager(workspaceProvider.getRemoteRepositoryManager()));
}

private List<ArtifactCoords> collectImportedPlatforms()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected MavenArtifactResolver catalogArtifactResolver() throws MojoExecutionEx
protected MavenArtifactResolver initArtifactResolver() throws MojoExecutionException {
return workspaceProvider.createArtifactResolver(BootstrapMavenContext.config()
.setUserSettings(session.getRequest().getUserSettingsFile())
.setRemoteRepositoryManager(remoteRepositoryManager)
.setRemoteRepositoryManager(workspaceProvider.getRemoteRepositoryManager())
// The system needs to be initialized with the bootstrap model builder to properly interpolate system properties set on the command line
// e.g. -Dquarkus.platform.version=xxx
//.setRepositorySystem(workspaceProvider.getRepositorySystem())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import org.junit.jupiter.api.Test;

import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContextConfig;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.resolver.maven.workspace.ModelUtils;
import io.quarkus.devtools.testing.RegistryClientTestHelper;
import io.quarkus.maven.components.QuarkusWorkspaceProvider;

class AddExtensionMojoTest {

Expand Down Expand Up @@ -64,10 +66,21 @@ void init() throws Exception {
new BootstrapMavenContext(BootstrapMavenContext.config()
.setCurrentProject(OUTPUT_POM.getAbsolutePath())
.setOffline(true)));
mojo.repoSystem = mvn.getSystem();
mojo.repoSession = mvn.getSession();
mojo.repos = mvn.getRepositories();
mojo.remoteRepositoryManager = mvn.getRemoteRepositoryManager();
mojo.workspaceProvider = new QuarkusWorkspaceProvider(null, null, null, null, null,
mvn.getRemoteRepositoryManager(),
mvn.getMavenContext().getSettingsDecrypter()) {
@Override
public BootstrapMavenContext createMavenContext(BootstrapMavenContextConfig<?> config) {
return mvn.getMavenContext();
}

@Override
public MavenArtifactResolver createArtifactResolver(BootstrapMavenContextConfig<?> config) {
return mvn;
}
};

final Model effectiveModel = model.clone();
final DependencyManagement dm = new DependencyManagement();
Expand Down

0 comments on commit 30a96b1

Please sign in to comment.