From b793d1f974f2cae2e39509de68c7254d8762b1c6 Mon Sep 17 00:00:00 2001 From: melloware Date: Wed, 30 Oct 2024 09:25:53 -0400 Subject: [PATCH] CuratedOutCome build test --- .../quinoa/deployment/QuinoaProcessor.java | 19 ++++-- .../items/QuinoaCurateOutcomeBuildItem.java | 58 +++++++++++++++++++ .../ROOT/pages/includes/quarkus-quinoa.adoc | 2 +- 3 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/QuinoaCurateOutcomeBuildItem.java diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/QuinoaProcessor.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/QuinoaProcessor.java index 2e4bbb86..70c8e796 100644 --- a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/QuinoaProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/QuinoaProcessor.java @@ -35,15 +35,18 @@ import io.quarkiverse.quinoa.deployment.items.ConfiguredQuinoaBuildItem; import io.quarkiverse.quinoa.deployment.items.InstalledPackageManagerBuildItem; import io.quarkiverse.quinoa.deployment.items.PublishedPackageBuildItem; +import io.quarkiverse.quinoa.deployment.items.QuinoaCurateOutcomeBuildItem; import io.quarkiverse.quinoa.deployment.items.TargetDirBuildItem; import io.quarkiverse.quinoa.deployment.packagemanager.PackageManagerInstall; import io.quarkiverse.quinoa.deployment.packagemanager.PackageManagerRunner; import io.quarkiverse.quinoa.deployment.packagemanager.types.PackageManagerType; +import io.quarkus.deployment.BootstrapConfig; import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.annotations.Record; +import io.quarkus.deployment.builditem.AppModelProviderBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; @@ -75,6 +78,8 @@ public class QuinoaProcessor { private static final String TARGET_BUILD_DIR_NAME = "build"; private static final String BUILD_FILE = "package.json"; + BootstrapConfig config; + @BuildStep FeatureBuildItem feature() { return new FeatureBuildItem(FEATURE); @@ -84,7 +89,8 @@ FeatureBuildItem feature() { public ConfiguredQuinoaBuildItem prepareQuinoaDirectory( LaunchModeBuildItem launchMode, QuinoaConfig userConfig, - OutputTargetBuildItem outputTarget) throws IOException { + OutputTargetBuildItem outputTarget, + QuinoaCurateOutcomeBuildItem curatedOutcome) throws IOException { if (!isEnabled(userConfig)) { LOG.info("Quinoa is disabled."); return null; @@ -95,7 +101,7 @@ public ConfiguredQuinoaBuildItem prepareQuinoaDirectory( return null; } final String configuredDir = userConfig.uiDir(); - final ProjectDirs projectDirs = resolveProjectDirs(userConfig, outputTarget); + final ProjectDirs projectDirs = resolveProjectDirs(userConfig, curatedOutcome); if (projectDirs == null) { return null; } @@ -111,6 +117,11 @@ public ConfiguredQuinoaBuildItem prepareQuinoaDirectory( return new ConfiguredQuinoaBuildItem(projectDirs.projectRootDir, projectDirs.uiDir, packageJson, resolvedConfig); } + @BuildStep + QuinoaCurateOutcomeBuildItem curateOutcome(AppModelProviderBuildItem appModelProvider) { + return new QuinoaCurateOutcomeBuildItem(appModelProvider.validateAndGet(config)); + } + @BuildStep public InstalledPackageManagerBuildItem install( ConfiguredQuinoaBuildItem configuredQuinoa, @@ -398,8 +409,8 @@ private static boolean shouldWatch(String relativeFilePath) { } private static ProjectDirs resolveProjectDirs(QuinoaConfig config, - OutputTargetBuildItem outputTarget) { - Path projectRoot = findProjectRoot(outputTarget.getOutputDirectory()); + QuinoaCurateOutcomeBuildItem curatedOutcome) { + Path projectRoot = curatedOutcome.getApplicationModuleDirectory(); Path configuredUIDirPath = Path.of(config.uiDir().trim()); if (projectRoot == null || !Files.isDirectory(projectRoot)) { if (configuredUIDirPath.isAbsolute() && Files.isDirectory(configuredUIDirPath)) { diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/QuinoaCurateOutcomeBuildItem.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/QuinoaCurateOutcomeBuildItem.java new file mode 100644 index 00000000..9e17b372 --- /dev/null +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/QuinoaCurateOutcomeBuildItem.java @@ -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. + *

+ * 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(); + } +} \ No newline at end of file diff --git a/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc b/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc index 5511f0bf..949b14d6 100644 --- a/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc +++ b/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc @@ -729,7 +729,7 @@ a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-publish]] [.description] -- -Runs package manager publish command. This is handy when the using justBuild() option to publish built web module or component to a registry. +Runs additionally package manager publish command. This is handy when using together with the justBuild() option to publish built web package to a registry. The command is executed after the build command and can be customized with the `PackageManagerCommandConfig++#++publish()` and `PackageManagerCommandConfig++#++publishEnv()`. ifdef::add-copy-button-to-env-var[] Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_PUBLISH+++[]