Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #26

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common-deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.quarkiverse.roq.generator.deployment;

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

import org.jboss.logging.Logger;

import io.quarkiverse.roq.generator.deployment.config.RoqBuildConfig;
import io.quarkiverse.roq.generator.deployment.items.RoqProjectBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;

public class RoqProjectProcessor {

private static final Logger LOG = Logger.getLogger(RoqProjectProcessor.class);

@BuildStep
RoqProjectBuildItem findProject(RoqBuildConfig config, OutputTargetBuildItem outputTarget) {
return new RoqProjectBuildItem(resolveProjectDirs(config, outputTarget));
}

/**
* Resolves the project directories based on the provided configuration and output target.
*
* @param config the build configuration
* @param outputTarget the output target build item
* @return a {@link RoqProjectBuildItem.RoqProject} object containing the resolved project root, site root, and data root
* directories, or {@code null} if the site root directory is not found
* @throws IllegalStateException if the project root is not found and the site directory is not absolute
*/
private static RoqProjectBuildItem.RoqProject resolveProjectDirs(RoqBuildConfig config,
OutputTargetBuildItem outputTarget) {
Path projectRoot = findProjectRoot(outputTarget.getOutputDirectory());
Path configuredSiteDirPath = Paths.get(config.siteDir().trim());

if (projectRoot == null || !Files.isDirectory(projectRoot)) {
if (configuredSiteDirPath.isAbsolute() && Files.isDirectory(configuredSiteDirPath)) {
configuredSiteDirPath = configuredSiteDirPath.normalize();
} else {
throw new IllegalStateException(
"If not absolute, the Site directory is resolved relative to the project root, but Roq was not able to find the project root.");
}
}

final Path siteRoot = projectRoot.resolve(configuredSiteDirPath).normalize();

if (!Files.isDirectory(siteRoot)) {
LOG.warnf(
"Roq directory not found 'quarkus.roq.site-dir=%s' resolved to '%s'. It is recommended to remove the quarkus-roq extension if not used.",
config.siteDir(), siteRoot.toAbsolutePath());
return null;
}

return new RoqProjectBuildItem.RoqProject(projectRoot, siteRoot);
}

private static Path findProjectRoot(Path outputDirectory) {
Path currentPath = outputDirectory;
do {
if (Files.exists(currentPath.resolve(Paths.get("src", "main")))
|| Files.exists(currentPath.resolve(Paths.get("config", "application.properties")))
|| Files.exists(currentPath.resolve(Paths.get("config", "application.yaml")))
|| Files.exists(currentPath.resolve(Paths.get("config", "application.yml")))) {
return currentPath.normalize();
}
if (currentPath.getParent() != null && Files.exists(currentPath.getParent())) {
currentPath = currentPath.getParent();
} else {
return null;
}
} while (true);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkiverse.roq.deployment.config;
package io.quarkiverse.roq.generator.deployment.config;

import java.util.Objects;

Expand All @@ -8,7 +8,7 @@
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.roq")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface RoqBuildConfig {

String DEFAULT_SITE_DIR = "src/main/site";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkiverse.roq.generator.deployment.items;

import java.nio.file.Path;

import io.quarkus.builder.item.SimpleBuildItem;

public final class RoqProjectBuildItem extends SimpleBuildItem {
private final RoqProject project;

public RoqProjectBuildItem(RoqProject project) {
this.project = project;
}

public RoqProject dirs() {
return project;
}

// TODO: in the future we might want to include a Scanner like in web-bundler to see if dependencies contains roq stuff

/**
* Container to store resolved directory locations.
*/
public record RoqProject(
/**
* The root directory of the project
*/
Path rootDir,
/**
* The site directory of the project defaults to /src/main/site
*/
Path siteDir) {

}
}
12 changes: 12 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-roq-common</artifactId>
<name>Quarkus Roq - Common</name>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkiverse.roq.runtime.util;
package io.quarkiverse.roq.util;

public final class PathUtils {

Expand Down

This file was deleted.

This file was deleted.

Loading