incubator-groovy git commit: Decouple XStream from SourceUnit and AntlrParserPlugin to prevent ClassNotFoundException

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

incubator-groovy git commit: Decouple XStream from SourceUnit and AntlrParserPlugin to prevent ClassNotFoundException

cchampeau
Repository: incubator-groovy
Updated Branches:
  refs/heads/master e9ae562c7 -> 058dd40f0


Decouple XStream from SourceUnit and AntlrParserPlugin to prevent ClassNotFoundException


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/058dd40f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/058dd40f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/058dd40f

Branch: refs/heads/master
Commit: 058dd40f04096bb4e9aa0a5cb8ece73991a34eed
Parents: e9ae562
Author: Cedric Champeau <[hidden email]>
Authored: Fri Jun 12 01:25:20 2015 +0200
Committer: Cedric Champeau <[hidden email]>
Committed: Fri Jun 12 01:25:34 2015 +0200

----------------------------------------------------------------------
 .../groovy/antlr/AntlrParserPlugin.java         | 66 +++++++++++++++-----
 .../org/codehaus/groovy/control/SourceUnit.java | 12 +---
 .../codehaus/groovy/control/XStreamUtils.java   | 35 +++++++++++
 3 files changed, 86 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/058dd40f/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index 25e3843..6359f9c 100644
--- a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -22,25 +22,67 @@ import antlr.RecognitionException;
 import antlr.TokenStreamException;
 import antlr.TokenStreamRecognitionException;
 import antlr.collections.AST;
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.StaxDriver;
 import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.antlr.parser.GroovyLexer;
 import org.codehaus.groovy.antlr.parser.GroovyRecognizer;
 import org.codehaus.groovy.antlr.parser.GroovyTokenTypes;
-import org.codehaus.groovy.antlr.treewalker.*;
-import org.codehaus.groovy.ast.*;
+import org.codehaus.groovy.antlr.treewalker.CompositeVisitor;
+import org.codehaus.groovy.antlr.treewalker.MindMapPrinter;
+import org.codehaus.groovy.antlr.treewalker.NodeAsHTMLPrinter;
+import org.codehaus.groovy.antlr.treewalker.PreOrderTraversal;
+import org.codehaus.groovy.antlr.treewalker.SourceCodeTraversal;
+import org.codehaus.groovy.antlr.treewalker.SourcePrinter;
+import org.codehaus.groovy.antlr.treewalker.Visitor;
+import org.codehaus.groovy.antlr.treewalker.VisitorAdapter;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.AnnotationNode;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.ConstructorNode;
+import org.codehaus.groovy.ast.EnumConstantClassNode;
+import org.codehaus.groovy.ast.FieldNode;
+import org.codehaus.groovy.ast.GenericsType;
+import org.codehaus.groovy.ast.ImportNode;
+import org.codehaus.groovy.ast.InnerClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.MixinNode;
+import org.codehaus.groovy.ast.ModuleNode;
+import org.codehaus.groovy.ast.PackageNode;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.PropertyNode;
 import org.codehaus.groovy.ast.expr.*;
-import org.codehaus.groovy.ast.stmt.*;
+import org.codehaus.groovy.ast.stmt.AssertStatement;
+import org.codehaus.groovy.ast.stmt.BlockStatement;
+import org.codehaus.groovy.ast.stmt.BreakStatement;
+import org.codehaus.groovy.ast.stmt.CaseStatement;
+import org.codehaus.groovy.ast.stmt.CatchStatement;
+import org.codehaus.groovy.ast.stmt.ContinueStatement;
+import org.codehaus.groovy.ast.stmt.EmptyStatement;
+import org.codehaus.groovy.ast.stmt.ExpressionStatement;
+import org.codehaus.groovy.ast.stmt.ForStatement;
+import org.codehaus.groovy.ast.stmt.IfStatement;
+import org.codehaus.groovy.ast.stmt.ReturnStatement;
+import org.codehaus.groovy.ast.stmt.Statement;
+import org.codehaus.groovy.ast.stmt.SwitchStatement;
+import org.codehaus.groovy.ast.stmt.SynchronizedStatement;
+import org.codehaus.groovy.ast.stmt.ThrowStatement;
+import org.codehaus.groovy.ast.stmt.TryCatchStatement;
+import org.codehaus.groovy.ast.stmt.WhileStatement;
 import org.codehaus.groovy.control.CompilationFailedException;
 import org.codehaus.groovy.control.ParserPlugin;
 import org.codehaus.groovy.control.SourceUnit;
