Skip to content

Commit

Permalink
Upgrade to Quarkus 2.16.3.Final
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Feb 16, 2023
1 parent 6e7ecc0 commit 8b9858c
Show file tree
Hide file tree
Showing 7 changed files with 1,238 additions and 1,206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -28,6 +29,7 @@
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace;
import io.quarkus.bootstrap.util.IoUtils;
import io.quarkus.bootstrap.workspace.ArtifactSources;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.runtime.LaunchMode;

Expand All @@ -39,19 +41,27 @@
public class GoOfflineMojo extends AbstractMojo {

@Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject project;
MavenProject project;

@Component
private RepositorySystem repoSystem;
RepositorySystem repoSystem;

@Component
RemoteRepositoryManager remoteRepositoryManager;

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

@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true)
private List<RemoteRepository> repos;
List<RemoteRepository> repos;

/**
* Target launch mode corresponding to {@link io.quarkus.runtime.LaunchMode} for which the dependencies should be resolved.
* {@code io.quarkus.runtime.LaunchMode.TEST} is the default, since it includes both {@code provided} and {@code test}
* dependency scopes.
*/
@Parameter(property = "mode", required = false, defaultValue = "test")
String mode;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Expand All @@ -62,43 +72,47 @@ public void execute() throws MojoExecutionException, MojoFailureException {
project.getVersion());

final MavenArtifactResolver resolver = getResolver();
final BootstrapAppModelResolver appModelResolver = new BootstrapAppModelResolver(resolver);

final Set<String> excludedScopes;
if (mode.equalsIgnoreCase("test")) {
appModelResolver.setTest(true);
excludedScopes = Set.of();
} else if (mode.equalsIgnoreCase("dev") || mode.equalsIgnoreCase("development")) {
appModelResolver.setDevMode(true);
excludedScopes = Set.of("test");
} else if (mode.equalsIgnoreCase("prod") || mode.isEmpty()) {
excludedScopes = Set.of("test", "provided");
} else {
throw new IllegalArgumentException(
"Unrecognized mode '" + mode + "', supported values are test, dev, development, prod");
}

final DependencyNode root;
try {
root = resolver.collectDependencies(pom, List.of()).getRoot();
root = resolver.getSystem().collectDependencies(
resolver.getSession(),
resolver.newCollectManagedRequest(pom, List.of(), List.of(), List.of(), List.of(), excludedScopes))
.getRoot();
} catch (Exception e) {
throw new MojoExecutionException("Failed to collect dependencies of " + pom, e);
}

final List<Path> createdDirs = new ArrayList<>();
final LocalWorkspace workspace = resolver.getMavenContext().getWorkspace();
final List<Path> createdDirs = new ArrayList<>(workspace.getProjects().size());
try {
ensureResolvableModule(root, resolver.getMavenContext().getWorkspace(), createdDirs);
final ArtifactCoords appArtifact = ArtifactCoords.of(pom.getGroupId(), pom.getArtifactId(), pom.getClassifier(),
pom.getExtension(), pom.getVersion());
resolveAppModel(resolver, appArtifact, LaunchMode.NORMAL);
resolveAppModel(resolver, appArtifact, LaunchMode.DEVELOPMENT);
resolveAppModel(resolver, appArtifact, LaunchMode.TEST);
ensureResolvableModule(root, workspace, createdDirs);
appModelResolver.resolveModel(ArtifactCoords.of(pom.getGroupId(), pom.getArtifactId(), pom.getClassifier(),
pom.getExtension(), pom.getVersion()));
} catch (AppModelResolverException e) {
throw new MojoExecutionException("Failed to resolve Quarkus application model for " + project.getArtifact(), e);
} finally {
for (Path d : createdDirs) {
IoUtils.recursiveDelete(d);
}
}
}

private void resolveAppModel(final MavenArtifactResolver resolver, final ArtifactCoords appArtifact, LaunchMode mode)
throws MojoExecutionException {
final BootstrapAppModelResolver appModelResolver = new BootstrapAppModelResolver(resolver);
if (mode == LaunchMode.DEVELOPMENT) {
appModelResolver.setDevMode(true);
} else if (mode == LaunchMode.TEST) {
appModelResolver.setTest(true);
}
try {
appModelResolver.resolveModel(appArtifact);
} catch (AppModelResolverException e) {
throw new MojoExecutionException("Failed to resolve Quarkus application model for " + project.getArtifact(), e);
}
}

private MavenArtifactResolver getResolver() throws MojoExecutionException {
try {
return MavenArtifactResolver.builder()
Expand All @@ -118,7 +132,12 @@ private static void ensureResolvableModule(DependencyNode node, LocalWorkspace w
if (artifact != null) {
final LocalProject module = workspace.getProject(artifact.getGroupId(), artifact.getArtifactId());
if (module != null && !module.getRawModel().getPackaging().equals(ArtifactCoords.TYPE_POM)) {
final Path classesDir = module.getClassesDir();
final Path classesDir;
if (artifact.getClassifier().equals(ArtifactSources.TEST)) {
classesDir = module.getTestClassesDir();
} else {
classesDir = module.getClassesDir();
}
if (!Files.exists(classesDir)) {
Path topDirToCreate = classesDir;
while (!Files.exists(topDirToCreate.getParent())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ static Map<Path, Model> getProjectMap(MavenSession session) {
}
final Map<Path, Model> projectModels = new HashMap<>(allProjects.size());
for (MavenProject mp : allProjects) {
mp.getOriginalModel().setPomFile(mp.getFile());
projectModels.put(mp.getBasedir().toPath(), mp.getOriginalModel());
final Model model = mp.getOriginalModel();
model.setPomFile(mp.getFile());
// activated profiles or custom extensions may have overridden the build defaults
model.setBuild(mp.getModel().getBuild());
projectModels.put(mp.getBasedir().toPath(), model);
}
return projectModels;
}
Expand Down
Loading

0 comments on commit 8b9858c

Please sign in to comment.