Browse Source

Extract inner classes and move contentEuqls to FileUtil

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270804 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
3c5d592a35
6 changed files with 96 additions and 200 deletions
  1. +22
    -0
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/AddAsisRemove.java
  2. +22
    -0
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/CrLf.java
  3. +4
    -100
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/FixCRLF.java
  4. +22
    -0
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/text/AddAsisRemove.java
  5. +22
    -0
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/text/CrLf.java
  6. +4
    -100
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/text/FixCRLF.java

+ 22
- 0
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/AddAsisRemove.java View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.text;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* Enumerated attribute with the values "asis", "add" and "remove".
*/
public class AddAsisRemove
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"add", "asis", "remove"};
}
}

+ 22
- 0
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/CrLf.java View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.text;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
*/
public class CrLf
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"asis", "cr", "lf", "crlf"};
}
}

+ 4
- 100
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/FixCRLF.java View File

@@ -7,7 +7,6 @@
*/
package org.apache.tools.ant.taskdefs.text;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -16,17 +15,16 @@ import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.DirectoryScanner;

/**
* Task to convert text source files to local OS formatting conventions, as well
@@ -69,7 +67,6 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
* @version $Revision$ $Name$
*/

public class FixCRLF
extends MatchingTask
{
@@ -759,7 +756,8 @@ public class FixCRLF
{
// Compare the destination with the temp file
getLogger().debug( "destFile exists" );
if( !contentEquals( destFile, tmpFile ) )
boolean result = FileUtil.contentEquals( destFile, tmpFile );
if( !result )
{
getLogger().debug( destFile + " is being written" );
if( !destFile.delete() )
@@ -829,99 +827,6 @@ public class FixCRLF
}// end of finally
}

private boolean contentEquals( File f1, File f2 )
throws IOException
{
if( f1.exists() != f2.exists() )
{
return false;
}

if( !f1.exists() )
{
// two not existing files are equal
return true;
}

if( f1.isDirectory() || f2.isDirectory() )
{
// don't want to compare directory contents for now
return false;
}

InputStream in1 = null;
InputStream in2 = null;
try
{
in1 = new BufferedInputStream( new FileInputStream( f1 ) );
in2 = new BufferedInputStream( new FileInputStream( f2 ) );

int expectedByte = in1.read();
while( expectedByte != -1 )
{
if( expectedByte != in2.read() )
{
return false;
}
expectedByte = in1.read();
}
if( in2.read() != -1 )
{
return false;
}
return true;
}
finally
{
if( in1 != null )
{
try
{
in1.close();
}
catch( IOException e )
{
}
}
if( in2 != null )
{
try
{
in2.close();
}
catch( IOException e )
{
}
}
}
}

/**
* Enumerated attribute with the values "asis", "add" and "remove".
*
* @author RT
*/
public static class AddAsisRemove extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"add", "asis", "remove"};
}
}

/**
* Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
*
* @author RT
*/
public static class CrLf extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"asis", "cr", "lf", "crlf"};
}
}

class OneLiner
implements Iterator
{
@@ -1200,5 +1105,4 @@ public class FixCRLF
}
}
}

}

+ 22
- 0
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/text/AddAsisRemove.java View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.text;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* Enumerated attribute with the values "asis", "add" and "remove".
*/
public class AddAsisRemove
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"add", "asis", "remove"};
}
}

+ 22
- 0
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/text/CrLf.java View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.text;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
*/
public class CrLf
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"asis", "cr", "lf", "crlf"};
}
}

+ 4
- 100
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/text/FixCRLF.java View File

@@ -7,7 +7,6 @@
*/
package org.apache.tools.ant.taskdefs.text;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -16,17 +15,16 @@ import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.DirectoryScanner;

/**
* Task to convert text source files to local OS formatting conventions, as well
@@ -69,7 +67,6 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
* @version $Revision$ $Name$
*/

public class FixCRLF
extends MatchingTask
{
@@ -759,7 +756,8 @@ public class FixCRLF
{
// Compare the destination with the temp file
getLogger().debug( "destFile exists" );
if( !contentEquals( destFile, tmpFile ) )
boolean result = FileUtil.contentEquals( destFile, tmpFile );
if( !result )
{
getLogger().debug( destFile + " is being written" );
if( !destFile.delete() )
@@ -829,99 +827,6 @@ public class FixCRLF
}// end of finally
}

private boolean contentEquals( File f1, File f2 )
throws IOException
{
if( f1.exists() != f2.exists() )
{
return false;
}

if( !f1.exists() )
{
// two not existing files are equal
return true;
}

if( f1.isDirectory() || f2.isDirectory() )
{
// don't want to compare directory contents for now
return false;
}

InputStream in1 = null;
InputStream in2 = null;
try
{
in1 = new BufferedInputStream( new FileInputStream( f1 ) );
in2 = new BufferedInputStream( new FileInputStream( f2 ) );

int expectedByte = in1.read();
while( expectedByte != -1 )
{
if( expectedByte != in2.read() )
{
return false;
}
expectedByte = in1.read();
}
if( in2.read() != -1 )
{
return false;
}
return true;
}
finally
{
if( in1 != null )
{
try
{
in1.close();
}
catch( IOException e )
{
}
}
if( in2 != null )
{
try
{
in2.close();
}
catch( IOException e )
{
}
}
}
}

/**
* Enumerated attribute with the values "asis", "add" and "remove".
*
* @author RT
*/
public static class AddAsisRemove extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"add", "asis", "remove"};
}
}

/**
* Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
*
* @author RT
*/
public static class CrLf extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"asis", "cr", "lf", "crlf"};
}
}

class OneLiner
implements Iterator
{
@@ -1200,5 +1105,4 @@ public class FixCRLF
}
}
}

}

Loading…
Cancel
Save