You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/02 08:20:19 UTC
[1/3] groovy git commit: Minor refactoring
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_6_X 68cb66086 -> f2defdbcf
Minor refactoring
(cherry picked from commit 53b2a07)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/cfd4901c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/cfd4901c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/cfd4901c
Branch: refs/heads/GROOVY_2_6_X
Commit: cfd4901c3b8db81cac40bf1e2fb0fec6e4e4fcac
Parents: 68cb660
Author: sunlan <su...@apache.org>
Authored: Sat Dec 2 15:04:56 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Sat Dec 2 16:19:52 2017 +0800
----------------------------------------------------------------------
src/main/groovy/grape/GrabAnnotationTransformation.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/cfd4901c/src/main/groovy/grape/GrabAnnotationTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/grape/GrabAnnotationTransformation.java b/src/main/groovy/grape/GrabAnnotationTransformation.java
index e0b501f..dd55ff9 100644
--- a/src/main/groovy/grape/GrabAnnotationTransformation.java
+++ b/src/main/groovy/grape/GrabAnnotationTransformation.java
@@ -558,8 +558,9 @@ public class GrabAnnotationTransformation extends ClassCodeVisitorSupport implem
// assume gradle syntax
// see: http://www.gradle.org/latest/docs/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
Map<String, Object> parts = GrapeUtil.getIvyParts(allstr);
- for (String key : parts.keySet()) {
- String value = parts.get(key).toString();
+ for (Map.Entry<String, Object> entry : parts.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue().toString();
if (!key.equals("version") || !value.equals("*") || !exclude) {
node.addMember(key, constX(value));
}
[3/3] groovy git commit: Minor refactoring
Posted by su...@apache.org.
Minor refactoring
(cherry picked from commit 9b29e7f)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f2defdbc
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f2defdbc
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f2defdbc
Branch: refs/heads/GROOVY_2_6_X
Commit: f2defdbcf84cf2114464a1329b2b05eb79efd6eb
Parents: 2d84a1e
Author: sunlan <su...@apache.org>
Authored: Sat Dec 2 16:13:43 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Sat Dec 2 16:20:10 2017 +0800
----------------------------------------------------------------------
src/main/groovy/lang/GroovyShell.java | 16 +++++++++-------
.../org/codehaus/groovy/runtime/InvokerHelper.java | 5 +++--
2 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/f2defdbc/src/main/groovy/lang/GroovyShell.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GroovyShell.java b/src/main/groovy/lang/GroovyShell.java
index a889e51..4dc51c9 100644
--- a/src/main/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/lang/GroovyShell.java
@@ -39,6 +39,8 @@ import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.List;
+import static org.codehaus.groovy.runtime.InvokerHelper.MAIN_METHOD_NAME;
+
/**
* Represents a groovy shell capable of running arbitrary groovy scripts
*
@@ -271,9 +273,9 @@ public class GroovyShell extends GroovyObjectSupport {
}
try {
// let's find a main method
- scriptClass.getMethod("main", String[].class);
+ scriptClass.getMethod(MAIN_METHOD_NAME, String[].class);
// if that main method exist, invoke it
- return InvokerHelper.invokeMethod(scriptClass, "main", new Object[]{args});
+ return InvokerHelper.invokeMethod(scriptClass, MAIN_METHOD_NAME, new Object[]{args});
} catch (NoSuchMethodException e) {
// if it implements Runnable, try to instantiate it
if (Runnable.class.isAssignableFrom(scriptClass)) {
@@ -285,20 +287,20 @@ public class GroovyShell extends GroovyObjectSupport {
return runner.run(scriptClass, this.loader);
}
}
- String message = "This script or class could not be run.\n" +
+ StringBuilder message = new StringBuilder("This script or class could not be run.\n" +
"It should either:\n" +
"- have a main method,\n" +
"- be a JUnit test or extend GroovyTestCase,\n" +
"- implement the Runnable interface,\n" +
- "- or be compatible with a registered script runner. Known runners:\n";
+ "- or be compatible with a registered script runner. Known runners:\n");
if (runnerRegistry.isEmpty()) {
- message += " * <none>";
+ message.append(" * <none>");
} else {
for (String key : runnerRegistry.keySet()) {
- message += " * " + key + "\n";
+ message.append(" * ").append(key).append("\n");
}
}
- throw new GroovyRuntimeException(message);
+ throw new GroovyRuntimeException(message.toString());
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/f2defdbc/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
index 56e7a06..0e3b380 100644
--- a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -84,6 +84,7 @@ public class InvokerHelper {
private static final int ITEM_ALLOCATE_SIZE = 5;
public static final MetaClassRegistry metaRegistry = GroovySystem.getMetaClassRegistry();
+ public static final String MAIN_METHOD_NAME = "main";
public static void removeClass(Class clazz) {
metaRegistry.removeMetaClass(clazz);
@@ -451,7 +452,7 @@ public class InvokerHelper {
} catch (MissingPropertyException e) {
// They'll get empty args since none exist in the context.
}
- object.invokeMethod("main", argsToPass);
+ object.invokeMethod(MAIN_METHOD_NAME, argsToPass);
return null;
}
};
@@ -473,7 +474,7 @@ public class InvokerHelper {
return script;
}
- public static Script newScript(Class scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException {
+ public static Script newScript(Class<?> scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException {
Script script;
try {
Constructor constructor = scriptClass.getConstructor(Binding.class);
[2/3] groovy git commit: Minor refactoring
Posted by su...@apache.org.
Minor refactoring
(cherry picked from commit 5d2fcc6)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/2d84a1e4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2d84a1e4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2d84a1e4
Branch: refs/heads/GROOVY_2_6_X
Commit: 2d84a1e473adf692d40b51a2352eb1a68f44da10
Parents: cfd4901
Author: sunlan <su...@apache.org>
Authored: Sat Dec 2 15:44:47 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Sat Dec 2 16:20:01 2017 +0800
----------------------------------------------------------------------
src/main/groovy/lang/GroovyShell.java | 14 +------------
.../codehaus/groovy/runtime/InvokerHelper.java | 22 +++++++++++++-------
2 files changed, 15 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/2d84a1e4/src/main/groovy/lang/GroovyShell.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GroovyShell.java b/src/main/groovy/lang/GroovyShell.java
index b169e59..a889e51 100644
--- a/src/main/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/lang/GroovyShell.java
@@ -259,24 +259,12 @@ public class GroovyShell extends GroovyObjectSupport {
if (Script.class.isAssignableFrom(scriptClass)) {
// treat it just like a script if it is one
try {
- Constructor constructor = scriptClass.getConstructor(Binding.class);
- Script script = (Script) constructor.newInstance(context);
+ Script script = InvokerHelper.newScript(scriptClass, context);
return script.run();
} catch (InstantiationException e) {
// ignore instantiation errors,, try to do main
} catch (IllegalAccessException e) {
// ignore instantiation errors, try to do main
- } catch (NoSuchMethodException e) {
- try {
- // Fallback for non-standard "Scripts" that don't have contextual constructor.
- Script script = (Script) scriptClass.newInstance();
- script.setBinding(context);
- return script.run();
- } catch (InstantiationException e1) {
- // ignore instantiation errors, try to do main
- } catch (IllegalAccessException e1) {
- // ignore instantiation errors, try to do main
- }
} catch (InvocationTargetException e) {
// ignore instantiation errors, try to do main
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/2d84a1e4/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
index 6f7406a..56e7a06 100644
--- a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -435,14 +435,7 @@ public class InvokerHelper {
} else {
try {
if (Script.class.isAssignableFrom(scriptClass)) {
- try {
- Constructor constructor = scriptClass.getConstructor(Binding.class);
- script = (Script) constructor.newInstance(context);
- } catch (NoSuchMethodException e) {
- // Fallback for non-standard "Script" classes.
- script = (Script) scriptClass.newInstance();
- script.setBinding(context);
- }
+ script = newScript(scriptClass, context);
} else {
final GroovyObject object = (GroovyObject) scriptClass.newInstance();
// it could just be a class, so let's wrap it in a Script
@@ -480,6 +473,19 @@ public class InvokerHelper {
return script;
}
+ public static Script newScript(Class scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException {
+ Script script;
+ try {
+ Constructor constructor = scriptClass.getConstructor(Binding.class);
+ script = (Script) constructor.newInstance(context);
+ } catch (NoSuchMethodException e) {
+ // Fallback for non-standard "Script" classes.
+ script = (Script) scriptClass.newInstance();
+ script.setBinding(context);
+ }
+ return script;
+ }
+
/**
* Sets the properties on the given object
*/