git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271488 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,126 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant; | |||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | |||||
import java.io.OutputStream; | |||||
import java.util.Hashtable; | |||||
/** | |||||
* Logs content written by a thread and forwards the buffers onto the project | |||||
* object which will forward the content to the appropriate task | |||||
* | |||||
* @author Conor MacNeill | |||||
*/ | |||||
public class DemuxOutputStream extends OutputStream | |||||
{ | |||||
private final static int MAX_SIZE = 1024; | |||||
private Hashtable buffers = new Hashtable(); | |||||
// private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | |||||
private boolean skip = false; | |||||
private boolean isErrorStream; | |||||
private Project project; | |||||
/** | |||||
* Creates a new instance of this class. | |||||
* | |||||
* @param project Description of Parameter | |||||
* @param isErrorStream Description of Parameter | |||||
*/ | |||||
public DemuxOutputStream( Project project, boolean isErrorStream ) | |||||
{ | |||||
this.project = project; | |||||
this.isErrorStream = isErrorStream; | |||||
} | |||||
/** | |||||
* Writes all remaining | |||||
* | |||||
* @exception IOException Description of Exception | |||||
*/ | |||||
public void close() | |||||
throws IOException | |||||
{ | |||||
flush(); | |||||
} | |||||
/** | |||||
* Writes all remaining | |||||
* | |||||
* @exception IOException Description of Exception | |||||
*/ | |||||
public void flush() | |||||
throws IOException | |||||
{ | |||||
if( getBuffer().size() > 0 ) | |||||
{ | |||||
processBuffer(); | |||||
} | |||||
} | |||||
/** | |||||
* Write the data to the buffer and flush the buffer, if a line separator is | |||||
* detected. | |||||
* | |||||
* @param cc data to log (byte). | |||||
* @exception IOException Description of Exception | |||||
*/ | |||||
public void write( int cc ) | |||||
throws IOException | |||||
{ | |||||
final byte c = (byte)cc; | |||||
if( ( c == '\n' ) || ( c == '\r' ) ) | |||||
{ | |||||
if( !skip ) | |||||
{ | |||||
processBuffer(); | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
ByteArrayOutputStream buffer = getBuffer(); | |||||
buffer.write( cc ); | |||||
if( buffer.size() > MAX_SIZE ) | |||||
{ | |||||
processBuffer(); | |||||
} | |||||
} | |||||
skip = ( c == '\r' ); | |||||
} | |||||
/** | |||||
* Converts the buffer to a string and sends it to <code>processLine</code> | |||||
*/ | |||||
protected void processBuffer() | |||||
{ | |||||
String output = getBuffer().toString(); | |||||
project.demuxOutput( output, isErrorStream ); | |||||
resetBuffer(); | |||||
} | |||||
private ByteArrayOutputStream getBuffer() | |||||
{ | |||||
Thread current = Thread.currentThread(); | |||||
ByteArrayOutputStream buffer = (ByteArrayOutputStream)buffers.get( current ); | |||||
if( buffer == null ) | |||||
{ | |||||
buffer = new ByteArrayOutputStream(); | |||||
buffers.put( current, buffer ); | |||||
} | |||||
return buffer; | |||||
} | |||||
private void resetBuffer() | |||||
{ | |||||
Thread current = Thread.currentThread(); | |||||
buffers.remove( current ); | |||||
} | |||||
} |
@@ -1,79 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant; | |||||
import java.util.Enumeration; | |||||
import java.util.Hashtable; | |||||
import org.apache.tools.ant.types.FilterSet; | |||||
/** | |||||
* Central representation of an Ant project. This class defines a Ant project | |||||
* with all of it's targets and tasks. It also provides the mechanism to kick | |||||
* off a build using a particular target name. <p> | |||||
* | |||||
* This class also encapsulates methods which allow Files to be refered to using | |||||
* abstract path names which are translated to native system file paths at | |||||
* runtime as well as defining various project properties. | |||||
* | |||||
* @author duncan@x180.com | |||||
*/ | |||||
public class Project | |||||
{ | |||||
private Hashtable properties = new Hashtable(); | |||||
private FilterSet globalFilterSet = new FilterSet(); | |||||
/** | |||||
* Records the latest task on a thread | |||||
*/ | |||||
private Hashtable threadTasks = new Hashtable(); | |||||
public FilterSet getGlobalFilterSet() | |||||
{ | |||||
return globalFilterSet; | |||||
} | |||||
/** | |||||
* get a copy of the property hashtable | |||||
* | |||||
* @return the hashtable containing all properties, user included | |||||
*/ | |||||
public Hashtable getProperties() | |||||
{ | |||||
Hashtable propertiesCopy = new Hashtable(); | |||||
Enumeration e = properties.keys(); | |||||
while( e.hasMoreElements() ) | |||||
{ | |||||
Object name = e.nextElement(); | |||||
Object value = properties.get( name ); | |||||
propertiesCopy.put( name, value ); | |||||
} | |||||
return propertiesCopy; | |||||
} | |||||
public void demuxOutput( String line, boolean isError ) | |||||
{ | |||||
Task task = (Task)threadTasks.get( Thread.currentThread() ); | |||||
if( task == null ) | |||||
{ | |||||
//fireMessageLogged( this, line, isError ? MSG_ERR : MSG_INFO ); | |||||
} | |||||
else | |||||
{ | |||||
if( isError ) | |||||
{ | |||||
task.handleErrorOutput( line ); | |||||
} | |||||
else | |||||
{ | |||||
task.handleOutput( line ); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -1,126 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant; | |||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | |||||
import java.io.OutputStream; | |||||
import java.util.Hashtable; | |||||
/** | |||||
* Logs content written by a thread and forwards the buffers onto the project | |||||
* object which will forward the content to the appropriate task | |||||
* | |||||
* @author Conor MacNeill | |||||
*/ | |||||
public class DemuxOutputStream extends OutputStream | |||||
{ | |||||
private final static int MAX_SIZE = 1024; | |||||
private Hashtable buffers = new Hashtable(); | |||||
// private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | |||||
private boolean skip = false; | |||||
private boolean isErrorStream; | |||||
private Project project; | |||||
/** | |||||
* Creates a new instance of this class. | |||||
* | |||||
* @param project Description of Parameter | |||||
* @param isErrorStream Description of Parameter | |||||
*/ | |||||
public DemuxOutputStream( Project project, boolean isErrorStream ) | |||||
{ | |||||
this.project = project; | |||||
this.isErrorStream = isErrorStream; | |||||
} | |||||
/** | |||||
* Writes all remaining | |||||
* | |||||
* @exception IOException Description of Exception | |||||
*/ | |||||
public void close() | |||||
throws IOException | |||||
{ | |||||
flush(); | |||||
} | |||||
/** | |||||
* Writes all remaining | |||||
* | |||||
* @exception IOException Description of Exception | |||||
*/ | |||||
public void flush() | |||||
throws IOException | |||||
{ | |||||
if( getBuffer().size() > 0 ) | |||||
{ | |||||
processBuffer(); | |||||
} | |||||
} | |||||
/** | |||||
* Write the data to the buffer and flush the buffer, if a line separator is | |||||
* detected. | |||||
* | |||||
* @param cc data to log (byte). | |||||
* @exception IOException Description of Exception | |||||
*/ | |||||
public void write( int cc ) | |||||
throws IOException | |||||
{ | |||||
final byte c = (byte)cc; | |||||
if( ( c == '\n' ) || ( c == '\r' ) ) | |||||
{ | |||||
if( !skip ) | |||||
{ | |||||
processBuffer(); | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
ByteArrayOutputStream buffer = getBuffer(); | |||||
buffer.write( cc ); | |||||
if( buffer.size() > MAX_SIZE ) | |||||
{ | |||||
processBuffer(); | |||||
} | |||||
} | |||||
skip = ( c == '\r' ); | |||||
} | |||||
/** | |||||
* Converts the buffer to a string and sends it to <code>processLine</code> | |||||
*/ | |||||
protected void processBuffer() | |||||
{ | |||||
String output = getBuffer().toString(); | |||||
project.demuxOutput( output, isErrorStream ); | |||||
resetBuffer(); | |||||
} | |||||
private ByteArrayOutputStream getBuffer() | |||||
{ | |||||
Thread current = Thread.currentThread(); | |||||
ByteArrayOutputStream buffer = (ByteArrayOutputStream)buffers.get( current ); | |||||
if( buffer == null ) | |||||
{ | |||||
buffer = new ByteArrayOutputStream(); | |||||
buffers.put( current, buffer ); | |||||
} | |||||
return buffer; | |||||
} | |||||
private void resetBuffer() | |||||
{ | |||||
Thread current = Thread.currentThread(); | |||||
buffers.remove( current ); | |||||
} | |||||
} |
@@ -1,79 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.tools.ant; | |||||
import java.util.Enumeration; | |||||
import java.util.Hashtable; | |||||
import org.apache.tools.ant.types.FilterSet; | |||||
/** | |||||
* Central representation of an Ant project. This class defines a Ant project | |||||
* with all of it's targets and tasks. It also provides the mechanism to kick | |||||
* off a build using a particular target name. <p> | |||||
* | |||||
* This class also encapsulates methods which allow Files to be refered to using | |||||
* abstract path names which are translated to native system file paths at | |||||
* runtime as well as defining various project properties. | |||||
* | |||||
* @author duncan@x180.com | |||||
*/ | |||||
public class Project | |||||
{ | |||||
private Hashtable properties = new Hashtable(); | |||||
private FilterSet globalFilterSet = new FilterSet(); | |||||
/** | |||||
* Records the latest task on a thread | |||||
*/ | |||||
private Hashtable threadTasks = new Hashtable(); | |||||
public FilterSet getGlobalFilterSet() | |||||
{ | |||||
return globalFilterSet; | |||||
} | |||||
/** | |||||
* get a copy of the property hashtable | |||||
* | |||||
* @return the hashtable containing all properties, user included | |||||
*/ | |||||
public Hashtable getProperties() | |||||
{ | |||||
Hashtable propertiesCopy = new Hashtable(); | |||||
Enumeration e = properties.keys(); | |||||
while( e.hasMoreElements() ) | |||||
{ | |||||
Object name = e.nextElement(); | |||||
Object value = properties.get( name ); | |||||
propertiesCopy.put( name, value ); | |||||
} | |||||
return propertiesCopy; | |||||
} | |||||
public void demuxOutput( String line, boolean isError ) | |||||
{ | |||||
Task task = (Task)threadTasks.get( Thread.currentThread() ); | |||||
if( task == null ) | |||||
{ | |||||
//fireMessageLogged( this, line, isError ? MSG_ERR : MSG_INFO ); | |||||
} | |||||
else | |||||
{ | |||||
if( isError ) | |||||
{ | |||||
task.handleErrorOutput( line ); | |||||
} | |||||
else | |||||
{ | |||||
task.handleOutput( line ); | |||||
} | |||||
} | |||||
} | |||||
} |