stevel 2003/10/23 22:54:23 Modified: src/testcases/org/apache/tools/ant/taskdefs/optional Tag: ANT_16_BRANCH DotnetTest.java src/main/org/apache/tools/ant/taskdefs/optional/dotnet Tag: ANT_16_BRANCH DotnetCompile.java JSharp.java NetCommand.java src/etc/testcases/taskdefs/optional Tag: ANT_16_BRANCH dotnet.xml Log: Ant1.6 backport of fix for bug#19630; no handling large files. Needs testing on mono! (split into multple commits as CVS is whining) Revision Changes Path No revision No revision 1.5.2.1 +8 -0 ant/src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java Index: DotnetTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/DotnetTest.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- DotnetTest.java 21 Sep 2003 22:29:54 -0000 1.5 +++ DotnetTest.java 24 Oct 2003 05:54:22 -0000 1.5.2.1 @@ -157,5 +157,13 @@ public void testJsharp() throws Exception { executeTarget("jsharp"); } + + /** + * test we can handle jsharp (if found) + */ + public void testResponseFile() throws Exception { + executeTarget("testCSCresponseFile"); + } + } No revision No revision 1.17.2.2 +27 -0 ant/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java Index: DotnetCompile.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetCompile.java,v retrieving revision 1.17.2.1 retrieving revision 1.17.2.2 diff -u -r1.17.2.1 -r1.17.2.2 --- DotnetCompile.java 23 Sep 2003 08:29:07 -0000 1.17.2.1 +++ DotnetCompile.java 24 Oct 2003 05:54:23 -0000 1.17.2.2 @@ -205,6 +205,11 @@ */ protected Vector referenceFilesets = new Vector(); + /** + * flag to set to to use @file based command cache + */ + private boolean useResponseFile = false; + private static final int AUTOMATIC_RESPONSE_FILE_THRESHOLD = 64; /** * constructor inits everything and set up the search pattern @@ -796,6 +801,25 @@ return "**/*." + getFileExtension(); } + /** + * getter for flag + * @return + */ + public boolean isUseResponseFile() { + return useResponseFile; + } + + /** + * Flag to turn on response file use; default=false. + * When set the command params are saved to a file and + * this is passed in with @file. The task automatically switches + * to this mode with big commands; this option is here for + * testing and emergencies + * @param useResponseFile + */ + public void setUseResponseFile(boolean useResponseFile) { + this.useResponseFile = useResponseFile; + } /** * do the work by building the command line and then calling it @@ -806,6 +830,9 @@ throws BuildException { validate(); NetCommand command = createNetCommand(); + //set up response file options + command.setAutomaticResponseFileThreshold(AUTOMATIC_RESPONSE_FILE_THRESHOLD); + command.setUseResponseFile(useResponseFile); //fill in args fillInSharedParameters(command); addResources(command); 1.5.2.2 +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.5.2.1 retrieving revision 1.5.2.2 diff -u -r1.5.2.1 -r1.5.2.2 --- JSharp.java 27 Sep 2003 03:00:05 -0000 1.5.2.1 +++ JSharp.java 24 Oct 2003 05:54:23 -0000 1.5.2.2 @@ -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.25.2.1 +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.25.2.1 diff -u -r1.25 -r1.25.2.1 --- NetCommand.java 21 Sep 2003 20:20:03 -0000 1.25 +++ NetCommand.java 24 Oct 2003 05:54:23 -0000 1.25.2.1 @@ -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); } } No revision No revision 1.13.2.3 +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.13.2.2 retrieving revision 1.13.2.3 diff -u -r1.13.2.2 -r1.13.2.3 --- dotnet.xml 6 Oct 2003 14:25:31 -0000 1.13.2.2 +++ dotnet.xml 24 Oct 2003 05:54:23 -0000 1.13.2.3 @@ -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]