Issue #124366: display BUILD SUCCESSFUL in green, etc. Involves adding API: InputOutput AntSession.getIO() diff --git a/o.apache.tools.ant.module/apichanges.xml b/o.apache.tools.ant.module/apichanges.xml --- a/o.apache.tools.ant.module/apichanges.xml +++ b/o.apache.tools.ant.module/apichanges.xml @@ -107,6 +107,23 @@ + + + Added AntSession.getIO + + + + + +

+ Added ability to get the underlying InputOutput + object for advanced formatting. +

+
+ + +
+ Added AntScriptUtils diff --git a/o.apache.tools.ant.module/nbproject/project.properties b/o.apache.tools.ant.module/nbproject/project.properties --- a/o.apache.tools.ant.module/nbproject/project.properties +++ b/o.apache.tools.ant.module/nbproject/project.properties @@ -39,7 +39,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.5 -spec.version.base=3.34.0 +spec.version.base=3.35.0 compile.ant.jar=${ant.core.lib} src-bridge.cp.extra=build/classes:${compile.ant.jar} extra.module.files=\ diff --git a/o.apache.tools.ant.module/nbproject/project.xml b/o.apache.tools.ant.module/nbproject/project.xml --- a/o.apache.tools.ant.module/nbproject/project.xml +++ b/o.apache.tools.ant.module/nbproject/project.xml @@ -162,7 +162,7 @@ - 1.11 + 1.16 diff --git a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java --- a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java +++ b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java @@ -83,6 +83,7 @@ import org.openide.util.NbBundle; import org.openide.util.NbCollections; import org.openide.util.RequestProcessor; +import org.openide.windows.InputOutput; import org.openide.windows.OutputWriter; /** @@ -154,8 +155,8 @@ return null; } - public boolean run(File buildFile, List targets, InputStream in, OutputWriter out, OutputWriter err, - Map properties, int verbosity, String displayName, Runnable interestingOutputCallback, ProgressHandle handle) { + public boolean run(File buildFile, List targets, InputStream in, OutputWriter out, OutputWriter err, Map properties, + int verbosity, String displayName, Runnable interestingOutputCallback, ProgressHandle handle, InputOutput io) { if (!classpathInitialized) { classpathInitialized = true; // #46171: Ant expects this path to have itself and whatever else you loaded with it, @@ -184,7 +185,7 @@ // first use the ProjectHelper to create the project object // from the given build file. - final NbBuildLogger logger = new NbBuildLogger(buildFile, out, err, verbosity, displayName, interestingOutputCallback, handle); + final NbBuildLogger logger = new NbBuildLogger(buildFile, out, err, verbosity, displayName, interestingOutputCallback, handle, io); Vector targs; try { project = new Project(); diff --git a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java --- a/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java +++ b/o.apache.tools.ant.module/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java @@ -84,6 +84,7 @@ import org.openide.util.NbCollections; import org.openide.util.RequestProcessor; import org.openide.util.WeakSet; +import org.openide.windows.InputOutput; import org.openide.windows.OutputListener; import org.openide.windows.OutputWriter; @@ -110,6 +111,7 @@ private String[] targets = null; final OutputWriter out; final OutputWriter err; + final InputOutput io; private final int verbosity; private final String displayName; private final Runnable interestingOutputCallback; @@ -166,11 +168,13 @@ this.lastTask = lastTask; } - public NbBuildLogger(File origScript, OutputWriter out, OutputWriter err, int verbosity, String displayName, Runnable interestingOutputCallback, ProgressHandle handle) { + public NbBuildLogger(File origScript, OutputWriter out, OutputWriter err, int verbosity, String displayName, + Runnable interestingOutputCallback, ProgressHandle handle, InputOutput io) { thisSession = LoggerTrampoline.ANT_SESSION_CREATOR.makeAntSession(this); this.origScript = origScript; this.out = out; this.err = err; + this.io = io; this.verbosity = verbosity; this.displayName = displayName; this.interestingOutputCallback = interestingOutputCallback; @@ -760,6 +764,10 @@ verifyRunning(); return new Hyperlink(file, message, line1, column1, line2, column2); } + + public InputOutput getIO() { + return io; + } // Accessors for stuff which is specific to particular versions of Ant. private static final Method targetGetLocation; // 1.6.2+ diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/BridgeInterface.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/BridgeInterface.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/BridgeInterface.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/BridgeInterface.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import org.netbeans.api.progress.ProgressHandle; +import org.openide.windows.InputOutput; import org.openide.windows.OutputWriter; /** @@ -66,9 +67,11 @@ * @param displayName a user-presentable name for the session * @param interestingOutputCallback will be called if and when some interesting output appears, or input is requested * @param handle a progress handle to update if appropriate (switch to sleeping and back to indeterminate) + * @param io raw I/O handle for more advanced output * @return true if the build succeeded, false if it failed for any reason */ - boolean run(File buildFile, List targets, InputStream in, OutputWriter out, OutputWriter err, Map properties, int verbosity, String displayName, Runnable interestingOutputCallback, ProgressHandle handle); + boolean run(File buildFile, List targets, InputStream in, OutputWriter out, OutputWriter err, Map properties, + int verbosity, String displayName, Runnable interestingOutputCallback, ProgressHandle handle, InputOutput io); /** * Try to stop a running build. diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/DummyBridgeImpl.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/DummyBridgeImpl.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/DummyBridgeImpl.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/bridge/DummyBridgeImpl.java @@ -51,6 +51,7 @@ import org.openide.ErrorManager; import org.openide.util.NbBundle; import org.openide.util.Enumerations; +import org.openide.windows.InputOutput; import org.openide.windows.OutputWriter; /** @@ -106,7 +107,8 @@ return null; } - public boolean run(File buildFile, List targets, InputStream in, OutputWriter out, OutputWriter err, Map properties, int verbosity, String displayName, Runnable interestingOutputCallback, ProgressHandle handle) { + public boolean run(File buildFile, List targets, InputStream in, OutputWriter out, OutputWriter err, Map properties, + int verbosity, String displayName, Runnable interestingOutputCallback, ProgressHandle handle, InputOutput io) { err.println(NbBundle.getMessage(DummyBridgeImpl.class, "ERR_cannot_run_target")); problem.printStackTrace(err); return false; diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/LoggerTrampoline.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/LoggerTrampoline.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/LoggerTrampoline.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/LoggerTrampoline.java @@ -48,6 +48,7 @@ import org.apache.tools.ant.module.spi.AntLogger; import org.apache.tools.ant.module.spi.AntSession; import org.apache.tools.ant.module.spi.TaskStructure; +import org.openide.windows.InputOutput; import org.openide.windows.OutputListener; /** @@ -94,6 +95,7 @@ int getVerbosity(); String getDisplayName(); OutputListener createStandardHyperlink(URL file, String message, int line1, int column1, int line2, int column2); + InputOutput getIO(); } public interface AntEventImpl { diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/StandardLogger.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/StandardLogger.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/StandardLogger.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/StandardLogger.java @@ -41,7 +41,9 @@ package org.apache.tools.ant.module.run; +import java.awt.Color; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.net.MalformedURLException; @@ -61,6 +63,8 @@ import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; import org.openide.util.lookup.ServiceProvider; +import org.openide.windows.IOColorLines; +import org.openide.windows.InputOutput; import org.openide.windows.OutputListener; /** @@ -233,7 +237,7 @@ time = mockTotalTime; } if (t == null) { - session.println(formatMessageWithTime("FMT_finished_target_printed", time), false, null); + formatColoredMessageWithTime(session, "FMT_finished_target_printed", false, time); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(StandardLogger.class, "FMT_finished_target_status", session.getDisplayName())); } else { if (isStopException(t.getCause())) { @@ -263,10 +267,10 @@ } } if (isStopException(t)) { - event.getSession().println(formatMessageWithTime("FMT_target_stopped_printed", time), true, null); + formatColoredMessageWithTime(session, "FMT_target_stopped_printed", true, time); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(StandardLogger.class, "FMT_target_stopped_status", event.getSession().getDisplayName())); } else { - event.getSession().println(formatMessageWithTime("FMT_target_failed_printed", time), true, null); // #10305 + formatColoredMessageWithTime(session, "FMT_target_failed_printed", true, time); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(StandardLogger.class, "FMT_target_failed_status", event.getSession().getDisplayName())); } } @@ -290,11 +294,21 @@ * Total time: {0} minutes * {1} seconds */ - private static String formatMessageWithTime(String key, long millis) { + private static void formatColoredMessageWithTime(AntSession session, String key, boolean error, long millis) { int secs = (int) (millis / 1000); int minutes = secs / 60; int seconds = secs % 60; - return NbBundle.getMessage(StandardLogger.class, key, minutes, seconds); + String msg = NbBundle.getMessage(StandardLogger.class, key, minutes, seconds); + InputOutput io = session.getIO(); + if (IOColorLines.isSupported(io)) { + try { + IOColorLines.println(io, msg, error ? Color.RED : Color.GREEN); + return; + } catch (IOException x) { + ERR.log(Level.INFO, null, x); + } + } + session.println(msg, error, null); } @Override diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java @@ -495,7 +495,7 @@ handle.start(); setEnabledEQ(sa, true); setEnabledEQ(ra, false); - ok = AntBridge.getInterface().run(buildFile, targetNames, in, out, err, properties, verbosity, displayName, interestingOutputCallback, handle); + ok = AntBridge.getInterface().run(buildFile, targetNames, in, out, err, properties, verbosity, displayName, interestingOutputCallback, handle, io); } finally { if (io != null) { diff --git a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntSession.java b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntSession.java --- a/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntSession.java +++ b/o.apache.tools.ant.module/src/org/apache/tools/ant/module/spi/AntSession.java @@ -44,6 +44,8 @@ import java.io.File; import java.net.URL; import org.apache.tools.ant.module.run.LoggerTrampoline; +import org.openide.windows.IOColors; +import org.openide.windows.InputOutput; import org.openide.windows.OutputListener; /** @@ -222,6 +224,15 @@ public OutputListener createStandardHyperlink(URL file, String message, int line1, int column1, int line2, int column2) { return impl.createStandardHyperlink(file, message, line1, column1, line2, column2); } + + /** + * Obtains the I/O handle for advanced operations such as {@link IOColors}. + * @return an I/O handle + * @since org.apache.tools.ant.module/3 3.35 + */ + public InputOutput getIO() { + return impl.getIO(); + } @Override public String toString() { diff --git a/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/run/StandardLoggerTest.java b/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/run/StandardLoggerTest.java --- a/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/run/StandardLoggerTest.java +++ b/o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/run/StandardLoggerTest.java @@ -63,6 +63,8 @@ import org.openide.util.NbBundle; import org.openide.util.Utilities; import org.openide.util.WeakSet; +import org.openide.windows.IOProvider; +import org.openide.windows.InputOutput; import org.openide.windows.OutputEvent; import org.openide.windows.OutputListener; @@ -273,6 +275,10 @@ return new MockHyperlink(file.toExternalForm(), message, line1, column1, line2, column2); } + public InputOutput getIO() { + return IOProvider.getDefault().getIO("", true); + } + public void println(String message, boolean err, OutputListener listener) { messages.add(new Message(message, err, listener)); }