Repository: incubator-edgent Updated Branches: refs/heads/master e4ef5308b -> ebc03d9d6
[gradle] Add test7 setup and run processing Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/f31573f1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/f31573f1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/f31573f1 Branch: refs/heads/master Commit: f31573f1775cecb514352cbd5cc6a375a4eeab0c Parents: 8fbe5fd Author: Dale LaBossiere <dlab...@us.ibm.com> Authored: Thu Sep 22 12:18:49 2016 -0400 Committer: Dale LaBossiere <dlab...@us.ibm.com> Committed: Thu Sep 22 12:18:49 2016 -0400 ---------------------------------------------------------------------- DEVELOPMENT.md | 36 +++++++- build.gradle | 181 ++++++++++++++++++++++++------------- platform/android/build.gradle | 8 +- platform/java7/build.gradle | 81 +++++++++++++---- platform/java7/build.xml | 22 +++-- 5 files changed, 235 insertions(+), 93 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/f31573f1/DEVELOPMENT.md ---------------------------------------------------------------------- diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 3e05159..735afc8 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -93,14 +93,46 @@ following statement: } ``` -Closing ant reopening a pull request will kick off a new build against the pull request. +Closing and reopening a pull request will kick off a new build against the pull request. ### Test reports -Running the reports target produces two reports: +Running the `reports` target produces two reports: * `reports/junit/index.html` - JUnit test report * `reports/coverage/index.html` - Code coverage report. +### Testing Edgent with Java7 + +All of the standard build system _tasks_ above must be run with +`JAVA_HOME` set to use a Java8 VM. + +As noted above, the `release` task includes generation of Java7 +compatible versions of the Edgent jars. After the release task has been run, +Edgent may be tested in a Java7 context using some special _test7_ tasks. + +See [JAVA_SUPPORT](JAVA_SUPPORT.md) for information about what +Edgent features are supported in the different environments. + +``` sh + # run with JAVA_HOME set for Java8 +$ ant -buildfile platform/java7 test7.setup # compile the Edgent tests to operate in a java7 environment + + # run with JAVA_HOME set for Java7 +$ ant -buildfile platform/java7 test7.run # run the tests with a java7 VM +``` + +[WIP] with the Gradle tooling +``` sh + # run with JAVA_HOME set for Java8 +$ ./gradlew test7Compile # compile the Edgent tests to operate in a java7 environment + + # run with JAVA_HOME set for Java7 +$ ./gradlew test7Run # run the tests with a java7 VM + + # run with JAVA_HOME set for Java8 +$ ./gradlew test7Reports # generate the junit and coverage tests +``` + ### [WIP] Building With Gradle Work is ongoing to replace the Ant based build system with a Gradle based one http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/f31573f1/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index aae5fe3..820c7f9 100644 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,7 @@ ext { ':test', ':utils' ] - filteredSubprojects = subprojects*.findAll { + filteredSubprojects = subprojects.findAll { project -> !aggregatorOnlyProjects.contains(project.path) } @@ -407,6 +407,8 @@ subprojects { from rootProject.file('NOTICE') } } + + ext.adjustTest7Classpath = false test { filter { @@ -441,9 +443,78 @@ subprojects { classpath = classpath.filter { ! it.path.startsWith(project.libsDir.path) } classpath = files(project.jar.archivePath) + classpath + + if (adjustTest7Classpath) { + // Add special java7 processing... (on top of the other test.doFirst classpath manipulations) + + // Change from using the normal test classes dir to the java7 test classes dir + classpath -= files(sourceSets.test.output.classesDir) + classpath = files(sourceSets.test.output.classesDir.toString().replace('test', 'java7Test')) + classpath + + // Switch from java8 jars to java7 jars + classpath = files(classpath.collect { it.toString().replace('java8', 'java7') }) + } logger.debug "$project.path test.classpath: " + classpath.collect { it.toString() } } } + + ext.unsupportedJava7TestProjects = [ // why not on all of these? (match ant_test7.run, see JAVA_SUPPORT.md) + // projects with no tests will be automatically avoided for java7 tests + // otherwise those that are not yet supported for java7 (not in ant_test7.{setup,run}) must be added here + ':api:graph', // no runnable tests + ':analytics:math3', + ':analytics:sensors', + ':connectors:command', + ':connectors:csv', + ':connectors:file', + ':connectors:jdbc', + ':connectors:mqtt', + ':connectors:kafka', + ':connectors:serial', + ':connectors:wsclient', + ':connectors:wsclient-javax.websocket', + ':connectors:javax.websocket-client', + ':connectors:edgent.javax.websocket', + ':connectors:javax.websocket-server', + ':console:server', + ':console:servlets', + ':providers:development', + ':utils:streamscope', + ':test:fvtiot', + ':test:svt', + ] + + ext.j7TestClassesDir = file("$project.buildDir/classes/java7Test") + + task test7AdjustTestTask << { + if (! tasks.getByName('test').enabled + || unsupportedJava7TestProjects.contains(project.path) + || sourceSets.test.allSource.isEmpty()) { + test.enabled = false + return + } + adjustTest7Classpath = true + if (!j7TestClassesDir.exists()) { + // implicit dependency: :platform:java7:test7Compile + logger.error " ERROR: Run the test7Compile task. $j7TestClassesDir does not exist." + throw new TaskExecutionException() + } + test { + testClassesDir = j7TestClassesDir + outputs.upToDateWhen { false } // always run - task is never "up to date" + } + } + + task test7Run() { + description = "Run the test7Compile'd tests against the java7 target jars - run after :platform:java7:test7Compile and with JAVA_HOME==java7-VM" + // fwiw trying to leverage :platform:java7:ant_test7.run was problematic + + dependsOn ':platform:java7:verifyJava7Built', test7AdjustTestTask, test + // implicit dependency: :platform:java7:test7Compile + test.mustRunAfter = [ test7AdjustTestTask, ':platform:java7:verifyJava7Built' ] + + outputs.upToDateWhen { false } // always run - never "up to date" + } assemble.doLast { // augment assemble with our additional target dir update processing @@ -503,6 +574,7 @@ dependencies { task createJunitReport << { description = "Generates a Junit report from all subprojects (use after 'test')" + ant.delete(dir: "${target_report_dir}/tests") ant.taskdef(name: 'junitreport', classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator', classpath: configurations.junitLibs.asPath) @@ -513,8 +585,13 @@ task createJunitReport << { ant.move(file: "TESTS-TestSuites.xml", tofile: "${target_report_dir}/TESTS-TestSuites.xml") } -task jacocoTestReport << { +task jacocoTestReport { description = "Generates a coverage report from all subprojects (use after 'test')" + ext.test7AdjustJacocoReport = false +} +jacocoTestReport << { + + ant.delete(dir: "${target_report_dir}/coverage") def libDir = new File("${target_java8_dir}", "lib") def utilsDir = new File("${target_java8_dir}", "utils") @@ -546,18 +623,15 @@ task jacocoTestReport << { executionData.addToAntBuilder(ant, 'resources') } - // the 'test' task directly uses the built class files - // (test doesn't assemble jars nor populate target_dir with them) - jococoClassfilesFromJars = false; + platformTargetDir = target_java8_dir + if (test7AdjustJacocoReport) { + platformTargetDir = target_java7_dir + } structure(name: project.name) { group(name: "Edgent API") { classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/lib", includes: "edgent.api.*.jar") - } else { - fileset(dir: "api", includes: "**/build/classes/main/**/*.class") - } + fileset(dir: "$platformTargetDir/lib", includes: "edgent.api.*.jar") } sourcefiles { fileset(dir: "./api/function/src/main/java", includes: "**/*.java") @@ -569,11 +643,7 @@ task jacocoTestReport << { } group(name: "Edgent SPI") { classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/lib", includes: "edgent.spi.*.jar") - } else { - fileset(dir: "spi", includes: "**/build/classes/main/**/*.class") - } + fileset(dir: "$platformTargetDir/lib", includes: "edgent.spi.*.jar") } sourcefiles { fileset(dir: "./spi/graph/src/main/java", includes: "**/*.java") @@ -582,11 +652,7 @@ task jacocoTestReport << { } group(name: "Edgent Runtime") { classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/lib", includes: "edgent.runtime.*.jar") - } else { - fileset(dir: "runtime", includes: "**/build/classes/main/**/*.class") - } + fileset(dir: "$platformTargetDir/lib", includes: "edgent.runtime.*.jar") } sourcefiles { fileset(dir: "./runtime/etiao/src/main/java", includes: "**/*.java") @@ -595,11 +661,7 @@ task jacocoTestReport << { } group(name: "Edgent Utilities") { classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/utils", includes: "**/edgent.utils.*.jar") - } else { - fileset(dir: "utils", includes: "**/build/classes/main/**/*.class") - } + fileset(dir: "$platformTargetDir/utils", includes: "**/edgent.utils.*.jar") } sourcefiles { fileset(dir: "./utils/metrics/src/main/java", includes: "**/*.java") @@ -608,11 +670,7 @@ task jacocoTestReport << { } group(name: "Edgent Connectors") { classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/connectors", includes: "**/edgent.connectors.*.jar") - } else { - fileset(dir: "connectors", includes: "**/build/classes/main/**/*.class") - } + fileset(dir: "$platformTargetDir/connectors", includes: "**/edgent.connectors.*.jar") } sourcefiles { fileset(dir: "./connectors/common/src/main/java", includes: "**/*.java") @@ -631,41 +689,31 @@ task jacocoTestReport << { } group(name: "Edgent Providers") { classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/lib", includes: "edgent.providers.*.jar") - } else { - fileset(dir: "providers", includes: "**/build/classes/main/**/*.class") - } + fileset(dir: "$platformTargetDir/lib", includes: "edgent.providers.*.jar") } sourcefiles { fileset(dir: "./providers/direct/src/main/java", includes: "**/*.java") fileset(dir: "./providers/development/src/main/java", includes: "**/*.java") } } - group(name: "Edgent Analytics") { - classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/analytics", includes: "**/edgent.analytics.*.jar") - } else { - fileset(dir: "analytics", includes: "**/build/classes/main/**/*.class") + if (!test7AdjustJacocoReport) { + group(name: "Edgent Analytics") { + classfiles { + fileset(dir: "$platformTargetDir/analytics", includes: "**/edgent.analytics.*.jar") } - } - sourcefiles { - fileset(dir: "./analytics/math3/src/main/java", includes: "**/*.java") - fileset(dir: "./analytics/sensors/src/main/java", includes: "**/*.java") - } - } - group(name: "Edgent Console") { - classfiles { - if (jococoClassfilesFromJars) { - fileset(dir: "${target_java8_dir}/console", includes: "**/edgent.console.*.jar") - } else { - fileset(dir: "console", includes: "**/build/classes/main/**/*.class") + sourcefiles { + fileset(dir: "./analytics/math3/src/main/java", includes: "**/*.java") + fileset(dir: "./analytics/sensors/src/main/java", includes: "**/*.java") } } - sourcefiles { - fileset(dir: "./console/server/src/main/java", includes: "**/*.java") - fileset(dir: "./console/servlets/src/main/java", includes: "**/*.java") + group(name: "Edgent Console") { + classfiles { + fileset(dir: "$platformTargetDir/console", includes: "**/edgent.console.*.jar") + } + sourcefiles { + fileset(dir: "./console/server/src/main/java", includes: "**/*.java") + fileset(dir: "./console/servlets/src/main/java", includes: "**/*.java") + } } } } @@ -769,7 +817,7 @@ task releaseTarGz(type: Tar) { assemble { description = "Assemble distribution artifacts and populate the target_dir with jars, doc, etc. Like 'build' w/o 'test'" - dependsOn filteredSubprojects*.assemble, aggregateJavadoc, copyScripts + dependsOn filteredSubprojects.assemble, aggregateJavadoc, copyScripts aggregateJavadoc.mustRunAfter filteredSubprojects*.assemble } @@ -785,11 +833,11 @@ task cleanAll { task release { description = 'Assemble distribution artifacts, populate target_dir, and create a release tgz' dependsOn cleanAll, addMiscDistFiles, assemble, - ':platform:java7:addJava7Target', ':platform:android:addAndroidTarget', + ':platform:java7:addJava7TargetDir', ':platform:android:addAndroidTargetDir', releaseTarGz addMiscDistFiles.mustRunAfter cleanAll assemble.mustRunAfter addMiscDistFiles - releaseTarGz.mustRunAfter assemble,':platform:java7:addJava7Target',':platform:android:addAndroidTarget' + releaseTarGz.mustRunAfter assemble,':platform:java7:addJava7TargetDir',':platform:android:addAndroidTargetDir' } task reports { @@ -797,11 +845,22 @@ task reports { dependsOn createJunitReport, jacocoTestReport } +task test7AdjustJacocoReport << { + jacocoTestReport.test7AdjustJacocoReport = true + logger.lifecycle "### NOTE: [WIP] test7 jacoco reporting ###" +} + +task test7Reports { + description = "Generate JUnit and Coverage reports of prior test run. Use after 'test7Run'" + dependsOn createJunitReport, test7AdjustJacocoReport, jacocoTestReport + jacocoTestReport.mustRunAfter test7AdjustJacocoReport +} + // build: inject test report generation and javadoc generation (for early problem detection) // make 'build' like "all test reports" build { - dependsOn filteredSubprojects*.build - finalizedBy reports // after build's test task + dependsOn filteredSubprojects.build, reports + reports.mustRunAfter filteredSubprojects.build } task wrapper(type: Wrapper) { http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/f31573f1/platform/android/build.gradle ---------------------------------------------------------------------- diff --git a/platform/android/build.gradle b/platform/android/build.gradle index 8231922..1812c45 100644 --- a/platform/android/build.gradle +++ b/platform/android/build.gradle @@ -12,7 +12,7 @@ * limitations under the License. */ -defaultTasks 'addAndroidTarget' +defaultTasks 'addAndroidTargetDir' // Avoid creating/staging an empty jar (this is a 'java' subproject) jar { @@ -33,10 +33,10 @@ clean { dependsOn ant_clean } -task addAndroidTarget { +task addAndroidTargetDir { description = "Assemble distribution artifacts for android (from java7 artifacts)" - dependsOn ':platform:java7:addJava7Target', clean, ant_all - ant_all.mustRunAfter ':platform:java7:addJava7Target' + dependsOn ':platform:java7:addJava7TargetDir', clean, ant_all + ant_all.mustRunAfter ':platform:java7:addJava7TargetDir' ant_all.mustRunAfter clean // TODO the following isn't cutting it for adding up-to-date for this task http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/f31573f1/platform/java7/build.gradle ---------------------------------------------------------------------- diff --git a/platform/java7/build.gradle b/platform/java7/build.gradle index 6930ffe..b20e75d 100644 --- a/platform/java7/build.gradle +++ b/platform/java7/build.gradle @@ -12,46 +12,46 @@ * limitations under the License. */ -defaultTasks 'addJava7Target' +defaultTasks 'addJava7TargetDir' // Avoid creating/staging an empty jar (this is a 'java' subproject) jar { deleteAllActions() } -// let the existing ant script do all of the work +// let the existing ant script do some of the work ant.importBuild('build.xml') { antTargetName -> 'ant_' + antTargetName } +ant.properties['edgent'] = rootProject.projectDir ant.properties['edgent8.target'] = target_java8_dir ant.properties['edgent7.target'] = target_java7_dir ant.properties['ext.dir'] = target_java8_ext_dir -ant.properties['slf4j.ext.dir'] = "" -ant.properties['gson.ext.dir'] = "" -ant.properties['metrics.ext.dir'] = "" clean { dependsOn ant_clean } +task preAntTask << { + // recompute/set other inputs to the ant tasks + ant.path(id: 'edgent.classpath') { + fileset(dir: target_java8_ext_dir) { + exclude(name: '**/slf4j-jdk*.jar') + } + } + ant.properties.qcp = ant.references['edgent.classpath'] +} + ant_retro7.doFirst { println "Performing a longer running ant task (e.g., ~30sec; run with --info to see it all)..." } -task addJava7Target { - description = "Assemble distribution artifacts for java7 (from java8 artifacts)" - dependsOn ':assemble', clean, ant_retro7 - ant_retro7.mustRunAfter clean - ant_retro7.mustRunAfter ':assemble' - - // TODO the following isn't cutting it for adding up-to-date for this task - // so as to avoid unnecessarily running clean,retro7 - // ... well things just don't quite work the way I hoped. - // A task's dependencies are run before a task is checked for UTD - // inputs.dir(target_java8_dir) - // outputs.dir(target_java7_dir) +task addJava7TargetDir { + description = "Assemble distribution artifacts for java7 (from java8 artifacts - run with JAVA_HOME==java8-VM)" + dependsOn ':assemble', clean, preAntTask, ant_retro7 + ant_retro7.mustRunAfter = [ clean, ':assemble', preAntTask ] } // unlike the above, this has the benefit(?) of producing the ant output to stdout @@ -71,4 +71,51 @@ task addJava7Target { // '-Dmetrics.ext.dir=""' //} +// N.B. for java7 testing, use the test7Compile and test7Run tasks +// +// <edgentRepo>/gradlew :platform:java7:test7Compile (or just test7Compile) -- run with JAVA_HOME==java8-VM to check the java7 jars +// <edgentRepo>/gradlew test7Run (or <project>:test7Run for individual project) -- run with JAVA_HOME==java7-VM (can run w/j8 to smoketest the process). + +task verifyJava7Built { + dependsOn 'ant_verify.java7.built' +} + +task preAntTest7Setup { + description = "Stage the java8 built test classes where ant_test7.setup expects them" + dependsOn filteredSubprojects*.compileTestJava, preAntTask + doLast { + println "N.B. test7Compile must be run after the 'release' task (which creates the 'java7' tree in the targetdir)" + // copy java8 test classes where ant_test7.setup expects them + filteredSubprojects.each { project -> + ant.delete(dir: "$project.projectDir/test.classes") + copy { + from project.sourceSets.test.output.classesDir + into "$project.projectDir/test.classes" + } + } + // recompute/set other inputs to the ant tasks + ant.path(id: 'tc.classes') { + dirset(dir: rootProject.projectDir) { + include(name: '**/test.classes') + } + } + ant.properties['tccp'] = ant.references['tc.classes'] + } +} +task test7Compile { + description = "Compile the test classes for java7 (run with JAVA_HOME==java8-VM)" + dependsOn preAntTest7Setup, 'ant_test7.setup' + tasks.getByName('ant_test7.setup').mustRunAfter preAntTest7Setup + doLast { + // copy ant_test7.setup generated classes to their project.buildDir/classes/java7Test + filteredSubprojects.each { project -> + ant.delete(dir: project.j7TestClassesDir) + copy { + from "$project.projectDir/test.classes" + into project.j7TestClassesDir + } + ant.delete(dir: "$project.projectDir/test.classes") + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/f31573f1/platform/java7/build.xml ---------------------------------------------------------------------- diff --git a/platform/java7/build.xml b/platform/java7/build.xml index f53dbbe..f517c40 100644 --- a/platform/java7/build.xml +++ b/platform/java7/build.xml @@ -30,16 +30,15 @@ <property name="input.dir" location="classes.in"/> <property name="output.dir" location="classes.out"/> - <property name="test.classes.dir" location="classes.test"/> <property name="ext.dir" location="${edgent}/ext"/> - <property name="slf4j.version" location="1.7.12"/> - <property name="gson.version" location="2.2.4"/> - <property name="metrics.version" location="3.1.2"/> + <property name="slf4j.version" value="1.7.12"/> + <property name="gson.version" value="2.2.4"/> + <property name="metrics.version" value="3.1.2"/> - <property name="slf4j.ext.dir" location="slf4j-${slf4j.version}/"/> - <property name="gson.ext.dir" location="google-gson-${gson.version}/"/> - <property name="metrics.ext.dir" location="metrics-${metrics.version}/"/> + <property name="slf4j.ext.dir" value="slf4j-${slf4j.version}/"/> + <property name="gson.ext.dir" value="google-gson-${gson.version}/"/> + <property name="metrics.ext.dir" value="metrics-${metrics.version}/"/> <path id="edgent.classpath"> <pathelement location="${ext.dir}/${slf4j.ext.dir}slf4j-api-${slf4j.version}.jar"/> @@ -64,7 +63,7 @@ <unzip dest="${input.dir}" src="${edgent8.target}/@{qdir}/@{qjar}"/> - <exec executable="java"> + <exec executable="java" failonerror="true"> <arg value="-Dretrolambda.inputDir=${input.dir}"/> <arg value="-Dretrolambda.classpath=${edgent8.target}/@{qdir}/@{qjar}:${qcp}"/> <arg value="-Dretrolambda.outputDir=${output.dir}"/> @@ -194,7 +193,10 @@ <delete dir="${edgent}/@{tdir}/test7.classes"/> <mkdir dir="${edgent}/@{tdir}/test7.classes"/> - <exec executable="java"> + <!-- <echo message="#### qcp7 ${qcp7}"/> --> + <!-- <echo message="#### qcp ${qcp}"/> --> + <!-- <echo message="#### tccp ${tccp}"/> --> + <exec executable="java" failonerror="true"> <arg value="-Dretrolambda.inputDir=${edgent}/@{tdir}/test.classes"/> <arg value="-Dretrolambda.classpath=${qcp7}:${qcp}:${tccp}"/> <arg value="-Dretrolambda.outputDir=${edgent}/@{tdir}/test7.classes"/> @@ -263,6 +265,7 @@ <retro7.test.setup tdir="api/topology" /> <retro7.test.setup tdir="spi/graph" /> <retro7.test.setup tdir="spi/topology" /> + <retro7.test.setup tdir="runtime/appservice" /> <retro7.test.setup tdir="runtime/etiao" /> <retro7.test.setup tdir="runtime/jmxcontrol" /> <retro7.test.setup tdir="runtime/jsoncontrol" /> @@ -293,6 +296,7 @@ <retro7.test.run tdir="api/topology" /> <retro7.test.run tdir="spi/graph" /> <retro7.test.run tdir="spi/topology" /> + <retro7.test.run tdir="runtime/appservice" /> <retro7.test.run tdir="runtime/etiao" /> <retro7.test.run tdir="runtime/jmxcontrol" /> <retro7.test.run tdir="runtime/jsoncontrol" />