git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270870 13f79535-47bb-0310-9956-ffa450edef68master
@@ -11,10 +11,13 @@ import java.io.File; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.aut.nativelib.ExecException; | import org.apache.aut.nativelib.ExecException; | ||||
import org.apache.aut.nativelib.ExecManager; | |||||
import org.apache.aut.nativelib.ExecMetaData; | import org.apache.aut.nativelib.ExecMetaData; | ||||
import org.apache.aut.nativelib.impl.DefaultExecManager; | |||||
import org.apache.avalon.excalibur.io.IOUtil; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.factorys.ExecManagerFactory; | |||||
import org.apache.myrmidon.services.ServiceException; | |||||
/** | /** | ||||
* Runs an external program. | * Runs an external program. | ||||
@@ -36,34 +39,6 @@ public class Execute | |||||
*/ | */ | ||||
private boolean m_useVMLauncher = true; | private boolean m_useVMLauncher = true; | ||||
private static File getAntHomeDirectory() | |||||
{ | |||||
final String antHome = System.getProperty( "myrmidon.home" ); | |||||
if( null == antHome ) | |||||
{ | |||||
final String message = | |||||
"Cannot locate antRun script: Property 'ant.home' not specified"; | |||||
throw new IllegalStateException( message ); | |||||
} | |||||
return new File( antHome ); | |||||
} | |||||
/** | |||||
* Creates a new execute object. | |||||
* | |||||
* @param streamHandler the stream handler used to handle the input and | |||||
* output streams of the subprocess. | |||||
*/ | |||||
public Execute( final ExecuteStreamHandler streamHandler ) | |||||
{ | |||||
//m_streamHandler = streamHandler; | |||||
} | |||||
public Execute() | |||||
{ | |||||
} | |||||
public void setTimeout( final long timeout ) | public void setTimeout( final long timeout ) | ||||
{ | { | ||||
m_timeout = timeout; | m_timeout = timeout; | ||||
@@ -142,8 +117,8 @@ public class Execute | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
final DefaultExecManager manager = | |||||
new DefaultExecManager( getAntHomeDirectory() ); | |||||
final ExecManagerFactory factory = new ExecManagerFactory(); | |||||
final ExecManager manager = (ExecManager)factory.createService(); | |||||
final ExecMetaData metaData = | final ExecMetaData metaData = | ||||
new ExecMetaData( m_command, m_environment, | new ExecMetaData( m_command, m_environment, | ||||
@@ -154,5 +129,14 @@ public class Execute | |||||
{ | { | ||||
throw new TaskException( ee.getMessage(), ee ); | throw new TaskException( ee.getMessage(), ee ); | ||||
} | } | ||||
catch( final ServiceException se ) | |||||
{ | |||||
throw new TaskException( se.getMessage(), se ); | |||||
} | |||||
finally | |||||
{ | |||||
IOUtil.shutdownStream( m_output ); | |||||
IOUtil.shutdownStream( m_error ); | |||||
} | |||||
} | } | ||||
} | } |
@@ -10,13 +10,15 @@ package org.apache.tools.ant.taskdefs.exec; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.aut.nativelib.DefaultExecOutputHandler; | import org.apache.aut.nativelib.DefaultExecOutputHandler; | ||||
import org.apache.aut.nativelib.ExecException; | import org.apache.aut.nativelib.ExecException; | ||||
import org.apache.aut.nativelib.ExecManager; | |||||
import org.apache.aut.nativelib.ExecMetaData; | import org.apache.aut.nativelib.ExecMetaData; | ||||
import org.apache.aut.nativelib.ExecOutputHandler; | import org.apache.aut.nativelib.ExecOutputHandler; | ||||
import org.apache.aut.nativelib.impl.DefaultExecManager; | |||||
import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.factorys.ExecManagerFactory; | |||||
import org.apache.myrmidon.services.ServiceException; | |||||
/** | /** | ||||
* Runs an external program. | * Runs an external program. | ||||
@@ -38,19 +40,6 @@ public class Execute2 | |||||
*/ | */ | ||||
private boolean m_useVMLauncher = true; | private boolean m_useVMLauncher = true; | ||||
private static File getAntHomeDirectory() | |||||
{ | |||||
final String antHome = System.getProperty( "myrmidon.home" ); | |||||
if( null == antHome ) | |||||
{ | |||||
final String message = | |||||
"Cannot locate antRun script: Property 'ant.home' not specified"; | |||||
throw new IllegalStateException( message ); | |||||
} | |||||
return new File( antHome ); | |||||
} | |||||
public void setTimeout( final long timeout ) | public void setTimeout( final long timeout ) | ||||
{ | { | ||||
m_timeout = timeout; | m_timeout = timeout; | ||||
@@ -66,7 +55,7 @@ public class Execute2 | |||||
* | * | ||||
* @param commandline the commandline of the subprocess to launch | * @param commandline the commandline of the subprocess to launch | ||||
*/ | */ | ||||
public void setCommandline( String[] commandline ) | |||||
public void setCommandline( final String[] commandline ) | |||||
{ | { | ||||
m_command = commandline; | m_command = commandline; | ||||
} | } | ||||
@@ -117,8 +106,8 @@ public class Execute2 | |||||
try | try | ||||
{ | { | ||||
final DefaultExecManager manager = | |||||
new DefaultExecManager( getAntHomeDirectory() ); | |||||
final ExecManagerFactory factory = new ExecManagerFactory(); | |||||
final ExecManager manager = (ExecManager)factory.createService(); | |||||
final ExecMetaData metaData = | final ExecMetaData metaData = | ||||
new ExecMetaData( m_command, m_environment, | new ExecMetaData( m_command, m_environment, | ||||
@@ -130,5 +119,9 @@ public class Execute2 | |||||
{ | { | ||||
throw new TaskException( ee.getMessage(), ee ); | throw new TaskException( ee.getMessage(), ee ); | ||||
} | } | ||||
catch( final ServiceException se ) | |||||
{ | |||||
throw new TaskException( se.getMessage(), se ); | |||||
} | |||||
} | } | ||||
} | } |
@@ -11,10 +11,13 @@ import java.io.File; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.aut.nativelib.ExecException; | import org.apache.aut.nativelib.ExecException; | ||||
import org.apache.aut.nativelib.ExecManager; | |||||
import org.apache.aut.nativelib.ExecMetaData; | import org.apache.aut.nativelib.ExecMetaData; | ||||
import org.apache.aut.nativelib.impl.DefaultExecManager; | |||||
import org.apache.avalon.excalibur.io.IOUtil; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.factorys.ExecManagerFactory; | |||||
import org.apache.myrmidon.services.ServiceException; | |||||
/** | /** | ||||
* Runs an external program. | * Runs an external program. | ||||
@@ -36,34 +39,6 @@ public class Execute | |||||
*/ | */ | ||||
private boolean m_useVMLauncher = true; | private boolean m_useVMLauncher = true; | ||||
private static File getAntHomeDirectory() | |||||
{ | |||||
final String antHome = System.getProperty( "myrmidon.home" ); | |||||
if( null == antHome ) | |||||
{ | |||||
final String message = | |||||
"Cannot locate antRun script: Property 'ant.home' not specified"; | |||||
throw new IllegalStateException( message ); | |||||
} | |||||
return new File( antHome ); | |||||
} | |||||
/** | |||||
* Creates a new execute object. | |||||
* | |||||
* @param streamHandler the stream handler used to handle the input and | |||||
* output streams of the subprocess. | |||||
*/ | |||||
public Execute( final ExecuteStreamHandler streamHandler ) | |||||
{ | |||||
//m_streamHandler = streamHandler; | |||||
} | |||||
public Execute() | |||||
{ | |||||
} | |||||
public void setTimeout( final long timeout ) | public void setTimeout( final long timeout ) | ||||
{ | { | ||||
m_timeout = timeout; | m_timeout = timeout; | ||||
@@ -142,8 +117,8 @@ public class Execute | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
final DefaultExecManager manager = | |||||
new DefaultExecManager( getAntHomeDirectory() ); | |||||
final ExecManagerFactory factory = new ExecManagerFactory(); | |||||
final ExecManager manager = (ExecManager)factory.createService(); | |||||
final ExecMetaData metaData = | final ExecMetaData metaData = | ||||
new ExecMetaData( m_command, m_environment, | new ExecMetaData( m_command, m_environment, | ||||
@@ -154,5 +129,14 @@ public class Execute | |||||
{ | { | ||||
throw new TaskException( ee.getMessage(), ee ); | throw new TaskException( ee.getMessage(), ee ); | ||||
} | } | ||||
catch( final ServiceException se ) | |||||
{ | |||||
throw new TaskException( se.getMessage(), se ); | |||||
} | |||||
finally | |||||
{ | |||||
IOUtil.shutdownStream( m_output ); | |||||
IOUtil.shutdownStream( m_error ); | |||||
} | |||||
} | } | ||||
} | } |
@@ -10,13 +10,15 @@ package org.apache.tools.ant.taskdefs.exec; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Properties; | import java.util.Properties; | ||||
import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.aut.nativelib.DefaultExecOutputHandler; | import org.apache.aut.nativelib.DefaultExecOutputHandler; | ||||
import org.apache.aut.nativelib.ExecException; | import org.apache.aut.nativelib.ExecException; | ||||
import org.apache.aut.nativelib.ExecManager; | |||||
import org.apache.aut.nativelib.ExecMetaData; | import org.apache.aut.nativelib.ExecMetaData; | ||||
import org.apache.aut.nativelib.ExecOutputHandler; | import org.apache.aut.nativelib.ExecOutputHandler; | ||||
import org.apache.aut.nativelib.impl.DefaultExecManager; | |||||
import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.factorys.ExecManagerFactory; | |||||
import org.apache.myrmidon.services.ServiceException; | |||||
/** | /** | ||||
* Runs an external program. | * Runs an external program. | ||||
@@ -38,19 +40,6 @@ public class Execute2 | |||||
*/ | */ | ||||
private boolean m_useVMLauncher = true; | private boolean m_useVMLauncher = true; | ||||
private static File getAntHomeDirectory() | |||||
{ | |||||
final String antHome = System.getProperty( "myrmidon.home" ); | |||||
if( null == antHome ) | |||||
{ | |||||
final String message = | |||||
"Cannot locate antRun script: Property 'ant.home' not specified"; | |||||
throw new IllegalStateException( message ); | |||||
} | |||||
return new File( antHome ); | |||||
} | |||||
public void setTimeout( final long timeout ) | public void setTimeout( final long timeout ) | ||||
{ | { | ||||
m_timeout = timeout; | m_timeout = timeout; | ||||
@@ -66,7 +55,7 @@ public class Execute2 | |||||
* | * | ||||
* @param commandline the commandline of the subprocess to launch | * @param commandline the commandline of the subprocess to launch | ||||
*/ | */ | ||||
public void setCommandline( String[] commandline ) | |||||
public void setCommandline( final String[] commandline ) | |||||
{ | { | ||||
m_command = commandline; | m_command = commandline; | ||||
} | } | ||||
@@ -117,8 +106,8 @@ public class Execute2 | |||||
try | try | ||||
{ | { | ||||
final DefaultExecManager manager = | |||||
new DefaultExecManager( getAntHomeDirectory() ); | |||||
final ExecManagerFactory factory = new ExecManagerFactory(); | |||||
final ExecManager manager = (ExecManager)factory.createService(); | |||||
final ExecMetaData metaData = | final ExecMetaData metaData = | ||||
new ExecMetaData( m_command, m_environment, | new ExecMetaData( m_command, m_environment, | ||||
@@ -130,5 +119,9 @@ public class Execute2 | |||||
{ | { | ||||
throw new TaskException( ee.getMessage(), ee ); | throw new TaskException( ee.getMessage(), ee ); | ||||
} | } | ||||
catch( final ServiceException se ) | |||||
{ | |||||
throw new TaskException( se.getMessage(), se ); | |||||
} | |||||
} | } | ||||
} | } |