Skip to content

Commit 9803e10

Browse files
committed
GROOVY-11573: propagate parameters configuration to java compiler
4_0_X backport
1 parent 8b28d7d commit 9803e10

File tree

6 files changed

+196
-150
lines changed

6 files changed

+196
-150
lines changed

src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.codehaus.groovy.control.CompilerConfiguration;
2424
import org.codehaus.groovy.control.ConfigurationException;
2525
import org.codehaus.groovy.control.messages.WarningMessage;
26+
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
2627
import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods;
2728
import org.codehaus.groovy.runtime.StringGroovyMethods;
2829
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
@@ -325,7 +326,7 @@ public static class VersionProvider implements IVersionProvider {
325326
public String[] getVersion() {
326327
return new String[]{
327328
"Groovy compiler version " + GroovySystem.getVersion(),
328-
"Copyright 2003-2023 The Apache Software Foundation. https://groovy-lang.org/",
329+
"Copyright 2003-2025 The Apache Software Foundation. https://groovy-lang.org/",
329330
"",
330331
};
331332
}
@@ -421,7 +422,7 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
421422
configuration.setClasspath(classpath);
422423
}
423424

424-
if (targetDir != null && targetDir.getName().length() > 0) {
425+
if (targetDir != null && !targetDir.getName().isEmpty()) {
425426
configuration.setTargetDirectory(targetDir);
426427
}
427428

@@ -451,12 +452,12 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
451452
compilerOptions.put("stubDir", stubDirectory);
452453
}
453454
if (keepStubs) {
454-
compilerOptions.put("keepStubs", true);
455+
compilerOptions.put("keepStubs", Boolean.TRUE);
455456
}
456457
configuration.setJointCompilationOptions(compilerOptions);
457458
}
458459

459-
final List<String> transformations = new ArrayList<>();
460+
List<String> transformations = new ArrayList<>();
460461
if (compileStatic) {
461462
transformations.add("ast(groovy.transform.CompileStatic)");
462463
}
@@ -477,6 +478,15 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
477478
scripts.addAll(StringGroovyMethods.tokenize(configScripts, ','));
478479
}
479480
processConfigScripts(scripts, configuration);
481+
// GROOVY-11573: propagate parameters configuration
482+
if (jointCompilation && configuration.getParameters()) {
483+
Map<String, Object> options = configuration.getJointCompilationOptions();
484+
String[] flags = (String[]) options.getOrDefault("flags", new String[0]);
485+
if (!DefaultGroovyMethods.contains(flags, "parameters")) {
486+
flags = DefaultGroovyMethods.plus(flags, "parameters");
487+
options.put("flags", flags);
488+
}
489+
}
480490
}
481491

482492
return configuration;

subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml

+49-68
Original file line numberDiff line numberDiff line change
@@ -20,200 +20,181 @@
2020
2121
-->
2222

23-
<project name="Test Groovyc Task" default="test1">
23+
<project name="Test Groovyc Task">
2424

25-
<property name="srcPath" value="."/>
26-
<property name="destPath" value="${user.dir}/build/classes/groovy/test"/>
27-
28-
<property name="javaVersion" value="8"/>
25+
<property name="srcPath" location="."/>
26+
<property name="destPath" location="${user.dir}/build/classes/groovy/test"/>
2927

3028
<path id="groovyMaterials">
3129
<pathelement path="${java.class.path}"/>
3230
</path>
3331

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

34+
<presetdef name="compile-plain">
35+
<groovyc srcdir="${srcPath}" destdir="${destPath}" targetBytecode="8"/>
36+
</presetdef>
37+
38+
<presetdef name="compile-joint">
39+
<groovyc srcdir="${srcPath}" destdir="${destPath}" targetBytecode="8">
40+
<javac debug="true" source="8" target="8"/>
41+
</groovyc>
42+
</presetdef>
43+
44+
3645
<target name="GroovycTest1_NoFork_NoClasspath">
37-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy"/>
46+
<compile-plain includes="GroovycTest1.groovy"/>
3847
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
3948
</target>
4049

4150
<target name="GroovycTest1_NoFork_WithGroovyClasspath">
42-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy"
43-
classpathref="groovyMaterials"/>
51+
<compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials"/>
4452
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
4553
</target>
4654

4755
<target name="GroovycTest1_NoFork_WithJavaClasspath">
48-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy"/>
56+
<compile-plain includes="GroovycTest1.groovy"/>
4957
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
5058
</target>
5159

5260
<target name="GroovycTest1_NoFork_WithBothClasspath">
53-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy"
54-
classpathref="groovyMaterials"/>
61+
<compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials"/>
5562
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
5663
</target>
5764

