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

Feature/spring boot 3.0.x #341

Merged
merged 15 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,7 @@ Temporary Items
gradle/

# Visual Studio Code
.vscode
.vscode

# local scripts
*.sh
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ If you run this task on an existing project it will override the `main.gradle`,

- **`package`** `= <package.we.need>`: You can specify the main or default package of your project. `Default Value = co.com.bancolombia`

- **`type`** `= <imperative | reactive>`: With this parameter the task will generate a POO project. `Default Value = imperative`
- **`type`** `= <imperative | reactive>`: With this parameter the task will generate a POO project. `Default Value = reactive`

- **`name`** `= NameProject`: This parameter is going to specify the name of the project. `Default Value = cleanArchitecture`

Expand All @@ -80,11 +80,11 @@ If you run this task on an existing project it will override the `main.gradle`,

- **`language`** `= <JAVA | KOTLIN>`: Specify if you want to use this plugin . `Default Value = JAVA`

- **`javaVersion`** `= <VERSION_1_8 | VERSION_11 | VERSION_17>`: Java version . `Default Value = VERSION_11`
- **`javaVersion`** `= <VERSION_1_8 | VERSION_11 | VERSION_17>`: Java version . `Default Value = VERSION_17`

```shell
gradle cleanArchitecture --package=co.com.bancolombia --type=imperative --name=NameProject --coverage=jacoco --lombok=true
gradle ca --package=co.com.bancolombia --type=imperative --name=NameProject --coverage=jacoco --lombok=true
gradle cleanArchitecture --package=co.com.bancolombia --type=reactive --name=NameProject --coverage=jacoco --lombok=true
gradle ca --package=co.com.bancolombia --type=reactive --name=NameProject --coverage=jacoco --lombok=true
```

