incubator-groovy git commit: Create extension module test jars at build time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

incubator-groovy git commit: Create extension module test jars at build time

cchampeau
Repository: incubator-groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X da341730f -> 11713b73e


Create extension module test jars at build time


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 11713b73ee5a56b4aa2c383f9e47c865233b9e3b
Parents: da34173
Author: Cedric Champeau <[hidden email]>
Authored: Wed Jun 17 05:22:21 2015 +0200
Committer: Cedric Champeau <[hidden email]>
Committed: Wed Jun 17 05:24:43 2015 +0200

----------------------------------------------------------------------
 gradle/test.gradle                              |  30 ++++++++++++++++++
 .../runtime/m12n/Groovy7225Extension.java       |  31 +++++++++++++++++++
 .../groovy/runtime/m12n/TestMapExtension.java   |  27 ++++++++++++++++
 .../m12n/TestStaticStringExtension2.java        |  25 +++++++++++++++
 .../runtime/m12n/TestStringExtension2.java      |  30 ++++++++++++++++++
 .../org.codehaus.groovy.runtime.ExtensionModule |   6 ++++
 .../1.0.7225-test/module-test-1.0.7225-test.jar | Bin 2541 -> 0 bytes
 .../1.2-test/module-test-1.2-test.jar           | Bin 3326 -> 0 bytes
 .../stc/STCExtensionMethodsTest.groovy          |   4 +--
 .../m12n/ExtensionModuleHelperForTests.groovy   |   2 +-
 .../runtime/m12n/ExtensionModuleTest.groovy     |  16 +++++-----
 11 files changed, 160 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/gradle/test.gradle
----------------------------------------------------------------------
diff --git a/gradle/test.gradle b/gradle/test.gradle
index 7f964a8..df294c6 100644
--- a/gradle/test.gradle
+++ b/gradle/test.gradle
@@ -119,3 +119,33 @@ def buildExcludeFilter() {
         excludes.any { f.file =~ it }
     }
 }
+
+// some tests require Jars, but those are not allowed in the source directory
+// by the Apache policy, so we need to build them and add them to the test
+// resources classpath
+
+ext.extModuleFixtureDir = file("$projectDir/src/test-fixtures/extmodule")
+ext.extModuleOutputDir = file("$buildDir/testFixtures/extmodule")
+ext.extModuleRepoDir = file("$extModuleOutputDir/repo")
+
+task compileTestExtensionModule(type:JavaCompile) {
+    classpath = files(jar.archivePath)
+    source fileTree("$extModuleFixtureDir/src/main/java")
+    destinationDir = file("$extModuleOutputDir/classes")
+    sourceCompatibility = 1.6
+    targetCompatibility = 1.6
+}
+
+task testExtensionModuleJar(type:Jar) {
+    description = 'Builds a sample extension module used in tests'
+    dependsOn compileTestExtensionModule
+    baseName = 'module-test'
+    version = '1.3'
+    from { compileTestExtensionModule.destinationDir }
+    from files("$extModuleFixtureDir/src/main/resources")
+    // emulate Maven repo format for output
+    destinationDir = file("$extModuleRepoDir/jars/module-test/module-test/${version}")
+}
+
+test.dependsOn(testExtensionModuleJar)
+test.classpath += files(extModuleRepoDir)

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/Groovy7225Extension.java
----------------------------------------------------------------------
diff --git a/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/Groovy7225Extension.java b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/Groovy7225Extension.java
new file mode 100644
index 0000000..c6fd7c4
--- /dev/null
+++ b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/Groovy7225Extension.java
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.runtime.m12n;
+
+import groovy.lang.Closure;
+
+public class Groovy7225Extension {
+    public static String groovy7225(String self) {
+        return self+": ok";
+    }
+
+    public static String groovy7225(Closure closure) {
+        return "{\"field\":\"value\"}";
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestMapExtension.java
----------------------------------------------------------------------
diff --git a/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestMapExtension.java b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestMapExtension.java
new file mode 100644
index 0000000..93f250b
--- /dev/null
+++ b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestMapExtension.java
@@ -0,0 +1,27 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.runtime.m12n;
+
+import java.util.Map;
+
+public class TestMapExtension {
+    public static int taille(Map<?,?> map) {
+        return map.size();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStaticStringExtension2.java
----------------------------------------------------------------------
diff --git a/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStaticStringExtension2.java b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStaticStringExtension2.java
new file mode 100644
index 0000000..aeb3913
--- /dev/null
+++ b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStaticStringExtension2.java
@@ -0,0 +1,25 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.runtime.m12n;
+
+public class TestStaticStringExtension2 {
+    public static int answer2(String self) {
+        return 42;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStringExtension2.java
----------------------------------------------------------------------
diff --git a/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStringExtension2.java b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStringExtension2.java
new file mode 100644
index 0000000..d3fab79
--- /dev/null
+++ b/src/test-fixtures/extmodule/src/main/java/org/codehaus/groovy/runtime/m12n/TestStringExtension2.java
@@ -0,0 +1,30 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.codehaus.groovy.runtime.m12n;
+
+public class TestStringExtension2 {
+    public static String reverseToUpperCase2(String self) {
+        return new StringBuilder(self.toUpperCase()).reverse().toString();
+    }
+
+    public static int taille(String self) {
+        return self.length();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test-fixtures/extmodule/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
----------------------------------------------------------------------
diff --git a/src/test-fixtures/extmodule/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule b/src/test-fixtures/extmodule/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
new file mode 100644
index 0000000..941f9b3
--- /dev/null
+++ b/src/test-fixtures/extmodule/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
@@ -0,0 +1,6 @@
+// This file is used to test the extension module framework
+moduleName=Test module for Grab
+moduleVersion=1.3
+extensionClasses=org.codehaus.groovy.runtime.m12n.TestStringExtension2,org.codehaus.groovy.runtime.m12n.TestMapExtension,org.codehaus.groovy.runtime.m12n.Groovy7225Extension
+staticExtensionClasses=org.codehaus.groovy.runtime.m12n.TestStaticStringExtension2
+

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test-resources/jars/module-test/module-test/1.0.7225-test/module-test-1.0.7225-test.jar
----------------------------------------------------------------------
diff --git a/src/test-resources/jars/module-test/module-test/1.0.7225-test/module-test-1.0.7225-test.jar b/src/test-resources/jars/module-test/module-test/1.0.7225-test/module-test-1.0.7225-test.jar
deleted file mode 100644
index d08e03c..0000000
Binary files a/src/test-resources/jars/module-test/module-test/1.0.7225-test/module-test-1.0.7225-test.jar and /dev/null differ

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test-resources/jars/module-test/module-test/1.2-test/module-test-1.2-test.jar
----------------------------------------------------------------------
diff --git a/src/test-resources/jars/module-test/module-test/1.2-test/module-test-1.2-test.jar b/src/test-resources/jars/module-test/module-test/1.2-test/module-test-1.2-test.jar
deleted file mode 100644
index 2678d82..0000000
Binary files a/src/test-resources/jars/module-test/module-test/1.2-test/module-test-1.2-test.jar and /dev/null differ

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy b/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
index b8260c8..3794f65 100644
--- a/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
+++ b/src/test/groovy/transform/stc/STCExtensionMethodsTest.groovy
@@ -43,7 +43,7 @@ class STCExtensionMethodsTest extends StaticTypeCheckingTestCase {
         String.metaClass = impl
         ExtensionModuleRegistry registry = GroovySystem.metaClassRegistry.moduleRegistry
         // ensure that the module isn't loaded
-        assert !registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.2-test' }
+        assert !registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.3' }
 
         // find jar resource
         def jarURL = this.class.getResource("/jars")
@@ -52,7 +52,7 @@ class STCExtensionMethodsTest extends StaticTypeCheckingTestCase {
         def resolver = "@GrabResolver(name='local',root='$jarURL')"
 
         assertScript resolver + """
-        @Grab('module-test:module-test:1.2-test')
+        @Grab('module-test:module-test:1.3')
         import org.codehaus.groovy.runtime.m12n.*
 
         // the following methods are added by the Grab test module

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
index 997fc50..1753c85 100644
--- a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
+++ b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
@@ -71,7 +71,7 @@ public class ExtensionModuleHelperForTests {
             baseDir.deleteDir()
             if (err) {
                 throw new RuntimeException("$err\nClasspath: ${cp.join('\n')}")
-            } else if ( ! out.contains("OK")) {
+            } else if ( out.contains('FAILURES') || ! out.contains("OK")) {
                 throw new RuntimeException("$out\nClasspath: ${cp.join('\n')}")
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/11713b73/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleTest.groovy b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleTest.groovy
index 61c315b..1a17dbf 100644
--- a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleTest.groovy
@@ -41,7 +41,7 @@ class ExtensionModuleTest extends GroovyTestCase {
         ExtensionModuleHelperForTests.doInFork '''
             ExtensionModuleRegistry registry = GroovySystem.metaClassRegistry.moduleRegistry
             // ensure that the module isn't loaded
-            assert !registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.2-test' }
+            assert !registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.3' }
 
             // find jar resource
             def jarURL = this.class.getResource("/jars")
@@ -50,12 +50,12 @@ class ExtensionModuleTest extends GroovyTestCase {
             def resolver = "@GrabResolver('$jarURL')"
 
             assertScript resolver + """
-            @Grab(value='module-test:module-test:1.2-test', changing='true')
+            @Grab(value='module-test:module-test:1.3', changing='true')
             import org.codehaus.groovy.runtime.m12n.*
 
             // ensure that the module is now loaded
             ExtensionModuleRegistry registry = GroovySystem.metaClassRegistry.moduleRegistry
-            assert registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.2-test' }
+            assert registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.3' }
 
             // the following methods are added by the 'Test module for Grab' module
             def str = 'This is a string'
@@ -64,7 +64,7 @@ class ExtensionModuleTest extends GroovyTestCase {
             """
 
             // the module should still be available
-            assert registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.2-test' }
+            assert registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.3' }
         '''
     }
 
@@ -72,7 +72,7 @@ class ExtensionModuleTest extends GroovyTestCase {
         ExtensionModuleHelperForTests.doInFork '''
             ExtensionModuleRegistry registry = GroovySystem.metaClassRegistry.moduleRegistry
             // ensure that the module isn't loaded
-            assert !registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.2-test' }
+            assert !registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.3' }
 
             // find jar resource
             def jarURL = this.class.getResource("/jars")
@@ -81,7 +81,7 @@ class ExtensionModuleTest extends GroovyTestCase {
             def resolver = "@GrabResolver('$jarURL')"
 
             assertScript resolver + """
-            @Grab(value='module-test:module-test:1.2-test', changing='true')
+            @Grab(value='module-test:module-test:1.3', changing='true')
             import org.codehaus.groovy.runtime.m12n.*
 
             def map = [:]
@@ -98,7 +98,7 @@ class ExtensionModuleTest extends GroovyTestCase {
         ExtensionModuleHelperForTests.doInFork '''
             ExtensionModuleRegistry registry = GroovySystem.metaClassRegistry.moduleRegistry
             // ensure that the module isn't loaded
-            assert !registry.modules.any { it.name == 'Groovy Test 7225' && it.version == '1.0.7225-test' }
+            assert !registry.modules.any { it.name == 'Test module for Grab' && it.version == '1.3' }
 
             // find jar resource
             def jarURL = this.class.getResource("/jars")
@@ -106,7 +106,7 @@ class ExtensionModuleTest extends GroovyTestCase {
 
             assertScript """
             @GrabResolver('$jarURL')
-            @Grab(value='module-test:module-test:1.0.7225-test', changing='true')
+            @Grab(value='module-test:module-test:1.3', changing='true')
             import org.codehaus.groovy.runtime.m12n.*
 
             assert 'test'.groovy7225() == 'test: ok'