Skip to content

Commit

Permalink
CuratedOutCome build test
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Oct 30, 2024
1 parent ad069c3 commit b793d1f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
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();
}
}
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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+++[]
Expand Down

0 comments on commit b793d1f

Please sign in to comment.