**_The structure will look like this for java:_**
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
public class Constants {
public static final String PLUGIN_TASK_GROUP = "Clean Architecture";
public static final String APP_SERVICE = "app-service";
public static final String PATH_GRAPHQL = "/graphqlpath";
public static final String SECRETS_VERSION = "3.2.0";
public static final String SPRING_BOOT_VERSION = "2.7.7";
public static final String SONAR_VERSION = "3.0";
public static final String LOMBOK_VERSION = "1.18.24";
public static final String PATH_GRAPHQL = "/graphql";
public static final String SECRETS_VERSION = "4.0.0";
public static final String SPRING_BOOT_VERSION = "3.0.2";
public static final String SONAR_VERSION = "3.5.0.2730";
public static final String LOMBOK_VERSION = "1.18.26";
public static final String JACOCO_VERSION = "0.8.8";
public static final String COBERTURA_VERSION = "3.0.0";
public static final String RCOMMONS_ASYNC_COMMONS_STARTER_VERSION = "1.0.5";
public static final String COBERTURA_VERSION = "4.0.0";
public static final String RCOMMONS_ASYNC_COMMONS_STARTER_VERSION = "2.0.0";
public static final String RCOMMONS_OBJECT_MAPPER_VERSION = "0.1.0";
public static final String PLUGIN_VERSION = "2.4.10";
public static final String GRADLE_WRAPPER_VERSION = "7.4.2";
public static final String GRADLE_WRAPPER_VERSION = "7.6";
public static final String KOTLIN_VERSION = "1.6.10";
public static final String AWS_BOM_VERSION = "2.18.39";
public static final String COMMONS_JMS_VERSION = "0.6.0";
public static final String AWS_BOM_VERSION = "2.19.31";
public static final String COMMONS_JMS_VERSION = "1.0.0";
public static final String GRAPHQL_KICKSTART_VERSION = "15.0.0";
public static final String TOMCAT_EXCLUSION_KOTLIN =
"configurations {\n"
+ "\tall {\n"
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/co/com/bancolombia/factory/ModuleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private void initialize() {
params.put("coberturaVersion", Constants.COBERTURA_VERSION);
params.put("lombokVersion", Constants.LOMBOK_VERSION);
params.put("commonsJmsVersion", Constants.COMMONS_JMS_VERSION);
params.put("graphqlKickStartVersion", Constants.GRAPHQL_KICKSTART_VERSION);
params.put("secretsVersion", Constants.SECRETS_VERSION);
loadPackage();
loadLanguage();
Expand Down Expand Up @@ -196,13 +197,20 @@ public Set<String> findExpressions(String path, String regex) {
}

public void appendDependencyToModule(String module, String dependency) throws IOException {
logger.lifecycle("adding dependency {} to module {}", dependency, module);
String buildFilePath = project.getChildProjects().get(module).getBuildFile().getPath();
buildFilePath = buildFilePath.replace(project.getProjectDir().getPath(), ".");
if (isKotlin() && !buildFilePath.endsWith(KTS)) {
buildFilePath += KTS;
}
updateFile(buildFilePath, current -> Utils.addDependency(current, dependency));
updateFile(
buildFilePath,
current -> {
String res = Utils.addDependency(current, dependency);
if (!current.equals(res)) {
logger.lifecycle("adding dependency {} to module {}", dependency, module);
}
return res;
});
}

public void appendConfigurationToModule(String module, String configuration) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
import co.com.bancolombia.factory.commons.ObjectMapperFactory;
import co.com.bancolombia.factory.validations.ReactiveTypeValidation;
import java.io.IOException;
import org.gradle.api.logging.Logger;
Expand All @@ -21,5 +22,6 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
String dependency = buildImplementationFromProject(builder.isKotlin(), ":r2dbc-postgresql");
builder.appendDependencyToModule(APP_SERVICE, dependency);
builder.appendToSettings("r2dbc-postgresql", "infrastructure/driven-adapters");
new ObjectMapperFactory().buildModule(builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static co.com.bancolombia.utils.Utils.buildImplementationFromProject;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.exceptions.ValidationException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
import co.com.bancolombia.factory.commons.ObjectMapperFactory;
Expand All @@ -15,6 +16,11 @@ public class DrivenAdapterRedis implements ModuleFactory {

@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
if (builder.isReactive() && Mode.REPOSITORY == builder.getParam(PARAM_MODE)) {
// https://github.com/spring-projects/spring-data-redis/issues/1823
throw new ValidationException(
"This mode is only available for imperative projects, please use `template` mode");
}
Logger logger = builder.getProject().getLogger();
String typePath = getPathType(builder.isReactive());
String modePath = getPathMode((Mode) builder.getParam(PARAM_MODE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public class EntryPointGraphql implements ModuleFactory {
@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.runValidations(ReactiveTypeValidation.class);
String name = builder.getStringParam("task-param-pathgql");
if (!name.startsWith("/")) {
String path = builder.getStringParam("task-param-pathgql");
if (!path.startsWith("/")) {
throw new IllegalArgumentException("The path must start with /");
}
builder.appendToSettings("graphql-api", "infrastructure/entry-points");
builder.appendToProperties("graphql.servlet").put("enabled", true).put("mapping", name);
builder.appendToProperties("graphql.servlet").put("enabled", true).put("mapping", path);
builder
.appendToProperties("graphql.playground")
.put("mapping", "/playground")
.put("endpoint", name)
.put("endpoint", path)
.put("enabled", true);
String dependency = buildImplementationFromProject(builder.isKotlin(), ":graphql-api");
builder.appendDependencyToModule(APP_SERVICE, dependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public static String appendValidate(
int start = main.indexOf(match);
return main.substring(0, start) + concatValue + main.substring(start);
}

public static String replace(String content, String previous, String next) {
return content.replace(previous, next);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package co.com.bancolombia.factory.upgrades.actions;

import static co.com.bancolombia.Constants.MainFiles.MAIN_GRADLE;

import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.upgrades.UpgradeAction;
import lombok.SneakyThrows;

public class UpgradeY2023M02D08Java implements UpgradeAction {

@Override
@SneakyThrows
public boolean up(ModuleBuilder builder) {
builder.updateExpression(MAIN_GRADLE, "JavaVersion.VERSION_11", "JavaVersion.VERSION_17");
return true;
}

@Override
public String name() {
return "2.4.10->3.0.0";
}

@Override
public String description() {
return "Update Java Version 17";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package co.com.bancolombia.factory.upgrades.actions;

import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.upgrades.UpdateUtils;
import co.com.bancolombia.factory.upgrades.UpgradeAction;
import co.com.bancolombia.utils.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.SneakyThrows;
import org.gradle.api.logging.Logger;

public class UpgradeY2023M02D08JavaxJakarta implements UpgradeAction {

@Override
@SneakyThrows
public boolean up(ModuleBuilder builder) {
Logger logger = builder.getProject().getLogger();
File root = builder.getProject().getRootDir();
AtomicBoolean applied = new AtomicBoolean(false);
FileUtils.allFiles(
root, file -> apply(builder, file, applied, logger), (dir, name) -> name.endsWith(".java"));
return applied.get();
}

private void apply(ModuleBuilder builder, File file, AtomicBoolean applied, Logger logger) {
try {
builder.updateFile(
file.getAbsolutePath(),
content -> {
String res = UpdateUtils.replace(content, "javax.persistence", "jakarta.persistence");
if (!content.equals(res)) {
logger.debug("javax to jakarta applied in: ${}", file.getName());
applied.set(true);
}
return res;
});
} catch (IOException e) {
logger.warn("Error applying javax to jakarta persistence", e);
}
}

@Override
public String name() {
return "2.4.10->3.0.0";
}

@Override
public String description() {
return "Update javax.persistence to jakarta.persistence";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package co.com.bancolombia.factory.upgrades.actions;

import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.upgrades.UpdateUtils;
import co.com.bancolombia.factory.upgrades.UpgradeAction;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.SneakyThrows;

public class UpgradeY2023M02D08Redis implements UpgradeAction {

@Override
@SneakyThrows
public boolean up(ModuleBuilder builder) {
String repository =
"infrastructure/driven-adapters/redis/src/main/java/"
+ builder.getParam("packagePath")
+ "/redis/repository/RedisRepository.java";
String repositoryAdapter =
"infrastructure/driven-adapters/redis/src/main/java/"
+ builder.getParam("packagePath")
+ "/redis/repository/helper/RepositoryAdapterOperations.java";

if (builder.getProject().file(repository).getAbsoluteFile().exists()
&& builder.getProject().file(repositoryAdapter).getAbsoluteFile().exists()) {
AtomicBoolean applied = new AtomicBoolean(false);
apply(builder, repository, applied);
apply(builder, repositoryAdapter, applied);
builder.appendDependencyToModule(
"redis", "implementation 'jakarta.persistence:jakarta.persistence-api'");
return applied.get();
}
return false;
}

private void apply(ModuleBuilder builder, String file, AtomicBoolean applied) throws IOException {
String prev = "org.springframework.data.repository.CrudRepository";
String next = "org.springframework.data.keyvalue.repository.KeyValueRepository";
builder.updateFile(
file,
content -> {
String res = UpdateUtils.replace(content, prev, next);
res = UpdateUtils.replace(res, "CrudRepository", "KeyValueRepository");
if (!content.equals(res)) {
applied.set(true);
}
return res;
});
}

@Override
public String name() {
return "2.4.10->3.0.0";
}

@Override
public String description() {
return "Update Redis CrudRepository to KeyValueRepository";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
public class GenerateStructureTask extends CleanArchitectureDefaultTask {
private static final String REACTIVE = "reactive";
private String packageName = "co.com.bancolombia";
private ProjectType type = ProjectType.IMPERATIVE;
private ProjectType type = ProjectType.REACTIVE;
private CoveragePlugin coverage = CoveragePlugin.JACOCO;
private String name = "cleanArchitecture";
private BooleanOption lombok = BooleanOption.TRUE;
private BooleanOption metrics = BooleanOption.TRUE;
private BooleanOption force = BooleanOption.FALSE;
private Language language = Language.JAVA;
private JavaVersion javaVersion = JavaVersion.VERSION_11;
private JavaVersion javaVersion = JavaVersion.VERSION_17;

@Option(option = "package", description = "Set principal package to use in the project")
public void setPackage(String packageName) {
Expand Down Expand Up @@ -106,6 +106,7 @@ public void generateStructureTask() throws IOException, CleanException {
logger.lifecycle("Clean Architecture plugin version: {}", Utils.getVersionPlugin());
logger.lifecycle("Package: {}", packageName);
logger.lifecycle("Project Type: {}", type);
logger.lifecycle("Java Version: {}", javaVersion);
logger.lifecycle("Project Name: {}", name);
builder.addParamPackage(packageName);
builder.addParam("projectName", name);
Expand Down Expand Up @@ -175,6 +176,7 @@ public enum Language {
}

public enum JavaVersion {
@Deprecated
VERSION_1_8,
VERSION_11,
VERSION_17
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/co/com/bancolombia/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.function.Consumer;
import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -108,4 +109,22 @@ public static String toRelative(String path) {
}
return "./" + path;
}

public static void allFiles(final File root, final Consumer<File> handler) {
allFiles(root, handler, (dir, name) -> true);
}

public static void allFiles(
final File root, final Consumer<File> handler, final FilenameFilter filter) {
if (root.isDirectory()) {
File[] files = root.listFiles();
if (files != null) {
Arrays.stream(files).forEach(file -> allFiles(file, handler, filter));
}
} else {
if (filter.accept(root.getParentFile(), root.getName())) {
handler.accept(root);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ public class RestConsumerConfig {

private ClientHttpConnector getClientHttpConnector() {
/*
IF YO REQUIRE APPEND SSL CERTIFICATE SELF SIGNED
SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();*/
IF YO REQUIRE APPEND SSL CERTIFICATE SELF SIGNED: this should be in the default cacerts trustore
*/
return new ReactorClientHttpConnector(HttpClient.create()
//.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext))
.compress(true)
.keepAlive(true)
.option(CONNECT_TIMEOUT_MILLIS, timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ open class RestConsumerConfig(

private fun getClientHttpConnector(): ClientHttpConnector {
/*
IF YO REQUIRE APPEND SSL CERTIFICATE SELF SIGNED
val sslContext =
SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE)
.build()*/
IF YO REQUIRE APPEND SSL CERTIFICATE SELF SIGNED: this should be in the default cacerts trustore
*/
return ReactorClientHttpConnector(
HttpClient.create() //.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext))
HttpClient.create()
.compress(true)
.keepAlive(true)
.option(CONNECT_TIMEOUT_MILLIS, timeout)
Expand Down
Loading