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

Scaffold kotlin code #188

Merged
merged 26 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cde4e24
add language option and enum to structure task
ElvertMora Sep 30, 2021
ca6ad73
fix space
ElvertMora Sep 30, 2021
c07cea6
update gradle library
jakspok Sep 30, 2021
d42466d
Update Readme
jakspok Sep 30, 2021
255ff9b
redefining project structure in base
ElvertMora Oct 4, 2021
425f9e9
redefining project structure in base
ElvertMora Oct 12, 2021
32fcdf3
redefining project structure in base
ElvertMora Oct 14, 2021
58b1436
fis test
ElvertMora Oct 14, 2021
2be6747
Add kotlin files driver-adapters
jakspok Oct 20, 2021
5119641
Merge branch 'scaffold-kotlin-code' of https://github.com/bancolombia…
jakspok Oct 20, 2021
52ed16f
Update License MIT To Apache 2.0
jakspok Oct 20, 2021
5d1648c
Delete LICENSE MIT
jakspok Oct 20, 2021
41b82b3
fix version
ElvertMora Oct 20, 2021
3727420
Merge branch 'master' into scaffold-kotlin-code
ElvertMora Oct 20, 2021
84ee20b
resolve kotlin and java dependencies on generate driver-adapters
ElvertMora Oct 22, 2021
c191cbf
resolve kotlin and java dependencies on generate driver-adapters mong…
ElvertMora Oct 29, 2021
cd1932f
Fix Class Kotlin
jakspok Nov 2, 2021
9ab91fc
resolve kotlin and java dependencies on generate driver-adapters
ElvertMora Nov 3, 2021
efc59f9
add entryponints reactive and imperative webflux and spring mvc
ElvertMora Nov 5, 2021
9bfa8e6
fix entrypoint router webflux
ElvertMora Nov 5, 2021
609a8b5
fix dependecie
ElvertMora Nov 5, 2021
62baa50
Fix Dependency
jakspok Nov 5, 2021
0d47d3d
fix: the config files are created in the main module now is in the sa…
ElvertMora Nov 8, 2021
daec158
update documentation
ElvertMora Nov 8, 2021
c6a988e
Fix version gradle github
jakspok Nov 8, 2021
348833b
Add column language support
jakspok Nov 9, 2021
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
196 changes: 153 additions & 43 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ tasks.register('installGitHooks', Copy) {
}

tasks.named('wrapper') {
gradleVersion = '6.7'
gradleVersion = '6.9.1'
}

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package=co.com.bancolombia
systemProp.version=1.9.9
systemProp.version=2.0.0