5865
<target name="GroovycTest1_ForkGroovy_NoClasspath">
59-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true"/>
66+
<compile-plain includes="GroovycTest1.groovy" fork="true"/>
6067
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
6168
</target>
6269

6370
<target name="GroovycTest1_ForkGroovy_WithGroovyClasspath">
64-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials"
65-
fork="true"/>
71+
<compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true"/>
6672
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
6773
</target>
6874

6975
<target name="GroovycTest1_ForkGroovy_WithJavaClasspath">
70-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true"/>
76+
<compile-plain includes="GroovycTest1.groovy" fork="true"/>
7177
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
7278
</target>
7379

7480
<target name="GroovycTest1_ForkGroovy_WithBothClasspath">
75-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials"
76-
fork="true"/>
81+
<compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true"/>
7782
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
7883
</target>
7984

8085
<target name="GroovycTest1_Joint_NoFork_NoClasspath">
81-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovyTest2.java">
82-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
83-
</groovyc>
86+
<compile-joint includes="GroovycTest1.groovy,GroovyTest2.java"/>
8487
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
8588
<java classname="org.codehaus.groovy.ant.GroovycTest2"/>
8689
</target>
8790

8891
<target name="GroovycTest1_Joint_NoFork_WithGroovyClasspath">
89-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java"
90-
classpathref="groovyMaterials">
91-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
92-
</groovyc>
92+
<compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" classpathref="groovyMaterials"/>
9393
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
9494
<java classname="org.codehaus.groovy.ant.GroovycTest2"/>
9595
</target>
9696

9797
<target name="Groovyc_Joint_NoFork_NestedCompilerArg_WithGroovyClasspath">
98-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="IncorrectGenericsUsage.java"
99-
classpathref="groovyMaterials">
100-
<javac source="${javaVersion}" target="${javaVersion}" debug="true">
98+
<compile-joint includes="IncorrectGenericsUsage.java" classpathref="groovyMaterials">
99+
<javac>
101100
<compilerarg value="-Xlint"/>
102101
</javac>
103-
</groovyc>
102+
</compile-joint>
104103
</target>
105104

106105
<target name="GroovycTest1_Joint_NoFork_WithJavaClasspath">
107-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java">
108-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
109-
</groovyc>
106+
<compile-joint includes="GroovycTest1.groovy,GroovycTest2.java"/>
110107
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
111108
<java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/>
112109
</target>
113110

114111
<target name="GroovycTest1_Joint_NoFork_WithBothClasspath">
115-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java"
116-
classpathref="groovyMaterials">
117-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
118-
</groovyc>
112+
<compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" classpathref="groovyMaterials"/>
119113
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
120114
<java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/>
121115
</target>
122116

123117
<target name="GroovycTest1_Joint_ForkGroovy_NoClasspath">
124-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true">
125-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
126-
</groovyc>
118+
<compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"/>
127119
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
128120
<java classname="org.codehaus.groovy.ant.GroovycTest2"/>
129121
</target>
130122

131123
<target name="GroovycTest1_Joint_ForkGroovy_WithGroovyClasspath">
132-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"
133-
classpathref="groovyMaterials">
134-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
135-
</groovyc>
124+
<compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true" classpathref="groovyMaterials"/>
136125
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
137126
<java classname="org.codehaus.groovy.ant.GroovycTest2"/>
138127
</target>
139128

140129
<target name="GroovycTest1_Joint_ForkGroovy_WithJavaClasspath">
141-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true">
142-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
143-
</groovyc>
130+
<compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"/>
144131
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
145132
<java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/>
146133
</target>
147134

148135
<target name="GroovycTest1_Joint_ForkGroovy_WithBothClasspath">
149-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"
150-
classpathref="groovyMaterials">
151-
<javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
152-
</groovyc>
136+
<compile-joint includes="GroovycTest1.groovy,GroovycTest2.java" fork="true" classpathref="groovyMaterials"/>
153137
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
154138
<java classname="org.codehaus.groovy.ant.GroovycTest2" classpathref="groovyMaterials"/>
155139
</target>
156140

157141
<target name="GroovycTest1_ForkGroovy_NoClasspath_WithJavaHome">
158-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true"
159-
javahome="${alt.java.home}"/>
142+
<compile-plain includes="GroovycTest1.groovy" fork="true" javahome="${alt.java.home}"/>
160143
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
161144
</target>
162145

