cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1348245 - in /cxf/trunk: api/src/main/java/org/apache/cxf/common/util/ rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/ tools/common/src/main/java/org/apache/cxf/tools/common/
Date Fri, 08 Jun 2012 21:14:09 GMT
Author: dkulp
Date: Fri Jun  8 21:14:09 2012
New Revision: 1348245

URL: http://svn.apache.org/viewvc?rev=1348245&view=rev
Log:
Remove some reflection that is no longer needed with Java6+

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java?rev=1348245&r1=1348244&r2=1348245&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java Fri Jun  8 21:14:09
2012
@@ -23,12 +23,15 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.io.Writer;
-import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Locale;
+
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
 
 import org.apache.cxf.helpers.FileUtils;
 
@@ -124,12 +127,7 @@ public class Compiler {
     public boolean compileFiles(String[] files) {
         String endorsed = SystemPropertyAction.getProperty("java.endorsed.dirs");
         if (!forceFork) {
-            try { 
-                Class.forName("javax.tools.JavaCompiler");
-                return useJava6Compiler(files);
-            } catch (Exception ex) {
-                //ignore - fork javac
-            }
+            return useJava6Compiler(files);
         }
         
         List<String> list = new ArrayList<String>();
@@ -172,32 +170,23 @@ public class Compiler {
         return internalCompile(list.toArray(new String[list.size()]), idx);
     }
 
-    private boolean useJava6Compiler(String[] files) 
-        throws Exception {
-        
-        Object compiler = Class.forName("javax.tools.ToolProvider")
-            .getMethod("getSystemJavaCompiler").invoke(null);
-        Object fileManager = compiler.getClass().getMethod("getStandardFileManager", 
-                                                           Class.forName("javax.tools.DiagnosticListener"),
-                                                           Locale.class,
-                                                           Charset.class).invoke(compiler,
null, null, null);
-        Object fileList = fileManager.getClass().getMethod("getJavaFileObjectsFromStrings",
Iterable.class)
-            .invoke(fileManager, Arrays.asList(files));
+    private boolean useJava6Compiler(String[] files) {
+        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null,
null);
+        Iterable<? extends JavaFileObject> fileList 
+            = fileManager.getJavaFileObjectsFromStrings(Arrays.asList(files));
         
         
         List<String> args = new ArrayList<String>();
         addArgs(args);
-        Object task = compiler.getClass().getMethod("getTask", 
-                                                    Writer.class,
-                                                    Class.forName("javax.tools.JavaFileManager"),
-                                                    Class.forName("javax.tools.DiagnosticListener"),
-                                                    Iterable.class,
-                                                    Iterable.class,
-                                                    Iterable.class)
-                                                    .invoke(compiler, null, fileManager,
null, 
-                                                            args, null, fileList);
-        Boolean ret = (Boolean)task.getClass().getMethod("call").invoke(task);
-        fileManager.getClass().getMethod("close").invoke(fileManager);
+        CompilationTask task = compiler.getTask(null, fileManager, null, args, null, fileList);
+        Boolean ret = task.call();
+        try {
+            fileManager.close();
+        } catch (IOException e) {
+            System.err.print("[ERROR] IOException during compiling.");
+            e.printStackTrace();
+        }
         return ret;
     }
 

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java?rev=1348245&r1=1348244&r2=1348245&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
Fri Jun  8 21:14:09 2012
@@ -593,7 +593,7 @@ public class DynamicClientFactory {
         
         javaCompiler.setClassPath(classPath);
         javaCompiler.setOutputDir(dest);
-        javaCompiler.setTarget("1.5");
+        javaCompiler.setTarget("1.6");
         
         return javaCompiler.compileFiles(srcList); 
     }

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java?rev=1348245&r1=1348244&r2=1348245&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java (original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java Fri Jun
 8 21:14:09 2012
@@ -48,9 +48,6 @@ public class ClassUtils {
         
         compiler.setEncoding((String)context.get(ToolConstants.CFG_ENCODING));
         
-        if ("1.5".equals(System.getProperty("java.specification.version"))) {
-            compiler.setTarget("1.5");
-        }
         if (context.get(ToolConstants.CFG_CLASSDIR) != null) {
             compiler.setOutputDir((String)context.get(ToolConstants.CFG_CLASSDIR));
         }



Mime
View raw message