Skip to content

Commit

Permalink
Adds gradle support - checkstyle, jacoco code coverage, maven publishig.
Browse files Browse the repository at this point in the history
Adds checkstyle code quality checks

Adds jacoco test coverage plugin

Adds publishing (artifactory)

Fails build on jacoco coverage failures

Ignoring more idea files
  • Loading branch information
adrianbk committed Aug 22, 2014
1 parent 91a7a7a commit dd32de6
Show file tree
Hide file tree
Showing 28 changed files with 532 additions and 49 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.idea/workspace.xml
.idea/tasks.xml
.idea/misc.xml
.idea/libraries/
*.iml
swagger-springmvc.iml
target
.settings
.classpath
.project
.DS_Store
build/
.gradle/
13 changes: 0 additions & 13 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apply from: "$rootDir/gradle/dependencies.gradle"


buildscript {
repositories {
jcenter()
}

dependencies {
classpath "com.github.adrianbk:gradle-jvmsrc-plugin:0.6.1"
}
}

subprojects {
apply plugin: 'groovy'
sourceCompatibility = 1.6
targetCompatibility = 1.6

group = 'com.mangofactory'
version = '0.7.77'

apply plugin: 'com.github.adrianbk.jvmsrc'
jvmsrc {
packageName "${group}.swagger"
}


apply plugin: 'checkstyle'
checkstyle{
configFile = file("$rootDir/config/checkstyle.xml")
}

apply plugin: 'maven-publish'
apply from: "$rootDir/gradle/publishing.gradle"

apply from: "$rootDir/gradle/coverage.gradle"

repositories {
jcenter()
}

buildscript {
repositories {
jcenter()
}
}
}

task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
File renamed without changes.
55 changes: 55 additions & 0 deletions gradle/coverage.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apply plugin: 'jacoco'

ext {
minCoverage = 80
}

jacocoTestReport {
reports {
xml.enabled true
}

doLast {
def report = file("${jacoco.reportsDir}/test/jacocoTestReport.xml")
logger.lifecycle("Checking coverage results: ${report}")

def parser = new XmlParser()
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
def results = parser.parse(report)

def percentage = {
def covered = it.'@covered' as Double
def missed = it.'@missed' as Double
((covered / (covered + missed)) * 100).round(2)
}

def counters = results.counter
def metrics = [:]
metrics << ['instruction': percentage(counters.find { it.'@type'.equals('INSTRUCTION') })]
metrics << ['branch': percentage(counters.find { it.'@type'.equals('BRANCH') })]
metrics << ['line': percentage(counters.find { it.'@type'.equals('LINE') })]
metrics << ['complexity': percentage(counters.find { it.'@type'.equals('COMPLEXITY') })]
metrics << ['method': percentage(counters.find { it.'@type'.equals('METHOD') })]
metrics << ['class': percentage(counters.find { it.'@type'.equals('CLASS') })]


def failures = []
metrics.each {
if (it.value < minCoverage) {
failures.add("- ${it.key} coverage rate is: ${it.value}%, minimum is ${minCoverage}%")
}
}


if (failures) {
logger.quiet("------------------ Code Coverage Failed -----------------------")
failures.each {
logger.quiet(it)
}
logger.quiet("---------------------------------------------------------------")
throw new GradleException("Code coverage failed")
}
}
}
check.dependsOn jacocoTestReport
53 changes: 53 additions & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
ext {
swaggerCore = "1.3.5"
spring = "3.2.7.RELEASE"
scalaLib = "2.10.0"
groovy = "2.3.6"
spock = "0.7-groovy-2.0"
jackson = "2.2.3"
guava = "15.0"
springHateoas = "0.10.0.RELEASE"
slf4j = "1.7.5"
mockito = "1.9.5"
servlet = "2.5"
guava = "15.0"
classmate = "1.0.0"
}


ext.libs = [

test : [
"org.springframework:spring-test:${spring}",
"cglib:cglib-nodep:2.2",
"org.objenesis:objenesis:1.2",
"org.mockito:mockito-all:${mockito}",
"com.jayway.jsonpath:json-path:0.8.1",
"org.slf4j:slf4j-simple:1.7.5",
"org.yaml:snakeyaml:1.9",
"org.spockframework:spock-spring:${spock}",
"org.spockframework:spock-core:${spock}"
],

swaggerCore : [
"com.wordnik:swagger-core_2.10:${swaggerCore}"
],

spring : [
"org.springframework:spring-web:$spring",
"org.springframework:spring-webmvc:$spring"
],

clientProvided: [
"org.scala-lang:scala-library:${scalaLib}",
"javax.servlet:servlet-api:${servlet}"
],

core : [
"org.codehaus.groovy:groovy-all:${groovy}",
"com.google.guava:guava:${guava}",
"com.fasterxml:classmate:1.0.0",
"org.slf4j:slf4j-api:${slf4j}"
]

]
34 changes: 34 additions & 0 deletions gradle/publishing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ext {
artifactRepoBase = 'http://localhost:8081/artifactory'

releaseRepos = {
maven {
name 'jcenter'
// url "${artifactRepoBase}/oss-${project.version.endsWith('-SNAPSHOT') ? 'snapshot' : 'release'}-local"
url "${artifactRepoBase}/libs-${project.version.endsWith('-SNAPSHOT') ? 'snapshot' : 'release'}-local"

credentials {
username = 'admin'
// password = project.hasProperty('bintray_key') ? project.getProperty('bintray_key') : ''
password = 'password'
}
}

//TODO - deploy release versions on bintray
// if (!project.version.endsWith('-SNAPSHOT')) {
// maven {
// name 'bintray'
// url "https://api.bintray.com/maven/adrianbkelly/maven/${artifactLabel}"
// credentials {
// username = 'adrianbkelly'
// password = project.hasProperty('bintray_key') ? project.getProperty('bintray_key') : ''
// }
// }
// }
}
}

task packageSources(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Aug 06 20:10:22 EST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip
Loading

0 comments on commit dd32de6

Please sign in to comment.