You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/12/22 14:09:24 UTC
[groovy] branch master updated: cleanup to remove IDE warnings
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 286edad cleanup to remove IDE warnings
286edad is described below
commit 286edad0269577e150a129e7315474ca4d1d56ba
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Dec 23 00:09:18 2021 +1000
cleanup to remove IDE warnings
---
.../org/codehaus/groovy/classgen/TestSupport.java | 18 ++-------
.../main/java/org/codehaus/groovy/ant/Groovy.java | 47 +++++++++++-----------
2 files changed, 28 insertions(+), 37 deletions(-)
diff --git a/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java b/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java
index dfb16f7..d882724 100644
--- a/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java
+++ b/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java
@@ -55,7 +55,6 @@ public class TestSupport extends GroovyTestCase implements Opcodes {
protected static boolean DUMP_CLASS = false;
- // ClassLoader parentLoader = Thread.currentThread().getContextClassLoader();
final ClassLoader parentLoader = getClass().getClassLoader();
protected final GroovyClassLoader loader =
VMPluginFactory.getPlugin().doPrivileged(
@@ -66,8 +65,7 @@ public class TestSupport extends GroovyTestCase implements Opcodes {
protected Class loadClass(ClassNode classNode) {
classNode.setModule(module);
- Class fooClass = loader.defineClass(classNode, classNode.getName() + ".groovy", "groovy.testSupport");
- return fooClass;
+ return loader.defineClass(classNode, classNode.getName() + ".groovy", "groovy.testSupport");
}
protected void assertSetProperty(Object bean, String property, Object newValue) throws Exception {
@@ -88,14 +86,6 @@ public class TestSupport extends GroovyTestCase implements Opcodes {
Object[] args = { };
Object value = invokeMethod(bean, method, args);
- /*
- System.out.println("Expected: " + expected);
- System.out.println("Value: " + value);
-
- if (expected == null) { System.out.println("Expected is null"); }
- if (value == null) { System.out.println("value is null"); }
- */
-
assertEquals("property value", expected, value);
}
@@ -150,20 +140,20 @@ public class TestSupport extends GroovyTestCase implements Opcodes {
GroovyCodeSource gcs = VMPluginFactory.getPlugin().doPrivileged(
(PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(text, scriptName, "/groovy/testSupport")
);
- Class groovyClass = loader.parseClass(gcs);
+ Class<?> groovyClass = loader.parseClass(gcs);
Script script = InvokerHelper.createScript(groovyClass, new Binding());
script.run();
}
protected void assertScriptFile(String fileName) throws Exception {
log.info("About to execute script: " + fileName);
- Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
+ Class<?> groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
Script script = InvokerHelper.createScript(groovyClass, new Binding());
script.run();
}
protected GroovyObject compile(String fileName) throws Exception {
- Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
+ Class<?> groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
GroovyObject object = (GroovyObject) groovyClass.getDeclaredConstructor().newInstance();
assertTrue(object != null);
return object;
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
index 940b9f2..4d15d2d 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
@@ -93,7 +93,7 @@ public class Groovy extends Java {
/**
* files to load
*/
- private final Vector<FileSet> filesets = new Vector<FileSet>();
+ private final Vector<FileSet> filesets = new Vector<>();
/**
* The input resource
@@ -129,7 +129,6 @@ public class Groovy extends Java {
* Compiler configuration.
* <p>
* Used to specify the debug output to print stacktraces in case something fails.
- * TODO: Could probably be reused to specify the encoding of the files to load or other properties.
*/
private final CompilerConfiguration configuration = new CompilerConfiguration();
@@ -400,24 +399,7 @@ public class Groovy extends Java {
reader = new InputStreamReader(new BufferedInputStream(src.getInputStream()), Charset.defaultCharset());
}
}
- try {
- final long len = src.getSize();
- log.debug("resource size = " + (len != Resource.UNKNOWN_SIZE ? String.valueOf(len) : "unknown"));
- if (len == 0) {
- log.info("Ignoring empty resource");
- command = null;
- } else {
- try (ChainReaderHelper.ChainReader chainReader = new ChainReaderHelper(getProject(), reader, filterChains).with(crh -> {
- if (len != Resource.UNKNOWN_SIZE && len <= Integer.MAX_VALUE) {
- crh.setBufferSize((int) len);
- }
- }).getAssembledReader()) {
- command = chainReader.readFully();
- }
- }
- } catch (final IOException ioe) {
- throw new BuildException("Unable to load resource: ", ioe, getLocation());
- }
+ readCommandFromReader(reader);
} else {
if (src != null) {
log.info("Ignoring supplied resource as direct script text found");
@@ -440,6 +422,27 @@ public class Groovy extends Java {
log.verbose("Statements executed successfully");
}
+ private void readCommandFromReader(Reader reader) {
+ try {
+ final long len = src.getSize();
+ log.debug("resource size = " + (len != Resource.UNKNOWN_SIZE ? String.valueOf(len) : "unknown"));
+ if (len == 0) {
+ log.info("Ignoring empty resource");
+ command = null;
+ } else {
+ try (ChainReaderHelper.ChainReader chainReader = new ChainReaderHelper(getProject(), reader, filterChains).with(crh -> {
+ if (len != Resource.UNKNOWN_SIZE && len <= Integer.MAX_VALUE) {
+ crh.setBufferSize((int) len);
+ }
+ }).getAssembledReader()) {
+ command = chainReader.readFully();
+ }
+ }
+ } catch (final IOException ioe) {
+ throw new BuildException("Unable to load resource: ", ioe, getLocation());
+ }
+ }
+
@Override
public Commandline.Argument createArg() {
return cmdline.createArgument();
@@ -701,7 +704,7 @@ public class Groovy extends Java {
private void createNewArgs(String txt) throws IOException {
final String[] args = cmdline.getCommandline();
// Temporary file - delete on exit, create (assured unique name).
- final File tempFile = FileUtils.getFileUtils().createTempFile(PREFIX, SUFFIX, null, true, true);
+ final File tempFile = FileUtils.getFileUtils().createTempFile(null, PREFIX, SUFFIX, null, true, true);
final String[] commandline = new String[args.length + 1];
ResourceGroovyMethods.write(tempFile, txt);
commandline[0] = tempFile.getCanonicalPath();
@@ -753,8 +756,6 @@ public class Groovy extends Java {
*/
protected void printResults(PrintStream out) {
log.debug("printResults()");
-// StringBuilder line = new StringBuilder();
-// out.println(line);
out.println();
}