of) and use it in Touch as well as BuildNumber. Various JDK 1.1 issues. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272157 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -60,6 +60,7 @@ import java.io.IOException; | |||||
| import java.util.Properties; | import java.util.Properties; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.BuildException; | 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. | * This is a basic task that can be used to track build numbers. | ||||
| @@ -125,7 +126,7 @@ public class BuildNumber | |||||
| output = new FileOutputStream( m_file ); | output = new FileOutputStream( m_file ); | ||||
| final String header = "Build Number for ANT. Do not edit!"; | final String header = "Build Number for ANT. Do not edit!"; | ||||
| properties.store( output, header ); | |||||
| properties.save( output, header ); | |||||
| } | } | ||||
| catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
| { | { | ||||
| @@ -230,7 +231,7 @@ public class BuildNumber | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| m_file.createNewFile(); | |||||
| FileUtils.newFileUtils().createNewFile(m_file); | |||||
| } | } | ||||
| catch( final IOException ioe ) | catch( final IOException ioe ) | ||||
| { | { | ||||
| @@ -168,9 +168,7 @@ public class Touch extends Task { | |||||
| if (!file.exists()) { | if (!file.exists()) { | ||||
| log("Creating "+file, Project.MSG_INFO); | log("Creating "+file, Project.MSG_INFO); | ||||
| try { | try { | ||||
| FileOutputStream fos = new FileOutputStream(file); | |||||
| fos.write(new byte[0]); | |||||
| fos.close(); | |||||
| fileUtils.createNewFile(file); | |||||
| } catch (IOException ioe) { | } catch (IOException ioe) { | ||||
| throw new BuildException("Could not create "+file, ioe, | throw new BuildException("Could not create "+file, ioe, | ||||
| location); | location); | ||||
| @@ -53,7 +53,7 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.cvslib; | package org.apache.tools.ant.taskdefs.cvslib; | ||||
| import java.util.ArrayList; | |||||
| import java.util.Vector; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| /** | /** | ||||
| @@ -68,7 +68,7 @@ class CVSEntry | |||||
| private Date m_date; | private Date m_date; | ||||
| private final String m_author; | private final String m_author; | ||||
| private final String m_comment; | 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 ) | public CVSEntry( Date date, String author, String comment ) | ||||
| { | { | ||||
| @@ -79,12 +79,12 @@ class CVSEntry | |||||
| public void addFile( String file, String revision ) | 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 ) | 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() | Date getDate() | ||||
| @@ -102,7 +102,7 @@ class CVSEntry | |||||
| return m_comment; | return m_comment; | ||||
| } | } | ||||
| ArrayList getFiles() | |||||
| Vector getFiles() | |||||
| { | { | ||||
| return m_files; | return m_files; | ||||
| } | } | ||||
| @@ -56,6 +56,7 @@ package org.apache.tools.ant.taskdefs.cvslib; | |||||
| import java.text.ParseException; | import java.text.ParseException; | ||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.Enumeration; | |||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import java.util.Properties; | import java.util.Properties; | ||||
| @@ -109,8 +110,13 @@ class ChangeLogParser | |||||
| */ | */ | ||||
| CVSEntry[] getEntrySetAsArray() | 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; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -360,7 +360,7 @@ public class ChangeLogTask | |||||
| //Skip dates that are too late | //Skip dates that are too late | ||||
| continue; | continue; | ||||
| } | } | ||||
| results.add( cvsEntry ); | |||||
| results.addElement( cvsEntry ); | |||||
| } | } | ||||
| final CVSEntry[] resultArray = new CVSEntry[ results.size() ]; | final CVSEntry[] resultArray = new CVSEntry[ results.size() ]; | ||||
| @@ -55,7 +55,7 @@ package org.apache.tools.ant.taskdefs.cvslib; | |||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
| import java.util.Iterator; | |||||
| import java.util.Enumeration; | |||||
| /** | /** | ||||
| * Class used to generate an XML changelog. | * Class used to generate an XML changelog. | ||||
| @@ -99,10 +99,10 @@ class ChangeLogWriter | |||||
| output.println( "\t\t<time>" + c_outputTime.format( entry.getDate() ) + "</time>" ); | output.println( "\t\t<time>" + c_outputTime.format( entry.getDate() ) + "</time>" ); | ||||
| output.println( "\t\t<author>" + entry.getAuthor() + "</author>" ); | 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<file>" ); | ||||
| output.println( "\t\t\t<name>" + file.getName() + "</name>" ); | output.println( "\t\t\t<name>" + file.getName() + "</name>" ); | ||||
| output.println( "\t\t\t<revision>" + file.getRevision() + "</revision>" ); | output.println( "\t\t\t<revision>" + file.getRevision() + "</revision>" ); | ||||
| @@ -62,8 +62,8 @@ package org.apache.tools.ant.taskdefs.cvslib; | |||||
| */ | */ | ||||
| class RCSFile | class RCSFile | ||||
| { | { | ||||
| private final String m_name; | |||||
| private final String m_revision; | |||||
| private String m_name; | |||||
| private String m_revision; | |||||
| private String m_previousRevision; | private String m_previousRevision; | ||||
| RCSFile( final String name, final String rev ) | RCSFile( final String name, final String rev ) | ||||
| @@ -810,5 +810,35 @@ public class FileUtils { | |||||
| } | } | ||||
| return text; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -372,6 +372,16 @@ public class FileUtilsTest extends TestCase { | |||||
| new File("docs.xml"))); | new File("docs.xml"))); | ||||
| } | } | ||||
| /** | |||||
| * 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 | * adapt file separators to local conventions | ||||
| */ | */ | ||||