Skip to content

Commit

Permalink
Support Gradle 5 (#26)
Browse files Browse the repository at this point in the history
* Support Gradle 5

also migrate from ConventionTask to DefaultTask
  • Loading branch information
ngyukman authored Feb 22, 2019
1 parent 989bd1a commit 38cd536
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 142 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## 1.11
### Added
* Add threshold parameter for OpenCover. [usage] (https://github.com/OpenCover/opencover/wiki/Usage).
* Support Gradle 5

### Updated
* Migrate from ConventionTask to DefaultTask

## 1.8

Expand Down
32 changes: 7 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
buildscript {
repositories {
jcenter()
maven {
url "https://dl.bintray.com/ullink/gradle-plugins"
}
}
dependencies {
classpath "nu.studer:gradle-plugindev-plugin:1.0.4.MULTI"
classpath 'net.researchgate:gradle-release:2.4.0'
}
plugins {
id 'nu.studer.plugindev' version '1.0.12'
id 'net.researchgate.release' version '2.8.0'
}

apply plugin: 'groovy'
apply plugin: 'nu.studer.plugindev'
apply plugin: 'net.researchgate.release'

dependencies {
compile 'commons-io:commons-io:1.3.2'
Expand All @@ -23,9 +14,7 @@ dependencies {
group = 'com.ullink.gradle'
description 'gradle-opencover-plugin is a Gradle plugin for getting code coverage using OpenCover'


bintray {
// to remove when upgraded plugindev to 1.0.4
user project.properties.bintrayUser
key project.properties.bintrayApiKey
pkg.repo = 'gradle-plugins'
Expand All @@ -43,17 +32,10 @@ plugindev {
authorEmail '[email protected]'
projectUrl "https://github.com/Ullink/${project.name}"
projectInceptionYear '2015'

pluginImplementation {
pluginId 'com.ullink.opencover'
pluginImplementationClass 'com.ullink.gradle.opencover.OpenCoverPlugin'
}
pluginImplementation {
pluginId = 'com.ullink.opencover-nunit'
pluginImplementationClass 'com.ullink.gradle.opencover.OpenCoverNUnitPlugin'
}
pluginId = 'com.ullink.opencover-nunit'
pluginImplementationClass 'com.ullink.gradle.opencover.OpenCoverNUnitPlugin'

done()
}

project.tasks.afterReleaseBuild.dependsOn project.tasks.bintrayUpload
afterReleaseBuild.dependsOn project.tasks.bintrayUpload
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 1.11-SNAPSHOT
version = 1.11
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Jan 02 22:28:22 CET 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
78 changes: 43 additions & 35 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,31 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -90,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand All @@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down Expand Up @@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
14 changes: 4 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
73 changes: 38 additions & 35 deletions src/main/groovy/com/ullink/gradle/opencover/OpenCover.groovy
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package com.ullink.gradle.opencover

import groovyx.gpars.GParsPool
import org.apache.commons.io.FilenameUtils
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Task
import org.gradle.api.internal.ConventionTask
import groovyx.gpars.GParsPool
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

import java.util.concurrent.atomic.AtomicLong

class OpenCover extends ConventionTask {
def openCoverHome
def openCoverVersion
def targetExec
def targetExecArgs
def parallelForks
def parallelTargetExecArgs
def registerMode
List targetAssemblies
class OpenCover extends DefaultTask {
Property<String> openCoverHome
Property<String> openCoverVersion
Property<File> targetExec
ListProperty<String> targetExecArgs
Property<Boolean> parallelForks
ListProperty<String> parallelTargetExecArgs
Property<String> registerMode
@InputFiles
ConfigurableFileCollection targetAssemblies
def excludeByFile
def excludeByAttribute
def hideSkipped
Expand All @@ -31,15 +38,15 @@ class OpenCover extends ConventionTask {
static def fileNameId = new AtomicLong(1)

OpenCover() {
conventionMapping.map 'registerMode', { 'user' }

inputs.files {
getTargetAssemblies()
}

outputs.dir {
getReportsFolder()
}
openCoverHome = project.getObjects().property(String)
openCoverVersion = project.getObjects().property(String)
registerMode = project.getObjects().property(String)
targetExec = project.getObjects().property(File)
targetExecArgs = project.getObjects().listProperty(String)
parallelForks = project.getObjects().property(Boolean)
parallelTargetExecArgs = project.getObjects().listProperty(String)

registerMode.set('user')
}

def inputsOutputsFrom(Task task) {
Expand All @@ -62,16 +69,12 @@ class OpenCover extends ConventionTask {
new File(project.buildDir, 'opencover')
}

@OutputDirectory
def getReportsFolder() {
new File(outputFolder, 'reports')
}

def getCoverageReportPath() {
coverageReportPath
}

@TaskAction

def build() {
reportsFolder.mkdirs()

Expand All @@ -81,7 +84,7 @@ class OpenCover extends ConventionTask {
def runOpenCover() {
def commandLineArgs = getCommonOpenCoverArgs()

if (!getParallelForks() || getParallelTargetExecArgs().size() == 0) {
if (!parallelForks.get() || parallelTargetExecArgs.empty()) {
coverageReportPath = new File(reportsFolder, "coverage.xml")
runSingleOpenCover(commandLineArgs)
} else {
Expand All @@ -92,7 +95,7 @@ class OpenCover extends ConventionTask {

def getCommonOpenCoverArgs() {
def commandLineArgs = [openCoverConsole, '-mergebyhash']
if (getRegisterMode()) commandLineArgs += '-register:' + getRegisterMode()
if (registerMode.get()) commandLineArgs += '-register:' + registerMode.get()
if (returnTargetCode) commandLineArgs += '-returntargetcode'
if (mergeOutput) commandLineArgs += '-mergeoutput'
if (excludeByFile) commandLineArgs += '-excludebyfile:' + excludeByFile
Expand All @@ -101,27 +104,27 @@ class OpenCover extends ConventionTask {
if (hideSkipped) commandLineArgs += '-hideskipped:' + hideSkipped
if (threshold) commandLineArgs += '-threshold:' + threshold

def filters = getTargetAssemblies().collect { "+[${FilenameUtils.getBaseName(project.file(it).name)}]*" }
def filters = targetAssemblies.collect { "+[${FilenameUtils.getBaseName(it.name)}]*" }
commandLineArgs += '-filter:\\"' + filters.join(' ') + '\\"'

commandLineArgs += "-target:${getTargetExec()}"
commandLineArgs += "-target:${targetExec.get()}"
commandLineArgs += "-targetdir:${project.buildDir}"

commandLineArgs
}

def runSingleOpenCover(ArrayList commandLineArgs) {
commandLineArgs += ["\"-targetargs:${getTargetExecArgs().collect({ escapeArg(it) }).join(' ')}\""]
commandLineArgs += "-output:${getCoverageReportPath()}"
commandLineArgs += ["\"-targetargs:${targetExecArgs.get().collect({ escapeArg(it) }).join(' ')}\""]
commandLineArgs += "-output:${coverageReportPath}"

execute(commandLineArgs)
}

def runMultipleOpenCovers(ArrayList commandLineArgs) {
def targetExecArgs = getParallelTargetExecArgs()
logger.info "Preparing to run ${targetExecArgs.size()} tests..."
def execArgs = parallelTargetExecArgs.get()
logger.info "Preparing to run ${execArgs.size()} tests..."
GParsPool.withPool {
targetExecArgs.eachParallel {
execArgs.eachParallel {
def fileName = "${fileNameId.getAndIncrement()}"
logger.info("Filename generated for the ${it} input was ${fileName}")
def currentTestArgs = ["\"-targetargs:${it.collect({ escapeArg(it) }).join(' ')}\""]
Expand All @@ -148,7 +151,7 @@ class OpenCover extends ConventionTask {
}

if (!ignoreFailures && mbr.exitValue < 0) {
throw new GradleException("${openCoverConsole} execution failed (ret=${mbr.exitValue})");
throw new GradleException("${openCoverConsole} execution failed (ret=${mbr.exitValue})")
}
}
}
Loading

0 comments on commit 38cd536

Please sign in to comment.