You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2007/07/16 20:52:09 UTC

svn commit: r556695 - /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PrettyPrinter.java

Author: dims
Date: Mon Jul 16 11:52:08 2007
New Revision: 556695

URL: http://svn.apache.org/viewvc?view=rev&rev=556695
Log:
Swallow any output from jalopy 1.5-rc3. Provide a mechanism to switch off jalopy

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PrettyPrinter.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PrettyPrinter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PrettyPrinter.java?view=diff&rev=556695&r1=556694&r2=556695
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PrettyPrinter.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PrettyPrinter.java Mon Jul 16 11:52:08 2007
@@ -22,9 +22,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.PrintStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.Properties;
 
 /**
  * Tidies up the java source code using Jalopy.
@@ -41,8 +44,23 @@
      * @param file
      */
     public static void prettify(File file) {
+        // If the user has set "axis2.jalopy=false" on the system property,
+        // then just return back to caller
+        String property = System.getProperty("axis2.jalopy");
+        if(JavaUtils.isFalseExplicitly(property)){
+            return;
+        }
+        PrintStream backupOutputStream = System.out;
+        PrintStream backupErrorStream = System.err;
+        System.setOut(new PrintStream(new ByteArrayOutputStream()));
+        System.setErr(new PrintStream(new ByteArrayOutputStream()));
         try {
-            Loader.loadClass("org.apache.log4j.Priority");
+            Class clazzConfigurator = Loader.loadClass("org.apache.log4j.PropertyConfigurator");
+            Method configure = clazzConfigurator.getMethod("configure", new Class[]{Properties.class});
+            Properties properties = new Properties();
+            properties.setProperty("log4j.logger.de.hunsicker.jalopy.io",
+                    System.getProperty("log4j.logger.de.hunsicker.jalopy.io", "FATAL"));
+            configure.invoke(null, new Object[]{properties});
 
             // Create an instance of the Jalopy bean
             Class clazz = Loader.loadClass("de.hunsicker.jalopy.Jalopy");
@@ -77,6 +95,9 @@
             log.warn("Exception occurred while trying to pretty print file " + file, e);
         } catch (Throwable t) {
             log.debug("Exception occurred while trying to pretty print file " + file, t);
+        } finally {
+            System.setOut(backupOutputStream);
+            System.setErr(backupErrorStream);
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org