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

fix(kotlin): Remove kotlin support since 3.17.3 #453

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
181 changes: 35 additions & 146 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ sonar {
googleJavaFormat {
toolVersion = "1.7"
exclude '**/examples-ca/**'
exclude '**/UtilsTest.java'
}

dependencyCheck {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,6 @@ public void init() throws IOException {
runner.withPluginClasspath();
}

public void initKotlin() throws IOException {
// Setup the test build
deleteStructure(projectDir.toPath());
Files.createDirectories(projectDir.toPath());
writeString(new File(projectDir, "settings.gradle.kts"), "");
writeString(
new File(projectDir, "build.gradle.kts"),
"plugins {" + " id(\"co.com.bancolombia.cleanArchitecture\")" + "}");
runner = GradleRunner.create();
runner.forwardOutput();
runner.withPluginClasspath();
}

@AfterAll
public static void clean() {
deleteStructure(projectDir.toPath());
Expand Down Expand Up @@ -1143,202 +1130,6 @@ public void shouldUpdateProjectWithOneDependency() {
assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void canRunTaskGenerateDrivenAdapterKtorClient() throws IOException {
canRunTaskGenerateStructureKotlinWithOutParameters();
String task = "generateDrivenAdapter";
String type = "KTOR";

runner.withArguments(task, "--type=" + type);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/ktor-client/src/main/kotlin/co/com/bancolombia/client/KtorClient.kt")
.exists());
assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/ktor-client/src/main/kotlin/co/com/bancolombia/client/config/KtorConfig.kt")
.exists());
assertTrue(
new File("build/functionalTest/infrastructure/driven-adapters/ktor-client/build.gradle.kts")
.exists());

assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void canRunTaskGenerateStructureKotlinWithOutParameters() throws IOException {
initKotlin();
String task = "ca";

runner.withArguments(task, "--language=" + "KOTLIN");
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
// Verify the result
assertTrue(new File("build/functionalTest/README.md").exists());
assertTrue(new File("build/functionalTest/.gitignore").exists());
assertTrue(new File("build/functionalTest/build.gradle.kts").exists());
assertTrue(new File("build/functionalTest/lombok.config").exists());
assertTrue(new File("build/functionalTest/settings.gradle.kts").exists());

assertTrue(new File("build/functionalTest/infrastructure/driven-adapters/").exists());
assertTrue(new File("build/functionalTest/infrastructure/entry-points").exists());
assertTrue(new File("build/functionalTest/infrastructure/helpers").exists());

assertTrue(
new File("build/functionalTest/domain/model/src/main/kotlin/co/com/bancolombia/model")
.exists());
assertTrue(
new File("build/functionalTest/domain/model/src/test/kotlin/co/com/bancolombia/model")
.exists());
assertTrue(new File("build/functionalTest/domain/model/build.gradle.kts").exists());
assertTrue(
new File("build/functionalTest/domain/usecase/src/main/kotlin/co/com/bancolombia/usecase")
.exists());
assertTrue(
new File("build/functionalTest/domain/usecase/src/test/kotlin/co/com/bancolombia/usecase")
.exists());
assertTrue(new File("build/functionalTest/domain/usecase/build.gradle.kts").exists());

assertTrue(new File("build/functionalTest/applications/app-service/build.gradle.kts").exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/kotlin/co/com/bancolombia/MainApplication.kt")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/kotlin/co/com/bancolombia/config/UseCasesConfig.kt")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/kotlin/co/com/bancolombia/config")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/resources/application.yaml")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/resources/log4j2.properties")
.exists());
assertTrue(
new File("build/functionalTest/applications/app-service/src/test/kotlin/co/com/bancolombia")
.exists());

assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void canRunTaskGenerateStructureKotlinReactive() throws IOException {
initKotlin();
String task = "ca";

runner.withArguments(task, "--type=reactive", "--language=" + "KOTLIN");
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
// Verify the result
assertTrue(new File("build/functionalTest/README.md").exists());
assertTrue(new File("build/functionalTest/.gitignore").exists());
assertTrue(new File("build/functionalTest/build.gradle.kts").exists());
assertTrue(new File("build/functionalTest/lombok.config").exists());
assertTrue(new File("build/functionalTest/settings.gradle.kts").exists());

assertTrue(new File("build/functionalTest/infrastructure/driven-adapters/").exists());
assertTrue(new File("build/functionalTest/infrastructure/entry-points").exists());
assertTrue(new File("build/functionalTest/infrastructure/helpers").exists());

assertTrue(
new File("build/functionalTest/domain/model/src/main/kotlin/co/com/bancolombia/model")
.exists());
assertTrue(
new File("build/functionalTest/domain/model/src/test/kotlin/co/com/bancolombia/model")
.exists());
assertTrue(new File("build/functionalTest/domain/model/build.gradle.kts").exists());
assertTrue(
new File("build/functionalTest/domain/usecase/src/main/kotlin/co/com/bancolombia/usecase")
.exists());
assertTrue(
new File("build/functionalTest/domain/usecase/src/test/kotlin/co/com/bancolombia/usecase")
.exists());
assertTrue(new File("build/functionalTest/domain/usecase/build.gradle.kts").exists());

assertTrue(new File("build/functionalTest/applications/app-service/build.gradle.kts").exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/kotlin/co/com/bancolombia/MainApplication.kt")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/kotlin/co/com/bancolombia/config/UseCasesConfig.kt")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/kotlin/co/com/bancolombia/config")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/resources/application.yaml")
.exists());
assertTrue(
new File(
"build/functionalTest/applications/app-service/src/main/resources/log4j2.properties")
.exists());
assertTrue(
new File("build/functionalTest/applications/app-service/src/test/kotlin/co/com/bancolombia")
.exists());

assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void canRunTaskGenerateDynamoDBDrivenAdapterInKotlin() throws IOException {
canRunTaskGenerateStructureKotlinWithOutParameters();
String task = "generateDrivenAdapter";
String type = "DYNAMODB";

runner.withArguments(task, "--type=" + type);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/dynamo-db/src/main/kotlin/co/com/bancolombia/dynamodb/DynamoDBTemplateAdapter.kt")
.exists());
assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/dynamo-db/src/main/kotlin/co/com/bancolombia/dynamodb/config/DynamoDBConfig.kt")
.exists());
assertTrue(
new File("build/functionalTest/infrastructure/driven-adapters/dynamo-db/build.gradle.kts")
.exists());

assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void canRunTaskGenerateDynamoDBDrivenAdapterInKotlinReactive() throws IOException {
canRunTaskGenerateStructureKotlinReactive();
String task = "generateDrivenAdapter";
String type = "DYNAMODB";

runner.withArguments(task, "--type=" + type);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/dynamo-db/src/main/kotlin/co/com/bancolombia/dynamodb/DynamoDBTemplateAdapter.kt")
.exists());
assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/dynamo-db/src/main/kotlin/co/com/bancolombia/dynamodb/config/DynamoDBConfig.kt")
.exists());
assertTrue(
new File("build/functionalTest/infrastructure/driven-adapters/dynamo-db/build.gradle.kts")
.exists());

assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void shouldGenerateDynamoDBDrivenAdapterInJava() {
canRunTaskGenerateStructureWithOutParameters();
Expand Down Expand Up @@ -1435,26 +1226,6 @@ public void shouldGenerateBinStashDrivenAdapterInJavaNoReactive() {
assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void shouldGenerateBinStashDrivenAdapterInKotlin() throws IOException {
canRunTaskGenerateStructureKotlinWithOutParameters();
String task = "generateDrivenAdapter";
String type = "BINSTASH";

runner.withArguments(task, "--type=" + type);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();

assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/bin-stash/src/main/kotlin/co/com/bancolombia/binstash/config/BinStashCacheConfig.kt")
.exists());
assertTrue(
new File("build/functionalTest/infrastructure/driven-adapters/bin-stash/build.gradle.kts")
.exists());
assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void shouldGenerateBinStashDrivenAdapter() {
canRunTaskGenerateStructureWithOutLombok();
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ public final class Constants {
public static final String DEPENDENCY_CHECK_VERSION = "9.1.0";
// custom
public static final String GRADLE_WRAPPER_VERSION = "8.7";
public static final String KOTLIN_VERSION = "1.9.20";

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class MainFiles {
public static final String KTS = ".kts";
public static final String BUILD_GRADLE = "./build.gradle";
public static final String BUILD_GRADLE_KTS = BUILD_GRADLE + KTS;
public static final String MAIN_GRADLE = "./main.gradle";
public static final String SETTINGS_GRADLE = "./settings.gradle";
public static final String DOCKERFILE = "./deployment/Dockerfile";
public static final String APP_BUILD_GRADLE = "./applications/app-service/build.gradle";
public static final String APP_BUILD_GRADLE_KTS = APP_BUILD_GRADLE + KTS;
public static final String APPLICATION_PROPERTIES =
"applications/app-service/src/main/resources/application.yaml";
public static final String GRADLE_PROPERTIES = "./gradle.properties";
Expand Down
44 changes: 6 additions & 38 deletions src/main/java/co/com/bancolombia/factory/ModuleBuilder.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package co.com.bancolombia.factory;

import static co.com.bancolombia.Constants.MainFiles.APPLICATION_PROPERTIES;
import static co.com.bancolombia.Constants.MainFiles.KTS;
import static co.com.bancolombia.task.GenerateStructureTask.Language.JAVA;
import static co.com.bancolombia.task.GenerateStructureTask.Language.KOTLIN;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Description;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Header;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Normal;
Expand Down Expand Up @@ -56,8 +53,8 @@

public class ModuleBuilder {
private static final String DEFINITION_FILES = "definition.json";
private static final String LANGUAGE = "language";
public static final String LATEST_RELEASE = "latestRelease";
public static final String SETTINGS_GRADLE = "settings.gradle";
private final DefaultResolver resolver = new DefaultResolver();
private final MustacheFactory mustacheFactory = new DefaultMustacheFactory();
private final Map<String, FileModel> files = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -93,7 +90,6 @@ private void initialize() {
params.put("metrics", withMetrics());
addConstantsFromClassToModuleBuilder(this, Constants.class);
loadPackage();
loadLanguage();
loadIsExample();
}

Expand Down Expand Up @@ -165,11 +161,6 @@ public void setupFromTemplate(String resourceGroup) throws IOException, ParamNot
addDir(Utils.fillPath(folder, params));
}
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());
Expand All @@ -179,16 +170,16 @@ public void setupFromTemplate(String resourceGroup) throws IOException, ParamNot
}

public void appendToSettings(String module, String baseDir) throws IOException {
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));
logger.lifecycle("adding module {} to " + SETTINGS_GRADLE, module);
updateFile(
SETTINGS_GRADLE,
settings -> Utils.addModule(settings, Utils.INCLUDE_MODULE_JAVA, module, baseDir));
}

public void removeFromSettings(String module) throws IOException {
logger.lifecycle("removing {} from settings.gradle", module);
updateFile(
"settings.gradle" + (isKotlin() ? ".kts" : ""),
SETTINGS_GRADLE,
settings -> {
String moduleKey = ":" + module;
return Utils.removeLinesIncludes(settings, moduleKey);
Expand All @@ -210,9 +201,6 @@ public Set<String> findExpressions(String path, String regex) {

public String getSecretsBackendEnabled() {
String fileName = "applications/app-service/build.gradle";
if (isKotlin()) {
fileName += ".kts";
}
if (!findExpressions(fileName, "com.github.bancolombia:aws-secrets").isEmpty()) {
return "AWS_SECRETS_MANAGER";
} else if (!findExpressions(fileName, "com.github.bancolombia:vault").isEmpty()) {
Expand Down Expand Up @@ -241,9 +229,6 @@ public void setUpSecretsInAdapter() throws CleanException, IOException {
public void appendDependencyToModule(String module, String dependency) throws IOException {
String buildFilePath = project.getChildProjects().get(module).getBuildFile().getPath();
buildFilePath = buildFilePath.replace(project.getProjectDir().getPath(), ".");
if (isKotlin() && !buildFilePath.endsWith(KTS)) {
buildFilePath += KTS;
}
updateFile(
buildFilePath,
current -> {
Expand Down Expand Up @@ -335,10 +320,6 @@ public boolean analyticsEnabled() throws IOException {
return "true".equals(value);
}

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

public boolean isEnableLombok() {
return getABooleanProperty("lombok", true);
}
Expand Down Expand Up @@ -414,19 +395,6 @@ private void loadIsExample() {
}
}

private void loadLanguage() {
String language = null;
try {
language = FileUtils.readProperties(project.getProjectDir().getPath(), LANGUAGE);
} catch (IOException e) {
logger.debug("cannot read language from gradle.properties");
}
if (language == null) {
language = JAVA.name().toLowerCase();
}
this.params.put(LANGUAGE, language);
}

private void loadLatestRelease() {
Release latestRelease = operations.getLatestPluginVersion();
if (latestRelease != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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");
String dependency = buildImplementationFromProject(builder.isKotlin(), ":async-event-bus");
String dependency = buildImplementationFromProject(":async-event-bus");
builder.appendDependencyToModule(APP_SERVICE, dependency);
}
}
Loading
Loading