This is an automated email from the ASF dual-hosted git repository. emilles pushed a commit to branch GROOVY_4_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 9803e109a96154e88118c0132ffa8583dd14f03f Author: Eric Milles <[email protected]> AuthorDate: Sun Feb 23 14:52:40 2025 -0600 GROOVY-11573: propagate parameters configuration to java compiler 4_0_X backport --- .../codehaus/groovy/tools/FileSystemCompiler.java | 18 ++- .../org/codehaus/groovy/ant/GroovycTest.xml | 117 +++++++---------- .../org/codehaus/groovy/ant/GroovycTest2.java | 15 +-- ...oovycTest2.java => ParameterMetadataCheck.java} | 15 +-- .../ant/{GroovycTest2.java => params.groovy} | 20 +-- .../org/codehaus/groovy/ant/GroovycTest.java | 143 +++++++++++---------- 6 files changed, 149 insertions(+), 179 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java index d2f486158c..0ee479a705 100644 --- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java +++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java @@ -23,6 +23,7 @@ import org.codehaus.groovy.control.CompilationUnit; import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.ConfigurationException; import org.codehaus.groovy.control.messages.WarningMessage; +import org.codehaus.groovy.runtime.DefaultGroovyMethods; import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods; import org.codehaus.groovy.runtime.StringGroovyMethods; import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit; @@ -325,7 +326,7 @@ public class FileSystemCompiler { public String[] getVersion() { return new String[]{ "Groovy compiler version " + GroovySystem.getVersion(), - "Copyright 2003-2023 The Apache Software Foundation. https://groovy-lang.org/", + "Copyright 2003-2025 The Apache Software Foundation. https://groovy-lang.org/", "", }; } @@ -421,7 +422,7 @@ public class FileSystemCompiler { configuration.setClasspath(classpath); } - if (targetDir != null && targetDir.getName().length() > 0) { + if (targetDir != null && !targetDir.getName().isEmpty()) { configuration.setTargetDirectory(targetDir); } @@ -451,12 +452,12 @@ public class FileSystemCompiler { compilerOptions.put("stubDir", stubDirectory); } if (keepStubs) { - compilerOptions.put("keepStubs", true); + compilerOptions.put("keepStubs", Boolean.TRUE); } configuration.setJointCompilationOptions(compilerOptions); } - final List<String> transformations = new ArrayList<>(); + List<String> transformations = new ArrayList<>(); if (compileStatic) { transformations.add("ast(groovy.transform.CompileStatic)"); } @@ -477,6 +478,15 @@ public class FileSystemCompiler { scripts.addAll(StringGroovyMethods.tokenize(configScripts, ',')); } processConfigScripts(scripts, configuration); + // GROOVY-11573: propagate parameters configuration + if (jointCompilation && configuration.getParameters()) { + Map<String, Object> options = configuration.getJointCompilationOptions(); + String[] flags = (String[]) options.getOrDefault("flags", new String[0]); + if (!DefaultGroovyMethods.contains(flags, "parameters")) { + flags = DefaultGroovyMethods.plus(flags, "parameters"); + options.put("flags", flags); + } + } } return configuration; diff --git a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml index 0f27303941..d70cb5ab0e 100644 --- a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml +++ b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml @@ -20,12 +20,10 @@ --> -<project name="Test Groovyc Task" default="test1"> +<project name="Test Groovyc Task"> - <property name="srcPath" value="."/> - <property name="destPath" value="${user.dir}/build/classes/groovy/test"/> - - <property name="javaVersion" value="8"/> + <property name="srcPath" location="."/> + <property name="destPath" location="${user.dir}/build/classes/groovy/test"/> <path id="groovyMaterials"> <pathelement path="${java.class.path}"/> @@ -33,187 +31,170 @@ <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovyMaterials"/> + <presetdef name="compile-plain"> + <groovyc srcdir="${srcPath}" destdir="${destPath}" targetBytecode="8"/> + </presetdef> + + <presetdef name="compile-joint"> + <groovyc srcdir="${srcPath}" destdir="${destPath}" targetBytecode="8"> + <javac debug="true" source="8" target="8"/> + </groovyc> + </presetdef> + + <target name="GroovycTest1_NoFork_NoClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy"/> + <compile-plain includes="GroovycTest1.groovy"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> </target> <target name="GroovycTest1_NoFork_WithGroovyClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" - classpathref="groovyMaterials"/> + <compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> </target> <target name="GroovycTest1_NoFork_WithJavaClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy"/> + <compile-plain includes="GroovycTest1.groovy"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_NoFork_WithBothClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" - classpathref="groovyMaterials"/> + <compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_ForkGroovy_NoClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true"/> + <compile-plain includes="GroovycTest1.groovy" fork="true"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> </target> <target name="GroovycTest1_ForkGroovy_WithGroovyClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials" - fork="true"/> + <compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> </target> <target name="GroovycTest1_ForkGroovy_WithJavaClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true"/> + <compile-plain includes="GroovycTest1.groovy" fork="true"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_ForkGroovy_WithBothClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials" - fork="true"/> + <compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_Joint_NoFork_NoClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovyTest2.java"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovyTest2.java"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> <java classname="org.codehaus.groovy.ant.GroovycTest2"/> </target> <target name="GroovycTest1_Joint_NoFork_WithGroovyClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" - classpathref="groovyMaterials"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> <java classname="org.codehaus.groovy.ant.GroovycTest2"/> </target> <target name="Groovyc_Joint_NoFork_NestedCompilerArg_WithGroovyClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="IncorrectGenericsUsage.java" - classpathref="groovyMaterials"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"> + <compile-joint includes="IncorrectGenericsUsage.java" classpathref="groovyMaterials"> + <javac> <compilerarg value="-Xlint"/> </javac> - </groovyc> + </compile-joint> </target> <target name="GroovycTest1_Joint_NoFork_WithJavaClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovycTest2.java"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_Joint_NoFork_WithBothClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" - classpathref="groovyMaterials"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_Joint_ForkGroovy_NoClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> <java classname="org.codehaus.groovy.ant.GroovycTest2"/> </target> <target name="GroovycTest1_Joint_ForkGroovy_WithGroovyClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true" - classpathref="groovyMaterials"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> <java classname="org.codehaus.groovy.ant.GroovycTest2"/> </target> <target name="GroovycTest1_Joint_ForkGroovy_WithJavaClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_Joint_ForkGroovy_WithBothClasspath"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true" - classpathref="groovyMaterials"> - <javac source="${javaVersion}" target="${javaVersion}" debug="true"/> - </groovyc> + <compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> <java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_ForkGroovy_NoClasspath_WithJavaHome"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true" - javahome="${alt.java.home}"/> + <compile-plain includes="GroovycTest1.groovy" fork="true" javahome="${alt.java.home}"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> </target> <target name="GroovycTest1_ForkGroovy_WithGroovyClasspath_WithJavaHome"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials" - fork="true" javahome="${alt.java.home}"/> + <compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true" javahome="${alt.java.home}"/> <java classname="org.codehaus.groovy.ant.GroovycTest1"/> </target> <target name="GroovycTest1_ForkGroovy_WithJavaClasspath_WithJavaHome"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true" - javahome="${alt.java.home}"/> + <compile-plain includes="GroovycTest1.groovy" fork="true" javahome="${alt.java.home}"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_ForkGroovy_WithBothClasspath_WithJavaHome"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials" - fork="true" javahome="${alt.java.home}"/> + <compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true" javahome="${alt.java.home}"/> <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/> </target> <target name="GroovycTest1_ForkGroovy_NoClasspath_Fail"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovyTestBad1.groovy" fork="true"/> - <java classname="org.codehaus.groovy.ant.GroovycTest1"/> + <compile-plain includes="GroovyTestBad1.groovy" fork="true"/> </target> <target name="noForkNoAntRuntime"> - <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="false" includeAntRuntime="false"/> + <compile-plain includes="GroovycTest1.groovy" fork="false" includeAntRuntime="false"/> </target> <!-- GROOVY-9197 --> <target name="jointForkedCompilation_ExternalJarOnClasspath"> - <presetdef name="compile"> - <groovyc fork="true" includeantruntime="false"> - <javac debug="true" source="${javaVersion}" target="${javaVersion}"/> - </groovyc> - </presetdef> - <path id="the.classpath"> <path refid="groovyMaterials"/> <fileset file="commons-lang3-3.4.jar"/> </path> - <compile srcdir="${srcPath}" destdir="${destPath}" includes="MakesExternalReference.java"> + <compile-joint fork="true" includeantruntime="false" includes="MakesExternalReference.java"> <classpath refid="the.classpath"/> - </compile> + </compile-joint> <java classname="org.codehaus.groovy.ant.MakesExternalReference" classpathref="the.classpath"/> </target> + <!-- GROOVY-11573 --> + <target name="jointForkedCompilation_ParameterMetadataCheck"> + <compile-joint fork="true" configscript="params.groovy" includes="ParameterMetadataCheck.java"/> + <java classname="org.codehaus.groovy.ant.ParameterMetadataCheck"/> + </target> + <target name="clean"> <delete quiet="true"> <fileset dir="${destPath}/org/codehaus/groovy/ant"> + <include name="*_Result.txt"/> <include name="GroovycTest1*.class"/> <include name="GroovycTest2*.class"/> <include name="IncorrectGenericsUsage.class"/> <include name="MakesExternalReference.class"/> + <include name="ParameterMetadataCheck.class"/> </fileset> </delete> </target> diff --git a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java index b421a19005..8f5057d4f0 100644 --- a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java +++ b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java @@ -22,17 +22,12 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -class GroovycTest2 { - static void main(String[] args) throws IOException { - FileOutputStream fout = new FileOutputStream( - new File("build/classes/groovy/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt")); - try { +public class GroovycTest2 { + public static void main(String[] args) throws IOException { + File file = new File("build/classes/groovy/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt"); + file.createNewFile(); + try (FileOutputStream fout = new FileOutputStream(file)) { fout.write("OK.".getBytes()); - } finally { - try { - fout.close(); - } catch (IOException ignore) { - } } } } diff --git a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/ParameterMetadataCheck.java similarity index 72% copy from subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java copy to subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/ParameterMetadataCheck.java index b421a19005..f21acda704 100644 --- a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java +++ b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/ParameterMetadataCheck.java @@ -22,17 +22,12 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -class GroovycTest2 { - static void main(String[] args) throws IOException { - FileOutputStream fout = new FileOutputStream( - new File("build/classes/groovy/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt")); - try { +public class ParameterMetadataCheck { + public static void main(String[] args) throws IOException { + File file = new File("build/classes/groovy/test/org/codehaus/groovy/ant/ParameterMetadataCheck_Result.txt"); + file.createNewFile(); + try (FileOutputStream fout = new FileOutputStream(file)) { fout.write("OK.".getBytes()); - } finally { - try { - fout.close(); - } catch (IOException ignore) { - } } } } diff --git a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/params.groovy similarity index 60% copy from subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java copy to subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/params.groovy index b421a19005..d4e5cfeb5d 100644 --- a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java +++ b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/params.groovy @@ -16,23 +16,5 @@ * specific language governing permissions and limitations * under the License. */ -package org.codehaus.groovy.ant; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -class GroovycTest2 { - static void main(String[] args) throws IOException { - FileOutputStream fout = new FileOutputStream( - new File("build/classes/groovy/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt")); - try { - fout.write("OK.".getBytes()); - } finally { - try { - fout.close(); - } catch (IOException ignore) { - } - } - } -} +configuration.parameters=true diff --git a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java index 393f4adec1..40fe133869 100644 --- a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java +++ b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java @@ -30,6 +30,7 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintStream; +import java.lang.reflect.Method; import java.net.URISyntaxException; import java.nio.file.Paths; import java.util.regex.Pattern; @@ -44,10 +45,12 @@ import static groovy.test.GroovyAssert.isAtLeastJdk; * matter as the tests remove all class files that should not pre-exist from this directory at each step. */ public class GroovycTest extends GroovyTestCase { + private final File antFile = new File("src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml"); private Project project; private static boolean warned = false; + @Override protected void setUp() { project = new Project(); project.init(); @@ -120,6 +123,70 @@ public class GroovycTest extends GroovyTestCase { } } + private void ensureExecutes(final String target) { + ensureNotPresent("GroovycTest1"); + project.executeTarget(target); + ensureResultOK("GroovycTest1"); + } + + private void ensureExecutesWithJavaHome(final String target) { + if (project.getProperty("alt.java.home") != null) { + ensureExecutes(target); + } else { + if (!warned) { + System.err.println("Forked Java tests skipped, not a sun JDK layout"); + warned = true; + } + } + } + + private void ensureFails(final String target) { + File badGroovy = new File(antFile.getParentFile(), "GroovyTestBad1.groovy"); + PrintStream ps = null; + try { + ps = new PrintStream(new FileOutputStream(badGroovy)); + } catch (FileNotFoundException e) { + fail("Could not create test file:" + badGroovy.getAbsolutePath()); + } + ps.println("class GroovyTest1Bad { Thi$ $hould Fail! (somehow) };:??''+_|\\|"); + ps.close(); + ensureNotPresent("GroovycTestBad1"); + try { + project.executeTarget(target); + fail("Ant script should have failed with execution exception"); + } catch (BuildException be) { + be.printStackTrace(); + ensureNotPresent("GroovycTestBad1"); + } finally { + badGroovy.delete(); + } + } + + /** + * For the code: + * private ArrayList<String> x = new ArrayList<String>(); + * x = (ArrayList)z ; + * Upto JDK6, 'javac -Xlint' produces the following output: + * found : java.util.ArrayList + * required: java.util.ArrayList<java.lang.String> + * But, OpenJDK seems to be producing the following output: + * required: ArrayList<String> + * found: ArrayList + * So, we first adjust the output a bit, so that difference in the output brought in by OpenJDK javac + * does not impact the test adversely + */ + private String adjustOutputToHandleOpenJDKJavacOutputDifference(String antOutput) { + if (!antOutput.contains("java.util.ArrayList") && antOutput.contains("ArrayList")) { + antOutput = antOutput.replace("ArrayList", "java.util.ArrayList"); + } + if (!antOutput.contains("java.lang.String") && antOutput.contains("String")) { + antOutput = antOutput.replace("String", "java.lang.String"); + } + return antOutput; + } + + //-------------------------------------------------------------------------- + public void testGroovycTest1_NoFork_NoClasspath() { if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_NoFork_NoClasspath"); @@ -141,22 +208,18 @@ public class GroovycTest extends GroovyTestCase { } public void testGroovycTest1_ForkGroovy_NoClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_ForkGroovy_NoClasspath"); } public void testGroovycTest1_ForkGroovy_WithGroovyClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_ForkGroovy_WithGroovyClasspath"); } public void testGroovycTest1_ForkGroovy_WithJavaClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_ForkGroovy_WithJavaClasspath"); } public void testGroovycTest1_ForkGroovy_WithBothClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_ForkGroovy_WithBothClasspath"); } @@ -192,29 +255,6 @@ public class GroovycTest extends GroovyTestCase { } } - /** - * For the code: - * private ArrayList<String> x = new ArrayList<String>(); - * x = (ArrayList)z ; - * Upto JDK6, 'javac -Xlint' produces the following output: - * found : java.util.ArrayList - * required: java.util.ArrayList<java.lang.String> - * But, OpenJDK seems to be producing the following output: - * required: ArrayList<String> - * found: ArrayList - * So, we first adjust the output a bit, so that difference in the output brought in by OpenJDK javac - * does not impact the test adversely - */ - private String adjustOutputToHandleOpenJDKJavacOutputDifference(String antOutput) { - if (!antOutput.contains("java.util.ArrayList") && antOutput.contains("ArrayList")) { - antOutput = antOutput.replace("ArrayList", "java.util.ArrayList"); - } - if (!antOutput.contains("java.lang.String") && antOutput.contains("String")) { - antOutput = antOutput.replace("String", "java.lang.String"); - } - return antOutput; - } - public void testGroovycTest1_Joint_NoFork_WithJavaClasspath() { if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_Joint_NoFork_WithJavaClasspath"); @@ -226,22 +266,18 @@ public class GroovycTest extends GroovyTestCase { } public void testGroovycTest1_Joint_ForkGroovy_NoClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_Joint_ForkGroovy_NoClasspath"); } public void testGroovycTest1_Joint_ForkGroovy_WithGroovyClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_Joint_ForkGroovy_WithGroovyClasspath"); } public void testGroovycTest1_Joint_ForkGroovy_WithJavaClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_Joint_ForkGroovy_WithJavaClasspath"); } public void testGroovycTest1_Joint_ForkGroovy_WithBothClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureExecutes("GroovycTest1_Joint_ForkGroovy_WithBothClasspath"); } @@ -271,48 +307,19 @@ public class GroovycTest extends GroovyTestCase { // GROOVY-9197 public void testJointCompilationPropagatesClasspath() { - if (isAtLeastJdk("18.0")) return; // GROOVY-10479 ensureNotPresent("MakesExternalReference"); project.executeTarget("jointForkedCompilation_ExternalJarOnClasspath"); ensureResultOK("MakesExternalReference"); } - private void ensureExecutes(String target) { - ensureNotPresent("GroovycTest1"); - project.executeTarget(target); - ensureResultOK("GroovycTest1"); - } - - private void ensureExecutesWithJavaHome(String target) { - if (project.getProperty("alt.java.home") != null) { - ensureExecutes(target); - } else { - if (!warned) { - System.err.println("Forked Java tests skipped, not a sun JDK layout"); - warned = true; - } - } - } + // GROOVY-11573 + public void testJointCompilationPropagatesParameters() throws Exception { + ensureNotPresent("ParameterMetadataCheck"); + project.executeTarget("jointForkedCompilation_ParameterMetadataCheck"); + ensureResultOK("ParameterMetadataCheck"); - private void ensureFails(String target) { - File badGroovy = new File(antFile.getParentFile(), "GroovyTestBad1.groovy"); - PrintStream ps = null; - try { - ps = new PrintStream(new FileOutputStream(badGroovy)); - } catch (FileNotFoundException e) { - fail("Could not create test file:" + badGroovy.getAbsolutePath()); - } - ps.println("class GroovyTest1Bad { Thi$ $hould Fail! (somehow) };:??''+_|\\|"); - ps.close(); - ensureNotPresent("GroovycTestBad1"); - try { - project.executeTarget(target); - fail("Ant script should have failed with execution exception"); - } catch (BuildException be) { - be.printStackTrace(); - ensureNotPresent("GroovycTestBad1"); - } finally { - badGroovy.delete(); - } + Class<?> c = Class.forName("org.codehaus.groovy.ant.ParameterMetadataCheck"); + Method m = c.getDeclaredMethod("main", String[].class); + assertEquals("args", m.getParameters()[0].getName()); } }
