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 2020/03/21 10:13:45 UTC
[groovy] branch GROOVY_3_0_X updated (220fbb2 -> 5e4283b)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 220fbb2 GROOVY-9442: GEP: Support for the new JDK14 string escape sequence (\s for single space) (update doco)
new dd355a4 remove/suppress spotbug warnings
new 5e4283b split groovyc Ant task doco into separate file
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/spec/doc/tools-groovyc.adoc | 190 +------------------
.../src/main/java/groovy/ant/AntBuilder.java | 57 +++---
.../groovy/ant/AntProjectPropertiesDelegate.java | 8 +-
.../main/java/org/codehaus/groovy/ant/Groovy.java | 37 ++--
.../main/java/org/codehaus/groovy/ant/Groovyc.java | 34 ++--
.../java/org/codehaus/groovy/ant/Groovydoc.java | 42 ++---
.../org/codehaus/groovy/ant/RootLoaderRef.java | 51 +++---
.../java/org/codehaus/groovy/ant/VerifyClass.java | 23 +--
.../groovy-ant/src/spec/doc/groovyc-ant-task.adoc | 204 +++++++++++++++++++++
9 files changed, 338 insertions(+), 308 deletions(-)
create mode 100644 subprojects/groovy-ant/src/spec/doc/groovyc-ant-task.adoc
[groovy] 01/02: remove/suppress spotbug warnings
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit dd355a439df985ae44fc8436c9f402b6b0388fed
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Mar 21 17:34:05 2020 +1000
remove/suppress spotbug warnings
---
.../src/main/java/groovy/ant/AntBuilder.java | 57 ++++++++++------------
.../groovy/ant/AntProjectPropertiesDelegate.java | 8 ++-
.../main/java/org/codehaus/groovy/ant/Groovy.java | 37 +++++++-------
.../main/java/org/codehaus/groovy/ant/Groovyc.java | 34 ++++++++-----
.../java/org/codehaus/groovy/ant/Groovydoc.java | 42 ++++++++--------
.../org/codehaus/groovy/ant/RootLoaderRef.java | 51 ++++++++++---------
.../java/org/codehaus/groovy/ant/VerifyClass.java | 23 ++++-----
7 files changed, 131 insertions(+), 121 deletions(-)
diff --git a/subprojects/groovy-ant/src/main/java/groovy/ant/AntBuilder.java b/subprojects/groovy-ant/src/main/java/groovy/ant/AntBuilder.java
index 87d3a80..9f90b35 100644
--- a/subprojects/groovy-ant/src/main/java/groovy/ant/AntBuilder.java
+++ b/subprojects/groovy-ant/src/main/java/groovy/ant/AntBuilder.java
@@ -18,8 +18,9 @@
*/
package groovy.ant;
-import groovy.util.BuilderSupport;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import groovy.namespace.QName;
+import groovy.util.BuilderSupport;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DemuxInputStream;
@@ -102,7 +103,7 @@ public class AntBuilder extends BuilderSupport {
/*
* GROOVY-4524: The following is not needed anymore as an ant Project already by default has inputhandler
* set to DefaultInputHandler. And if it is again set here, it mistakenly overrides the custom input handler
- * if set using -inputhandler switch.
+ * if set using -inputhandler switch.
*/
//this.project.setInputHandler(new DefaultInputHandler());
@@ -229,6 +230,7 @@ public class AntBuilder extends BuilderSupport {
* @param parent note: null when node is root
* @param node the node that now has all its children applied
*/
+ @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "False positive: bytecode needlessly but harmlessly assigns local to JVM register")
protected void nodeCompleted(final Object parent, final Object node) {
if (parent == null) insideTask = false;
antElementHandler.onEndElement(null, null, antXmlContext);
@@ -255,7 +257,7 @@ public class AntBuilder extends BuilderSupport {
if (saveStreams) {
// save original streams
synchronized (AntBuilder.class) {
- int currentStreamCount = streamCount++;
+ int currentStreamCount = streamCount++; // SuppressFBWarnings: DLS_DEAD_LOCAL_STORE
if (currentStreamCount == 0) {
// we are first, save the streams
savedProjectInputStream = project.getDefaultInputStream();
@@ -269,9 +271,9 @@ public class AntBuilder extends BuilderSupport {
System.setIn(demuxInputStream);
}
demuxOutputStream = new DemuxOutputStream(project, false);
- System.setOut(new PrintStream(demuxOutputStream));
+ System.setOut(printStream(demuxOutputStream));
demuxErrorStream = new DemuxOutputStream(project, true);
- System.setErr(new PrintStream(demuxErrorStream));
+ System.setErr(printStream(demuxErrorStream));
}
}
}
@@ -314,6 +316,12 @@ public class AntBuilder extends BuilderSupport {
}
}
+ @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "We are only wrapping stdout/stderr which are likely created with default encoding")
+ private PrintStream printStream(DemuxOutputStream outputStream) {
+ // we could make a saveStreamEncoding but seems like a rare scenario
+ return new PrintStream(outputStream);
+ }
+
// Copied from org.apache.tools.ant.Task, since we need to get a real thing before it gets nulled in DispatchUtils.execute
private Object performTask(Task task) {
@@ -335,31 +343,26 @@ public class AntBuilder extends BuilderSupport {
DispatchUtils.execute(task);
return realThing != null ? realThing : task;
- }
- catch (BuildException ex) {
+ } catch (BuildException ex) {
if (ex.getLocation() == Location.UNKNOWN_LOCATION) {
ex.setLocation(task.getLocation());
}
reason = ex;
throw ex;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
reason = ex;
BuildException be = new BuildException(ex);
be.setLocation(task.getLocation());
throw be;
- }
- catch (Error ex) {
+ } catch (Error ex) {
reason = ex;
throw ex;
- }
- finally {
+ } finally {
try {
final Method fireTaskFinished = Project.class.getDeclaredMethod("fireTaskFinished", Task.class, Throwable.class);
ReflectionUtils.trySetAccessible(fireTaskFinished);
fireTaskFinished.invoke(project, task, reason);
- }
- catch (Exception e) {
+ } catch (Exception e) {
BuildException be = new BuildException(e);
be.setLocation(task.getLocation());
throw be;
@@ -423,8 +426,7 @@ public class AntBuilder extends BuilderSupport {
try {
antElementHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
- }
- catch (final SAXParseException e) {
+ } catch (final SAXParseException e) {
log.log(Level.SEVERE, "Caught: " + e, e);
}
@@ -434,33 +436,26 @@ public class AntBuilder extends BuilderSupport {
}
private Target onDefineTarget(final Attributes attrs, String tagName, String ns) {
- final Target target = new Target();
- target.setProject(project);
- target.setLocation(new Location(antXmlContext.getLocator()));
try {
antTargetHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
final Target newTarget = getProject().getTargets().get(attrs.getValue("name"));
antXmlContext.setCurrentTarget(newTarget);
definingTarget = newTarget;
return newTarget;
- }
- catch (final SAXParseException e) {
+ } catch (final SAXParseException e) {
log.log(Level.SEVERE, "Caught: " + e, e);
+ return null;
}
- return null;
}
private Target onStartTarget(final Attributes attrs, String tagName, String ns) {
- final Target target = new Target();
- target.setProject(project);
- target.setLocation(new Location(antXmlContext.getLocator()));
try {
antTargetHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
final Target newTarget = getProject().getTargets().get(attrs.getValue("name"));
// execute dependencies (if any)
final Vector<Target> targets = new Vector<Target>();
- for (final Enumeration<String> deps = newTarget.getDependencies(); deps.hasMoreElements();) {
+ for (final Enumeration<String> deps = newTarget.getDependencies(); deps.hasMoreElements(); ) {
final String targetName = deps.nextElement();
targets.add(project.getTargets().get(targetName));
}
@@ -468,19 +463,17 @@ public class AntBuilder extends BuilderSupport {
antXmlContext.setCurrentTarget(newTarget);
return newTarget;
- }
- catch (final SAXParseException e) {
+ } catch (final SAXParseException e) {
log.log(Level.SEVERE, "Caught: " + e, e);
+ return null;
}
- return null;
}
protected void setText(Object task, String text) {
final char[] characters = text.toCharArray();
try {
antElementHandler.characters(characters, 0, characters.length, antXmlContext);
- }
- catch (final SAXParseException e) {
+ } catch (final SAXParseException e) {
log.log(Level.WARNING, "SetText failed: " + task + ". Reason: " + e, e);
}
}
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
index 5b511e6..273cdee 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
@@ -18,6 +18,7 @@
*/
package org.codehaus.groovy.ant;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.tools.ant.Project;
import java.util.Collection;
@@ -28,7 +29,9 @@ import java.util.Set;
public class AntProjectPropertiesDelegate extends Hashtable {
- private final Project project;
+ private transient final Project project;
+
+ private static final long serialVersionUID = -8311751517184349962L;
public AntProjectPropertiesDelegate(Project project) {
super();
@@ -45,7 +48,7 @@ public class AntProjectPropertiesDelegate extends Hashtable {
/**
* @throws UnsupportedOperationException is always thrown when this method is invoked. The Project properties are immutable.
- */
+ */
public synchronized void clear() {
throw new UnsupportedOperationException("Impossible to clear the project properties.");
}
@@ -54,6 +57,7 @@ public class AntProjectPropertiesDelegate extends Hashtable {
return project.getProperties().isEmpty();
}
+ @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Okay for our use case. The cloned delegate should have the correct type.")
public synchronized Object clone() {
return project.getProperties().clone();
}
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 8cca415..a2cbcc8 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
@@ -67,7 +67,9 @@ public class Groovy extends Java {
private static final String PREFIX = "embedded_script_in_";
private static final String SUFFIX = "groovy_Ant_task";
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
- /** encoding; set to null or empty means 'default' */
+ /**
+ * encoding; set to null or empty means 'default'
+ */
private String encoding = null;
private final LoggingHelper log = new LoggingHelper(this);
@@ -129,6 +131,7 @@ public class Groovy extends Java {
/**
* Declare the encoding to use when outputting to a file;
* Use "" for the platform's default encoding.
+ *
* @param encoding the character encoding to use.
* @since 3.0.3
*/
@@ -276,6 +279,7 @@ public class Groovy extends Java {
/**
* Set the script base class name
+ *
* @param scriptBaseClass the name of the base class for scripts
*/
public void setScriptBaseClass(final String scriptBaseClass) {
@@ -446,8 +450,7 @@ public class Groovy extends Java {
ReflectionUtils.trySetAccessible(contextField);
final Object context = contextField.get(propsHandler);
mavenPom = InvokerHelper.invokeMethod(context, "getProject", EMPTY_OBJECT_ARRAY);
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new BuildException("Impossible to retrieve Maven's Ant project: " + e.getMessage(), getLocation());
}
// load groovy into "root.maven" classloader instead of "root" so that
@@ -478,14 +481,14 @@ public class Groovy extends Java {
}
private void configureCompiler() {
- if (scriptBaseClass!=null) {
+ if (scriptBaseClass != null) {
configuration.setScriptBaseClass(scriptBaseClass);
}
if (indy) {
configuration.getOptimizationOptions().put("indy", Boolean.TRUE);
configuration.getOptimizationOptions().put("int", Boolean.FALSE);
}
- if (configscript!=null) {
+ if (configscript != null) {
Binding binding = new Binding();
binding.setVariable("configuration", configuration);
@@ -499,7 +502,7 @@ public class Groovy extends Java {
try {
shell.evaluate(confSrc);
} catch (IOException e) {
- throw new BuildException("Unable to configure compiler using configuration file: "+confSrc, e);
+ throw new BuildException("Unable to configure compiler using configuration file: " + confSrc, e);
}
}
}
@@ -523,8 +526,7 @@ public class Groovy extends Java {
script.setProperty("pom", mavenPom);
}
script.run();
- }
- catch (final MissingMethodException mme) {
+ } catch (final MissingMethodException mme) {
// not a script, try running through run method but properties will not be available
if (scriptFile != null) {
try {
@@ -535,8 +537,7 @@ public class Groovy extends Java {
} else {
shell.run(txt, scriptName, cmdline.getCommandline());
}
- }
- catch (final CompilationFailedException | IOException e) {
+ } catch (final CompilationFailedException | IOException e) {
processError(e);
}
}
@@ -594,14 +595,16 @@ public class Groovy extends Java {
throw new IllegalStateException("GROOVY_HOME incorrectly defined. No lib directory found in: " + groovyHome);
}
final File[] files = jarDir.listFiles();
- for (File file : files) {
- try {
- log.debug("Adding jar to classpath: " + file.getCanonicalPath());
- } catch (IOException e) {
- // ignore
+ if (files != null) {
+ for (File file : files) {
+ try {
+ log.debug("Adding jar to classpath: " + file.getCanonicalPath());
+ } catch (IOException e) {
+ // ignore
+ }
+ path = super.createClasspath();
+ path.setLocation(file);
}
- path = super.createClasspath();
- path.setLocation(file);
}
}
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index 1119936..de46112 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -18,6 +18,7 @@
*/
package org.codehaus.groovy.ant;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import groovy.lang.GroovyClassLoader;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import org.apache.groovy.io.StringBuilderWriter;
@@ -940,7 +941,7 @@ public class Groovyc extends MatchingTask {
* @return the list of files as an array
*/
public File[] getFileList() {
- return compileList;
+ return Arrays.copyOf(compileList, compileList.length);
}
protected void checkParameters() throws BuildException {
@@ -1027,10 +1028,13 @@ public class Groovyc extends MatchingTask {
|| key.equals("source")
|| key.equals("target")) {
switch (key) {
- case "nativeheaderdir":
- key = "h"; break;
- case "release":
- key = "-" + key; // to get "--" when passed to javac
+ case "nativeheaderdir":
+ key = "h";
+ break;
+ case "release":
+ key = "-" + key; // to get "--" when passed to javac
+ break;
+ default:
}
// map "depend", "encoding", etc. to "-Jkey=val"
jointOptions.add("-J" + key + "=" + getProject().replaceProperties(e.getValue().toString()));
@@ -1101,14 +1105,14 @@ public class Groovyc extends MatchingTask {
bootstrapClasspath = ((AntClassLoader) loader).getClasspath().split(File.pathSeparator);
} else {
Class<?>[] bootstrapClasses = {
- FileSystemCompilerFacade.class,
- FileSystemCompiler.class,
- ParseTreeVisitor.class,
- ClassVisitor.class,
- CommandLine.class,
+ FileSystemCompilerFacade.class,
+ FileSystemCompiler.class,
+ ParseTreeVisitor.class,
+ ClassVisitor.class,
+ CommandLine.class,
};
bootstrapClasspath = Arrays.stream(bootstrapClasses).map(Groovyc::getLocation)
- .map(uri -> new File(uri).getAbsolutePath()).distinct().toArray(String[]::new);
+ .map(uri -> new File(uri).getAbsolutePath()).distinct().toArray(String[]::new);
}
if (bootstrapClasspath.length > 0) {
commandLineList.add("-classpath");
@@ -1233,7 +1237,7 @@ public class Groovyc extends MatchingTask {
try {
File tempFile = File.createTempFile("groovyc-files-", ".txt");
temporaryFiles.add(tempFile);
- PrintWriter pw = new PrintWriter(new FileWriter(tempFile));
+ PrintWriter pw = printWriter(tempFile);
for (File srcFile : compileList) {
pw.println(srcFile.getPath());
}
@@ -1249,6 +1253,12 @@ public class Groovyc extends MatchingTask {
}
}
+ @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "This is only used to store filenames when exceeding a particular length limit when in fork mode")
+ private PrintWriter printWriter(File tempFile) throws IOException {
+ // we could make a forkFileListEncoding but seems like a rare scenario
+ return new PrintWriter(new FileWriter(tempFile));
+ }
+
private String[] makeCommandLine(List<String> commandLineList) {
log.info("Compilation arguments:\n" + DefaultGroovyMethods.join((Iterable<String>) commandLineList, "\n"));
return commandLineList.toArray(EMPTY_STRING_ARRAY);
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java
index 3e1c283..4a50d9b 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java
@@ -32,7 +32,6 @@ import org.codehaus.groovy.tools.groovydoc.LinkArgument;
import org.codehaus.groovy.tools.groovydoc.gstringTemplates.GroovyDocTemplateInfo;
import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -331,7 +330,7 @@ public class Groovydoc extends Task {
* elements.
*
* @param resultantPackages a list to which we add the packages found
- * @param sourcePath a path to which we add each basedir found
+ * @param sourcePath a path to which we add each basedir found
* @since 1.5
*/
private void parsePackages(List<String> resultantPackages, Path sourcePath) {
@@ -399,21 +398,22 @@ public class Groovydoc extends Task {
return false;
});
- for (String filename : files) {
- sourceFilesToDoc.add(dir + File.separator + filename);
- }
-
- if (files.length > 0) {
- if (dir.isEmpty()) {
- log.warn(baseDir
- + " contains source files in the default package,"
- + " you must specify them as source files not packages.");
- } else {
- containsPackages = true;
- String pn = dir.replace(File.separatorChar, '.');
- if (!addedPackages.contains(pn)) {
- addedPackages.add(pn);
- resultantPackages.add(pn);
+ if (files != null) {
+ for (String filename : files) {
+ sourceFilesToDoc.add(dir + File.separator + filename);
+ }
+ if (files.length > 0) {
+ if (dir.isEmpty()) {
+ log.warn(baseDir
+ + " contains source files in the default package,"
+ + " you must specify them as source files not packages.");
+ } else {
+ containsPackages = true;
+ String pn = dir.replace(File.separatorChar, '.');
+ if (!addedPackages.contains(pn)) {
+ addedPackages.add(pn);
+ resultantPackages.add(pn);
+ }
}
}
}
@@ -509,12 +509,12 @@ public class Groovydoc extends Task {
links.add(result);
return result;
}
-
+
/**
* Creates and returns an array of package template classpath entries.
* <p>
* This method is meant to be overridden by custom GroovyDoc implementations, using custom package templates.
- *
+ *
* @return an array of package templates, whereas each entry is resolved as classpath entry, defaults to
* {@link GroovyDocTemplateInfo#DEFAULT_PACKAGE_TEMPLATES}.
*/
@@ -526,7 +526,7 @@ public class Groovydoc extends Task {
* Creates and returns an array of doc template classpath entries.
* <p>
* This method is meant to be overridden by custom GroovyDoc implementations, using custom doc templates.
- *
+ *
* @return an array of doc templates, whereas each entry is resolved as classpath entry, defaults to
* {@link GroovyDocTemplateInfo#DEFAULT_DOC_TEMPLATES}.
*/
@@ -538,7 +538,7 @@ public class Groovydoc extends Task {
* Creates and returns an array of class template classpath entries.
* <p>
* This method is meant to be overridden by custom GroovyDoc implementations, using custom class templates.
- *
+ *
* @return an array of class templates, whereas each entry is resolved as classpath entry, defaults to
* {@link GroovyDocTemplateInfo#DEFAULT_CLASS_TEMPLATES}.
*/
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/RootLoaderRef.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/RootLoaderRef.java
index 27e7c79..5055383 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/RootLoaderRef.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/RootLoaderRef.java
@@ -27,10 +27,12 @@ import org.apache.tools.ant.types.Reference;
import org.codehaus.groovy.tools.LoaderConfiguration;
import org.codehaus.groovy.tools.RootLoader;
-
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
/**
* Sets the RootLoader as reference.
- * Reexecution of this task will set a new instance of RootLoader for
+ * Re-execution of this task will set a new instance of RootLoader for
* the reference.
*
* arguments:
@@ -38,61 +40,57 @@ import org.codehaus.groovy.tools.RootLoader;
* <li>ref</li>
* <li>classpath</li>
* </ul>
- *
+ *
* all arguments are required.
*
* As ant requires an AntClassLoader as reference, this will create a RootLoader
* and set an AntClassLoader as child and stored in the reference. The AntClassLoader
* instance will not have a classpath nor will it have access to the classpath somehow,
- * all loading is done by the RootLoader parent. To avoid problems with loading classes
+ * all loading is done by the RootLoader parent. To avoid problems with loading classes
* multiple times and using them at the same time, this task will filter out the ant jars
* and the commons-logging jars. This only works if the ant jars are starting with "ant-" and
* the logging jar starts with "commons-logging-".
- *
+ *
* This was needed because if ant wants to access a task argument that uses for example a Path
* it look for a matching method which includes a matching class. But two classes of the same name
- * with different classloaders are different, so ant would not be able to find the method.
+ * with different class loaders are different, so ant would not be able to find the method.
*
* @see org.codehaus.groovy.tools.RootLoader
*/
public class RootLoaderRef extends MatchingTask {
private String name;
private Path taskClasspath;
-
+
/**
* sets the name of the reference which should store the Loader
*/
- public void setRef(String n){
+ public void setRef(String n) {
name = n;
}
-
+
public void execute() throws BuildException {
- if (taskClasspath==null || taskClasspath.size()==0) {
+ if (taskClasspath == null || taskClasspath.size() == 0) {
throw new BuildException("no classpath given");
}
Project project = getProject();
- AntClassLoader loader = new AntClassLoader(makeRoot(),true);
- project.addReference(name,loader);
- }
-
- private RootLoader makeRoot() {
String[] list = taskClasspath.list();
LoaderConfiguration lc = new LoaderConfiguration();
- for (int i=0; i<list.length; i++) {
- if (list[i].matches(".*ant-[^/]*jar$")) {
+ for (String s : list) {
+ if (s.matches(".*ant-[^/]*jar$")) {
continue;
}
- if (list[i].matches(".*commons-logging-[^/]*jar$")) {
+ if (s.matches(".*commons-logging-[^/]*jar$")) {
continue;
}
- if (list[i].matches(".*xerces-[^/]*jar$")) {
+ if (s.matches(".*xerces-[^/]*jar$")) {
continue;
}
- lc.addFile(list[i]);
+ lc.addFile(s);
}
- return new RootLoader(lc);
+ AntClassLoader loader = AccessController.doPrivileged((PrivilegedAction<AntClassLoader>) () -> new AntClassLoader(new RootLoader(lc), true));
+ project.addReference(name, loader);
}
-
+
/**
* Set the classpath to be used for this compilation.
*
@@ -101,22 +99,23 @@ public class RootLoaderRef extends MatchingTask {
public void setClasspath(Path classpath) {
if (taskClasspath == null) {
taskClasspath = classpath;
- }
- else {
+ } else {
taskClasspath.append(classpath);
}
}
-
+
/**
* Adds a reference to a classpath defined elsewhere.
+ *
* @param r a reference to a classpath
*/
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
}
-
+
/**
* Adds a path to the classpath.
+ *
* @return a class path to be configured
*/
public Path createClasspath() {
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/VerifyClass.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/VerifyClass.java
index 975c4c5..25249b8 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/VerifyClass.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/VerifyClass.java
@@ -78,17 +78,18 @@ public class VerifyClass extends MatchingTask {
private int execute(File dir) {
int fails = 0;
File[] files = dir.listFiles();
- for (int i = 0; i < files.length; i++) {
- File f = files[i];
- if (f.isDirectory()) {
- fails += execute(f);
- } else if (f.getName().endsWith(".class")) {
- try {
- boolean ok = readClass(f.getCanonicalPath());
- if (!ok) fails++;
- } catch (IOException ioe) {
- log(ioe.getMessage());
- throw new BuildException(ioe);
+ if (files != null) {
+ for (File f : files) {
+ if (f.isDirectory()) {
+ fails += execute(f);
+ } else if (f.getName().endsWith(".class")) {
+ try {
+ boolean ok = readClass(f.getCanonicalPath());
+ if (!ok) fails++;
+ } catch (IOException ioe) {
+ log(ioe.getMessage());
+ throw new BuildException(ioe);
+ }
}
}
}
[groovy] 02/02: split groovyc Ant task doco into separate file
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 5e4283b3c8a58af42a44e40a5ce1d538ad38ca22
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Mar 21 20:09:38 2020 +1000
split groovyc Ant task doco into separate file
---
src/spec/doc/tools-groovyc.adoc | 190 +------------------
.../groovy-ant/src/spec/doc/groovyc-ant-task.adoc | 204 +++++++++++++++++++++
2 files changed, 207 insertions(+), 187 deletions(-)
diff --git a/src/spec/doc/tools-groovyc.adoc b/src/spec/doc/tools-groovyc.adoc
index 6d81049..6193db6 100644
--- a/src/spec/doc/tools-groovyc.adoc
+++ b/src/spec/doc/tools-groovyc.adoc
@@ -61,192 +61,8 @@ a number of command line switches:
== Ant task
-[[ThegroovycAntTask-groovyc]]
-`<groovyc>`
-~~~~~~~~~~~
-
-[[ThegroovycAntTask-Description]]
-Description
-^^^^^^^^^^^
-
-Compiles Groovy source files and, if joint compilation option is used, Java source files.
-
-[[ThegroovycAntTask-Requiredtaskdef]]
-Required taskdef
-^^^^^^^^^^^^^^^^
-
-Assuming the groovy jars are in _groovy.libs_, you will need to declare this task
-at some point in the `build.xml` prior to the `groovyc` task being invoked.
-
-[source,xml]
------------------------------------------------------------------------
-<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
- <classpath>
- <fileset file="${groovy.libs}/groovy-ant-VERSION.jar"/>
- <fileset file="${groovy.libs}/groovy-VERSION.jar"/>
- </classpath>
-</taskdef>
------------------------------------------------------------------------
-
-[[ThegroovycAntTask-groovycAttributes]]
-<groovyc> Attributes
-^^^^^^^^^^^^^^^^^^^^
-
-[cols="<,<,<",options="header,footer"]
-|=======================================================================
-|Attribute |Description |Required
-
-|srcdir |Location of the Groovy (and possibly Java) source files. |Yes
-
-|destdir |Location to store the class files. |Yes
-
-|classpath |The classpath to use. |No
-
-|classpathref |The classpath to use given as a path references. |No
-
-|sourcepath |The sourcepath to use. |No
-
-|sourcepathref |The sourcepath to use given as a path reference. |No
-
-|encoding |Encoding of source files. |No
-
-|verbose |Asks the compiler for verbose output; defaults to no. |No
-
-|includeAntRuntime |Whether to include the Ant run-time libraries in the
-classpath; defaults to yes. |No
-
-|includeJavaRuntime |Whether to include the default run-time libraries
-from the executing VM in the classpath; defaults to no. |No
-
-|includeDestClasses |This property controls whether to include the destination
-classes directory in the classpath given to the compiler. The default value is "true". |No
-
-|fork |Whether to execute groovyc using a spawned instance of the JVM;
-defaults to no. |No
-
-|memoryInitialSize |The initial size of the memory for the underlying
-VM, if using fork mode; ignored otherwise. Defaults to the standard VM
-memory setting. (Examples: 83886080, 81920k, or 80m) |No
-
-|memoryMaximumSize |The maximum size of the memory for the underlying
-VM, if using fork mode; ignored otherwise. Defaults to the standard VM
-memory setting. (Examples: 83886080, 81920k, or 80m) |No
-
-|failonerror |Indicates whether compilation errors will fail the build;
-defaults to true. |No
-
-|proceed |Inverse alias for _failonerror_. |No
-
-|listfiles |Indicates whether the source files to be compiled will be
-listed; defaults to no. |No
-
-|stacktrace |if true each compile error message will contain a
-stacktrace |No
-
-|indy |Enable compilation with the ``invoke dynamic'' support when using
-Groovy 2.0 and beyond and running on JDK 7 |No
-
-|scriptBaseClass |Sets the base class for Groovy scripts |No
-
-|stubdir |Set the stub directory into which the Java source stub files should be generated.
-The directory need not exist and will not be deleted automatically - though its contents
-will be cleared unless 'keepStubs' is true. Ignored when forked. |No
-
-|keepStubs |Set the keepStubs flag. Defaults to false. Set to true for debugging.
-Ignored when forked. |No
-
-|forceLookupUnnamedFiles |The Groovyc Ant task is frequently used in the context of a build system
-that knows the complete list of source files to be compiled. In such a
-context, it is wasteful for the Groovy compiler to go searching the
-classpath when looking for source files and hence by default the
-Groovyc Ant task calls the compiler in a special mode with such searching
-turned off. If you wish the compiler to search for source files then
-you need to set this flag to true. Defaults to false. |No
-
-|configscript |Set the configuration file used to customize the compilation configuration. |No
-
-|parameters |Generates metadata for reflection on method parameter names on JDK 8 and above.
-Defaults to false. |No
-
-|previewFeatures |Enables the JEP preview features on JDK 12 and above.
-Defaults to false. |No
-
-|targetBytecode |Sets the bytecode compatibility level. |No
-
-|javahome |Sets the `java.home` value to use, default is the current JDK's home. |No
-
-|executable |Sets the name of the java executable to use when invoking the compiler in forked mode,
-ignored otherwise. |No
-
-|scriptExtension |Set the extension to use when searching for Groovy source files.
-Accepts extensions in the form *.groovy, .groovy or groovy. |No
-
-|updatedProperty |The property to set on compilation success. This property will not be set if
-the compilation fails, or if there are no files to compile. |No
-
-|errorProperty |The property to set on compilation failure. This property will be set if
-the compilation fails. |No
-
-|=======================================================================
-
-*Example:*
-
-[source,xml]
------------------------------------------------------------------------
-<path id="classpath.main">
- <fileset dir="${groovy.libs}" includes="*.jar" excludes="groovy-ant-*.jar"/>
- ...
-</path>
-<groovyc srcdir="${dir.sources}" destdir="${dir.classes}" classpathref="classpath.main"
- fork="true" includeantruntime="false" configscript="config.groovy" targetBytecode="1.8"/>
------------------------------------------------------------------------
-
-
-[[ThegroovycAntTask-groovycNestedElements]]
-<groovyc> Nested Elements
-^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[cols="<,<,<,<",options="header,footer"]
-|==========================================================
-|element |kind |Required |Replaces Attribute
-|src |a path structure |Yes (unless srcdir is used) |srcdir
-|classpath |a path structure |No |classpath or classpathref
-|javac |javac task |No |N/A
-|==========================================================
-
-*Notes:*
-
-* For path structures see for example
-http://ant.apache.org/manual/using.html#path
-* For usages of the `javac` task see
-https://ant.apache.org/manual/Tasks/javac.html
-* The nested `javac` task behaves more or less as documented for the top-level
-`javac` task. `srcdir`, `destdir`, `classpath`, `encoding` and `parameters`
-for the nested `javac` task are taken from the enclosing `groovyc` task. If
-these attributes are specified then they are added, they do not replace. In fact,
-you should not attempt to overwrite the destination. Other attributes and nested
-elements are unaffected, for example `fork`, `memoryMaximumSize`, etc. may be
-used freely.
-
-[[ThegroovycAntTask-JointCompilation]]
-Joint Compilation
-^^^^^^^^^^^^^^^^^
-
-Joint compilation is enabled by using an embedded `javac` element, as shown in the following example:
-
-[source,xml]
------------------------------------------------------------------------
-<groovyc srcdir="${testSourceDirectory}" destdir="${testClassesDirectory}" targetBytecode="1.8">
- <classpath>
- <pathelement path="${mainClassesDirectory}"/>
- <pathelement path="${testClassesDirectory}"/>
- <path refid="testPath"/>
- </classpath>
- <javac debug="true" source="1.8" target="1.8" />
-</groovyc>
------------------------------------------------------------------------
-
-More details about joint compilation can be found in the <<section-jointcompilation,joint compilation>> section.
+See the <<groovyc-ant-task.adoc#ThegroovycAntTask-groovyc,groovyc Ant task>> documentation.
+It allows the Groovy compiler to be invoked from http://ant.apache.org/[Apache Ant].
[[Gant]]
== Gant
@@ -433,7 +249,7 @@ for the Ant task.
It is important to know that if you don't enable joint compilation and try to compile
Java source files with the Groovy compiler, the Java source files will be compiled as
if they were Groovy sources. In some situations, this might work since most of the Java
-syntax is compatible with Groovy, but semantics would be different.
+syntax is compatible with Groovy, but there are a number of places where semantics could be different.
[[section-android]]
== Android support
diff --git a/subprojects/groovy-ant/src/spec/doc/groovyc-ant-task.adoc b/subprojects/groovy-ant/src/spec/doc/groovyc-ant-task.adoc
new file mode 100644
index 0000000..d157d5f
--- /dev/null
+++ b/subprojects/groovy-ant/src/spec/doc/groovyc-ant-task.adoc
@@ -0,0 +1,204 @@
+//////////////////////////////////////////
+
+ 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.
+
+//////////////////////////////////////////
+
+= The <groovyc> Ant Task
+
+[[ThegroovycAntTask-groovyc]]
+== `<groovyc>`
+
+[[ThegroovycAntTask-Description]]
+=== Description
+
+Compiles Groovy source files and, if joint compilation option is used, Java source files from http://ant.apache.org/[Apache Ant].
+
+[[ThegroovycAntTask-Requiredtaskdef]]
+=== Required taskdef
+
+Assuming the groovy jars are in _groovy.libs_, you will need to declare this task
+at some point in the `build.xml` prior to the `groovyc` task being invoked.
+Consider also adding any additional Groovy module jars, libraries and potentially transitive dependencies you might be using.
+
+[source,xml]
+-----------------------------------------------------------------------
+<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
+ <classpath>
+ <fileset file="${groovy.libs}/groovy-ant-VERSION.jar"/>
+ <fileset file="${groovy.libs}/groovy-VERSION.jar"/>
+ </classpath>
+</taskdef>
+-----------------------------------------------------------------------
+
+[[ThegroovycAntTask-groovycAttributes]]
+=== <groovyc> Attributes
+
+[cols="<,<,<",options="header,footer"]
+|=======================================================================
+|Attribute |Description |Required
+
+|srcdir |Location of the Groovy (and possibly Java) source files. |Yes
+
+|destdir |Location to store the class files. |Yes
+
+|classpath |The classpath to use. |No
+
+|classpathref |The classpath to use given as a path references. |No
+
+|sourcepath |The sourcepath to use. |No
+
+|sourcepathref |The sourcepath to use given as a path reference. |No
+
+|encoding |Encoding of source files. |No
+
+|verbose |Asks the compiler for verbose output; defaults to no. |No
+
+|includeAntRuntime |Whether to include the Ant run-time libraries in the
+classpath; defaults to yes. |No
+
+|includeJavaRuntime |Whether to include the default run-time libraries
+from the executing VM in the classpath; defaults to no. |No
+
+|includeDestClasses |This property controls whether to include the destination
+classes directory in the classpath given to the compiler. The default value is "true". |No
+
+|fork |Whether to execute groovyc using a spawned instance of the JVM;
+defaults to no. |No
+
+|memoryInitialSize |The initial size of the memory for the underlying
+VM, if using fork mode; ignored otherwise. Defaults to the standard VM
+memory setting. (Examples: 83886080, 81920k, or 80m) |No
+
+|memoryMaximumSize |The maximum size of the memory for the underlying
+VM, if using fork mode; ignored otherwise. Defaults to the standard VM
+memory setting. (Examples: 83886080, 81920k, or 80m) |No
+
+|failonerror |Indicates whether compilation errors will fail the build;
+defaults to true. |No
+
+|proceed |Inverse alias for _failonerror_. |No
+
+|listfiles |Indicates whether the source files to be compiled will be
+listed; defaults to no. |No
+
+|stacktrace |if true each compile error message will contain a
+stacktrace |No
+
+|indy |Enable compilation with the ``invoke dynamic'' support when using
+Groovy 2.0 and beyond and running on JDK 7 |No
+
+|scriptBaseClass |Sets the base class for Groovy scripts |No
+
+|stubdir |Set the stub directory into which the Java source stub files should be generated.
+The directory need not exist and will not be deleted automatically - though its contents
+will be cleared unless 'keepStubs' is true. Ignored when forked. |No
+
+|keepStubs |Set the keepStubs flag. Defaults to false. Set to true for debugging.
+Ignored when forked. |No
+
+|forceLookupUnnamedFiles |The Groovyc Ant task is frequently used in the context of a build system
+that knows the complete list of source files to be compiled. In such a
+context, it is wasteful for the Groovy compiler to go searching the
+classpath when looking for source files and hence by default the
+Groovyc Ant task calls the compiler in a special mode with such searching
+turned off. If you wish the compiler to search for source files then
+you need to set this flag to true. Defaults to false. |No
+
+|configscript |Set the configuration file used to customize the compilation configuration. |No
+
+|parameters |Generates metadata for reflection on method parameter names on JDK 8 and above.
+Defaults to false. |No
+
+|previewFeatures |Enables the JEP preview features on JDK 12 and above.
+Defaults to false. |No
+
+|targetBytecode |Sets the bytecode compatibility level. |No
+
+|javahome |Sets the `java.home` value to use, default is the current JDK's home. |No
+
+|executable |Sets the name of the java executable to use when invoking the compiler in forked mode,
+ignored otherwise. |No
+
+|scriptExtension |Set the extension to use when searching for Groovy source files.
+Accepts extensions in the form *.groovy, .groovy or groovy. |No
+
+|updatedProperty |The property to set on compilation success. This property will not be set if
+the compilation fails, or if there are no files to compile. |No
+
+|errorProperty |The property to set on compilation failure. This property will be set if
+the compilation fails. |No
+
+|=======================================================================
+
+*Example:*
+
+[source,xml]
+-----------------------------------------------------------------------
+<path id="classpath.main">
+ <fileset dir="${groovy.libs}" includes="*.jar" excludes="groovy-ant-*.jar"/>
+ ...
+</path>
+<groovyc srcdir="${dir.sources}" destdir="${dir.classes}" classpathref="classpath.main"
+ fork="true" includeantruntime="false" configscript="config.groovy" targetBytecode="1.8"/>
+-----------------------------------------------------------------------
+
+
+[[ThegroovycAntTask-groovycNestedElements]]
+=== <groovyc> Nested Elements
+
+[cols="<,<,<,<",options="header,footer"]
+|==========================================================
+|element |kind |Required |Replaces Attribute
+|src |a path structure |Yes (unless srcdir is used) |srcdir
+|classpath |a path structure |No |classpath or classpathref
+|javac |javac task |No |N/A
+|==========================================================
+
+*Notes:*
+
+* For path structures see for example
+http://ant.apache.org/manual/using.html#path
+* For usages of the `javac` task see
+https://ant.apache.org/manual/Tasks/javac.html
+* The nested `javac` task behaves more or less as documented for the top-level
+`javac` task. `srcdir`, `destdir`, `classpath`, `encoding` and `parameters`
+for the nested `javac` task are taken from the enclosing `groovyc` task. If
+these attributes are specified then they are added, they do not replace. In fact,
+you should not attempt to overwrite the destination. Other attributes and nested
+elements are unaffected, for example `fork`, `memoryMaximumSize`, etc. may be
+used freely.
+
+[[ThegroovycAntTask-JointCompilation]]
+=== Joint Compilation
+
+Joint compilation is enabled by using an embedded `javac` element, as shown in the following example:
+
+[source,xml]
+-----------------------------------------------------------------------
+<groovyc srcdir="${testSourceDirectory}" destdir="${testClassesDirectory}" targetBytecode="1.8">
+ <classpath>
+ <pathelement path="${mainClassesDirectory}"/>
+ <pathelement path="${testClassesDirectory}"/>
+ <path refid="testPath"/>
+ </classpath>
+ <javac debug="true" source="1.8" target="1.8" />
+</groovyc>
+-----------------------------------------------------------------------
+
+More details about joint compilation can be found in the <<tools-groovyc.adoc#section-jointcompilation,joint compilation>> section.