stevel 2003/10/23 22:52:55 Modified: src/main/org/apache/tools/ant/taskdefs/optional/dotnet JSharp.java NetCommand.java src/etc/testcases/taskdefs/optional dotnet.xml Log: fix for bug#19630; no handling large files. Needs testing on mono! Revision Changes Path 1.8 +1 -1 ant/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java Index: JSharp.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/JSharp.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- JSharp.java 24 Sep 2003 00:58:29 -0000 1.7 +++ JSharp.java 24 Oct 2003 05:52:55 -0000 1.8 @@ -69,7 +69,7 @@ * * @author Steve Loughran * @since ant1.6 - * @ant.task category="dotnet" + * @ant.task category="dotnet" name="jsharpc" */ public class JSharp extends DotnetCompile { 1.26 +101 -1 ant/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java Index: NetCommand.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- NetCommand.java 21 Sep 2003 20:20:03 -0000 1.25 +++ NetCommand.java 24 Oct 2003 05:52:55 -0000 1.26 @@ -65,12 +65,17 @@ import java.io.File; import java.io.IOException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.io.BufferedOutputStream; +import java.io.FileNotFoundException; import java.util.Hashtable; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; import org.apache.tools.ant.taskdefs.LogStreamHandler; @@ -131,6 +136,21 @@ private File directory; /** + * flag to set to to use @file based command cache + */ + private boolean useResponseFile=false; + + /** + * name of a temp file; may be null + */ + private File temporaryCommandFile; + + /** + * internal threshold for auto-switch + */ + private int automaticResponseFileThreshold = 64; + + /** * constructor * [EMAIL PROTECTED] title (for logging/errors) @@ -232,6 +252,38 @@ } /** + * getter + * @return response file state + */ + public boolean isUseResponseFile() { + return useResponseFile; + } + + /** + * set this to true to always use the response file + * @param useResponseFile + */ + public void setUseResponseFile(boolean useResponseFile) { + this.useResponseFile = useResponseFile; + } + + /** + * getter for threshold + * @return 0 for disabled, or a threshold for enabling response files + */ + public int getAutomaticResponseFileThreshold() { + return automaticResponseFileThreshold; + } + + /** + * set threshold for automatically using response files -use 0 for off + * @param automaticResponseFileThreshold + */ + public void setAutomaticResponseFileThreshold(int automaticResponseFileThreshold) { + this.automaticResponseFileThreshold = automaticResponseFileThreshold; + } + + /** * set up the command sequence.. */ protected void prepareExecutor() { @@ -272,7 +324,7 @@ //in verbose mode we always log stuff logVerbose(commandLine.describeCommand()); } - executable.setCommandline(commandLine.getCommandline()); + setExecutableCommandLine(); err = executable.execute(); if (Execute.isFailure(err)) { if (failOnError) { @@ -283,6 +335,54 @@ } } catch (IOException e) { throw new BuildException(title + " failed: " + e, e, owner.getLocation()); + } finally { + if (temporaryCommandFile != null) { + temporaryCommandFile.delete(); + } + } + } + + /** + * set the executable command line + */ + private void setExecutableCommandLine() { + + String[] commands = commandLine.getCommandline(); + //always trigger file mode if commands are big enough + if (automaticResponseFileThreshold>0 && + commands.length > automaticResponseFileThreshold) { + useResponseFile = true; + } + if (!useResponseFile || commands.length <= 1) { + //the simple action is to send the command line in as is + executable.setCommandline(commands); + } else { + //but for big operations, we save all the params to a temp file + //and set @tmpfile as the command -then we remember to delete the tempfile + //afterwards + FileOutputStream fos = null; + FileUtils fileUtils = FileUtils.newFileUtils(); + + temporaryCommandFile = fileUtils.createTempFile("cmd", ".txt", null); + owner.log("Using response file"+temporaryCommandFile,Project.MSG_VERBOSE); + + try { + fos = new FileOutputStream(temporaryCommandFile); + PrintWriter out = new PrintWriter(new BufferedOutputStream(fos)); + //start at 1 because element 0 is the executable name + for (int i = 1; i < commands.length; ++i) { + out.println(commands[i]); + } + out.flush(); + out.close(); + } catch (IOException ex) { + throw new BuildException("saving command stream to " + temporaryCommandFile, ex); + } + + String newCommandLine[] = new String[2]; + newCommandLine[0] = commands[0]; + newCommandLine[1] = "@" + temporaryCommandFile.getAbsolutePath(); + executable.setCommandline(newCommandLine); } } 1.16 +25 -0 ant/src/etc/testcases/taskdefs/optional/dotnet.xml Index: dotnet.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/dotnet.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- dotnet.xml 6 Oct 2003 14:24:49 -0000 1.15 +++ dotnet.xml 24 Oct 2003 05:52:55 -0000 1.16 @@ -101,6 +101,16 @@ </and> </condition> <property name="mono.executable" value="mint"/> + + <!-- now set a prop of the compiler name to whatever we found --> + <condition property="cs.compiler" value="csc"> + <isset property="csc.found"/> + </condition> + + <condition property="cs.compiler" value="mcs"> + <isset property="mcs.found"/> + </condition> + </target> <target name="init" depends="probe_for_apps"> @@ -333,6 +343,21 @@ </jsharpc> <exec executable="${jsharp.exe}" failonerror="true" /> </target> + + <target name="testCSCresponseFile" depends="validate_csc" > + <property name="testCSCresponseFile.exe" + location="${build.dir}/testCSCresponseFile.exe" /> + <csc + destFile="${testCSCresponseFile.exe}" + targetType="exe" + executable="${cs.compiler}" + useResponseFile="true" + > + </csc> + <available property="app.created" file="${testCSCresponseFile.exe}"/> + <fail unless="app.created">No app ${testCSCresponseFile.exe} created</fail> + <delete file="${testCSCresponseFile.exe}"/> + </target> </project>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]