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/cobertura #69

Merged
merged 4 commits into from
Jun 23, 2020
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
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,43 @@ To use the plugin you need Gradle version 5 or later, to start add the following

```groovy
plugins {
id "co.com.bancolombia.cleanArchitecture" version "1.6.2"
id "co.com.bancolombia.cleanArchitecture" version "1.6.3"
}
```



Tasks
=====
The Scaffolding Clean Architecture plugin will allow you create 6 task :
The Scaffolding Clean Architecture plugin will allow you run 8 tasks :

1 The ```cleanArchitecture | ca``` task will generate a clean architecture structure in your project, this task have three optional parameters; ```package``` , ```type``` and ```name```.
1 The ```cleanArchitecture | ca``` task will generate a clean architecture structure in your project, this task has three optional parameters; ```package``` , ```type``` and ```name```.

```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```

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

- ```coverage = <jacoco | cobertura>```: This parameter is going to specify the coverage tool for the project. ```Default Value = jacoco```


```sh
gradle cleanArchitecture --package=co.com.bancolombia --type=imperative --name=NameProject
gradle ca
gradle cleanArchitecture --package=co.com.bancolombia --type=imperative --name=NameProject --coverage=JACOCO
gradle ca --package=co.com.bancolombia --type=imperative --name=NameProject --coverage=JACOCO
```

2 The ```generateModel | gm``` task will generate a class and interface in model layer, this task have one required parameter ```name```.
2 The ```generateModel | gm``` task will generate a class and interface in model layer, this task has one required parameter ```name```.
```sh
gradle generateModel --name=[modelName]
gradle gm --name [modelName]
```
3 The ```generateUseCase | guc``` task will generate a class in model layer, this task have one required parameter ```name```.
3 The ```generateUseCase | guc``` task will generate a class in model layer, this task has one required parameter ```name```.
```sh
gradle generateUseCase --name=[useCaseName]
gradle guc --name [useCaseName]
```
4 The ```generateDrivenAdapter | gda``` task will generate a class in Infrastructure layer, this task have one required parameter ```type```.
4 The ```generateDrivenAdapter | gda``` task will generate a class in Infrastructure layer, this task has one required parameter ```type```.
```sh
gradle generateDrivenAdapter --type=[drivenAdapterType]
gradle gda --type [drivenAdapterType]
Expand All @@ -61,7 +63,7 @@ gradle gda --type [drivenAdapterType]
|MONGODB |Mongo Repository |--secret [true-false]|
|ASYNCEVENTBUS |Async Event Bus | |

5 The ```generateEntryPoint | gep``` task will generate a class in Infrastructure layer, this task have one required parameter ```type```.
5 The ```generateEntryPoint | gep``` task will generate a class in Infrastructure layer, this task has one required parameter ```type```.
```sh
gradle generateEntryPoint --type=[entryPointType]
gradle gep --type [entryPointType]
Expand All @@ -79,7 +81,7 @@ gradle validateStructure
gradle vs
```

7 The ```generatePipeline | gpl``` task will generate CI pipeline inside the folder "./deployment/", this task have one required parameter ```type```.
7 The ```generatePipeline | gpl``` task will generate CI pipeline inside the folder "./deployment/", this task has one required parameter ```type```.
```sh
gradle generatePipeline --type=[pipelineType]
gradle gpl --type=[pipelineType]
Expand All @@ -90,7 +92,7 @@ gradle gpl --type=[pipelineType]
|AZURE |Azure Pipeline|


