diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java index 62a7e1437acf6..122ffd5be3a1c 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java @@ -1,14 +1,11 @@ package io.quarkus.maven; -import static io.quarkus.devtools.project.CodestartResourceLoadersBuilder.getCodestartResourceLoaders; - import java.io.BufferedWriter; import java.io.IOException; import java.io.StringWriter; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.apache.maven.execution.MavenSession; @@ -18,24 +15,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; @@ -56,9 +52,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; @@ -75,7 +68,7 @@ public abstract class QuarkusProjectMojoBase extends AbstractMojo { private String bomVersion; @Component - RemoteRepositoryManager remoteRepositoryManager; + QuarkusWorkspaceProvider workspaceProvider; private List importedPlatforms; @@ -108,10 +101,14 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("Failed to initialize Quarkus Maven extension manager", e); } } else { - final List codestartsResourceLoader = getCodestartResourceLoaders(resolveExtensionCatalog()); - quarkusProject = QuarkusProject.of(baseDir(), resolveExtensionCatalog(), - codestartsResourceLoader, - log, buildTool, JavaVersion.NA); + final ExtensionCatalog extensionCatalog = resolveExtensionCatalog(); + final List codestartsResourceLoader = CodestartResourceLoadersBuilder + .codestartLoadersBuilder() + .artifactResolver(artifactResolver()) + .catalog(extensionCatalog) + .build(); + quarkusProject = QuarkusProject.of(baseDir(), extensionCatalog, + codestartsResourceLoader, log, buildTool, JavaVersion.NA); } doExecute(quarkusProject, getMessageWriter()); @@ -155,7 +152,7 @@ protected List getImportedPlatforms() throws MojoExecutionExcept if (importedPlatforms == null) { if (project.getFile() == null) { if (bomGroupId == null && bomArtifactId == null && bomVersion == null) { - return Collections.emptyList(); + return List.of(); } final ExtensionCatalogResolver catalogResolver = getExtensionCatalogResolver(); if (!catalogResolver.hasRegistries()) { @@ -172,7 +169,7 @@ protected List getImportedPlatforms() throws MojoExecutionExcept } catch (RegistryResolutionException e) { throw new MojoExecutionException("Failed to resolve the catalog of Quarkus platforms", e); } - return importedPlatforms = Collections.singletonList(platformBom); + return importedPlatforms = List.of(platformBom); } importedPlatforms = collectImportedPlatforms(); } @@ -180,7 +177,7 @@ protected List getImportedPlatforms() throws MojoExecutionExcept } protected MavenArtifactResolver catalogArtifactResolver() throws MojoExecutionException { - return artifactResolver; + return artifactResolver(); } protected MavenArtifactResolver artifactResolver() throws MojoExecutionException { @@ -188,23 +185,19 @@ protected MavenArtifactResolver artifactResolver() throws MojoExecutionException } 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); - } + var config = BootstrapMavenContext.config() + .setArtifactTransferLogging(getLog().isDebugEnabled()) + .setRemoteRepositoryManager(workspaceProvider.getRemoteRepositoryManager()) + .setRepositorySystem(workspaceProvider.getRepositorySystem()) + .setRemoteRepositories(repos) + .setWorkspaceDiscovery(false) + .setRepositorySystemSession(repoSession); + return workspaceProvider.createArtifactResolver(config); } - private List collectImportedPlatforms() - throws MojoExecutionException { + private List collectImportedPlatforms() { final List descriptors = new ArrayList<>(4); - final List constraints = project.getDependencyManagement() == null ? Collections.emptyList() + final List constraints = project.getDependencyManagement() == null ? List.of() : project.getDependencyManagement().getDependencies(); if (!constraints.isEmpty()) { final MessageWriter log = getMessageWriter(); @@ -222,17 +215,6 @@ private List collectImportedPlatforms() return descriptors; } - private String getQuarkusCoreVersion() { - final List constraints = project.getDependencyManagement() == null ? Collections.emptyList() - : project.getDependencyManagement().getDependencies(); - for (Dependency d : constraints) { - if (d.getArtifactId().endsWith("quarkus-core") && d.getGroupId().equals("io.quarkus")) { - return d.getVersion(); - } - } - return null; - } - protected void validateParameters() throws MojoExecutionException { } @@ -241,8 +223,8 @@ protected abstract void doExecute(QuarkusProject quarkusProject, MessageWriter l private Artifact projectArtifact() { return projectArtifact == null - ? projectArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), null, "pom", - project.getVersion()) + ? projectArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), null, + ArtifactCoords.TYPE_POM, project.getVersion()) : projectArtifact; } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java index 62a346128a09c..b578cc533b7ef 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java @@ -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()) diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java index 8cecb28fedae0..7a9f65bf28b34 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java @@ -86,8 +86,8 @@ public static QuarkusProject getProject(Artifact projectPom, Model projectModel, final List importedPlatforms; final String quarkusVersion; if (projectPom == null) { - managedDeps = Collections.emptyList(); - deps = () -> Collections.emptyList(); + managedDeps = List.of(); + deps = List::of; importedPlatforms = Collections.emptyList(); // TODO allow multiple streams in the same catalog for now quarkusVersion = null;// defaultQuarkusVersion.get(); diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/AddExtensionMojoTest.java b/integration-tests/maven/src/test/java/io/quarkus/maven/AddExtensionMojoTest.java index e6cf6aae6f121..791474682bc9e 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/AddExtensionMojoTest.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/AddExtensionMojoTest.java @@ -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 { @@ -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();