Skip to content

Commit

Permalink
prepare for version profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Sep 2, 2023
1 parent a5cb54f commit f4be6c3
Show file tree
Hide file tree
Showing 121 changed files with 4,011 additions and 65 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<properties>
<snapshot.version>HEAD-SNAPSHOT</snapshot.version>
<next.release.version>2.0.0</next.release.version>
<release.version>${next.release.version}-${snapshot.version}</release.version>
<release.version>0.0.0-HEAD-SNAPSHOT</release.version>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -169,6 +169,7 @@
</activation>
<properties>
<compiler.majorVersion>${project.version}</compiler.majorVersion>
<release.version>${project.version}</release.version>
</properties>
</profile>
<profile>
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/dominokit/cli/ToolVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.dominokit.cli;

public class ToolVersion {

private final String key;
private final String version;

public static ToolVersion of(String key, String version){
return new ToolVersion(key, version);
}

private ToolVersion(String key, String version) {
this.key = key;
this.version = version;
}

public String getKey() {
return key;
}

public String getVersion() {
return version;
}
}
83 changes: 83 additions & 0 deletions src/main/java/org/dominokit/cli/VersionProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.dominokit.cli;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class VersionProfile {

private static VersionProfile INSTANCE;

private final String version;
private final String templatesPath;
private final List<ToolVersion> toolsVersions = new ArrayList<>();

public VersionProfile(String version,String templatesPath, ToolVersion... toolVersions) {
this.version = version;
this.templatesPath = templatesPath;
this.toolsVersions.addAll(Arrays.asList(toolVersions));
}

public String getVersion() {
return version;
}

public String getTemplatesPath() {
return templatesPath;
}

public List<ToolVersion> getToolsVersions() {
return toolsVersions;
}

public static void setVersion(String version){
INSTANCE = get(version);
}

public static VersionProfile get(){
return INSTANCE;
}

private static VersionProfile get(String version){
switch (version){
case "v1" :
return new VersionProfile(version, version,
ToolVersion.of("domino_ui_version", "1.0.1"),
ToolVersion.of("domino_history_version", "1.0.0"),
ToolVersion.of("domino_mvp_version", "1.0.0"),
ToolVersion.of("domino_rest_version", "1.0.0"),
ToolVersion.of("domino_jackson_version", "1.0.0"),
ToolVersion.of("quarkus_version", "2.16.7.Final"),
ToolVersion.of("vertx_version", "3.9.0"),
ToolVersion.of("gwt_version", "2.10.0"),
ToolVersion.of("j2cl_maven_plugin_version", "0.21")
);
case "v2" :
return new VersionProfile(version, version,
ToolVersion.of("domino_ui_version", "2.0.0-RC1"),
ToolVersion.of("domino_history_version", "1.0.0"),
ToolVersion.of("domino_mvp_version", "HEAD-SNAPSHOT"),
ToolVersion.of("domino_rest_version", "1.0.0"),
ToolVersion.of("domino_jackson_version", "1.0.0"),
ToolVersion.of("quarkus_version", "2.16.7.Final"),
ToolVersion.of("vertx_version", "3.9.0"),
ToolVersion.of("gwt_version", "2.10.0"),
ToolVersion.of("j2cl_maven_plugin_version", "0.21")
);
case "dev" :
return new VersionProfile(version, "v2",
ToolVersion.of("domino_ui_version", "HEAD-SNAPSHOT"),
ToolVersion.of("domino_history_version", "HEAD-SNAPSHOT"),
ToolVersion.of("domino_mvp_version", "HEAD-SNAPSHOT"),
ToolVersion.of("domino_rest_version", "HEAD-SNAPSHOT"),
ToolVersion.of("domino_jackson_version", "HEAD-SNAPSHOT"),
ToolVersion.of("quarkus_version", "2.16.7.Final"),
ToolVersion.of("vertx_version", "3.9.0"),
ToolVersion.of("gwt_version", "2.10.0"),
ToolVersion.of("j2cl_maven_plugin_version", "0.21")
);

}
throw new IllegalArgumentException("Invalid versions profile ["+version+"] use one of [v1, v2, dev].");
}
}
11 changes: 0 additions & 11 deletions src/main/java/org/dominokit/cli/commands/DominoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
description = """
Executes domino commands
Use this command to generate basic template project or an MVP project.
The versions used in the project dependencies can be set dynamically using env variable as the following :
- DOMINO_CLI_DOMINO_UI_VERSION
- DOMINO_CLI_DOMINO_HISTORY_VERSION
- DOMINO_CLI_DOMINO_MVP_VERSION
- DOMINO_CLI_DOMINO_REST_VERSION
- DOMINO_CLI_DOMINO_JACKSON_VERSION
- DOMINO_CLI_QUARKUS_VERSION
- DOMINO_CLI_VERTX_VERSION
- DOMINO_CLI_GWT_VERSION
- DOMINO_CLI_J2CL_PLUGIN_VERSION
""",
subcommands = {
CommandLine.HelpCommand.class,
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/dominokit/cli/commands/GenerateAppCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Model;
import org.dominokit.cli.PomUtil;
import org.dominokit.cli.VersionProfile;
import org.dominokit.cli.generator.project.Project;
import org.dominokit.cli.generator.project.ProjectCreator;
import org.dominokit.cli.generator.project.ProjectCreatorFactory;
Expand Down Expand Up @@ -55,6 +56,16 @@ public class GenerateAppCommand implements Runnable {
)
private String type;

@Option(
names = {"-v", "--version"},
description = "DominoKit tools version " +
"\n\t\t -[v1] : Will generate a project using DominoKi tools version 1.x.x" +
"\n\t\t -[v2] : Will generate a project using DominoKi tools version 2.x.x" +
"\n\t\t -[dev] : Will generate a project using DominoKi tools HEAD-SNAPSHOT versions",
defaultValue = "v2"
)
private String version;

@Option(
names = {"-api", "--generate-api"},
fallbackValue = "true",
Expand All @@ -74,6 +85,8 @@ public class GenerateAppCommand implements Runnable {
@Override
public void run() {

VersionProfile.setVersion(version);

Model parentPom = null;
PathUtils.setWorkingDir(workingDire);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dominokit.cli.commands;

import org.dominokit.cli.VersionProfile;
import org.dominokit.cli.generator.module.Module;
import org.dominokit.cli.generator.module.ModuleCreatorFactory;

Expand Down Expand Up @@ -31,6 +32,16 @@ public class GenerateModuleCommand implements Runnable {
)
private boolean single = false;

@Option(
names = {"-v", "--version"},
description = "DominoKit tools version " +
"\n\t\t -[v1] : Will generate a project using DominoKi tools version 1.x.x" +
"\n\t\t -[v2] : Will generate a project using DominoKi tools version 2.x.x" +
"\n\t\t -[dev] : Will generate a project using DominoKi tools HEAD-SNAPSHOT versions",
defaultValue = "v2"
)
private String version;

@Option(
names = {"-t", "--tests"},
fallbackValue = "true",
Expand Down Expand Up @@ -78,6 +89,7 @@ public class GenerateModuleCommand implements Runnable {
@Override
public void run() {

VersionProfile.setVersion(version);
PathUtils.setWorkingDir(workingDire);

try {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/dominokit/cli/generator/ResourceFile.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dominokit.cli.generator;

import org.apache.commons.io.IOUtils;
import org.dominokit.cli.VersionProfile;
import org.dominokit.cli.generator.exception.FailedToCreateResourceException;

import java.io.File;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void write(String path, Map<String, Object> context) {
Path filePath = Paths.get(path, name).toAbsolutePath();
File file = filePath.toFile();
if (!file.exists()) {
byte[] content = IOUtils.resourceToByteArray("projects-templates"+template, getClass().getClassLoader());
byte[] content = IOUtils.resourceToByteArray("projects-templates/"+ VersionProfile.get().getTemplatesPath()+template, getClass().getClassLoader());
Files.write(filePath, content);
}
} catch (IOException e) {
Expand Down
35 changes: 18 additions & 17 deletions src/main/java/org/dominokit/cli/generator/TemplateProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import org.dominokit.cli.VersionProfile;

import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -26,12 +27,12 @@ public static void render(String templatePath, Map<String, Object> context, Writ
}

private static void fillVersions(Map<String, Object> context) {
Arrays.stream(Versions.values())
.forEach(version -> {
context.put(version.name(), Optional.ofNullable(System.getProperty(version.getEnvVariable()))
.or(() -> Optional.ofNullable(System.getenv(version.getEnvVariable())))
.orElse(version.get()));
});
VersionProfile.get()
.getToolsVersions()
.forEach(version -> context.put(version.getKey(), Optional.ofNullable(System.getProperty(version.getKey()))
.orElse(version.getVersion())
)
);
}

public static String render(String templatePath, Map<String, Object> context) throws IOException, TemplateException {
Expand All @@ -43,16 +44,16 @@ public static String render(String templatePath, Map<String, Object> context) th
}

private static Configuration getEngine() {
if (isNull(cfg)) {
cfg = new Configuration(Configuration.VERSION_2_3_29);
cfg.setClassLoaderForTemplateLoading(TemplateProvider.class.getClassLoader(), "/projects-templates");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
cfg.setLogTemplateExceptions(false);
cfg.setWrapUncheckedExceptions(true);
cfg.setFallbackOnNullLoopVariable(false);

}
return cfg;
if (isNull(cfg)) {
cfg = new Configuration(Configuration.VERSION_2_3_29);
cfg.setClassLoaderForTemplateLoading(TemplateProvider.class.getClassLoader(), "/projects-templates/"+VersionProfile.get().getTemplatesPath());
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
cfg.setLogTemplateExceptions(false);
cfg.setWrapUncheckedExceptions(true);
cfg.setFallbackOnNullLoopVariable(false);

}
return cfg;
}
}
29 changes: 0 additions & 29 deletions src/main/java/org/dominokit/cli/generator/Versions.java

This file was deleted.

54 changes: 54 additions & 0 deletions src/main/resources/projects-templates/v1/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ${name}-api project

This project uses Quarkus, the Supersonic Subatomic Java Framework.

If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .

## Running the application in dev mode

You can run your application in dev mode that enables live coding using:
```shell script
mvn compile quarkus:dev
```

> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:9090/q/dev/.
## Packaging and running the application

The application can be packaged using:
```shell script
mvn package
```
It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory.
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory.

If you want to build an _über-jar_, execute the following command:
```shell script
mvn package -Dquarkus.package.type=uber-jar
```

The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`.

## Creating a native executable

You can create a native executable using:
```shell script
mvn package -Pnative
```

Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
```shell script
mvn package -Pnative -Dquarkus.native.container-build=true
```

You can then execute your native executable with: `./target/${name}-api-1.0.0-SNAPSHOT-runner`

If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html.

## Provided examples

### RESTEasy JAX-RS example

REST is easy peasy with this Hello World RESTEasy resource.

[Related guide section...](https://quarkus.io/guides/${name}-api#the-jax-rs-resources)
Loading

0 comments on commit f4be6c3

Please sign in to comment.