Skip to content

Commit

Permalink
Merge pull request #48 from mxenabled/mpc/disallow-config-overwrite
Browse files Browse the repository at this point in the history
feat: support config overrides and the disabling of checkstyle
  • Loading branch information
mcoburnmx authored Jun 3, 2024
2 parents e821c27 + 0fc9fac commit 4125d55
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ _In build.gradle_
```
coppuccino {
rootDir = "" # Relative path to project root
overwriteConfigs = true # Set to false to allow a project to manage its own copy of configs (e.g. spotbugs/exclude.xml)
coverage {
minimumCoverage = 0.0 # Required percentage of test code coverage.
excludes [ # Package paths to exclude from coverage calculation
Expand All @@ -57,6 +58,9 @@ coppuccino {
lockingEnabled = true
excludePreReleaseVersions = true # Set to false to allow for #.#.3.pre release versions to be included in --write-locks
}
java {
enabled = true # Set to false to disable checkstyle (e.g. for projects that have no java files)
}
kotlin {
enabled = false # Set to true to enable kotlin linting with Detekt
}
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id "com.github.mxenabled.hush" version "2.3.5"
id "com.github.mxenabled.vogue" version "1.0.2"
id "com.github.mxenabled.vogue" version "1.0.3"
id "groovy"
id "java-gradle-plugin"
id "java-library"
Expand Down
5 changes: 3 additions & 2 deletions src/main/groovy/com/mx/coppuccino/CoppuccinoPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ class CoppuccinoPlugin implements Plugin<Project> {
def coppuccino = project.extensions.create('coppuccino', CoppuccinoPluginExtension)
def coverage = project.extensions.coppuccino.extensions.create('coverage', CoppuccinoCoverageExtension)
def dependencies = project.extensions.coppuccino.extensions.create('dependencies', CoppuccinoDependenciesExtension)
def javaEx = project.extensions.coppuccino.extensions.create('java', CoppuccinoJavaExtension)
def kotlinEx = project.extensions.coppuccino.extensions.create('kotlin', CoppuccinoKotlinExtension)

project.plugins.withType(JavaPlugin) {
project.afterEvaluate {
def initCopConfig = new CopyCopConfig(coppuccino.rootDir, project)
def initCopConfig = new CopyCopConfig(coppuccino.rootDir, project, coppuccino.overwriteConfigs)
initCopConfig.run()
}

Expand All @@ -65,7 +66,7 @@ class CoppuccinoPlugin implements Plugin<Project> {
// **************************************
quality {
checkstyleVersion = '8.29'
checkstyle = true
checkstyle = javaEx.enabled
codenarc = false
pmd = true
spotbugs = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.mx.coppuccino

class CoppuccinoPluginExtension {
String rootDir = ""
boolean overwriteConfigs = true
}

class CoppuccinoCoverageExtension {
Expand All @@ -36,6 +37,11 @@ class CoppuccinoDependenciesExtension {
boolean excludePreReleaseVersions = true
}

class CoppuccinoJavaExtension {
// Enable java support by default
boolean enabled = true
}

class CoppuccinoKotlinExtension {
// Disable kotlin support by default
boolean enabled = false
Expand Down
9 changes: 8 additions & 1 deletion src/main/groovy/com/mx/coppuccino/CopyCopConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class CopyCopConfig {

String projectRoot
Project project
Boolean overwriteConfigs

CopyCopConfig(String projectRoot, Project project) {
CopyCopConfig(String projectRoot, Project project, Boolean overwriteConfigs) {
this.projectRoot = projectRoot
this.project = project
this.overwriteConfigs = overwriteConfigs
}

void run() {
Expand All @@ -48,6 +50,11 @@ class CopyCopConfig {
private void copyConfigFile(String resourcePath, String dest) {
File target = new File(Paths.get(projectRoot, dest).toString())
ensureDirectory(target.getParentFile())

if (!overwriteConfigs && target.exists()) {
return
}

InputStream stream = getClass().getResourceAsStream(resourcePath)
target.text = ''
target << stream.text
Expand Down

0 comments on commit 4125d55

Please sign in to comment.