Skip to content

Commit

Permalink
GROOVY-11573: propagate parameters configuration to java compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 23, 2025
1 parent c7800e8 commit 6fd3b7e
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 150 deletions.
18 changes: 14 additions & 4 deletions src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.ConfigurationException;
import org.codehaus.groovy.control.messages.WarningMessage;
import org.codehaus.groovy.runtime.ArrayGroovyMethods;
import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods;
import org.codehaus.groovy.runtime.StringGroovyMethods;
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
Expand Down Expand Up @@ -421,7 +422,7 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
configuration.setClasspath(classpath);
}

if (targetDir != null && targetDir.getName().length() > 0) {
if (targetDir != null && !targetDir.getName().isEmpty()) {
configuration.setTargetDirectory(targetDir);
}

Expand Down Expand Up @@ -451,12 +452,12 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
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)");
}
Expand All @@ -477,6 +478,15 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
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 (!ArrayGroovyMethods.contains(flags, "parameters")) {
flags = ArrayGroovyMethods.plus(flags, "parameters");
options.put("flags", flags);
}
}
}

return configuration;
Expand Down Expand Up @@ -508,7 +518,7 @@ private String[] javacFlags() {
if (previewFeatures) {
result.add("-enable-preview");
}
return result.isEmpty() ? null : result.toArray(new String[0]);
return result.isEmpty() ? null : result.toArray(String[]::new);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,200 +20,181 @@
-->

<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}"/>
</path>

<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovyMaterials"/>

<presetdef name="compile-plain">
<groovyc srcdir="${srcPath}" destdir="${destPath}"/>
</presetdef>

<presetdef name="compile-joint">
<groovyc srcdir="${srcPath}" destdir="${destPath}">
<javac debug="true" release="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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
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) {
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.ant;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
configuration.parameters=true
Loading

0 comments on commit 6fd3b7e

Please sign in to comment.