git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270586 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -7,13 +7,8 @@ | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.ccm; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.OutputStream; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler; | |||
| import org.apache.myrmidon.framework.exec.ExecOutputHandler; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| /** | |||
| @@ -23,7 +18,7 @@ import org.apache.tools.ant.types.Commandline; | |||
| */ | |||
| public class CCMCreateTask | |||
| extends Continuus | |||
| implements ExecuteStreamHandler | |||
| implements ExecOutputHandler | |||
| { | |||
| /** | |||
| * /comment -- comments associated to the task | |||
| @@ -138,47 +133,48 @@ public class CCMCreateTask | |||
| public void execute() | |||
| throws TaskException | |||
| { | |||
| final Commandline commandLine = new Commandline(); | |||
| // build the command line from what we got the format | |||
| // as specified in the CCM.EXE help | |||
| commandLine.setExecutable( getCcmCommand() ); | |||
| commandLine.createArgument().setValue( getCcmAction() ); | |||
| checkOptions( commandLine ); | |||
| final int result = run( commandLine, this ); | |||
| if( result != 0 ) | |||
| final Commandline commandLine = determineTask(); | |||
| if( null == m_task ) | |||
| { | |||
| String msg = "Failed executing: " + commandLine.toString(); | |||
| throw new TaskException( msg ); | |||
| final String message = "Error determining task"; | |||
| throw new TaskException( message ); | |||
| } | |||
| //create task ok, set this task as the default one | |||
| final Commandline commandLine2 = new Commandline(); | |||
| commandLine2.setExecutable( getCcmCommand() ); | |||
| commandLine2.createArgument().setValue( COMMAND_DEFAULT_TASK ); | |||
| commandLine2.createArgument().setValue( m_task ); | |||
| final Commandline cmd = new Commandline(); | |||
| cmd.setExecutable( getCcmCommand() ); | |||
| cmd.createArgument().setValue( COMMAND_DEFAULT_TASK ); | |||
| cmd.createArgument().setValue( m_task ); | |||
| getLogger().debug( commandLine.toString() ); | |||
| final int result2 = run( commandLine2 ); | |||
| final int result2 = run( cmd, null ); | |||
| if( result2 != 0 ) | |||
| { | |||
| String msg = "Failed executing: " + commandLine2.toString(); | |||
| throw new TaskException( msg ); | |||
| final String message = "Failed executing: " + cmd.toString(); | |||
| throw new TaskException( message ); | |||
| } | |||
| } | |||
| // implementation of org.apache.tools.ant.taskdefs.ExecuteStreamHandler interface | |||
| public void start() | |||
| throws IOException | |||
| private Commandline determineTask() | |||
| throws TaskException | |||
| { | |||
| } | |||
| final Commandline commandLine = new Commandline(); | |||
| public void stop() | |||
| { | |||
| // build the command line from what we got the format | |||
| // as specified in the CCM.EXE help | |||
| commandLine.setExecutable( getCcmCommand() ); | |||
| commandLine.createArgument().setValue( getCcmAction() ); | |||
| checkOptions( commandLine ); | |||
| final int result = run( commandLine, this ); | |||
| if( result != 0 ) | |||
| { | |||
| final String message = "Failed executing: " + commandLine.toString(); | |||
| throw new TaskException( message ); | |||
| } | |||
| return commandLine; | |||
| } | |||
| /** | |||
| @@ -218,55 +214,41 @@ public class CCMCreateTask | |||
| } | |||
| /** | |||
| * @param is The new ProcessErrorStream value | |||
| * @exception IOException Description of Exception | |||
| * Receive notification about the process writing | |||
| * to standard output. | |||
| */ | |||
| public void setProcessErrorStream( final InputStream error ) | |||
| throws IOException | |||
| public void stdout( final String line ) | |||
| { | |||
| final BufferedReader reader = new BufferedReader( new InputStreamReader( error ) ); | |||
| final String errorLine = reader.readLine(); | |||
| if( errorLine != null ) | |||
| { | |||
| getLogger().debug( "err " + errorLine ); | |||
| } | |||
| } | |||
| getLogger().debug( "buffer:" + line ); | |||
| final String task = getTask( line ); | |||
| public void setProcessInputStream( final OutputStream output ) | |||
| throws IOException | |||
| { | |||
| setTask( task ); | |||
| getLogger().debug( "task is " + m_task ); | |||
| } | |||
| /** | |||
| * read the output stream to retrieve the new task number. | |||
| */ | |||
| public void setProcessOutputStream( final InputStream input ) | |||
| throws TaskException, IOException | |||
| private String getTask( final String line ) | |||
| { | |||
| try | |||
| { | |||
| final BufferedReader reader = | |||
| new BufferedReader( new InputStreamReader( input ) ); | |||
| final String buffer = reader.readLine(); | |||
| if( buffer != null ) | |||
| { | |||
| getLogger().debug( "buffer:" + buffer ); | |||
| String taskstring = buffer.substring( buffer.indexOf( ' ' ) ).trim(); | |||
| taskstring = taskstring.substring( 0, taskstring.lastIndexOf( ' ' ) ).trim(); | |||
| setTask( taskstring ); | |||
| getLogger().debug( "task is " + m_task ); | |||
| } | |||
| } | |||
| catch( final NullPointerException npe ) | |||
| { | |||
| getLogger().error( "error procession stream , null pointer exception", npe ); | |||
| throw new TaskException( npe.getClass().getName(), npe ); | |||
| final String task = line.substring( line.indexOf( ' ' ) ).trim(); | |||
| return task.substring( 0, task.lastIndexOf( ' ' ) ).trim(); | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| getLogger().error( "error procession stream " + e.getMessage() ); | |||
| throw new TaskException( e.getMessage(), e ); | |||
| final String message = "error procession stream " + e.getMessage(); | |||
| getLogger().error( message, e ); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * Receive notification about the process writing | |||
| * to standard error. | |||
| */ | |||
| public void stderr( final String line ) | |||
| { | |||
| getLogger().debug( "err " + line ); | |||
| } | |||
| } | |||
| @@ -9,12 +9,10 @@ package org.apache.tools.ant.taskdefs.optional.ccm; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.taskdefs.exec.Execute; | |||
| import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler; | |||
| import org.apache.tools.ant.taskdefs.exec.LogOutputStream; | |||
| import org.apache.tools.ant.taskdefs.exec.LogStreamHandler; | |||
| import org.apache.myrmidon.framework.exec.ExecOutputHandler; | |||
| import org.apache.tools.ant.taskdefs.exec.Execute2; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| /** | |||
| @@ -28,7 +26,7 @@ import org.apache.tools.ant.types.Commandline; | |||
| * @author Benoit Moussaud benoit.moussaud@criltelecom.com | |||
| */ | |||
| public abstract class Continuus | |||
| extends Task | |||
| extends AbstractTask | |||
| { | |||
| /** | |||
| * Constant for the thing to execute | |||
| @@ -108,13 +106,17 @@ public abstract class Continuus | |||
| return toReturn; | |||
| } | |||
| protected int run( final Commandline cmd, | |||
| final ExecuteStreamHandler handler ) | |||
| protected int run( final Commandline cmd, final ExecOutputHandler handler ) | |||
| throws TaskException | |||
| { | |||
| try | |||
| { | |||
| final Execute exe = new Execute( handler ); | |||
| final Execute2 exe = new Execute2(); | |||
| setupLogger( exe ); | |||
| if( null != handler ) | |||
| { | |||
| exe.setExecOutputHandler( handler ); | |||
| } | |||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||
| exe.setCommandline( cmd.getCommandline() ); | |||
| return exe.execute(); | |||
| @@ -124,13 +126,4 @@ public abstract class Continuus | |||
| throw new TaskException( "Error", ioe ); | |||
| } | |||
| } | |||
| protected int run( final Commandline cmd ) | |||
| throws TaskException | |||
| { | |||
| final LogOutputStream output = new LogOutputStream( getLogger(), false ); | |||
| final LogOutputStream error = new LogOutputStream( getLogger(), true ); | |||
| final LogStreamHandler handler = new LogStreamHandler( output, error ); | |||
| return run( cmd, handler ); | |||
| } | |||
| } | |||
| @@ -7,13 +7,8 @@ | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.ccm; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.OutputStream; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler; | |||
| import org.apache.myrmidon.framework.exec.ExecOutputHandler; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| /** | |||
| @@ -23,7 +18,7 @@ import org.apache.tools.ant.types.Commandline; | |||
| */ | |||
| public class CCMCreateTask | |||
| extends Continuus | |||
| implements ExecuteStreamHandler | |||
| implements ExecOutputHandler | |||
| { | |||
| /** | |||
| * /comment -- comments associated to the task | |||
| @@ -138,47 +133,48 @@ public class CCMCreateTask | |||
| public void execute() | |||
| throws TaskException | |||
| { | |||
| final Commandline commandLine = new Commandline(); | |||
| // build the command line from what we got the format | |||
| // as specified in the CCM.EXE help | |||
| commandLine.setExecutable( getCcmCommand() ); | |||
| commandLine.createArgument().setValue( getCcmAction() ); | |||
| checkOptions( commandLine ); | |||
| final int result = run( commandLine, this ); | |||
| if( result != 0 ) | |||
| final Commandline commandLine = determineTask(); | |||
| if( null == m_task ) | |||
| { | |||
| String msg = "Failed executing: " + commandLine.toString(); | |||
| throw new TaskException( msg ); | |||
| final String message = "Error determining task"; | |||
| throw new TaskException( message ); | |||
| } | |||
| //create task ok, set this task as the default one | |||
| final Commandline commandLine2 = new Commandline(); | |||
| commandLine2.setExecutable( getCcmCommand() ); | |||
| commandLine2.createArgument().setValue( COMMAND_DEFAULT_TASK ); | |||
| commandLine2.createArgument().setValue( m_task ); | |||
| final Commandline cmd = new Commandline(); | |||
| cmd.setExecutable( getCcmCommand() ); | |||
| cmd.createArgument().setValue( COMMAND_DEFAULT_TASK ); | |||
| cmd.createArgument().setValue( m_task ); | |||
| getLogger().debug( commandLine.toString() ); | |||
| final int result2 = run( commandLine2 ); | |||
| final int result2 = run( cmd, null ); | |||
| if( result2 != 0 ) | |||
| { | |||
| String msg = "Failed executing: " + commandLine2.toString(); | |||
| throw new TaskException( msg ); | |||
| final String message = "Failed executing: " + cmd.toString(); | |||
| throw new TaskException( message ); | |||
| } | |||
| } | |||
| // implementation of org.apache.tools.ant.taskdefs.ExecuteStreamHandler interface | |||
| public void start() | |||
| throws IOException | |||
| private Commandline determineTask() | |||
| throws TaskException | |||
| { | |||
| } | |||
| final Commandline commandLine = new Commandline(); | |||
| public void stop() | |||
| { | |||
| // build the command line from what we got the format | |||
| // as specified in the CCM.EXE help | |||
| commandLine.setExecutable( getCcmCommand() ); | |||
| commandLine.createArgument().setValue( getCcmAction() ); | |||
| checkOptions( commandLine ); | |||
| final int result = run( commandLine, this ); | |||
| if( result != 0 ) | |||
| { | |||
| final String message = "Failed executing: " + commandLine.toString(); | |||
| throw new TaskException( message ); | |||
| } | |||
| return commandLine; | |||
| } | |||
| /** | |||
| @@ -218,55 +214,41 @@ public class CCMCreateTask | |||
| } | |||
| /** | |||
| * @param is The new ProcessErrorStream value | |||
| * @exception IOException Description of Exception | |||
| * Receive notification about the process writing | |||
| * to standard output. | |||
| */ | |||
| public void setProcessErrorStream( final InputStream error ) | |||
| throws IOException | |||
| public void stdout( final String line ) | |||
| { | |||
| final BufferedReader reader = new BufferedReader( new InputStreamReader( error ) ); | |||
| final String errorLine = reader.readLine(); | |||
| if( errorLine != null ) | |||
| { | |||
| getLogger().debug( "err " + errorLine ); | |||
| } | |||
| } | |||
| getLogger().debug( "buffer:" + line ); | |||
| final String task = getTask( line ); | |||
| public void setProcessInputStream( final OutputStream output ) | |||
| throws IOException | |||
| { | |||
| setTask( task ); | |||
| getLogger().debug( "task is " + m_task ); | |||
| } | |||
| /** | |||
| * read the output stream to retrieve the new task number. | |||
| */ | |||
| public void setProcessOutputStream( final InputStream input ) | |||
| throws TaskException, IOException | |||
| private String getTask( final String line ) | |||
| { | |||
| try | |||
| { | |||
| final BufferedReader reader = | |||
| new BufferedReader( new InputStreamReader( input ) ); | |||
| final String buffer = reader.readLine(); | |||
| if( buffer != null ) | |||
| { | |||
| getLogger().debug( "buffer:" + buffer ); | |||
| String taskstring = buffer.substring( buffer.indexOf( ' ' ) ).trim(); | |||
| taskstring = taskstring.substring( 0, taskstring.lastIndexOf( ' ' ) ).trim(); | |||
| setTask( taskstring ); | |||
| getLogger().debug( "task is " + m_task ); | |||
| } | |||
| } | |||
| catch( final NullPointerException npe ) | |||
| { | |||
| getLogger().error( "error procession stream , null pointer exception", npe ); | |||
| throw new TaskException( npe.getClass().getName(), npe ); | |||
| final String task = line.substring( line.indexOf( ' ' ) ).trim(); | |||
| return task.substring( 0, task.lastIndexOf( ' ' ) ).trim(); | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| getLogger().error( "error procession stream " + e.getMessage() ); | |||
| throw new TaskException( e.getMessage(), e ); | |||
| final String message = "error procession stream " + e.getMessage(); | |||
| getLogger().error( message, e ); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * Receive notification about the process writing | |||
| * to standard error. | |||
| */ | |||
| public void stderr( final String line ) | |||
| { | |||
| getLogger().debug( "err " + line ); | |||
| } | |||
| } | |||
| @@ -9,12 +9,10 @@ package org.apache.tools.ant.taskdefs.optional.ccm; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.taskdefs.exec.Execute; | |||
| import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler; | |||
| import org.apache.tools.ant.taskdefs.exec.LogOutputStream; | |||
| import org.apache.tools.ant.taskdefs.exec.LogStreamHandler; | |||
| import org.apache.myrmidon.framework.exec.ExecOutputHandler; | |||
| import org.apache.tools.ant.taskdefs.exec.Execute2; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| /** | |||
| @@ -28,7 +26,7 @@ import org.apache.tools.ant.types.Commandline; | |||
| * @author Benoit Moussaud benoit.moussaud@criltelecom.com | |||
| */ | |||
| public abstract class Continuus | |||
| extends Task | |||
| extends AbstractTask | |||
| { | |||
| /** | |||
| * Constant for the thing to execute | |||
| @@ -108,13 +106,17 @@ public abstract class Continuus | |||
| return toReturn; | |||
| } | |||
| protected int run( final Commandline cmd, | |||
| final ExecuteStreamHandler handler ) | |||
| protected int run( final Commandline cmd, final ExecOutputHandler handler ) | |||
| throws TaskException | |||
| { | |||
| try | |||
| { | |||
| final Execute exe = new Execute( handler ); | |||
| final Execute2 exe = new Execute2(); | |||
| setupLogger( exe ); | |||
| if( null != handler ) | |||
| { | |||
| exe.setExecOutputHandler( handler ); | |||
| } | |||
| exe.setWorkingDirectory( getBaseDirectory() ); | |||
| exe.setCommandline( cmd.getCommandline() ); | |||
| return exe.execute(); | |||
| @@ -124,13 +126,4 @@ public abstract class Continuus | |||
| throw new TaskException( "Error", ioe ); | |||
| } | |||
| } | |||
| protected int run( final Commandline cmd ) | |||
| throws TaskException | |||
| { | |||
| final LogOutputStream output = new LogOutputStream( getLogger(), false ); | |||
| final LogOutputStream error = new LogOutputStream( getLogger(), true ); | |||
| final LogStreamHandler handler = new LogStreamHandler( output, error ); | |||
| return run( cmd, handler ); | |||
| } | |||
| } | |||