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(archunitsonar): Fix UpgradeAction for jacoco merged report adding arch unit issues to sonar #549

Merged
merged 2 commits into from
Sep 19, 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
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ https://bancolombia.github.io/scaffold-clean-architecture/docs/contributing
- [ ] The documentation is up-to-date
- [ ] The pull request has a descriptive title that describes what has changed, and provides enough context for the changelog
- [ ] If the pull request has a new driven-adapter or entry-point, you should add it to docs and `sh_generate_project.sh` files for generated code tests.
- [ ] If the pull request has changed structural files, you have implemented an UpgradeAction according to the [guide](http://localhost:3000/scaffold-clean-architecture/docs/contributing#more-on-pull-requests)
- [ ] If the pull request has a new Gradle Task, you should add `Analytics` according to the [guide](http://localhost:3000/scaffold-clean-architecture/docs/contributing)
- [ ] If the pull request has changed structural files, you have implemented an UpgradeAction according to the [guide](https://bancolombia.github.io/scaffold-clean-architecture/docs/contributing#more-on-pull-requests)
- [ ] If the pull request has a new Gradle Task, you should add `Analytics` according to the [guide](https://bancolombia.github.io/scaffold-clean-architecture/docs/contributing)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.com.bancolombia.factory.upgrades.actions;

import co.com.bancolombia.Constants;
import co.com.bancolombia.exceptions.InvalidStateException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.upgrades.UpdateUtils;
import co.com.bancolombia.factory.upgrades.UpgradeAction;
Expand All @@ -11,15 +12,22 @@ public class UpgradeY2023M10D02SonarRules implements UpgradeAction {
"\n" + " property \"sonar.externalIssuesReportPaths\", \"build/issues.json\"";
public static final String ISSUES_JSON = "issues.json";
public static final String JACOCO_TEST_REPORT_XML = "jacocoTestReport.xml\"";
public static final String JACOCO_MERGED_REPORT_XML = "jacocoMergedReport.xml\"";

@Override
@SneakyThrows
public boolean up(ModuleBuilder builder) {
return builder.updateFile(
Constants.MainFiles.BUILD_GRADLE,
content ->
UpdateUtils.insertAfterMatch(
content, JACOCO_TEST_REPORT_XML, ISSUES_JSON, CONCAT_VALUE));
return builder.updateFile(Constants.MainFiles.BUILD_GRADLE, this::insert);
}

private String insert(String content) {
try {
return UpdateUtils.insertAfterMatch(
content, JACOCO_TEST_REPORT_XML, ISSUES_JSON, CONCAT_VALUE);
} catch (InvalidStateException ignored) {
return UpdateUtils.insertAfterMatch(
content, JACOCO_MERGED_REPORT_XML, ISSUES_JSON, CONCAT_VALUE);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@ void shouldApplyUpdate() throws IOException {
assertTrue(applied);
verify(builder, times(1)).addFile(file, expectedText);
}

@Test
void shouldApplyUpdateWhenMergedReport() throws IOException {
String file = Constants.MainFiles.BUILD_GRADLE;
// Arrange
DefaultResolver resolver = new DefaultResolver();
String text = FileUtils.getResourceAsString(resolver, "sonar-rules/before-merged.txt");
String expectedText = FileUtils.getResourceAsString(resolver, "sonar-rules/after-merged.txt");
builder.addFile(file, text);
// Act
boolean applied = updater.up(builder);
// Assert
assertTrue(applied);
verify(builder, times(1)).addFile(file, expectedText);
}
}
35 changes: 35 additions & 0 deletions src/test/resources/sonar-rules/after-merged.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
buildscript {
ext {
cleanArchitectureVersion = '3.6.1'
springBootVersion = '3.1.1'
sonarVersion = '4.2.1.3168'
jacocoVersion = '0.8.10'
lombokVersion = '1.18.28'
}
}

plugins {
id 'co.com.bancolombia.cleanArchitecture' version "${cleanArchitectureVersion}"
id 'org.springframework.boot' version "${springBootVersion}" apply false
id 'org.sonarqube' version "${sonarVersion}"
id 'jacoco'
}
apply plugin: 'co.com.bancolombia.cleanArchitecture'

sonarqube {
def modules = subprojects.projectDir.collect { "${it.toString().replace(project.projectDir.toString() + "/", "")}" }
properties {
property "sonar.sourceEnconding", "UTF-8"
property "sonar.modules", "${modules.join(',')}"
property "sonar.sources", "src,deployment,settings.gradle,main.gradle,build.gradle,${modules.collect { "${it}/build.gradle" }.join(',')}"
property "sonar.exclusions","**/MainApplication.java"
property "sonar.test", "src/test"
property "sonar.java.binaries", ""
property "sonar.junit.reportsPath", ""
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacocoMergedReport/jacocoMergedReport.xml"
property "sonar.externalIssuesReportPaths", "build/issues.json"
}
}

apply from: './main.gradle'
34 changes: 34 additions & 0 deletions src/test/resources/sonar-rules/before-merged.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
buildscript {
ext {
cleanArchitectureVersion = '3.6.1'
springBootVersion = '3.1.1'
sonarVersion = '4.2.1.3168'
jacocoVersion = '0.8.10'
lombokVersion = '1.18.28'
}
}

plugins {
id 'co.com.bancolombia.cleanArchitecture' version "${cleanArchitectureVersion}"
id 'org.springframework.boot' version "${springBootVersion}" apply false
id 'org.sonarqube' version "${sonarVersion}"
id 'jacoco'
}
apply plugin: 'co.com.bancolombia.cleanArchitecture'

sonarqube {
def modules = subprojects.projectDir.collect { "${it.toString().replace(project.projectDir.toString() + "/", "")}" }
properties {
property "sonar.sourceEnconding", "UTF-8"
property "sonar.modules", "${modules.join(',')}"
property "sonar.sources", "src,deployment,settings.gradle,main.gradle,build.gradle,${modules.collect { "${it}/build.gradle" }.join(',')}"
property "sonar.exclusions","**/MainApplication.java"
property "sonar.test", "src/test"
property "sonar.java.binaries", ""
property "sonar.junit.reportsPath", ""
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacocoMergedReport/jacocoMergedReport.xml"
}
}

apply from: './main.gradle'
Loading