-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #22: Add config for site and data directories
- Loading branch information
Showing
9 changed files
with
296 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?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-deployment</artifactId> | ||
<name>Quarkus Roq - Common - Deployment</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-vertx-http-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
common-deployment/src/main/java/io/quarkiverse/roq/deployment/config/RoqBuildConfig.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,38 @@ | ||
package io.quarkiverse.roq.deployment.config; | ||
|
||
import java.util.Objects; | ||
|
||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.WithDefault; | ||
|
||
@ConfigMapping(prefix = "quarkus.roq") | ||
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) | ||
public interface RoqBuildConfig { | ||
|
||
String DEFAULT_SITE_DIR = "src/main/site"; | ||
String DEFAULT_DATA_DIR = "data/"; | ||
|
||
/** | ||
* Path to the static root directory (relative to the project root). | ||
*/ | ||
@WithDefault(DEFAULT_SITE_DIR) | ||
String siteDir(); | ||
|
||
/** | ||
* Path to the static data directory (relative to the site directory `quarkus.roq.site-dir`). | ||
*/ | ||
@WithDefault(DEFAULT_DATA_DIR) | ||
String dataDir(); | ||
|
||
static boolean isEqual(RoqBuildConfig q1, RoqBuildConfig q2) { | ||
if (!Objects.equals(q1.siteDir(), q2.siteDir())) { | ||
return false; | ||
} | ||
if (!Objects.equals(q1.dataDir(), q2.dataDir())) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...-deployment/src/main/java/io/quarkiverse/roq/deployment/config/RoqProjectDirectories.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,88 @@ | ||
package io.quarkiverse.roq.deployment.config; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
|
||
/** | ||
* Container to store resolved directory locations. | ||
*/ | ||
public class RoqProjectDirectories { | ||
|
||
/** | ||
* The root directory of the project | ||
*/ | ||
private final Path rootDir; | ||
|
||
/** | ||
* The site directory of the project defaults to /src/main/site | ||
*/ | ||
private final Path siteDir; | ||
|
||
/** | ||
* The data directory defaults to "data/" relative to root directory. | ||
*/ | ||
private final Path dataDir; | ||
|
||
public RoqProjectDirectories(Path rootDir, Path siteDir, Path dataDir) { | ||
this.rootDir = rootDir; | ||
this.siteDir = siteDir; | ||
this.dataDir = dataDir; | ||
} | ||
|
||
public Path getRootDir() { | ||
return rootDir; | ||
} | ||
|
||
public Path getSiteDir() { | ||
return siteDir; | ||
} | ||
|
||
public Path getDataDir() { | ||
return dataDir; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
RoqProjectDirectories that = (RoqProjectDirectories) o; | ||
return Objects.equals(getRootDir(), that.getRootDir()) && Objects.equals(getSiteDir(), that.getSiteDir()) | ||
&& Objects.equals(getDataDir(), that.getDataDir()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getRootDir(), getSiteDir(), getDataDir()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", RoqProjectDirectories.class.getSimpleName() + "[", "]") | ||
.add("rootDir=" + rootDir) | ||
.add("siteDir=" + siteDir) | ||
.add("dataDir=" + dataDir) | ||
.toString(); | ||
} | ||
|
||
public 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); | ||
} | ||
} |
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
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
Oops, something went wrong.