You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2002/04/02 10:42:45 UTC
cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/util FileUtilsTest.java
bodewig 02/04/02 00:42:45
Modified: src/main/org/apache/tools/ant/taskdefs BuildNumber.java
Touch.java
src/main/org/apache/tools/ant/taskdefs/cvslib CVSEntry.java
ChangeLogParser.java ChangeLogTask.java
ChangeLogWriter.java RCSFile.java
src/main/org/apache/tools/ant/util FileUtils.java
src/testcases/org/apache/tools/ant/util FileUtilsTest.java
Log:
Add method to FileUtils that emulates File.createNewFile (well, sort
of) and use it in Touch as well as BuildNumber.
Various JDK 1.1 issues.
Revision Changes Path
1.3 +4 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java
Index: BuildNumber.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BuildNumber.java 29 Mar 2002 01:40:12 -0000 1.2
+++ BuildNumber.java 2 Apr 2002 08:42:44 -0000 1.3
@@ -60,6 +60,7 @@
import java.util.Properties;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.util.FileUtils;
/**
* This is a basic task that can be used to track build numbers.
@@ -70,7 +71,7 @@
* by one and write it back out into the file.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.2 $ $Date: 2002/03/29 01:40:12 $
+ * @version $Revision: 1.3 $ $Date: 2002/04/02 08:42:44 $
* @ant.task name="buildnumber"
*/
public class BuildNumber
@@ -125,7 +126,7 @@
output = new FileOutputStream( m_file );
final String header = "Build Number for ANT. Do not edit!";
- properties.store( output, header );
+ properties.save( output, header );
}
catch( final IOException ioe )
{
@@ -230,7 +231,7 @@
{
try
{
- m_file.createNewFile();
+ FileUtils.newFileUtils().createNewFile(m_file);
}
catch( final IOException ioe )
{
1.19 +1 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Touch.java
Index: Touch.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Touch.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Touch.java 3 Mar 2002 01:46:20 -0000 1.18
+++ Touch.java 2 Apr 2002 08:42:44 -0000 1.19
@@ -168,9 +168,7 @@
if (!file.exists()) {
log("Creating "+file, Project.MSG_INFO);
try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(new byte[0]);
- fos.close();
+ fileUtils.createNewFile(file);
} catch (IOException ioe) {
throw new BuildException("Could not create "+file, ioe,
location);
1.2 +6 -6 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java
Index: CVSEntry.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CVSEntry.java 28 Mar 2002 22:58:21 -0000 1.1
+++ CVSEntry.java 2 Apr 2002 08:42:44 -0000 1.2
@@ -53,7 +53,7 @@
*/
package org.apache.tools.ant.taskdefs.cvslib;
-import java.util.ArrayList;
+import java.util.Vector;
import java.util.Date;
/**
@@ -61,14 +61,14 @@
*
* @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a>
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.1 $ $Date: 2002/03/28 22:58:21 $
+ * @version $Revision: 1.2 $ $Date: 2002/04/02 08:42:44 $
*/
class CVSEntry
{
private Date m_date;
private final String m_author;
private final String m_comment;
- private final ArrayList m_files = new ArrayList();
+ private final Vector m_files = new Vector();
public CVSEntry( Date date, String author, String comment )
{
@@ -79,12 +79,12 @@
public void addFile( String file, String revision )
{
- m_files.add( new RCSFile( file, revision ) );
+ m_files.addElement( new RCSFile( file, revision ) );
}
public void addFile( String file, String revision, String previousRevision )
{
- m_files.add( new RCSFile( file, revision, previousRevision ) );
+ m_files.addElement( new RCSFile( file, revision, previousRevision ) );
}
Date getDate()
@@ -102,7 +102,7 @@
return m_comment;
}
- ArrayList getFiles()
+ Vector getFiles()
{
return m_files;
}
1.4 +9 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
Index: ChangeLogParser.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ChangeLogParser.java 1 Apr 2002 06:28:56 -0000 1.3
+++ ChangeLogParser.java 2 Apr 2002 08:42:44 -0000 1.4
@@ -56,6 +56,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
@@ -63,7 +64,7 @@
* A class used to parse the output of the CVS log command.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.3 $ $Date: 2002/04/01 06:28:56 $
+ * @version $Revision: 1.4 $ $Date: 2002/04/02 08:42:44 $
*/
class ChangeLogParser
{
@@ -109,8 +110,13 @@
*/
CVSEntry[] getEntrySetAsArray()
{
- final CVSEntry[] array = new CVSEntry[ m_entries.values().size() ];
- return (CVSEntry[])m_entries.values().toArray( array );
+ final CVSEntry[] array = new CVSEntry[ m_entries.size() ];
+ Enumeration enum = m_entries.elements();
+ int i = 0;
+ while (enum.hasMoreElements()) {
+ array[i++] = (CVSEntry) enum.nextElement();
+ }
+ return array;
}
/**
1.7 +2 -2 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java
Index: ChangeLogTask.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ChangeLogTask.java 31 Mar 2002 11:15:53 -0000 1.6
+++ ChangeLogTask.java 2 Apr 2002 08:42:44 -0000 1.7
@@ -100,7 +100,7 @@
*
* @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a>
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.6 $ $Date: 2002/03/31 11:15:53 $
+ * @version $Revision: 1.7 $ $Date: 2002/04/02 08:42:44 $
* @ant.task name="changelog"
*/
public class ChangeLogTask
@@ -360,7 +360,7 @@
//Skip dates that are too late
continue;
}
- results.add( cvsEntry );
+ results.addElement( cvsEntry );
}
final CVSEntry[] resultArray = new CVSEntry[ results.size() ];
1.2 +5 -5 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java
Index: ChangeLogWriter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ChangeLogWriter.java 28 Mar 2002 22:58:21 -0000 1.1
+++ ChangeLogWriter.java 2 Apr 2002 08:42:44 -0000 1.2
@@ -55,13 +55,13 @@
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
-import java.util.Iterator;
+import java.util.Enumeration;
/**
* Class used to generate an XML changelog.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.1 $ $Date: 2002/03/28 22:58:21 $
+ * @version $Revision: 1.2 $ $Date: 2002/04/02 08:42:44 $
*/
class ChangeLogWriter
{
@@ -99,10 +99,10 @@
output.println( "\t\t<time>" + c_outputTime.format( entry.getDate() ) + "</time>" );
output.println( "\t\t<author>" + entry.getAuthor() + "</author>" );
- final Iterator iterator = entry.getFiles().iterator();
- while( iterator.hasNext() )
+ final Enumeration enumeration = entry.getFiles().elements();
+ while( enumeration.hasMoreElements() )
{
- final RCSFile file = (RCSFile)iterator.next();
+ final RCSFile file = (RCSFile)enumeration.nextElement();
output.println( "\t\t<file>" );
output.println( "\t\t\t<name>" + file.getName() + "</name>" );
output.println( "\t\t\t<revision>" + file.getRevision() + "</revision>" );
1.2 +3 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/RCSFile.java
Index: RCSFile.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/RCSFile.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RCSFile.java 28 Mar 2002 22:58:21 -0000 1.1
+++ RCSFile.java 2 Apr 2002 08:42:44 -0000 1.2
@@ -58,12 +58,12 @@
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a>
- * @version $Revision: 1.1 $ $Date: 2002/03/28 22:58:21 $
+ * @version $Revision: 1.2 $ $Date: 2002/04/02 08:42:44 $
*/
class RCSFile
{
- private final String m_name;
- private final String m_revision;
+ private String m_name;
+ private String m_revision;
private String m_previousRevision;
RCSFile( final String name, final String rev )
1.21 +31 -1 jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java
Index: FileUtils.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- FileUtils.java 21 Mar 2002 08:09:19 -0000 1.20
+++ FileUtils.java 2 Apr 2002 08:42:44 -0000 1.21
@@ -95,7 +95,7 @@
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
* @author <a href="mailto:jtulley@novell.com">Jeff Tulley</a>
*
- * @version $Revision: 1.20 $
+ * @version $Revision: 1.21 $
*/
public class FileUtils {
@@ -810,5 +810,35 @@
}
return text;
}
+
+ /**
+ * Emulation of File.createNewFile for JDK 1.1
+ *
+ * <p>This method does <strong>not</strong> guarantee that the
+ * operation is atomic.</p>
+ *
+ * @since 1.21, Ant 1.5
+ */
+ public boolean createNewFile(File f) throws IOException {
+ if (f != null) {
+ if (f.exists()) {
+ return false;
+ }
+
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(f);
+ fos.write(new byte[0]);
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ }
+
+ return true;
+ }
+ return false;
+ }
+
}
1.9 +10 -0 jakarta-ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
Index: FileUtilsTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FileUtilsTest.java 8 Mar 2002 08:20:15 -0000 1.8
+++ FileUtilsTest.java 2 Apr 2002 08:42:44 -0000 1.9
@@ -373,6 +373,16 @@
}
/**
+ * Test createNewFile
+ */
+ public void testCreateNewFile() throws IOException {
+ removeThis = new File("dummy");
+ assertTrue(!removeThis.exists());
+ fu.createNewFile(removeThis);
+ assertTrue(removeThis.exists());
+ }
+
+ /**
* adapt file separators to local conventions
*/
private String localize(String path) {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>