Skip to content

Commit

Permalink
Refactored published Maven module reading a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Aug 31, 2023
1 parent 07a151a commit 9b3168d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
51 changes: 8 additions & 43 deletions domino/api/src/main/java/io/quarkus/domino/MavenProjectReader.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package io.quarkus.domino;

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
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.maven.dependency.ArtifactCoords;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
Expand All @@ -27,20 +23,9 @@ private static String getTypeForPackaging(String packaging) {
return PACKAGING_TYPE.getOrDefault(packaging, packaging);
}

public static List<ArtifactCoords> resolveModuleDependencies(MavenArtifactResolver resolver) {

final LocalWorkspace ws = resolver.getMavenContext().getWorkspace();
final List<Path> createdDirs = new ArrayList<>();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
for (Path p : createdDirs) {
IoUtils.recursiveDelete(p);
}
}
}));
ws.getProjects().values().forEach(p -> ensureResolvable(p, createdDirs));
final List<ArtifactCoords> result = new ArrayList<>();
public static List<ArtifactCoords> resolveModuleDependencies(LocalWorkspace ws) {
Objects.requireNonNull(ws, "Workspace is null");
final List<ArtifactCoords> result = new ArrayList<>(ws.getProjects().size());
for (LocalProject project : ws.getProjects().values()) {
if (isPublished(project)) {
var type = getTypeForPackaging(project.getRawModel().getPackaging());
Expand All @@ -54,12 +39,10 @@ public void run() {
private static boolean isPublished(LocalProject project) {
final Model model = project.getModelBuildingResult() == null ? project.getRawModel()
: project.getModelBuildingResult().getEffectiveModel();
String skipStr = model.getProperties().getProperty("maven.install.skip");
if (skipStr != null && Boolean.parseBoolean(skipStr)) {
return false;
}
skipStr = model.getProperties().getProperty("maven.deploy.skip");
if (skipStr != null && Boolean.parseBoolean(skipStr)) {
var modelProps = model.getProperties();
if (Boolean.parseBoolean(modelProps.getProperty("maven.install.skip"))
|| Boolean.parseBoolean(modelProps.getProperty("maven.deploy.skip"))
|| Boolean.parseBoolean(modelProps.getProperty("skipNexusStagingDeployMojo"))) {
return false;
}
if (model.getBuild() != null) {
Expand All @@ -76,22 +59,4 @@ private static boolean isPublished(LocalProject project) {
}
return true;
}

private static void ensureResolvable(LocalProject project, List<Path> createdDirs) {
if (!project.getRawModel().getPackaging().equals(ArtifactCoords.TYPE_POM)) {
final Path classesDir = project.getClassesDir();
if (!Files.exists(classesDir)) {
Path topDirToCreate = classesDir;
while (!Files.exists(topDirToCreate.getParent())) {
topDirToCreate = topDirToCreate.getParent();
}
try {
Files.createDirectories(classesDir);
createdDirs.add(topDirToCreate);
} catch (IOException e) {
throw new RuntimeException("Failed to create " + classesDir, e);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.resolver.maven.workspace.ModelUtils;
import io.quarkus.bootstrap.util.IoUtils;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.domino.pnc.PncVersionProvider;
import io.quarkus.maven.dependency.ArtifactCoords;
Expand Down Expand Up @@ -563,7 +564,38 @@ protected Iterable<ArtifactCoords> getProjectArtifacts() {
} else if (config.getProjectDir() != null) {
final BuildTool buildTool = BuildTool.forProjectDir(config.getProjectDir());
if (BuildTool.MAVEN.equals(buildTool)) {
result = MavenProjectReader.resolveModuleDependencies(resolver);
var ws = resolver.getMavenContext().getWorkspace();
result = MavenProjectReader.resolveModuleDependencies(ws);
if (!result.isEmpty()) {
final List<Path> createdDirs = new ArrayList<>(ws.getProjects().size());
for (var project : resolver.getMavenContext().getWorkspace().getProjects().values()) {
if (!project.getRawModel().getPackaging().equals(ArtifactCoords.TYPE_POM)) {
final Path classesDir = project.getClassesDir();
if (!Files.exists(classesDir)) {
Path topDirToCreate = classesDir;
while (!Files.exists(topDirToCreate.getParent())) {
topDirToCreate = topDirToCreate.getParent();
}
try {
Files.createDirectories(classesDir);
createdDirs.add(topDirToCreate);
} catch (IOException e) {
throw new RuntimeException("Failed to create " + classesDir, e);
}
}
}
}
if (!createdDirs.isEmpty()) {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
for (Path p : createdDirs) {
IoUtils.recursiveDelete(p);
}
}
}));
}
}
} else if (BuildTool.GRADLE.equals(buildTool)) {
preResolvedRootArtifacts = GradleProjectReader.resolveModuleDependencies(config.getProjectDir(),
config.isGradleJava8(), config.getGradleJavaHome(), resolver);
Expand Down

0 comments on commit 9b3168d

Please sign in to comment.