Skip to content

Commit

Permalink
Introduce CurateOutcomeBuildItem.getApplicationModuleDirectory()
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky authored and Alexey Loubyansky committed Nov 30, 2024
1 parent 2704a77 commit a3f6746
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package io.quarkus.deployment.pkg.builditem;

import java.nio.file.Files;
import java.nio.file.Path;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.utils.BuildToolHelper;
import io.quarkus.bootstrap.workspace.WorkspaceModule;
import io.quarkus.builder.item.SimpleBuildItem;

public final class CurateOutcomeBuildItem extends SimpleBuildItem {

private final ApplicationModel appModel;
private Path appModuleDir;

public CurateOutcomeBuildItem(ApplicationModel appModel) {
this.appModel = appModel;
Expand All @@ -14,4 +20,39 @@ public CurateOutcomeBuildItem(ApplicationModel appModel) {
public ApplicationModel getApplicationModel() {
return appModel;
}

/**
* Returns the application module directory, if the application is built from a source project.
* For a single module project it will the project directory. For a multimodule project,
* it will the directory of the application module.
* <p>
* During re-augmentation of applications packaged as {@code mutable-jar} this method will return the current directory,
* since the source project might not be available anymore.
*
* @return application module directory, never null
*/
public Path getApplicationModuleDirectory() {
if (appModuleDir == null) {
// modules are by default available in dev and test modes, and in prod mode if
// quarkus.bootstrap.workspace-discovery system or project property is true,
// otherwise it could be null
final WorkspaceModule module = appModel.getApplicationModule();
appModuleDir = module == null ? deriveModuleDirectoryFromArtifact() : module.getModuleDir().toPath();
}
return appModuleDir;
}

private Path deriveModuleDirectoryFromArtifact() {
var paths = appModel.getAppArtifact().getResolvedPaths();
for (var path : paths) {
if (Files.isDirectory(path)) {
var moduleDir = BuildToolHelper.getProjectDir(path);
if (moduleDir != null) {
return moduleDir;
}
}
}
// the module isn't available, return the current directory
return Path.of("").toAbsolutePath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Path getProjectDir(Path p) {
}
currentPath = currentPath.getParent();
}
log.warnv("Unable to find a project directory for {0}.", p);
log.warnv("Unable to find the project directory for {0}.", p);
return null;
}

Expand Down

0 comments on commit a3f6746

Please sign in to comment.