163146
<target name="GroovycTest1_ForkGroovy_WithGroovyClasspath_WithJavaHome">
164-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials"
165-
fork="true" javahome="${alt.java.home}"/>
147+
<compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true" javahome="${alt.java.home}"/>
166148
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
167149
</target>
168150

169151
<target name="GroovycTest1_ForkGroovy_WithJavaClasspath_WithJavaHome">
170-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="true"
171-
javahome="${alt.java.home}"/>
152+
<compile-plain includes="GroovycTest1.groovy" fork="true" javahome="${alt.java.home}"/>
172153
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
173154
</target>
174155

175156
<target name="GroovycTest1_ForkGroovy_WithBothClasspath_WithJavaHome">
176-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" classpathref="groovyMaterials"
177-
fork="true" javahome="${alt.java.home}"/>
157+
<compile-plain includes="GroovycTest1.groovy" classpathref="groovyMaterials" fork="true" javahome="${alt.java.home}"/>
178158
<java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
179159
</target>
180160

181161
<target name="GroovycTest1_ForkGroovy_NoClasspath_Fail">
182-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovyTestBad1.groovy" fork="true"/>
183-
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
162+
<compile-plain includes="GroovyTestBad1.groovy" fork="true"/>
184163
</target>
185164

186165
<target name="noForkNoAntRuntime">
187-
<groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy" fork="false" includeAntRuntime="false"/>
166+
<compile-plain includes="GroovycTest1.groovy" fork="false" includeAntRuntime="false"/>
188167
</target>
189168

190169
<!-- GROOVY-9197 -->
191170
<target name="jointForkedCompilation_ExternalJarOnClasspath">
192-
<presetdef name="compile">
193-
<groovyc fork="true" includeantruntime="false">
194-
<javac debug="true" source="${javaVersion}" target="${javaVersion}"/>
195-
</groovyc>
196-
</presetdef>
197-
198171
<path id="the.classpath">
199172
<path refid="groovyMaterials"/>
200173
<fileset file="commons-lang3-3.4.jar"/>
201174
</path>
202175

203-
<compile srcdir="${srcPath}" destdir="${destPath}" includes="MakesExternalReference.java">
176+
<compile-joint fork="true" includeantruntime="false" includes="MakesExternalReference.java">
204177
<classpath refid="the.classpath"/>
205-
</compile>
178+
</compile-joint>
206179

207180
<java classname="org.codehaus.groovy.ant.MakesExternalReference" classpathref="the.classpath"/>
208181
</target>
209182

183+
<!-- GROOVY-11573 -->
184+
<target name="jointForkedCompilation_ParameterMetadataCheck">
185+
<compile-joint fork="true" configscript="params.groovy" includes="ParameterMetadataCheck.java"/>
186+
<java classname="org.codehaus.groovy.ant.ParameterMetadataCheck"/>
187+
</target>
188+
210189
<target name="clean">
211190
<delete quiet="true">
212191
<fileset dir="${destPath}/org/codehaus/groovy/ant">
192+
<include name="*_Result.txt"/>
213193
<include name="GroovycTest1*.class"/>
214194
<include name="GroovycTest2*.class"/>
215195
<include name="IncorrectGenericsUsage.class"/>
216196
<include name="MakesExternalReference.class"/>
197+
<include name="ParameterMetadataCheck.class"/>
217198
</fileset>
218199
</delete>
219200
</target>

subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@
2222
import java.io.FileOutputStream;
2323
import java.io.IOException;
2424

25-
class GroovycTest2 {
26-
static void main(String[] args) throws IOException {
27-
FileOutputStream fout = new FileOutputStream(
28-
new File("build/classes/groovy/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt"));
29-
try {
25+
public class GroovycTest2 {
26+
public static void main(String[] args) throws IOException {
27+
File file = new File("build/classes/groovy/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt");
28+
file.createNewFile();
29+
try (FileOutputStream fout = new FileOutputStream(file)) {
3030
fout.write("OK.".getBytes());
31-
} finally {
32-
try {
33-
fout.close();
34-
} catch (IOException ignore) {
35-
}
3631
}
3732
}
3833
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.codehaus.groovy.ant;
20+
21+
import java.io.File;
22+
import java.io.FileOutputStream;
23+
import java.io.IOException;
24+
25+
public class ParameterMetadataCheck {
26+
public static void main(String[] args) throws IOException {
27+
File file = new File("build/classes/groovy/test/org/codehaus/groovy/ant/ParameterMetadataCheck_Result.txt");
28+
file.createNewFile();
29+
try (FileOutputStream fout = new FileOutputStream(file)) {
30+
fout.write("OK.".getBytes());
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
configuration.parameters=true

0 commit comments

Comments
 (0)