harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r449546 - in /incubator/harmony/enhanced/classlib/trunk/modules/tools: META-INF/ src/main/java/org/apache/harmony/tools/jarsigner/
Date Mon, 25 Sep 2006 02:31:34 GMT
Author: smishura
Date: Sun Sep 24 19:31:33 2006
New Revision: 449546

URL: http://svn.apache.org/viewvc?view=rev&rev=449546
Log:
Apply patch for HARMONY-1482 ([classlib][tools] JarSigner - improved message output)

Add java.util.logging to manifest

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSLogFormatter.java
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/tools/META-INF/MANIFEST.MF
    incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java
    incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/tools/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/tools/META-INF/MANIFEST.MF?view=diff&rev=449546&r1=449545&r2=449546
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/tools/META-INF/MANIFEST.MF (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/tools/META-INF/MANIFEST.MF Sun Sep 24
19:31:33 2006
@@ -15,6 +15,7 @@
  java.security,
  java.security.cert,
  java.util,
+ java.util.logging,
  javax.crypto,
  javax.security.auth.x500,
  org.apache.harmony.crypto.utils;version="1.0.0",

Added: incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSLogFormatter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSLogFormatter.java?view=auto&rev=449546
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSLogFormatter.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSLogFormatter.java
Sun Sep 24 19:31:33 2006
@@ -0,0 +1,34 @@
+/*
+ * 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.    
+ */
+
+package org.apache.harmony.tools.jarsigner;
+
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+
+/**
+ * Simple formatter to output given Strings without formatting.
+ */
+class JSLogFormatter extends SimpleFormatter {
+    @Override
+    public String format(LogRecord r) {
+        return r.getMessage();
+    }
+}
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSLogFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java?view=diff&rev=449546&r1=449545&r2=449546
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java
Sun Sep 24 19:31:33 2006
@@ -16,6 +16,8 @@
 
 package org.apache.harmony.tools.jarsigner;
 
+import java.io.OutputStream;
+
 
 /**
  * The main class that bundles command line parsing, interaction with the user,
@@ -39,8 +41,12 @@
      * @param args -
      *            command line with options.
      */
-    public static void run(String[] args) throws Exception {
+    public static void run(String[] args, OutputStream out) throws Exception {
         // TODO
+        if (out != System.out){
+            UserInteractor.setOutputStream(out);
+        }
+        
     }
 
     
@@ -52,7 +58,7 @@
      */
     public static void main(String[] args) {
         try {
-            run(args);
+            run(args, System.out);
         } catch (Exception e) {
             // System.out.println("JarSigner error: " + e);
             e.printStackTrace();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java?view=diff&rev=449546&r1=449545&r2=449546
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java
Sun Sep 24 19:31:33 2006
@@ -18,6 +18,10 @@
 
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.StreamHandler;
 
 /**
  * Class to interact with user - ask for confirmations, and necessary parameters
@@ -37,14 +41,81 @@
     // when ENTER is pressed.
     private static int newLineLength = 2;
 
+    // an instance of Logger, used to manage message output 
+    private final static Logger logger = Logger.getLogger("JarSignerLogger");
+    
+    // log handler 
+    private static StreamHandler logHandler = new StreamHandler(System.out,
+            new JSLogFormatter());
+
+    static {
+        // Do not send massages to another handlers.
+        logger.setUseParentHandlers(false);
+        // log to System.out by default.
+        logger.addHandler(logHandler);
+    }
+
     // Prints prompt and waits the user to enter the needed data,
     // tha data is returned.
-    static char [] getDataFromUser(String prompt) throws IOException{
-        System.out.print(prompt);
+    static char[] getDataFromUser(String prompt) throws IOException {
+        print(prompt);
         charsRead = in.read(readData);
         char[] password = new char[charsRead - newLineLength];
         System.arraycopy(readData, 0, password, 0, charsRead - newLineLength);
         return password;
+    }
+
+    static void setOutputStream(OutputStream out) {
+        logger.removeHandler(logHandler);
+        // reuse the Formatter from old handler 
+        logHandler = new StreamHandler(out, logHandler.getFormatter());
+        logger.addHandler(logHandler);
+    }
+
+    // prints the given message, if the output is not turned off with
+    // setNoOutput()
+    static void print(String msg) {
+        logger.info(msg);
+        logHandler.flush();
+    }
+
+    // prints the given message and a new line symbol, if the output is not
+    // turned off with setNoOutput()
+    static void println(String msg) {
+        logger.info(msg + "\n");
+        logHandler.flush();
+    }
+
+    // prints the given message, if verbose output is set with
+    // setVerboseOutput()
+    static void printIfVerbose(String msg) {
+        logger.fine(msg);
+        logHandler.flush();
+    }
+
+    // prints the given message and a new line symbol, if verbose output is set
+    // with setVerboseOutput()
+    static void printlnIfVerbose(String msg) {
+        logger.fine(msg + "\n");
+        logHandler.flush();
+    }
+
+    // turns off the output
+    static void setNoOutput() {
+        logger.setLevel(Level.OFF);
+        logger.setLevel(Level.OFF);
+    }
+
+    // sets the verbose output   
+    static void setVerboseOutput() {
+        logger.setLevel(Level.ALL);
+        logHandler.setLevel(Level.ALL);        
+    }
+
+    // sets the normal output
+    static void setNormalOutput() {
+        logger.setLevel(Level.INFO);
+        logHandler.setLevel(Level.INFO);
     }
 }
 



Mime
View raw message