4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ case "`uname`" in
Darwin* )
darwin=true
;;
MINGW* )
MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
Expand Down Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ public class Constants {
public static final String COBERTURA_VERSION = "3.0.0";
public static final String RCOMMONS_ASYNC_COMMONS_STARTER_VERSION = "1.0.3";
public static final String RCOMMONS_OBJECT_MAPPER_VERSION = "0.1.0";
public static final String PLUGIN_VERSION = "1.9.9";
public static final String GRADLE_WRAPPER_VERSION = "6.7";
public static final String PLUGIN_VERSION = "2.0.0";
public static final String GRADLE_WRAPPER_VERSION = "6.9.1";
public static final String TOMCAT_EXCLUSION_KOTLIN =
"configurations {\n"
+ "\tall {\n"
+ "\t\texclude(group = \"org.springframework.boot\", module = \"spring-boot-starter-tomcat\")\n"
+ "\t}\n"
+ "}";
public static final String TOMCAT_EXCLUSION =
"compile.exclude group: \"org.springframework.boot\", module:\"spring-boot-starter-tomcat\"";
public static final String COMMONS_JMS_VERSION = "0.0.3";
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/co/com/bancolombia/factory/ModuleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import org.gradle.api.logging.Logger;

public class ModuleBuilder {

private static final String APPLICATION_PROPERTIES =
"applications/app-service/src/main/resources/application.yaml";
private static final String DEFINITION_FILES = "definition.json";
private static final String LANGUAGE = "language";
private final DefaultResolver resolver = new DefaultResolver();
private final MustacheFactory mustacheFactory = new DefaultMustacheFactory();
private final Map<String, FileModel> files = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -92,7 +94,13 @@ public void setupFromTemplate(String resourceGroup) throws IOException, ParamNot
for (String folder : definition.getFolders()) {
addDir(Utils.fillPath(folder, params));
}
for (Map.Entry<String, String> fileEntry : definition.getFiles().entrySet()) {
Map<String, String> projectFiles = new HashMap<>(definition.getFiles());
if (isKotlin()) {
projectFiles.putAll(definition.getKotlin());
} else {
projectFiles.putAll(definition.getJava());
}
for (Map.Entry<String, String> fileEntry : projectFiles.entrySet()) {
String path = Utils.fillPath(fileEntry.getValue(), params);
String content = buildFromTemplate(fileEntry.getKey());
addDir(Utils.extractDir(path));
Expand All @@ -101,8 +109,10 @@ public void setupFromTemplate(String resourceGroup) throws IOException, ParamNot
}

public void appendToSettings(String module, String baseDir) throws IOException {
logger.lifecycle("adding module {} to settings.gradle", module);
updateFile("settings.gradle", settings -> Utils.addModule(settings, module, baseDir));
String settingsFile = "settings.gradle" + (isKotlin() ? ".kts" : "");
logger.lifecycle("adding module {} to " + settingsFile, module);
String include = isKotlin() ? Utils.INCLUDE_MODULE_KOTLIN : Utils.INCLUDE_MODULE_JAVA;
updateFile(settingsFile, settings -> Utils.addModule(settings, include, module, baseDir));
}

public void removeFromSettings(String module) throws IOException {
Expand Down Expand Up @@ -160,6 +170,8 @@ public void addParam(String key, Object value) {

public void loadPackage() throws IOException {
addParamPackage(FileUtils.readProperties(project.getProjectDir().getPath(), "package"));
this.params.put(
LANGUAGE, FileUtils.readProperties(project.getProjectDir().getPath(), LANGUAGE));
}

public void addParamPackage(String packageName) {
Expand Down Expand Up @@ -199,6 +211,10 @@ public Boolean isReactive() {
return getABooleanProperty("reactive");
}

public boolean isKotlin() {
return params.get(LANGUAGE).toString().equalsIgnoreCase("KOTLIN");
}

public Boolean isEnableLombok() {
return getABooleanProperty("lombok");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -12,6 +14,7 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder.runValidations(ReactiveTypeValidation.class);
builder.setupFromTemplate("driven-adapter/async-event-bus");
builder.appendToSettings("async-event-bus", "infrastructure/driven-adapters");
builder.appendDependencyToModule("app-service", "implementation project(':async-event-bus')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":async-event-bus");
builder.appendDependencyToModule("app-service", dependency);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -20,7 +22,8 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder
.appendToProperties("spring.jpa")
.put("databasePlatform", "org.hibernate.dialect.H2Dialect");
builder.appendDependencyToModule("app-service", "implementation project(':jpa-repository')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":jpa-repository");
builder.appendDependencyToModule("app-service", dependency);
if (builder.getBooleanParam("include-secret")) {
new DrivenAdapterSecrets().buildModule(builder);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -21,8 +23,9 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
.put("host", "localhost")
.put("protocol", "http")
.put("port", "4566")
.put("keyId", "add-your-key-here");
builder.appendDependencyToModule("app-service", "implementation project(':kms-repository')");
.put("keyId", "add-your-key-here"); // implementation project('kms-repository')
String dependency = buildImplementationFromProject(builder.isKotlin(), ":kms-repository");
builder.appendDependencyToModule("app-service", dependency);
new DrivenAdapterSecrets().buildModule(builder);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -11,7 +13,9 @@ public class DrivenAdapterMQ implements ModuleFactory {
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.setupFromTemplate(getTemplate(builder.isReactive()));
builder.appendToSettings("mq-sender", "infrastructure/driven-adapters");
builder.appendDependencyToModule("app-service", "implementation project(':mq-sender')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":mq-sender");

builder.appendDependencyToModule("app-service", dependency);

builder
.appendToProperties("commons.jms")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -20,7 +22,8 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
}
builder.appendToSettings("mongo-repository", "infrastructure/driven-adapters");
builder.appendToProperties("spring.data.mongodb").put("uri", "mongodb://localhost:27017/test");
builder.appendDependencyToModule("app-service", "implementation project(':mongo-repository')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":mongo-repository");
builder.appendDependencyToModule("app-service", dependency);
if (builder.getBooleanParam("include-secret")) {
new DrivenAdapterSecrets().buildModule(builder);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -15,7 +17,8 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder.runValidations(ReactiveTypeValidation.class);
logger.lifecycle("Generating for reactive project");
builder.setupFromTemplate("driven-adapter/r2dbc-postgresql");
builder.appendDependencyToModule("app-service", "implementation project(':r2dbc-postgresql')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":r2dbc-postgresql");
builder.appendDependencyToModule("app-service", dependency);
builder.appendToSettings("r2dbc-postgresql", "infrastructure/driven-adapters");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -12,7 +14,8 @@ public class DrivenAdapterRSocketRequester implements ModuleFactory {
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.runValidations(ReactiveTypeValidation.class);
builder.appendToSettings("rsocket-requester", "infrastructure/driven-adapters");
builder.appendDependencyToModule("app-service", "implementation project(':rsocket-requester')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":rsocket-requester");
builder.appendDependencyToModule("app-service", dependency);
builder.setupFromTemplate("driven-adapter/rsocket-requester");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -23,7 +25,8 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
} else {
builder.appendToProperties("spring.redis").put("host", "localhost").put("port", 6379);
}
builder.appendDependencyToModule("app-service", "implementation project(':redis')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":redis");
builder.appendDependencyToModule("app-service", dependency);
if (builder.getBooleanParam("include-secret")) {
new DrivenAdapterSecrets().buildModule(builder);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementation;
import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -14,19 +17,23 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
if (builder.isReactive()) {
logger.lifecycle("Generating rest-consumer for reactive project");
builder.setupFromTemplate("driven-adapter/consumer-rest/reactive-rest-consumer");
builder.appendDependencyToModule(
"app-service", "implementation 'org.springframework.boot:spring-boot-starter-webflux'");
String implementation =
buildImplementation(
builder.isKotlin(), "org.springframework.boot:spring-boot-starter-webflux");
builder.appendDependencyToModule("app-service", implementation);
builder.appendToProperties("adapter.restconsumer").put("timeout", 5000);
} else {
logger.lifecycle("Generating rest-consumer for imperative project");
builder.setupFromTemplate("driven-adapter/consumer-rest/rest-consumer");
builder.appendDependencyToModule(
"app-service", "implementation 'com.fasterxml.jackson.core:jackson-databind'");
String implementation =
buildImplementation(builder.isKotlin(), "com.fasterxml.jackson.core:jackson-databind");
builder.appendDependencyToModule("app-service", implementation);
}
builder
.appendToProperties("adapter.restconsumer")
.put("url", builder.getStringParam("task-param-url"));
builder.appendToSettings("rest-consumer", "infrastructure/driven-adapters");
builder.appendDependencyToModule("app-service", "implementation project(':rest-consumer')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":rest-consumer");
builder.appendDependencyToModule("app-service", dependency);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -20,7 +22,8 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
.put("bucketName", "")
.put("region", "us-east-1")
.put("endpoint", "");
builder.appendDependencyToModule("app-service", "implementation project(':s3-repository')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":s3-repository");
builder.appendDependencyToModule("app-service", dependency);
}

protected String getPathType(boolean isReactive) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.adapters;

import static co.com.bancolombia.utils.Utils.buildImplementation;

import co.com.bancolombia.Constants;
import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
Expand All @@ -20,13 +22,11 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder.setupFromTemplate("driven-adapter/secrets");
}
logger.lifecycle("Generating mode");
builder.appendDependencyToModule(
"app-service",
"implementation 'com.github.bancolombia:"
+ secretLibrary
+ ":"
+ Constants.SECRETS_VERSION
+ "'");
String dependency =
buildImplementation(
builder.isKotlin(),
"com.github.bancolombia:" + secretLibrary + ":" + Constants.SECRETS_VERSION);
builder.appendDependencyToModule("app-service", dependency);
builder.appendToProperties("aws").put("region", "us-east-1").put("secretName", "my-secret");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.commons;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.utils.Utils;
Expand All @@ -20,7 +22,8 @@ public static void generateGenericModule(
builder.addParam("name-dash", dashName);
builder.addParam("name-package", name.toLowerCase());
builder.appendToSettings(dashName, baseDir);
builder.appendDependencyToModule("app-service", "implementation project(':" + dashName + "')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":" + dashName);
builder.appendDependencyToModule("app-service", dependency);
builder.setupFromTemplate(template);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.commons;

import static co.com.bancolombia.utils.Utils.buildImplementation;

import co.com.bancolombia.Constants;
import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
Expand All @@ -11,10 +13,10 @@ public class ObjectMapperFactory implements ModuleFactory {
@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.setupFromTemplate("commons/object-mapper");
builder.appendDependencyToModule(
"app-service",
"implementation 'org.reactivecommons.utils:object-mapper:"
+ Constants.RCOMMONS_OBJECT_MAPPER_VERSION
+ "'");
String dependency =
buildImplementation(
builder.isKotlin(),
"org.reactivecommons.utils:object-mapper:" + Constants.RCOMMONS_OBJECT_MAPPER_VERSION);
builder.appendDependencyToModule("app-service", dependency);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.com.bancolombia.factory.entrypoints;

import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
Expand All @@ -12,7 +14,7 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder.runValidations(ReactiveTypeValidation.class);
builder.setupFromTemplate("entry-point/async-event-handler");
builder.appendToSettings("async-event-handler", "infrastructure/entry-points");
builder.appendDependencyToModule(
"app-service", "implementation project(':async-event-handler')");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":async-event-handler");
builder.appendDependencyToModule("app-service", dependency);
}
}
Loading