geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r567848 - in /geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands: AntBuilder.java ProcessLauncher.groovy StartServerCommand.groovy
Date Mon, 20 Aug 2007 22:04:52 GMT
Author: jdillon
Date: Mon Aug 20 15:04:51 2007
New Revision: 567848

URL: http://svn.apache.org/viewvc?rev=567848&view=rev
Log:
Tidy up output handling

Modified:
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java?rev=567848&r1=567847&r2=567848&view=diff
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
Mon Aug 20 15:04:51 2007
@@ -27,62 +27,60 @@
 
 import org.apache.commons.logging.Log;
 
+import org.apache.geronimo.gshell.console.IO;
+
 /**
- * Custom AntBuilder to hook up to desired logging muck.
+ * Custom Ant builder to setup the desired output formatting.
  *
  * @version $Rev$ $Date$
  */
 public class AntBuilder
     extends groovy.util.AntBuilder
 {
-    public AntBuilder(final Log log) {
-        super(createProject(log));
+    public AntBuilder(final Log log, final IO io) {
+        super(createProject(log, io));
     }
 
-    protected static Project createProject(final Log log) {
-        assert log != null;
-
+    protected static Project createProject(final Log log, final IO io) {
         Project project = new Project();
-
-        // Add a custom adapter for logging
-        BuildLogger logger = new LogAdapter(log);
-        logger.setOutputPrintStream(System.out);
-        logger.setErrorPrintStream(System.err);
-
-        // Allow debug messages from Ant tasks when `mvn -X` is used
-        if (log.isDebugEnabled()) {
-            logger.setMessageOutputLevel(Project.MSG_DEBUG);
-        }
-        else {
-            logger.setMessageOutputLevel(Project.MSG_INFO);
-        }
-
-        // Do not print task prefixes
-        logger.setEmacsMode(true);
-
-        project.addBuildListener(logger);
-
+        project.addBuildListener(new OutputAdapter(log, io));
         project.init();
         project.getBaseDir();
 
         return project;
     }
-
-    private static class LogAdapter
+    
+    private static class OutputAdapter
         extends DefaultLogger
     {
-        protected Log log;
+        private Log log;
+        
+        private IO io;
 
-        public LogAdapter(final Log log) {
+        public OutputAdapter(final Log log, final IO io) {
             assert log != null;
-
+            assert io != null;
+            
             this.log = log;
+            this.io = io;
+            
+            setOutputPrintStream(new PrintStream(io.outputStream, true));
+            setErrorPrintStream(new PrintStream(io.errorStream, true));
+            setEmacsMode(true);
+            
+            String level = System.getProperty("gshell.log.console.level");
+            if ("DEBUG".equals(level)) {
+                setMessageOutputLevel(Project.MSG_DEBUG);
+            }
+            else {
+                setMessageOutputLevel(Project.MSG_INFO);
+            }
         }
 
         protected void printMessage(final String message, final PrintStream stream, final
int priority) {
             assert message != null;
             assert stream != null;
-
+            
             switch (priority) {
                 case Project.MSG_ERR:
                     log.error(message);
@@ -93,13 +91,17 @@
                     break;
 
                 case Project.MSG_INFO:
-                    log.info(message);
+                    stream.println(message);
                     break;
 
                 case Project.MSG_VERBOSE:
                 case Project.MSG_DEBUG:
                     log.debug(message);
                     break;
+                
+                default:
+                    // Should never happen
+                    throw new Error("Invalid priority: " + priority);
             }
         }
     }

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy?rev=567848&r1=567847&r2=567848&view=diff
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
Mon Aug 20 15:04:51 2007
@@ -26,6 +26,8 @@
 import org.apache.commons.logging.Log
 import org.apache.commons.logging.LogFactory
 
+import org.apache.geronimo.gshell.console.IO
+
 /**
  * Helper to execute a process and perform some verification logic to determine if the process
is up or not.
  *
@@ -35,6 +37,8 @@
 {
     private Log log = LogFactory.getLog(this.class)
     
+    IO io
+    
     String name
     
     Closure process
@@ -48,6 +52,7 @@
     boolean background = false
     
     def launch() {
+        assert io
         assert process
         assert name
         
@@ -64,7 +69,8 @@
         
         def t = new Thread(runner, "$name Runner")
         
-        log.info("Launching $name")
+        io.out.println("Launching ${name}...")
+        io.flush()
         
         def watch = new StopWatch()
         watch.start()
@@ -107,7 +113,8 @@
             timeoutTask?.cancel()
         }
         
-        log.info("$name started in $watch")
+        io.out.println("$name started in $watch")
+        io.flush()
         
         if (!background) {
             log.debug("Waiting for $name to shutdown...")

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy?rev=567848&r1=567847&r2=567848&view=diff
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
Mon Aug 20 15:04:51 2007
@@ -262,7 +262,9 @@
     protected Object doExecute(Object[] args) throws Exception {
         assert args != null
         
-        def ant = new AntBuilder(log)
+        def io = getIO()
+        
+        def ant = new AntBuilder(log, io)
         
         if (!geronimoHome) {
             geronimoHome = new File(System.properties['gshell.home'])
@@ -287,11 +289,12 @@
         // If we are not backgrounding, then add a nice message for the user when ctrl-c
gets hit
         if (!background) {
             addShutdownHook({
-                log.info("Shutting down...")
+                io.out.println('Shutting down...')
+                io.flush()
             })
         }
         
-        def launcher = new ProcessLauncher(log: log, name: 'Geronimo Server', background:
background)
+        def launcher = new ProcessLauncher(log: log, io: io, name: 'Geronimo Server', background:
background)
         
         launcher.process = {
             try {



Mime
View raw message