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

Introduce roq-frontmatter #24

Merged
merged 5 commits into from
Aug 28, 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: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
fail-fast: false
matrix:
# os: [windows-latest, macos-latest, ubuntu-latest]
os: [ubuntu-latest]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Prepare git
Expand All @@ -56,4 +56,5 @@ jobs:
run: mvn -B clean install -Dno-format

- name: Build with Maven (Native)
run: mvn -B install -Dnative -Dquarkus.native.container-build -Dnative.surefire.skip
run: mvn -B install -Dnative -Dquarkus.native.container-build -Dnative.surefire.skip
if: ${{ !startsWith(matrix.os, 'windows') }}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.quarkiverse.roq.deployment;

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

import org.jboss.logging.Logger;

Expand All @@ -20,72 +17,19 @@ public class RoqProjectProcessor {
@BuildStep
RoqProjectBuildItem findProject(RoqConfig config, OutputTargetBuildItem outputTarget,
CurateOutcomeBuildItem curateOutcome) {
final RoqProjectBuildItem.RoqProject project = resolveProjectDirs(config, curateOutcome, outputTarget);

String resourceSiteDir;
try {
final boolean hasResourceSiteDir = Thread.currentThread().getContextClassLoader()
.getResources(config.resourceSiteDir()).hasMoreElements();
resourceSiteDir = hasResourceSiteDir ? config.resourceSiteDir() : null;
.getResources(config.siteDir()).hasMoreElements();
resourceSiteDir = hasResourceSiteDir ? config.siteDir() : null;
} catch (IOException e) {
resourceSiteDir = null;
}
final RoqProjectBuildItem roqProject = new RoqProjectBuildItem(project, resourceSiteDir);
final RoqProjectBuildItem roqProject = new RoqProjectBuildItem(resourceSiteDir);
if (!roqProject.isActive()) {
LOG.warn("Not Roq site directory found. It is recommended to remove the quarkus-roq extension if not used.");
}
return roqProject;
}

/**
* 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(RoqConfig config,
CurateOutcomeBuildItem curateOutcome,
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 {
LOG.warn(
"If not absolute, the Site directory is resolved relative to the project root, but Roq was not able to find the project root..");
return null;
}
}

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

if (!Files.isDirectory(siteRoot)) {
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
Expand Up @@ -11,28 +11,18 @@
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface RoqConfig {

String DEFAULT_SITE_DIR = "src/main/site";
String DEFAULT_RESOURCE_SITE_DIR = "site";
String DEFAULT_SITE_DIR = "site";

/**
* Path to the Roq site directory (relative to the project root).
*/
@WithDefault(DEFAULT_SITE_DIR)
String siteDir();

/**
* Path to the Roq site directory in the resources.
*/
@WithDefault(DEFAULT_RESOURCE_SITE_DIR)
String resourceSiteDir();

static boolean isEqual(RoqConfig q1, RoqConfig q2) {
if (!Objects.equals(q1.siteDir(), q2.siteDir())) {
return false;
}
if (!Objects.equals(q1.resourceSiteDir(), q2.resourceSiteDir())) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,26 @@
import io.quarkus.runtime.util.ClassPathUtils;

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

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

public RoqProject project() {
return project;
}

public boolean isActive() {
return project != null || resourceSiteDir != null;
return resourceSiteDir != null;
}

public void consumePathFromSite(String resource, Consumer<Path> consumer) throws IOException {
if (resourceSiteDir != null) {
ClassPathUtils.consumeAsPaths(PathUtils.join(resourceSiteDir, resource), consumer);
}
if (project != null) {
consumer.accept(project.siteDir().resolve(resource));
}
}

/**
* 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) {

public void consumeSite(Consumer<Path> consumer) throws IOException {
if (resourceSiteDir != null) {
ClassPathUtils.consumeAsPaths(resourceSiteDir, consumer);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public static String removeLeadingSlash(String path) {
public static String removeTrailingSlash(String path) {
return path.endsWith("/") ? path.substring(0, path.length() - 1) : path;
}

public static String removeExtension(String path) {
final int i = path.lastIndexOf(".");
return i > 0 ? path.substring(0, i) : path;
}
}
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/quarkus-roq-data.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_ROQ_DATA_DIR+++`
endif::add-copy-button-to-env-var[]
--|string
|`data`
|`_data`


a|icon:lock[title=Fixed at build time] [[quarkus-roq-data_quarkus-roq-data-enforce-bean]]`link:#quarkus-roq-data_quarkus-roq-data-enforce-bean[quarkus.roq.data.enforce-bean]`
Expand Down
17 changes: 0 additions & 17 deletions docs/modules/ROOT/pages/includes/quarkus-roq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_ROQ_SITE_DIR+++`
endif::add-copy-button-to-env-var[]
--|string
|`src/main/site`


a|icon:lock[title=Fixed at build time] [[quarkus-roq_quarkus-roq-resource-site-dir]]`link:#quarkus-roq_quarkus-roq-resource-site-dir[quarkus.roq.resource-site-dir]`


[.description]
--
Path to the Roq site directory in the resources.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_ROQ_RESOURCE_SITE_DIR+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_ROQ_RESOURCE_SITE_DIR+++`
endif::add-copy-button-to-env-var[]
--|string
|`site`

|===
115 changes: 115 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?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-integration-tests</artifactId>
<name>Quarkus Roq - Integration Tests</name>

<properties>
<skipITs>true</skipITs>
</properties>

<dependencies>
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.web-bundler</groupId>
<artifactId>quarkus-web-bundler</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>${basedir}/site</directory>
<targetPath>site</targetPath>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<skipITs>false</skipITs>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
</profile>
</profiles>
</project>
7 changes: 7 additions & 0 deletions integration-tests/site/_data/author.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: ROQ # add your name
Copy link
Member

@mcruzdev mcruzdev Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cool in the future to have more than one author

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a standard roq data, you can add an array if you want :)

img: iamroq.png # add your photo
about: All the tools to generate static websites out of your Quarkus web application. # add description
social-twitter: quarkusio # add your Twitter handle
social-facebook: # add your Facebook handle
social-github: quarkusio # add your Github handle
social-linkedin: quarkusio # add your Linkedin handle
23 changes: 23 additions & 0 deletions integration-tests/site/_data/events.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- title: "Tech Conference 2024"
description: "An annual conference bringing together tech enthusiasts, developers, and industry leaders to discuss the latest trends in technology."
date: "2024-09-15"

- title: "Autumn Art Expo"
description: "A showcase of contemporary art from emerging artists around the world, featuring paintings, sculptures, and installations."
date: "2024-10-05"

- title: "Culinary Arts Festival"
description: "A food festival celebrating the diversity of culinary arts, with cooking demonstrations, food tastings, and workshops by renowned chefs."
date: "2024-11-12"

- title: "Winter Music Gala"
description: "A gala event featuring performances by leading classical musicians and orchestras, celebrating the beauty of winter through music."
date: "2024-12-20"

- title: "Spring Film Festival"
description: "A week-long film festival showcasing independent films from around the globe, with screenings, Q&A sessions, and panel discussions."
date: "2025-03-10"

- title: "Summer Science Symposium"
description: "A symposium for scientists, researchers, and academics to present their latest research findings and discuss advancements in various fields of science."
date: "2025-06-22"
8 changes: 8 additions & 0 deletions integration-tests/site/_data/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: Hello, world! I'm Roq
description: > # this means to ignore newlines until "baseurl:"
Write an awesome description for your new site here. You can edit this
line in _data/config.yml. It will appear in your document head meta (for
Google search results) and in your feed.xml site description.
link: ':title/'
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
Loading