Browse Source

IDEA reformat, and changed destdir to be File type

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273325 13f79535-47bb-0310-9956-ffa450edef68
master
Erik Hatcher 23 years ago
parent
commit
8d3464f4e6
1 changed files with 51 additions and 53 deletions
  1. +51
    -53
      src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java

+ 51
- 53
src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java View File

@@ -69,9 +69,9 @@ import javax.media.jai.PlanarImage;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector;


/** /**
* A MatchingTask which relies on <A HREF="http://java.sun.com/products/java-media/jai">JAI (Java Advanced Imaging)</A> * A MatchingTask which relies on <A HREF="http://java.sun.com/products/java-media/jai">JAI (Java Advanced Imaging)</A>
@@ -98,7 +98,7 @@ public class Image extends MatchingTask {
protected File srcDir = null; protected File srcDir = null;
protected File destDir = null; protected File destDir = null;


/**
/**
* Adds a set of files to be deleted. * Adds a set of files to be deleted.
*/ */
public void addFileset(FileSet set) { public void addFileset(FileSet set) {
@@ -109,9 +109,9 @@ public class Image extends MatchingTask {
* If false, note errors to the output but keep going. * If false, note errors to the output but keep going.
* @param failonerror true or false * @param failonerror true or false
*/ */
public void setFailOnError(boolean failonerror) {
this.failonerror = failonerror;
}
public void setFailOnError(boolean failonerror) {
this.failonerror = failonerror;
}


/** /**
* Set the source dir to find the image files. * Set the source dir to find the image files.
@@ -131,14 +131,14 @@ public class Image extends MatchingTask {
* Sets whether or not to overwrite a file if there is a naming conflict. * Sets whether or not to overwrite a file if there is a naming conflict.
*/ */
public void setOverwrite(boolean overwrite) { public void setOverwrite(boolean overwrite) {
this.overwrite = overwrite;
this.overwrite = overwrite;
} }


/** /**
* Enables Garbage Collection after each image processed. Defaults to false. * Enables Garbage Collection after each image processed. Defaults to false.
*/ */
public void setGc(boolean gc) { public void setGc(boolean gc) {
garbage_collect = gc;
garbage_collect = gc;
} }




@@ -146,8 +146,8 @@ public class Image extends MatchingTask {
* Sets the destination directory for manipulated images. * Sets the destination directory for manipulated images.
* @param destination The destination directory * @param destination The destination directory
*/ */
public void setDestDir(String destination) {
destDir = new File(destination);
public void setDestDir(File destDir) {
this.destDir = destDir;
} }


/** /**
@@ -213,8 +213,8 @@ public class Image extends MatchingTask {
str_encoding = "TIFF"; str_encoding = "TIFF";
} }


if (destDir == null){
destDir = srcDir;
if (destDir == null) {
destDir = srcDir;
} }


File new_file = new File(destDir.getAbsolutePath() + File.separator + file.getName()); File new_file = new File(destDir.getAbsolutePath() + File.separator + file.getName());
@@ -231,19 +231,17 @@ public class Image extends MatchingTask {




} catch (IOException err) { } catch (IOException err) {
if (!failonerror) {
log("Error processing file: " + err);
} else {
throw new BuildException(err);
}
}

catch (java.lang.RuntimeException rerr) {
if (!failonerror) {
log("Error processing file: " + rerr);
} else {
throw new BuildException(rerr);
}
if (!failonerror) {
log("Error processing file: " + err);
} else {
throw new BuildException(err);
}
} catch (java.lang.RuntimeException rerr) {
if (!failonerror) {
log("Error processing file: " + rerr);
} else {
throw new BuildException(rerr);
}
} }


} }
@@ -251,58 +249,58 @@ public class Image extends MatchingTask {
/** /**
* Executes the Task * Executes the Task
*/ */
public void execute() {
public void execute() throws BuildException {


validateAttributes(); validateAttributes();


try { try {
DirectoryScanner ds = null; DirectoryScanner ds = null;
String [] files =null;
String[] files = null;
ArrayList filesList = new ArrayList(); ArrayList filesList = new ArrayList();




// deal with specified srcDir // deal with specified srcDir
if (srcDir != null){
ds = super.getDirectoryScanner(srcDir);
if (srcDir != null) {
ds = super.getDirectoryScanner(srcDir);


files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++){
filesList.add(new File(srcDir.getAbsolutePath() + File.separator + files[i]));
}
files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
filesList.add(new File(srcDir.getAbsolutePath() + File.separator + files[i]));
}
} }
// deal with the filesets // deal with the filesets
for (int i = 0; i < filesets.size(); i++) { for (int i = 0; i < filesets.size(); i++) {
FileSet fs = (FileSet) filesets.elementAt(i); FileSet fs = (FileSet) filesets.elementAt(i);
ds = fs.getDirectoryScanner(getProject()); ds = fs.getDirectoryScanner(getProject());
files =ds.getIncludedFiles();
files = ds.getIncludedFiles();
File fromDir = fs.getDir(getProject()); File fromDir = fs.getDir(getProject());
for (int j = 0; j < files.length; j++){
filesList.add(new File(fromDir.getAbsolutePath() + File.separator + files[j]));
for (int j = 0; j < files.length; j++) {
filesList.add(new File(fromDir.getAbsolutePath() + File.separator + files[j]));
} }
} }


if (!overwrite){
// remove any files that shouldn't be overwritten.
ArrayList filesToRemove = new ArrayList();
for(Iterator i = filesList.iterator();i.hasNext();){
File f = (File)i.next();
File new_file = new File(destDir.getAbsolutePath() + File.separator + f.getName());
if (new_file.exists()){
filesToRemove.add(f);
}
}
filesList.removeAll(filesToRemove);
if (!overwrite) {
// remove any files that shouldn't be overwritten.
ArrayList filesToRemove = new ArrayList();
for (Iterator i = filesList.iterator(); i.hasNext();) {
File f = (File) i.next();
File new_file = new File(destDir.getAbsolutePath() + File.separator + f.getName());
if (new_file.exists()) {
filesToRemove.add(f);
}
}
filesList.removeAll(filesToRemove);
} }




// iterator through all the files and process them. // iterator through all the files and process them.
for (Iterator i = filesList.iterator();i.hasNext();){
File file = (File)i.next();
for (Iterator i = filesList.iterator(); i.hasNext();) {
File file = (File) i.next();


processFile(file);
if (garbage_collect) {
System.gc();
}
processFile(file);
if (garbage_collect) {
System.gc();
}
} }




@@ -321,7 +319,7 @@ public class Image extends MatchingTask {
protected void validateAttributes() throws BuildException { protected void validateAttributes() throws BuildException {
if (srcDir == null && filesets.size() == 0) { if (srcDir == null && filesets.size() == 0) {
throw new BuildException("Specify at least one source " throw new BuildException("Specify at least one source "
+ "- a srcDir or a fileset.");
+ "- a srcDir or a fileset.");
} }


if (srcDir == null && destDir == null) { if (srcDir == null && destDir == null) {


Loading…
Cancel
Save