ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1373334 - in /ant/core/trunk: manual/running.html src/main/org/apache/tools/ant/Main.java src/main/org/apache/tools/ant/listener/SilentLogger.java
Date Wed, 15 Aug 2012 11:13:15 GMT
Author: hibou
Date: Wed Aug 15 11:13:15 2012
New Revision: 1373334

URL: http://svn.apache.org/viewvc?rev=1373334&view=rev
Log:
Add a log mode which logs nothing but ant task output and build failures; useful for using
ant output in scripts, like for cacti for instance

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java   (with props)
Modified:
    ant/core/trunk/manual/running.html
    ant/core/trunk/src/main/org/apache/tools/ant/Main.java

Modified: ant/core/trunk/manual/running.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/running.html?rev=1373334&r1=1373333&r2=1373334&view=diff
==============================================================================
--- ant/core/trunk/manual/running.html (original)
+++ ant/core/trunk/manual/running.html Wed Aug 15 11:13:15 2012
@@ -77,8 +77,10 @@ You can also access environment variable
 which instructs Ant to print less
 information to the console;
 <nobr><code>-verbose</code></nobr>, which causes Ant to print
-additional information to the console; and <nobr><code>-debug</code></nobr>,
-which causes Ant to print considerably more additional information.
+additional information to the console; <nobr><code>-debug</code></nobr>,
+which causes Ant to print considerably more additional information; and
+<nobr><code>-silent</code></nobr> which makes Ant print nothing but
task
+output and build failures (useful to capture Ant output by scripts).
 </p>
 
 <p>It is also possible to specify one or more targets that should be executed.
@@ -104,6 +106,7 @@ Options:
   -diagnostics           print information that might be helpful to
                          diagnose or report problems.
   -quiet, -q             be extra quiet
+  -silent, -S            print nothing but task outputs and build failures
   -verbose, -v           be extra verbose
   -debug, -d             print debugging information
   -emacs, -e             produce logging information without adornments

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Main.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Main.java?rev=1373334&r1=1373333&r2=1373334&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Main.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Main.java Wed Aug 15 11:13:15 2012
@@ -36,6 +36,7 @@ import java.util.Vector;
 import org.apache.tools.ant.input.DefaultInputHandler;
 import org.apache.tools.ant.input.InputHandler;
 import org.apache.tools.ant.launch.AntMain;
+import org.apache.tools.ant.listener.SilentLogger;
 import org.apache.tools.ant.property.GetProperty;
 import org.apache.tools.ant.property.ResolvePropertyMap;
 import org.apache.tools.ant.util.ClasspathUtils;
@@ -122,6 +123,11 @@ public class Main implements AntMain {
     private boolean emacsMode = false;
 
     /**
+     * Whether or not log output should be reduced to the minimum
+     */
+    private boolean silent = false;
+
+    /**
      * Whether or not this instance has successfully been
      * constructed and is ready to run.
      */
@@ -336,6 +342,8 @@ public class Main implements AntMain {
                 msgOutputLevel = Project.MSG_VERBOSE;
             } else if (arg.equals("-debug") || arg.equals("-d")) {
                 msgOutputLevel = Project.MSG_DEBUG;
+            } else if (arg.equals("-silent") || arg.equals("-S")) {
+                silent = true;
             } else if (arg.equals("-noinput")) {
                 allowInput = false;
             } else if (arg.equals("-logfile") || arg.equals("-l")) {
@@ -921,7 +929,11 @@ public class Main implements AntMain {
      */
     private BuildLogger createLogger() {
         BuildLogger logger = null;
-        if (loggerClassname != null) {
+        if (silent) {
+            logger = new SilentLogger();
+            msgOutputLevel = Project.MSG_WARN;
+            emacsMode = true;
+        } else if (loggerClassname != null) {
             try {
                 logger = (BuildLogger) ClasspathUtils.newInstance(
                         loggerClassname, Main.class.getClassLoader(),
@@ -958,6 +970,7 @@ public class Main implements AntMain {
         msg.append("  -diagnostics           print information that might be helpful to"
+ lSep);
         msg.append("                         diagnose or report problems." + lSep);
         msg.append("  -quiet, -q             be extra quiet" + lSep);
+        msg.append("  -silent, -S            print nothing but task outputs and build failures"
+ lSep);
         msg.append("  -verbose, -v           be extra verbose" + lSep);
         msg.append("  -debug, -d             print debugging information" + lSep);
         msg.append("  -emacs, -e             produce logging information without adornments"

Added: ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java?rev=1373334&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java Wed Aug 15 11:13:15
2012
@@ -0,0 +1,56 @@
+/*
+ *  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.tools.ant.listener;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.DefaultLogger;
+
+/**
+ * A logger which logs nothing but build failure and what task might output
+ * 
+ * @since 1.9.0
+ */
+public class SilentLogger extends DefaultLogger {
+
+    public void buildStarted(BuildEvent event) {
+        // log nothing
+    }
+
+    public void buildFinished(BuildEvent event) {
+        if (event.getException() != null) {
+            super.buildFinished(event);
+        }
+    }
+
+    public void targetStarted(BuildEvent event) {
+        // log nothing
+    }
+
+    public void targetFinished(BuildEvent event) {
+        // log nothing
+    }
+
+    public void taskStarted(BuildEvent event) {
+        // log nothing
+    }
+
+    public void taskFinished(BuildEvent event) {
+        // log nothing
+    }
+
+}

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/listener/SilentLogger.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message