-import org.codehaus.groovy.syntax.*;
+import org.codehaus.groovy.control.XStreamUtils;
+import org.codehaus.groovy.syntax.ASTHelper;
+import org.codehaus.groovy.syntax.Numbers;
+import org.codehaus.groovy.syntax.ParserException;
+import org.codehaus.groovy.syntax.Reduction;
+import org.codehaus.groovy.syntax.SyntaxException;
+import org.codehaus.groovy.syntax.Token;
+import org.codehaus.groovy.syntax.Types;
 import org.objectweb.asm.Opcodes;
 
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
 import java.io.PrintStream;
 import java.io.Reader;
 import java.security.AccessController;
@@ -231,15 +273,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
     }
 
     private void saveAsXML(String name, AST ast) {
-        XStream xstream = new XStream(new StaxDriver());
-        try {
-            xstream.toXML(ast, new FileWriter(name + ".antlr.xml"));
-            System.out.println("Written AST to " + name + ".antlr.xml");
-        }
-        catch (Exception e) {
-            System.out.println("Couldn't write to " + name + ".antlr.xml");
-            e.printStackTrace();
-        }
+        XStreamUtils.serialize(name, ast);
     }
 
     public ModuleNode buildAST(SourceUnit sourceUnit, ClassLoader classLoader, Reduction cst) throws ParserException {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/058dd40f/src/main/org/codehaus/groovy/control/SourceUnit.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/SourceUnit.java b/src/main/org/codehaus/groovy/control/SourceUnit.java
index c548584..d00c820 100644
--- a/src/main/org/codehaus/groovy/control/SourceUnit.java
+++ b/src/main/org/codehaus/groovy/control/SourceUnit.java
@@ -23,8 +23,6 @@ import antlr.MismatchedCharException;
 import antlr.MismatchedTokenException;
 import antlr.NoViableAltException;
 import antlr.NoViableAltForCharException;
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.StaxDriver;
 import groovy.lang.GroovyClassLoader;
 import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.ast.ModuleNode;
@@ -40,7 +38,6 @@ import org.codehaus.groovy.syntax.SyntaxException;
 import org.codehaus.groovy.tools.Utilities;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Reader;
 import java.net.URL;
@@ -292,14 +289,7 @@ public class SourceUnit extends ProcessingUnit {
     }
 
     private void saveAsXML(String name, ModuleNode ast) {
-        XStream xstream = new XStream(new StaxDriver());
-        try {
-            xstream.toXML(ast, new FileWriter(name + ".xml"));
-            System.out.println("Written AST to " + name + ".xml");
-        } catch (Exception e) {
-            System.out.println("Couldn't write to " + name + ".xml");
-            e.printStackTrace();
-        }
+        XStreamUtils.serialize(name, ast);
     }
 
     //---------------------------------------------------------------------------    // SOURCE SAMPLING

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/058dd40f/src/main/org/codehaus/groovy/control/XStreamUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/XStreamUtils.java b/src/main/org/codehaus/groovy/control/XStreamUtils.java
new file mode 100644
index 0000000..0049e17
--- /dev/null
+++ b/src/main/org/codehaus/groovy/control/XStreamUtils.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2003-2015 the original author or authors.
+ *
+ * Licensed 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.control;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.StaxDriver;
+
+import java.io.FileWriter;
+
+public abstract class XStreamUtils {
+    public static void serialize(final String name, final Object ast) {
+        XStream xstream = new XStream(new StaxDriver());
+        try {
+            xstream.toXML(ast, new FileWriter(name + ".xml"));
+            System.out.println("Written AST to " + name + ".xml");
+        } catch (Exception e) {
+            System.out.println("Couldn't write to " + name + ".xml");
+            e.printStackTrace();
+        }
+    }
+}