Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Oct 1, 2021
1 parent 93436ef commit fb6699f
Show file tree
Hide file tree
Showing 250 changed files with 2,194 additions and 6,627 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ dependencies {

// https://mvnrepository.com/artifact/org.apache.maven.shared/maven-invoker
compile group: 'org.apache.maven.shared', name: 'maven-invoker', version: '3.0.1'
// https://mvnrepository.com/artifact/org.freemarker/freemarker
implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.31'

}

Expand Down
54 changes: 0 additions & 54 deletions src/main/java/org/dominokit/cli/commands/DescriptorsGenerator.java

This file was deleted.

64 changes: 30 additions & 34 deletions src/main/java/org/dominokit/cli/commands/GenerateAppCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Model;
import org.dominokit.cli.PomUtil;
import org.dominokit.cli.model.Project;
import org.dominokit.cli.structure.files.VelocityContentProcessor;
import org.dominokit.cli.structure.files.VelocityStringContentProcessor;
import org.dominokit.cli.structure.folders.Folder;
import org.dominokit.cli.structure.folders.Folder_MapperImpl;
import org.dominokit.cli.creator.Project;
import org.dominokit.cli.creator.project.ProjectCreator;
import org.dominokit.cli.creator.project.ProjectCreatorFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static picocli.CommandLine.*;
import static picocli.CommandLine.Command;
import static picocli.CommandLine.HelpCommand;
import static picocli.CommandLine.Option;