8 The ```deleteModule | dm``` task will delete a sub project, this task have one required parameter ```module```.
8 The ```deleteModule | dm``` task will delete a sub project, this task has one required parameter ```module```.
```sh
gradle deleteModule --module=[name]
gradle dm --module=[name]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package=co.com.bancolombia
systemProp.version=1.6.2
systemProp.version=1.6.3
3 changes: 2 additions & 1 deletion src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class Constants {
public static final String SPRING_CLOUD_VERSION = "Greenwich.M1";
public static final String SONAR_VERSION = "2.7";
public static final String JACOCO_VERSION = "0.8.5";
public static final String PLUGIN_VERSION = "1.6.2";
public static final String COBERTURA_VERSION = "3.0.0";
public static final String SECRETS_VERSION = "2.1.0";
public static final String PLUGIN_VERSION = "1.6.3";

public enum BooleanOption {
TRUE, FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ModuleBuilder(Project project) {
params.put("springCloudVersion", Constants.SPRING_CLOUD_VERSION);
params.put("sonarVersion", Constants.SONAR_VERSION);
params.put("jacocoVersion", Constants.JACOCO_VERSION);
params.put("coberturaVersion", Constants.COBERTURA_VERSION);
}

public void persist() throws IOException {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/co/com/bancolombia/task/GenerateStructureTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GenerateStructureTask extends DefaultTask {

private String packageName = "co.com.bancolombia";
private ProjectType type = ProjectType.IMPERATIVE;
private CoveragePlugin coverage = CoveragePlugin.JACOCO;
private String name = "cleanArchitecture";

@Option(option = "package", description = "Set principal package to use in the project")
Expand All @@ -37,11 +38,21 @@ public void setName(String projectName) {
this.name = projectName;
}

@Option(option = "coverage", description = "Set project coverage plugin")
public void setCoveragePlugin(CoveragePlugin coverage) {
this.coverage = coverage;
}

@OptionValues("type")
public List<ProjectType> getAvailableProjectTypes() {
return new ArrayList<>(Arrays.asList(ProjectType.values()));
}

@OptionValues("coverage")
public List<CoveragePlugin> getCoveragePlugins() {
return new ArrayList<>(Arrays.asList(CoveragePlugin.values()));
}

@TaskAction
public void generateStructureTask() throws IOException, CleanException {
logger.lifecycle("Clean Architecture plugin version: {}", Utils.getVersionPlugin());
Expand All @@ -51,11 +62,17 @@ public void generateStructureTask() throws IOException, CleanException {
builder.addParamPackage(packageName);
builder.addParam("projectName", name);
builder.addParam("reactive", type == ProjectType.REACTIVE);
builder.addParam("jacoco", coverage == CoveragePlugin.JACOCO);
builder.addParam("cobertura", coverage == CoveragePlugin.COBERTURA);
builder.setupFromTemplate("structure");
builder.persist();
}

public enum ProjectType {
REACTIVE, IMPERATIVE
}

public enum CoveragePlugin {
JACOCO, COBERTURA
}
}
10 changes: 10 additions & 0 deletions src/main/resources/structure/root/build.gradle.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ buildscript {
springBootVersion = '{{springBootVersion}}'
springCloudVersion = '{{springCloudVersion}}'
sonarVersion = '{{sonarVersion}}'
{{#jacoco}}
jacocoVersion = '{{jacocoVersion}}'
{{/jacoco}}
{{#cobertura}}
coberturaVersion = '{{coberturaVersion}}'
{{/cobertura}}
}
}

plugins {
id 'co.com.bancolombia.cleanArchitecture' version "${cleanArchitectureVersion}"
id 'org.springframework.boot' version "${springBootVersion}"
id 'org.sonarqube' version "${sonarVersion}"
{{#jacoco}}
id 'jacoco'
{{/jacoco}}
{{#cobertura}}
id 'net.saliman.cobertura' version "${coberturaVersion}"
{{/cobertura}}
}

sonarqube {
Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/structure/root/main.gradle.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ allprojects {

subprojects {
apply plugin: 'java'
{{#jacoco}}
apply plugin: 'jacoco'
{{/jacoco}}
{{#cobertura}}
apply plugin: 'net.saliman.cobertura'
{{/cobertura}}
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -28,6 +33,7 @@ subprojects {
testCompileOnly 'org.projectlombok:lombok'
}

{{#jacoco}}
test.finalizedBy(project.tasks.jacocoTestReport)

jacocoTestReport {
Expand All @@ -39,6 +45,14 @@ subprojects {
html.destination file("${buildDir}/reports/jacocoHtml")
}
}
{{/jacoco}}
{{#cobertura}}
test.finalizedBy(project.tasks.cobertura)

cobertura {
coverageFormats = [ 'xml', 'html' ]
}
{{/cobertura}}

dependencyManagement {
imports {
Expand All @@ -48,6 +62,7 @@ subprojects {
}
}

{{#jacoco}}
jacoco {
toolVersion = "${jacocoVersion}"
reportsDir = file("$buildDir/reports")
Expand All @@ -65,6 +80,18 @@ task jacocoMergedReport(type: JacocoReport) {
html.enabled true
}
}
{{/jacoco}}
{{#cobertura}}
def files = subprojects.collect { new File(it.projectDir, '/build/cobertura/cobertura.ser') }

cobertura {
coverageFormats = ['xml', 'html']
coverageSourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
coverageMergeDatafiles = files
}

test.finalizedBy(project.tasks.cobertura)
{{/cobertura}}

tasks.withType(JavaCompile) {
options.compilerArgs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public void shouldReturnProjectTypes() {
assertEquals(Arrays.asList(GenerateStructureTask.ProjectType.values()), types);
}

@Test
public void shouldReturnCoveragePluginTypes() {
// Arrange
// Act
List<GenerateStructureTask.CoveragePlugin> types = task.getCoveragePlugins();
// Assert
assertEquals(Arrays.asList(GenerateStructureTask.CoveragePlugin.values()), types);
}

@Test
public void generateStructure() throws IOException, CleanException {
// Arrange
Expand Down Expand Up @@ -67,11 +76,12 @@ public void generateStructure() throws IOException, CleanException {
}

@Test
public void generateStructureReactive() throws IOException, CleanException {
public void generateStructureReactiveWithCobertura() throws IOException, CleanException {
// Arrange
task.setPackage("test");
task.setName("projectTest");
task.setType(GenerateStructureTask.ProjectType.REACTIVE);
task.setCoveragePlugin(GenerateStructureTask.CoveragePlugin.COBERTURA);
// Act
task.generateStructureTask();
// Assert
Expand Down