mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use real System.out under modern Ant versions (IDEA-199738)
Solves problem with duplicated messages in builds
This commit is contained in:
Binary file not shown.
@@ -16,20 +16,37 @@
|
||||
package org.jetbrains.jps.gant;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.BuildListener;
|
||||
import org.apache.tools.ant.DefaultLogger;
|
||||
import org.codehaus.gant.ant.Gant;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class GantWithClasspathTask extends Gant {
|
||||
public static PrintStream out = null;
|
||||
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
ClassLoader loader = getClass().getClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
for (BuildListener listener : this.getProject().getBuildListeners()) {
|
||||
if (listener instanceof DefaultLogger) {
|
||||
try {
|
||||
Field field = DefaultLogger.class.getDeclaredField("out");
|
||||
field.setAccessible(true);
|
||||
out = (PrintStream)field.get(listener);
|
||||
break;
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
Field field = Gant.class.getDeclaredField("file");
|
||||
field.setAccessible(true);
|
||||
|
||||
@@ -81,11 +81,20 @@ class BuildUtils {
|
||||
//if the build script is running under Ant or AntBuilder it may replace the standard System.out
|
||||
def field = Main.class.getDeclaredField("out")
|
||||
field.accessible = true
|
||||
return (PrintStream) field.get(null)
|
||||
return (PrintStream) field.get(null) // No longer works in recent Ant 1.9.x and 1.10
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
return System.out
|
||||
}
|
||||
try {
|
||||
def clazz = Class.forName("org.jetbrains.jps.gant.GantWithClasspathTask")
|
||||
def field = clazz.getDeclaredField("out")
|
||||
field.setAccessible(true)
|
||||
def out = field.get(null)
|
||||
if (out != null) return out as PrintStream
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
}
|
||||
return System.out
|
||||
}
|
||||
|
||||
static void defineFtpTask(BuildContext context) {
|
||||
|
||||
Reference in New Issue
Block a user