@Command(
name = "app",
Expand Down Expand Up @@ -50,17 +48,28 @@ public class GenerateAppCommand implements Runnable {

@Option(
names = {"-t", "--type"},
description = "The type of the project, available types are [mvp,basic], [mvp] will generate a domino-mvp application, [basic] will generate simple gwt with domino-ui application.",
description = "The type of the project :" +
"\n\t\t -[basic] : will generate a simple project with (client, shared, server)" +
"\n\t\t -[mvp] : will generate a domino-mvp project",
defaultValue = "mvp"
)
private String type;

@Option(
names = {"-j", "--j2cl"},
defaultValue = "false",
description = "if true will generate a module that target j2cl compiler."
names = {"-api", "--generate-api"},
fallbackValue = "true",
defaultValue = "true",
description = "If true will generate an api module for REST endpoints implementation, current implementation is Quarkus with jax-rs."
)
private boolean j2cl = false;
private boolean generateApi;

@Option(
names = {"-c", "--compiler"},
fallbackValue = "gwt",
defaultValue = "gwt",
description = "The Java to JavaScript compiler to be used possible values [gwt, j2cl] default is [gwt]"
)
private String compiler;

@Override
public void run() {
Expand All @@ -73,12 +82,10 @@ public void run() {
LOGGER.info("No parent pom was found, creating a root project.");
}

Project project = new Project();
Project project = new Project(name);

project.setName(name);
project.setArtifactId(name);


if (nonNull(parentPom)) {
project.setVersion(parentPom.getVersion());
project.setParentArtifactId(parentPom.getArtifactId());
Expand All @@ -99,37 +106,26 @@ public void run() {
.replace(" ", "")
);

project.setGenerateApi(generateApi);

try {

String projectTemplateConfig = new VelocityStringContentProcessor(getTemplateByType(j2cl, type), project)
.processedContent();
Folder folder = Folder_MapperImpl.INSTANCE
.read(projectTemplateConfig);
folder.write(Paths.get(PathUtils.getUserDir()), project);
ProjectCreator projectCreator = ProjectCreatorFactory.get(compiler, type);
projectCreator.create(project);

if(project.isHasParent()){
addProjectToParent(project, parentPom);
}

System.out.println("The following project have been created");
System.out.println(project);

} catch (IOException e) {
e.printStackTrace();
}
}

private String getTemplateByType(boolean j2cl, String type) {
String compiler = j2cl ? "j2cl" : "gwt";

if (type.equalsIgnoreCase("mvp")) {
return "template/project/" + compiler + "/domino-mvp.json";
} else if (type.equalsIgnoreCase("basic")) {
return "template/project/" + compiler + "/domino-basic.json";
}
LOGGER.log(Level.SEVERE, "Unrecognized application type : " + type);
throw new IllegalArgumentException("Unrecognized application type : " + type);
}

private void addProjectToParent(Project project, Model parentPomModel) throws IOException {

String parentPom;
try {
parentPom = PomUtil.asString(parentPomModel);
Expand Down
110 changes: 34 additions & 76 deletions src/main/java/org/dominokit/cli/commands/GenerateModuleCommand.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package org.dominokit.cli.commands;

import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Model;
import org.dominokit.cli.PomUtil;
import org.dominokit.cli.generator.MultiModuleGenerator;
import org.dominokit.cli.generator.SingleModuleGenerator;
import org.dominokit.cli.model.Module;
import org.dominokit.cli.model.Project;

import java.io.*;
import java.nio.charset.StandardCharsets;
import org.dominokit.cli.creator.module.Module;
import org.dominokit.cli.creator.module.ModuleCreatorFactory;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static picocli.CommandLine.*;
import static picocli.CommandLine.Command;
import static picocli.CommandLine.HelpCommand;
import static picocli.CommandLine.Option;

@Command(
name = "module",
Expand All @@ -34,7 +27,7 @@ public class GenerateModuleCommand implements Runnable {
names = {"-s", "--single"},
fallbackValue = "true",
defaultValue = "false",
description = "if true will split the module into more submodules, [name]-backend, [name]-frontend, [name]-frontend-ui, [name]-shared"
description = "If true it will merge client an shared as one module, a backend module will not be generated"
)
private boolean single = false;

Expand All @@ -46,62 +39,56 @@ public class GenerateModuleCommand implements Runnable {
)
private boolean generateTests = false;


@Option(
names = {"-j", "--j2cl"},
fallbackValue = "true",
defaultValue = "false",
description = "if true will generate a module that target j2cl compiler."
names = {"-c", "--compiler"},
fallbackValue = "gwt",
defaultValue = "gwt",
description = "The Java to JavaScript compiler to be used possible values [gwt, j2cl] default is [gwt]"
)
private boolean j2cl = false;
private String compiler;

@Option(
names = {"-sp", "--subpackage"},
description = "the module sub package, this will be appended to the application rootPackage"
)
private String subPackage;

@Option(
names = {"-p", "--prefix"},
description = "The module prefix to be used in the generated classes name, if not present module name will be used instead"
)
private String prefix;

@Option(
names = {"-d", "--dir"},
description = "absolute path to the module where the project should be generated."
)
private String workingDire;

@Option(
names = {"-b", "--backend"},
fallbackValue = "false",
defaultValue = "false",
description = "if true will generate a domino-mvp backend module, default implementation is vertx."
)
private boolean backend = false;


@Override
public void run() {


PathUtils.setWorkingDir(workingDire);

try {

Model projectPom = PomUtil.asModel("");

String artifactId = projectPom.getArtifactId();

Model frontendPom = PomUtil.asModel(artifactId + "-frontend");
Model backendPom = PomUtil.asModel(artifactId + "-backend");
Module module = new Module(name);

Project project = new Project();

project.setName(artifactId);
if (nonNull(projectPom.getParent())) {
project.setGroupId(projectPom.getParent().getGroupId());
project.setRootPackage(projectPom.getParent().getGroupId());
project.setVersion(projectPom.getParent().getVersion());
} else {
project.setGroupId(projectPom.getGroupId());
project.setRootPackage(projectPom.getGroupId());
project.setVersion(projectPom.getVersion());
}
project.setArtifactId(projectPom.getArtifactId());

Module module = new Module(project);
module.setProjectPom(projectPom);
module.setBackendPom(backendPom);
module.setFrontendPom(frontendPom);
module.setArtifactId(name);
module.setGenerateTests(generateTests);
module.setJ2cl(j2cl);
module.setCompiler(compiler);
module.setPrefix(prefix);
module.setGenerateBackend(backend);

if (isNull(subPackage) || subPackage.trim().isEmpty()) {
subPackage = name.toLowerCase()
Expand All @@ -110,40 +97,11 @@ public void run() {
}
module.setSubPackage(subPackage);

if (single) {
new SingleModuleGenerator().generate(module);
} else {
new MultiModuleGenerator().generate(module);
}

addModule(module);
System.out.println(this);
ModuleCreatorFactory.get(compiler, single).create(module.init());
System.out.println("The following module have been created");
System.out.println(module);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public String toString() {
return "Module generated with the following arguments" +
"\nname=" + name +
"\nsingle=" + single +
"\ngenerateTests=" + generateTests +
"\nj2cl=" + j2cl +
"\nsubPackage=" + subPackage +
"\nworkingDire=" + workingDire;
}

private void addModule(Module module) throws IOException {
String projectPomString = PomUtil.asString(module.getProjectPom());

if (projectPomString.contains("<modules>")) {
projectPomString = projectPomString.replace("</modules>", "\t<module>" + module.getArtifactId() + "</module>\n\t</modules>");
} else {
projectPomString = projectPomString.replace("</project>", "\n\t<modules>\n\t\t<module>" + module.getArtifactId() + "</module>\n\t</modules>\n</project>");
}
FileUtils.write(module.getProjectPom().getPomFile(), projectPomString, StandardCharsets.UTF_8);

}

}
2 changes: 1 addition & 1 deletion src/main/java/org/dominokit/cli/commands/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static String getUserDir() {
}
}

static void setWorkingDir(String workingDir) {
public static void setWorkingDir(String workingDir) {
PathUtils.workingDir = workingDir;
}
}
Loading

0 comments on commit fb6699f

Please sign in to comment.