Skip to content

Commit

Permalink
Fix upgrades (#234)
Browse files Browse the repository at this point in the history
* fix isKotlin method

* fix isKotlin method, fix language property, hide loadPackage function, fix dependencies replace expression
  • Loading branch information
juancgalvis authored May 3, 2022
1 parent 76f93a4 commit 9fa4563
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
38 changes: 26 additions & 12 deletions src/main/java/co/com/bancolombia/factory/ModuleBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package co.com.bancolombia.factory;

import static co.com.bancolombia.Constants.MainFiles.APPLICATION_PROPERTIES;
import static co.com.bancolombia.task.GenerateStructureTask.Language.JAVA;
import static co.com.bancolombia.task.GenerateStructureTask.Language.KOTLIN;

import co.com.bancolombia.Constants;
import co.com.bancolombia.adapters.RestService;
Expand Down Expand Up @@ -65,11 +67,8 @@ public ModuleBuilder(Project project) {
params.put("coberturaVersion", Constants.COBERTURA_VERSION);
params.put("lombokVersion", Constants.LOMBOK_VERSION);
params.put("commonsJmsVersion", Constants.COMMONS_JMS_VERSION);
try {
loadPackage();
} catch (IOException e) {
logger.debug("cannot read gradle.properties");
}
loadPackage();
loadLanguage();
}

public void persist() throws IOException {
Expand Down Expand Up @@ -208,12 +207,6 @@ public void addParam(String key, Object value) {
this.params.put(key, 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) {
this.params.put("package", packageName.toLowerCase());
this.params.put("packagePath", packageName.replaceAll("\\.", "\\/").toLowerCase());
Expand Down Expand Up @@ -252,7 +245,7 @@ public Boolean isReactive() {
}

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

public Boolean isEnableLombok() {
Expand Down Expand Up @@ -287,6 +280,27 @@ public Release getLatestRelease() {
return (Release) params.get(LATEST_RELEASE);
}

private void loadPackage() {
try {
addParamPackage(FileUtils.readProperties(project.getProjectDir().getPath(), "package"));
} catch (IOException e) {
logger.debug("cannot read package from gradle.properties");
}
}

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();
}
this.params.put(LANGUAGE, language);
}

private void loadLatestRelease() {
Release latestRelease = restService.getLatestPluginVersion();
if (latestRelease != null && !latestRelease.getTagName().equals(Utils.getVersionPlugin())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private Consumer<Optional<DependencyRelease>> applyToFile(
+ latestDependency.getGroup()
+ ":"
+ latestDependency.getArtifact()
+ ":[^\\$].+",
+ ":[^\\$].+['\"]",
"'" + latestDependency + "'"));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UpgradeY2022M04D26 implements UpgradeAction {
public static final String GRADLE_VERSION_WRAPPER =
"\n\n" + "tasks.named('wrapper') {" + "gradleVersion = '7.4.2'\n" + "}\n";
public static final String LANGUAGE_PROPERTY = "language";
public static final String LANGUAGE_PROPERTY_VALUER = "language=java";
public static final String LANGUAGE_PROPERTY_VALUER = "\nlanguage=java";

@Override
@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public void generateModelTask() throws IOException, ParamNotFoundException {
name = Utils.capitalize(name);
logger.lifecycle("Clean Architecture plugin version: {}", Utils.getVersionPlugin());
logger.lifecycle("Model Name: {}", name);
builder.loadPackage();
builder.addParam("modelName", name.toLowerCase());
builder.addParam("modelClassName", name);
builder.addParam("lombok", builder.isEnableLombok());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void generateUseCaseTask() throws IOException, ParamNotFoundException {
String useCaseName = className.replace(USECASE_CLASS_NAME, "").toLowerCase();
logger.lifecycle("Clean Architecture plugin version: {}", Utils.getVersionPlugin());
logger.lifecycle("Use Case Name: {}", name);
builder.loadPackage();
builder.addParam("useCaseName", useCaseName);
builder.addParam("useCaseClassName", className);
builder.addParam("lombok", builder.isEnableLombok());
Expand Down

0 comments on commit 9fa4563

Please sign in to comment.