donaldp 02/01/11 21:01:24
Modified: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
Java.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb
BorlandGenerateClient.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp
WLJspc.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers
JasperC.java
proposal/myrmidon/src/main/org/apache/tools/ant/types
CommandlineJava.java SysProperties.java
proposal/myrmidon/src/main/org/apache/tools/ant/util
SourceFileScanner.java
Log:
Start to refactor and cleanup javac task
Revision Changes Path
1.21 +76 -232
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Java.java
Index: Java.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Java.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Java.java 6 Jan 2002 02:02:52 -0000 1.20
+++ Java.java 12 Jan 2002 05:01:23 -0000 1.21
@@ -8,14 +8,13 @@
package org.apache.tools.ant.taskdefs;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import org.apache.myrmidon.api.TaskException;
+import org.apache.myrmidon.api.AbstractTask;
import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.exec.Execute;
-import org.apache.tools.ant.taskdefs.exec.LogOutputStream;
+import org.apache.tools.ant.taskdefs.exec.Execute2;
import org.apache.tools.ant.types.Argument;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.EnvironmentVariable;
@@ -29,41 +28,29 @@
* [EMAIL PROTECTED]</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
*/
-public class Java extends Task
+public class Java
+ extends AbstractTask
{
-
- private CommandlineJava cmdl = new CommandlineJava();
- private boolean fork = false;
- private File dir = null;
- private PrintStream outStream = null;
- private boolean failOnError = false;
- private File out;
+ private CommandlineJava m_cmdl = new CommandlineJava();
+ private boolean m_fork;
+ private File m_dir;
+ private PrintStream m_outStream;
/**
* Set the class name.
- *
- * @param s The new Classname value
- * @exception TaskException Description of Exception
*/
public void setClassname( String s )
- throws TaskException
{
- if( cmdl.getJar() != null )
- {
- throw new TaskException( "Cannot use 'jar' and 'classname'
attributes in same command" );
- }
- cmdl.setClassname( s );
+ m_cmdl.setClassname( s );
}
/**
* Set the classpath to be used for this compilation.
- *
- * @param s The new Classpath value
*/
- public void setClasspath( Path s )
+ public void setClasspath( final Path classpath )
throws TaskException
{
- createClasspath().append( s );
+ createClasspath().append( classpath );
}
/**
@@ -71,145 +58,83 @@
*
* @param d The new Dir value
*/
- public void setDir( File d )
+ public void setDir( final File dir )
{
- this.dir = d;
- }
-
- /**
- * Throw a TaskException if process returns non 0.
- *
- * @param fail The new Failonerror value
- */
- public void setFailonerror( boolean fail )
- {
- failOnError = fail;
+ m_dir = dir;
}
/**
* Set the forking flag.
- *
- * @param s The new Fork value
*/
- public void setFork( boolean s )
+ public void setFork( final boolean fork )
{
- this.fork = s;
+ m_fork = fork;
}
/**
* set the jar name...
- *
- * @param jarfile The new Jar value
- * @exception TaskException Description of Exception
*/
- public void setJar( File jarfile )
- throws TaskException
+ public void setJar( final File jar )
{
- if( cmdl.getClassname() != null )
- {
- throw new TaskException( "Cannot use 'jar' and 'classname'
attributes in same command." );
- }
- cmdl.setJar( jarfile.getAbsolutePath() );
+ m_cmdl.setJar( jar.getAbsolutePath() );
}
/**
* Set the command used to start the VM (only if fork==false).
- *
- * @param s The new Jvm value
*/
- public void setJvm( String s )
+ public void setJvm( final String jvm )
{
- cmdl.setVm( s );
+ m_cmdl.setVm( jvm );
}
/**
* -mx or -Xmx depending on VM version
- *
- * @param max The new Maxmemory value
- */
- public void setMaxmemory( String max )
- {
- cmdl.setMaxmemory( max );
- }
-
- /**
- * File the output of the process is redirected to.
- *
- * @param out The new Output value
*/
- public void setOutput( File out )
+ public void setMaxmemory( final String max )
{
- this.out = out;
+ m_cmdl.setMaxmemory( max );
}
/**
* Add a nested sysproperty element.
- *
- * @param sysp The feature to be added to the Sysproperty attribute
*/
- public void addSysproperty( EnvironmentVariable sysp )
+ public void addSysproperty( final EnvironmentVariable sysp )
{
- cmdl.addSysproperty( sysp );
- }
-
- /**
- * Clear out the arguments to this java task.
- */
- public void clearArgs()
- {
- cmdl.clearJavaArgs();
+ m_cmdl.addSysproperty( sysp );
}
/**
* Creates a nested arg element.
- *
- * @return Description of the Returned Value
*/
public Argument createArg()
{
- return cmdl.createArgument();
+ return m_cmdl.createArgument();
}
/**
* Creates a nested classpath element
- *
- * @return Description of the Returned Value
*/
public Path createClasspath()
throws TaskException
{
- return cmdl.createClasspath().createPath();
+ return m_cmdl.createClasspath().createPath();
}
/**
* Creates a nested jvmarg element.
- *
- * @return Description of the Returned Value
*/
public Argument createJvmarg()
{
- return cmdl.createVmArgument();
+ return m_cmdl.createVmArgument();
}
- /**
- * Do the execution.
- *
- * @exception TaskException Description of Exception
- */
public void execute()
throws TaskException
{
- int err = -1;
- if( ( err = executeJava() ) != 0 )
+ final int err = executeJava();
+ if( 0 != err )
{
- if( failOnError )
- {
- throw new TaskException( "Java returned: " + err );
- }
- else
- {
- getLogger().error( "Java Result: " + err );
- }
+ throw new TaskException( "Java returned: " + err );
}
}
@@ -223,188 +148,107 @@
public int executeJava()
throws TaskException
{
- String classname = cmdl.getClassname();
- if( classname == null && cmdl.getJar() == null )
+ final String classname = m_cmdl.getClassname();
+ final String jar = m_cmdl.getJar();
+ if( classname != null && jar != null )
+ {
+ throw new TaskException( "Only one of Classname and Jar can be
set." );
+ }
+ else if( classname == null && jar == null )
{
throw new TaskException( "Classname must not be null." );
}
- if( !fork && cmdl.getJar() != null )
+
+ if( !m_fork && jar != null )
{
throw new TaskException( "Cannot execute a jar in non-forked
mode. Please set fork='true'. " );
}
- if( fork )
+ if( m_fork )
{
- getLogger().debug( "Forking " + cmdl.toString() );
+ getLogger().debug( "Forking " + m_cmdl.toString() );
- return run( cmdl.getCommandline() );
+ return run( m_cmdl.getCommandline() );
}
else
{
- if( cmdl.getVmCommand().size() > 1 )
+ if( m_cmdl.getVmCommand().size() > 1 )
{
getLogger().warn( "JVM args ignored when same JVM is used."
);
}
- if( dir != null )
+ if( m_dir != null )
{
getLogger().warn( "Working directory ignored when same JVM
is used." );
}
- getLogger().debug( "Running in same VM " +
cmdl.getJavaCommand().toString() );
- run( cmdl );
+ getLogger().debug( "Running in same VM " +
m_cmdl.getJavaCommand().toString() );
+ run( m_cmdl );
return 0;
}
}
- protected void handleErrorOutput( String line )
- {
- if( outStream != null )
- {
- outStream.println( line );
- }
- else
- {
- super.handleErrorOutput( line );
- }
- }
-
- protected void handleOutput( String line )
- {
- if( outStream != null )
- {
- outStream.println( line );
- }
- else
- {
- super.handleOutput( line );
- }
- }
-
/**
* Executes the given classname with the given arguments as it was a
command
* line application.
- *
- * @param classname Description of Parameter
- * @param args Description of Parameter
- * @exception TaskException Description of Exception
*/
- protected void run( String classname, ArrayList args )
+ protected void run( final String classname, final ArrayList args )
throws TaskException
{
- CommandlineJava cmdj = new CommandlineJava();
- cmdj.setClassname( classname );
- for( int i = 0; i < args.size(); i++ )
+ final CommandlineJava java = new CommandlineJava();
+ java.setClassname( classname );
+
+ final int size = args.size();
+ for( int i = 0; i < size; i++ )
{
- cmdj.createArgument().setValue( (String)args.get( i ) );
+ final String arg = (String)args.get( i );
+ java.createArgument().setValue( arg );
}
- run( cmdj );
+ run( java );
}
/**
* Executes the given classname with the given arguments as it was a
command
* line application.
- *
- * @param command Description of Parameter
- * @exception TaskException Description of Exception
*/
- private void run( CommandlineJava command )
+ private void run( final CommandlineJava command )
throws TaskException
{
- ExecuteJava exe = new ExecuteJava();
+ final ExecuteJava exe = new ExecuteJava();
exe.setJavaCommand( command.getJavaCommand() );
exe.setClasspath( command.getClasspath() );
exe.setSystemProperties( command.getSystemProperties() );
- if( out != null )
- {
- try
- {
- outStream = new PrintStream( new FileOutputStream( out ) );
- exe.execute( getProject() );
- }
- catch( IOException io )
- {
- throw new TaskException( "Error", io );
- }
- finally
- {
- if( outStream != null )
- {
- outStream.close();
- }
- }
- }
- else
- {
- exe.execute( getProject() );
- }
+ exe.execute();
}
/**
* Executes the given classname with the given arguments in a separate
VM.
- *
- * @param command Description of Parameter
- * @return Description of the Returned Value
- * @exception TaskException Description of Exception
*/
- private int run( String[] command )
+ private int run( final String[] command )
throws TaskException
{
- FileOutputStream fos = null;
- try
- {
- Execute exe = null;
- if( out == null )
- {
- exe = new Execute();
- exe.setOutput( new LogOutputStream( getLogger(), false ) );
- exe.setError( new LogOutputStream( getLogger(), true ) );
-
- }
- else
- {
- fos = new FileOutputStream( out );
- exe = new Execute();
- exe.setOutput( fos );
- exe.setError( fos );
- }
-
- if( dir == null )
- {
- dir = getBaseDirectory();
- }
- else if( !dir.exists() || !dir.isDirectory() )
- {
- throw new TaskException( dir.getAbsolutePath() + " is not a
valid directory" );
- }
-
- exe.setWorkingDirectory( dir );
+ final Execute2 exe = new Execute2();
+ setupLogger( exe );
- exe.setCommandline( command );
- try
- {
- return exe.execute();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
+ if( m_dir == null )
+ {
+ m_dir = getBaseDirectory();
}
- catch( IOException io )
+ else if( !m_dir.exists() || !m_dir.isDirectory() )
{
- throw new TaskException( "Error", io );
+ final String message = m_dir.getAbsolutePath() + " is not a
valid directory";
+ throw new TaskException( message );
}
- finally
+
+ exe.setWorkingDirectory( m_dir );
+ exe.setCommandline( command );
+ try
{
- if( fos != null )
- {
- try
- {
- fos.close();
- }
- catch( IOException io )
- {
- }
- }
+ return exe.execute();
+ }
+ catch( IOException e )
+ {
+ final String message = "Error executing class";
+ throw new TaskException( message, e );
}
}
}
1.12 +1 -1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java
Index: BorlandGenerateClient.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- BorlandGenerateClient.java 4 Jan 2002 09:25:13 -0000 1.11
+++ BorlandGenerateClient.java 12 Jan 2002 05:01:23 -0000 1.12
@@ -198,7 +198,7 @@
getLogger().info( "mode : java" );
org.apache.tools.ant.taskdefs.Java execTask = null;
- execTask = (Java)getProject().createTask( "java" );
+ execTask = null;//(Java)getProject().createTask( "java" );
execTask.setDir( new File( "." ) );
execTask.setClassname(
"com.inprise.server.commandline.EJBUtilities" );
1.14 +2 -2
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java
Index: WLJspc.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- WLJspc.java 30 Dec 2001 00:21:52 -0000 1.13
+++ WLJspc.java 12 Jan 2002 05:01:23 -0000 1.14
@@ -170,7 +170,7 @@
// Therefore, takes loads of time
// Can pass directories at a time (*.jsp) but easily runs out of
memory on hefty dirs
// (even on a Sun)
- Java helperTask = (Java)getProject().createTask( "java" );
+ Java helperTask = null;//(Java)getProject().createTask( "java" );
helperTask.setFork( true );
helperTask.setClassname( "weblogic.jspc" );
String[] args = new String[ 12 ];
@@ -227,7 +227,7 @@
System.out.println( "arg = " + arg );
- helperTask.clearArgs();
+ //helperTask.clearArgs();
helperTask.createArg().setValue( arg );
helperTask.setClasspath( compileClasspath );
if( helperTask.executeJava() != 0 )
1.7 +2 -2
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java
Index: JasperC.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JasperC.java 23 Dec 2001 14:22:46 -0000 1.6
+++ JasperC.java 12 Jan 2002 05:01:23 -0000 1.7
@@ -34,14 +34,14 @@
{
// Create an instance of the compiler, redirecting output to
// the project log
- Java java = (Java)( getJspc().getProject() ).createTask( "java"
);
+ //FIXME
+ Java java = null;//(Java)( getJspc().getProject() ).createTask(
"java" );
if( getJspc().getClasspath() != null )
java.setClasspath( getJspc().getClasspath() );
java.setClassname( "org.apache.jasper.JspC" );
String args[] = cmd.getArguments();
for( int i = 0; i < args.length; i++ )
java.createArg().setValue( args[ i ] );
- java.setFailonerror( true );
java.execute();
return true;
}
1.15 +6 -4
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/CommandlineJava.java
Index: CommandlineJava.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/CommandlineJava.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- CommandlineJava.java 6 Jan 2002 02:32:21 -0000 1.14
+++ CommandlineJava.java 12 Jan 2002 05:01:23 -0000 1.15
@@ -8,7 +8,8 @@
package org.apache.tools.ant.types;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Os;
+import org.apache.aut.nativelib.Os;
+import java.io.File;
/**
* A representation of a Java command line that is nothing more than a
composite
@@ -18,7 +19,8 @@
* @author [EMAIL PROTECTED]
* @author <a href="[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
-public class CommandlineJava implements Cloneable
+public class CommandlineJava
+ implements Cloneable
{
private Commandline vmCommand = new Commandline();
private Commandline javaCommand = new Commandline();
@@ -265,8 +267,8 @@
// on Windows java.home doesn't always refer to the correct location,
// so we need to fall back to assuming java is somewhere on the
// PATH.
- java.io.File jExecutable =
- new java.io.File( System.getProperty( "java.home" ) +
+ File jExecutable =
+ new File( System.getProperty( "java.home" ) +
"/../bin/java" + extension );
if( jExecutable.exists() && !Os.isFamily( "netware" ) )
1.2 +1 -1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/SysProperties.java
Index: SysProperties.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/SysProperties.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SysProperties.java 30 Dec 2001 06:46:37 -0000 1.1
+++ SysProperties.java 12 Jan 2002 05:01:23 -0000 1.2
@@ -11,7 +11,7 @@
import java.util.Iterator;
import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.exec.ExecException;
+import org.apache.aut.nativelib.ExecException;
/**
* Specialized EnvironmentData class for System properties
1.9 +1 -1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/SourceFileScanner.java
Index: SourceFileScanner.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/SourceFileScanner.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SourceFileScanner.java 23 Dec 2001 14:23:48 -0000 1.8
+++ SourceFileScanner.java 12 Jan 2002 05:01:23 -0000 1.9
@@ -12,7 +12,7 @@
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Os;
+import org.apache.aut.nativelib.Os;
import org.apache.tools.ant.Task;
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>