-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
org.gradle.caching=true | ||
|
||
version = 0.0.0-SNAPSHOT | ||
|
||
dk.mada.style.sonar.projectKey = jskov_mada-style-gradle | ||
dk.mada.style.sonar.organization = jskov-github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/dk/mada/style/configurators/SonarConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package dk.mada.style.configurators; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.plugins.quality.Checkstyle; | ||
import org.gradle.api.tasks.TaskContainer; | ||
import org.sonarqube.gradle.SonarExtension; | ||
import org.sonarqube.gradle.SonarTask; | ||
|
||
import dk.mada.style.config.PluginConfiguration.SonarConfiguration; | ||
|
||
/** | ||
* Configures Sonar. | ||
*/ | ||
public class SonarConfigurator { | ||
/** The gradle project. */ | ||
private final Project project; | ||
/** The gradle logger. */ | ||
private final Logger logger; | ||
/** The sonarqube configuration. */ | ||
private final SonarConfiguration sonarConfig; | ||
|
||
/** | ||
* Creates new instance. | ||
* | ||
* @param project the gradle project | ||
* @param sonarConfig the sonarqube configuration | ||
*/ | ||
public SonarConfigurator(Project project, SonarConfiguration sonarConfig) { | ||
this.project = project; | ||
this.logger = project.getLogger(); | ||
this.sonarConfig = sonarConfig; | ||
} | ||
|
||
/** | ||
* Configures the sonarqube extension. | ||
* | ||
* @param se the spotless extension | ||
*/ | ||
public void configure(SonarExtension se) { | ||
logger.info("dk.mada.style configure sonar"); | ||
|
||
TaskContainer taskContainer = project.getTasks(); | ||
|
||
// Make sonar depend on checkstyle tasks (we want sonar to run last) | ||
taskContainer.withType(SonarTask.class, sonar -> taskContainer.withType(Checkstyle.class, sonar::dependsOn)); | ||
|
||
Map<String, String> inputProps = project.getProperties().entrySet().stream() | ||
.filter(e -> !e.getKey().equals("dk.mada.style.sonar.enabled")) | ||
.filter(e -> e.getKey().startsWith("dk.mada.style.sonar.")) | ||
.collect(Collectors.toMap(e -> e.getKey().replace("dk.mada.style.", ""), e -> Objects.toString(e.getValue()))); | ||
|
||
Map<String, String> combinedMadaSonarProps = new HashMap<>(); | ||
combinedMadaSonarProps.putAll(sonarConfig.madaConventionProperties()); | ||
combinedMadaSonarProps.putAll(inputProps); | ||
|
||
logger.info("Set sonar properties: {}", combinedMadaSonarProps); | ||
|
||
se.properties(sp -> combinedMadaSonarProps.forEach(sp::property)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters