remove builddir/classses/main from the test runtime classpath

makes tests fully run against the target-dir jars

Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/e83f2429
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/e83f2429
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/e83f2429

Branch: refs/heads/master
Commit: e83f24297d9c8e9a901575e17d0b32b665a038c4
Parents: 740fcd1
Author: Dale LaBossiere <dlab...@us.ibm.com>
Authored: Thu Sep 15 15:06:39 2016 -0400
Committer: Dale LaBossiere <dlab...@us.ibm.com>
Committed: Thu Sep 15 15:06:39 2016 -0400

----------------------------------------------------------------------
 build.gradle | 56 +++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/e83f2429/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index f37f672..2a76996 100644
--- a/build.gradle
+++ b/build.gradle
@@ -327,22 +327,6 @@ subprojects {
   compileTestJava {
     configure compileOptions
   }
-
-  test {
-    filter {
-      includeTestsMatching '*Test'  // can override via --tests command line 
option
-    }
-
-    systemProperty 'edgent.test.top.dir.file.path', rootProject.projectDir
-    systemProperty 'edgent.test.root.dir', rootProject.projectDir
-    testLogging {
-      exceptionFormat 'full'
-    }
-    reports {
-      junitXml.enabled = true
-      html.enabled = true
-    }
-  }
   
   dependencies {
     // common dependencies for tests
@@ -424,6 +408,46 @@ subprojects {
     }
   }
 
+  test {
+    filter {
+      includeTestsMatching '*Test'  // can override via --tests command line 
option
+    }
+
+    systemProperty 'edgent.test.top.dir.file.path', rootProject.projectDir
+    systemProperty 'edgent.test.root.dir', rootProject.projectDir
+    testLogging {
+      exceptionFormat 'full'
+    }
+    reports {
+      junitXml.enabled = true
+      html.enabled = true
+    }
+    doFirst {
+      // The project's tests are supposed to run against its target-dir jar.
+      // We must remove the project's $buildDir/{classes,resources}/main
+      // from the classpath so they're not used.  
+      // To be safe, just remove any project's {classes,resources}/main from
+      // the test classpath. 
+
+      classpath = project.sourceSets.test.runtimeClasspath
+      classpath = classpath.filter { ! ( it.path.endsWith("classes/main")
+                                         || it.path.endsWith("resources/main") 
)} 
+
+      // Hmm... for some reason the classpath (when printed here) also includes
+      // the project's src build/libs/ jar and by the default name
+      // (e.g., build/libs/oplets-0.4.1.jar) yet we've configured the jar task
+      // to generate the jar in the target-dir with a different name.  
+      // It also lacks that target-dir jar we added as a dependency 
+      // via addMyTargetDirProjectJarDependency 'testCompile'
+      // ???  
+      // Adjust accordingly.
+      
+      classpath = classpath.filter { ! 
it.path.startsWith(project.libsDir.path) } 
+      classpath = files(project.jar.archivePath) + classpath  // our jar first
+      logger.debug "$project.path test.classpath: " + classpath.collect { 
it.toString() }
+    }
+  }
+
   assemble.doLast {
     // augment assemble with our additional target dir update processing
     

Reply via email to