Skip to content

Commit

Permalink
Merge pull request #9 from bancolombia/feature/generateModel
Browse files Browse the repository at this point in the history
Feature/generate model
  • Loading branch information
santitigaga authored Dec 16, 2019
2 parents 8c179fa + 90163e6 commit b0b6d02
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 124 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: java

jdk:
- openjdk8

os:
- linux
script: ./gradlew build --refresh-dependencies --no-daemon --continue
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Build Status](https://travis-ci.com/bancolombia/scaffold-clean-architecture.svg?branch=master)](https://travis-ci.com/bancolombia/scaffold-clean-architecture)
# Scaffolding of Clean Architecture
Gradle plugin to create a java application based on Clean Architecture following our best practices!

Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ plugins {
}

group 'co.com.bancolombia.cleanArchitecture'
version '0.35'

version '0.38'

repositories {
// Use jcenter for resolving dependencies.
Expand Down Expand Up @@ -76,6 +77,7 @@ check {
}



pluginBundle {
website = 'https://github.com/bancolombia/scaffold-clean-architecture'
vcsUrl = 'https://github.com/bancolombia/scaffold-clean-architecture'
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package=co.com.bancolombia
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
package co.com.bancolombia;


import org.gradle.api.internal.project.IProjectFactory;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

import java.io.*;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand All @@ -26,7 +22,9 @@
*/
public class PluginCleanPluginFunctionalTest {

@Test public void canRunTask() throws IOException {
@Test public void canRunTaskCleanArchitectureWithOutParameters() throws IOException {

String task = "cleanArchitecture";
// Setup the test build
File projectDir = new File("build/functionalTest");
Files.createDirectories(projectDir.toPath());
Expand All @@ -40,7 +38,7 @@ public class PluginCleanPluginFunctionalTest {
GradleRunner runner = GradleRunner.create();
runner.forwardOutput();
runner.withPluginClasspath();
runner.withArguments("cleanArchitecture");
runner.withArguments(task);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
// Verify the result
Expand Down Expand Up @@ -69,10 +67,14 @@ public class PluginCleanPluginFunctionalTest {
assertTrue(new File("build/functionalTest/applications/app-service/src/main/resources/log4j2.properties").exists());
assertTrue(new File("build/functionalTest/applications/app-service/src/test/java/co/com/bancolombia").exists());

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

@Test public void canRunTaskWithParameters() throws IOException {
@Test public void canRunTaskCleanArchitectureWithParameters() throws IOException {
String task = "cleanArchitecture";
String _package = "co.com.test";
String projectName = "ProjectName";

// Setup the test build
File projectDir = new File("build/functionalTest");
Files.createDirectories(projectDir.toPath());
Expand All @@ -87,11 +89,11 @@ public class PluginCleanPluginFunctionalTest {
GradleRunner runner = GradleRunner.create();
runner.forwardOutput();
runner.withPluginClasspath();
runner.withArguments("cleanArchitecture","--name=ProjectName","--package=co.com.test");
runner.withArguments(task,"--name="+ projectName,"--package="+ _package);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
// Verify the result
assertTrue(result.getOutput().contains("Name Project: ProjectName"));
assertTrue(result.getOutput().contains( projectName));
assertTrue(result.getOutput().contains("Package: co/com/test"));


Expand Down Expand Up @@ -120,7 +122,33 @@ public class PluginCleanPluginFunctionalTest {
assertTrue(new File("build/functionalTest/applications/app-service/src/main/resources/log4j2.properties").exists());
assertTrue(new File("build/functionalTest/applications/app-service/src/test/java/co/com/test").exists());

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

@Test public void canRunTaskGenerateModelWithParameters() throws Exception {

String task = "generateModel";
String modelName = "testModel";
// Setup the test build
File projectDir = new File("build/functionalTest");
Files.createDirectories(projectDir.toPath());
writeString(new File(projectDir, "settings.gradle"), "");
writeString(new File(projectDir, "build.gradle"),
"plugins {" +
" id('co.com.bancolombia.cleanArchitecture')" +
"}");

// Run the build
GradleRunner runner = GradleRunner.create();
runner.forwardOutput();
runner.withPluginClasspath();
runner.withArguments(task,"--name="+ modelName);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();
assertTrue(new File("build/functionalTest/domain/model/src/main/java/co/com/bancolombia/model/testModel/gateways/TestModelRepository.java").exists());
assertTrue(new File("build/functionalTest/domain/model/src/main/java/co/com/bancolombia/model/testModel/TestModel.java").exists());

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

@Test public void createTasks() throws IOException {
Expand All @@ -143,6 +171,7 @@ public class PluginCleanPluginFunctionalTest {

// Verify the result
assertTrue(result.getOutput().contains("cleanArchitecture"));
assertTrue(result.getOutput().contains("generateModel"));

assertEquals(result.task(":tasks").getOutcome(), TaskOutcome.SUCCESS);
}
Expand Down
160 changes: 103 additions & 57 deletions src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package co.com.bancolombia;

public class Constants {

public static final String javaExtension = ".java";

/**
* Base Dirs
**/
Expand Down Expand Up @@ -28,9 +31,12 @@ public class Constants {
**/

public static final String model = "model";
public static final String gateway = "gateways";
public static final String repository = "Repository";
public static final String usecase = "usecase";

public static final String buildGradle = "build.gradle";
public static final String gradleProperties = "gradle.properties";
public static final String applicationProperties = "application.yaml";
public static final String mainApplication = "MainApplication.java";

Expand Down Expand Up @@ -151,41 +157,41 @@ public class Constants {
"## Entry Points\n" +
"Los entry points representan los puntos de entrada de la aplicación o el inicio de los flujos de negocio.";

public static final String mainGradleContent ="subprojects {\n"+
" apply plugin: \"java\"\n"+
" apply plugin: \"jacoco\"\n"+
" apply plugin: 'io.spring.dependency-management'\n"+
"\n"+
" sourceCompatibility = JavaVersion.VERSION_1_8\n"+
"\n"+
" repositories {\n"+
" \t\t mavenCentral()\n"+
" maven { url \"https://repo.spring.io/snapshot\" }\n"+
" maven { url \"https://repo.spring.io/milestone\" }\n"+
" \t\t//maven { url \"https://artifactory.apps.bancolombia.com:443/maven-bancolombia\" }\n"+
" }\n"+
"\n"+
" dependencies {\n"+
" testImplementation 'org.springframework.boot:spring-boot-starter-test'\n"+
"\n"+
" compileOnly 'org.projectlombok:lombok'\n"+
" annotationProcessor 'org.projectlombok:lombok'\n"+
" testAnnotationProcessor 'org.projectlombok:lombok'\n"+
" testCompileOnly 'org.projectlombok:lombok'\n"+
" }\n"+
"\n"+
"\n"+
" jacoco {\n"+
" toolVersion = '0.8.2'\n"+
" }\n"+
"\n"+
" dependencyManagement {\n"+
" imports {\n"+
" mavenBom \"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}\"\n"+
" mavenBom \"org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}\"\n"+
" }\n"+
" }\n"+
"}";
public static final String mainGradleContent = "subprojects {\n" +
" apply plugin: \"java\"\n" +
" apply plugin: \"jacoco\"\n" +
" apply plugin: 'io.spring.dependency-management'\n" +
"\n" +
" sourceCompatibility = JavaVersion.VERSION_1_8\n" +
"\n" +
" repositories {\n" +
" \t\t mavenCentral()\n" +
" maven { url \"https://repo.spring.io/snapshot\" }\n" +
" maven { url \"https://repo.spring.io/milestone\" }\n" +
" \t\t//maven { url \"https://artifactory.apps.bancolombia.com:443/maven-bancolombia\" }\n" +
" }\n" +
"\n" +
" dependencies {\n" +
" testImplementation 'org.springframework.boot:spring-boot-starter-test'\n" +
"\n" +
" compileOnly 'org.projectlombok:lombok'\n" +
" annotationProcessor 'org.projectlombok:lombok'\n" +
" testAnnotationProcessor 'org.projectlombok:lombok'\n" +
" testCompileOnly 'org.projectlombok:lombok'\n" +
" }\n" +
"\n" +
"\n" +
" jacoco {\n" +
" toolVersion = '0.8.2'\n" +
" }\n" +
"\n" +
" dependencyManagement {\n" +
" imports {\n" +
" mavenBom \"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}\"\n" +
" mavenBom \"org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}\"\n" +
" }\n" +
" }\n" +
"}";
public static final String buildGradleContent = "buildscript {\n" +
"\text {\n" +
"\t\tspringBootVersion = '2.1.1.RELEASE'\n" +
Expand All @@ -204,7 +210,7 @@ public class Constants {
"\n" +
"plugins {\n" +
"\tid \"org.sonarqube\" version \"2.6\"\n" +
"\tid \"co.com.bancolombia.cleanArchitecture\" version \"0.33\"\n" +
"\tid \"co.com.bancolombia.cleanArchitecture\" version \"0.38\"\n" +
"}\n" +
"subprojects {\n" +
" apply plugin: \"java\"\n" +
Expand All @@ -215,30 +221,37 @@ public class Constants {
" }\n" +
"}"+
"\n" +
"task testReport(type: TestReport) {\n" +
" destinationDir = file(\"$buildDir/reports/allTests\")\n" +
" // Include the results from the `test` task in all subprojects\n" +
" reportOn subprojects*.test\n" +
"}\n"+
"apply from: './main.gradle'";

public static final String log4jContent ="name=PropertiesConfig\n"+
"property.filename = logs\n"+
"appenders = console\n"+
"\n"+
"appender.console.type = Console\n"+
"appender.console.name = STDOUT\n"+
"appender.console.layout.type = PatternLayout\n"+
"appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n\n"+
"\n"+
"\n"+
"rootLogger.level = debug\n"+
"rootLogger.appenderRefs = stdout\n"+
public static final String buildGradleApplicationContent = "apply plugin: 'org.springframework.boot'\n" +
"\n" +
"\n" +
"\n" +
"dependencies {\n" +
" compile 'org.springframework.boot:spring-boot-starter'\n" +
" compile project(\":domain-usecase\")\n" +
"\n" +
" runtime('org.springframework.boot:spring-boot-devtools')\n" +
"}\n";


public static final String log4jContent = "name=PropertiesConfig\n" +
"property.filename = logs\n" +
"appenders = console\n" +
"\n" +
"appender.console.type = Console\n" +
"appender.console.name = STDOUT\n" +
"appender.console.layout.type = PatternLayout\n" +
"appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n\n" +
"\n" +
"\n" +
"rootLogger.level = debug\n" +
"rootLogger.appenderRefs = stdout\n" +
"rootLogger.appenderRef.stdout.ref = STDOUT";
public static final String testJava = "src/test/java";

public static String getSettingsGradleContent(String nameProject) {
return "rootProject.name = '"+ nameProject +"'\n" +
return "rootProject.name = '" + nameProject + "'\n" +
"\n" +
"FileTree buildFiles = fileTree(rootDir) {\n" +
" List excludes = gradle.startParameter.projectProperties.get(\"excludeProjects\")?.split(\",\")\n" +
Expand Down Expand Up @@ -277,10 +290,11 @@ public static String getSettingsGradleContent(String nameProject) {
public static String getApplicationPropertiesContent(String nameProject) {
return "##Spring Configuration\n" +
"server.port=8080\n" +
"spring.application.name="+nameProject;
"spring.application.name=" + nameProject;
}
public static String getMainApplicationContent(String nameProject){
return "package "+ nameProject + ";\n" +

public static String getMainApplicationContent(String nameProject) {
return "package " + nameProject + ";\n" +
"\n" +
"import org.springframework.boot.SpringApplication;\n" +
"import org.springframework.boot.autoconfigure.EnableAutoConfiguration;\n" +
Expand All @@ -295,6 +309,38 @@ public static String getMainApplicationContent(String nameProject){
" }\n" +
"}";
}

public static String getModel(String modelName, String _package) {
_package = _package.replaceAll( "\\/", "\\.");
return "package " + _package + "." + domain + "." + Utils.decapitalize(modelName) + ";\n" +
"\n" +
"import lombok.Builder;\n" +
"import lombok.Data;\n" +
"\n" +
"@Data\n" +
"@Builder(toBuilder = true)\n" +
"public class " + Utils.capitalize(modelName) + "{\n" +
"\n" +
"\n" +
"}\n";
}

public static String getInterfaceModel(String modelName, String _package) {
_package = _package.replaceAll( "\\/", "\\.");
return "package " + _package + "." + domain + "." + Utils.decapitalize(modelName) + "." + gateway + ";\n" +
"\n" +
"import " + _package + "." + domain + "." + Utils.decapitalize(modelName) + "." + Utils.capitalize(modelName) + ";\n" +
"\n" +
"public interface " + Utils.capitalize(modelName) + "Repository " + "{\n" +
"\n" +
"\n" +
"}\n";
}

public static String getGradlePropertiesContent (String _package){
_package = _package.replaceAll( "\\/", "\\.");
return "package=" + _package;
}
public static String getbuildGradleApplicationContent(){

return "apply plugin: 'org.springframework.boot'\n"+
Expand Down
Loading

0 comments on commit b0b6d02

Please sign in to comment.