-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...nt/src/main/java/io/quarkiverse/quinoa/deployment/items/QuinoaCurateOutcomeBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkiverse.quinoa.deployment.items; | ||
|
||
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 QuinoaCurateOutcomeBuildItem extends SimpleBuildItem { | ||
|
||
private final ApplicationModel appModel; | ||
private Path appModuleDir; | ||
|
||
public QuinoaCurateOutcomeBuildItem(ApplicationModel appModel) { | ||
this.appModel = 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters