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...@locus.apache.org on 2000/11/16 10:57:47 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/util MergingMapper.java SourceFileScanner.java
bodewig 00/11/16 01:57:47
Modified: src/main/org/apache/tools/ant/taskdefs Tar.java
UpToDate.java Zip.java
src/main/org/apache/tools/ant/util SourceFileScanner.java
Added: src/main/org/apache/tools/ant/util MergingMapper.java
Log:
Added a MergingMapper where multiple source files map to a single
target file. Use it in tar, zip, uptodate.
Revision Changes Path
1.6 +21 -6 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
Index: Tar.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Tar.java 2000/09/18 07:55:01 1.5
+++ Tar.java 2000/11/16 09:57:46 1.6
@@ -56,12 +56,14 @@
import java.io.*;
import org.apache.tools.ant.*;
+import org.apache.tools.ant.util.*;
import org.apache.tools.tar.*;
/**
* Creates a TAR archive.
*
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
+ * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class Tar extends MatchingTask {
@@ -72,15 +74,15 @@
/**
* This is the name/location of where to create the tar file.
*/
- public void setTarfile(String tarFilename) {
- tarFile = project.resolveFile(tarFilename);
+ public void setTarfile(File tarFile) {
+ this.tarFile = tarFile;
}
/**
* This is the base directory to look in for things to tar.
*/
- public void setBasedir(String baseDirname) {
- baseDir = project.resolveFile(baseDirname);
+ public void setBasedir(File baseDir) {
+ this.baseDir = baseDir;
}
public void execute() throws BuildException {
@@ -97,12 +99,18 @@
throw new BuildException("basedir does not exist!", location);
}
- log("Building tar: "+ tarFile.getAbsolutePath());
-
DirectoryScanner ds = super.getDirectoryScanner(baseDir);
String[] files = ds.getIncludedFiles();
+ if (archiveIsUpToDate(files)) {
+ log("Nothing to do: "+tarFile.getAbsolutePath()+" is up to date.",
+ Project.MSG_INFO);
+ return;
+ }
+
+ log("Building tar: "+ tarFile.getAbsolutePath(), Project.MSG_INFO);
+
TarOutputStream tOut = null;
try {
tOut = new TarOutputStream(new FileOutputStream(tarFile));
@@ -149,5 +157,12 @@
} finally {
fIn.close();
}
+ }
+
+ protected boolean archiveIsUpToDate(String[] files) {
+ SourceFileScanner sfs = new SourceFileScanner(this);
+ MergingMapper mm = new MergingMapper();
+ mm.setTo(tarFile.getAbsolutePath());
+ return sfs.restrict(files, baseDir, null, mm).length == 0;
}
}
1.2 +6 -22 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
Index: UpToDate.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/UpToDate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UpToDate.java 2000/09/20 14:49:37 1.1
+++ UpToDate.java 2000/11/16 09:57:46 1.2
@@ -56,6 +56,7 @@
import org.apache.tools.ant.*;
import org.apache.tools.ant.types.*;
+import org.apache.tools.ant.util.*;
import java.io.*;
import java.util.Enumeration;
import java.util.Date;
@@ -67,7 +68,7 @@
*
* @author William Ferguson <a href="mailto:williamf@mincom.com">williamf@mincom.com</a>
* @author Hiroaki Nakamura <a href="mailto:hnakamur@mc.neweb.ne.jp">hnakamur@mc.neweb.ne.jp</a>
- * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
+ * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class UpToDate extends MatchingTask {
@@ -137,26 +138,9 @@
}
protected boolean scanDir(File srcDir, File destFile, String files[]) {
- long destLastModified = destFile.lastModified();
- long now = (new Date()).getTime();
- if (destLastModified > now) {
- log("Warning: destfile modified in the future: " +
- destFile.getPath(), Project.MSG_WARN);
- }
-
- for (int i = 0; i < files.length; i++) {
- File srcFile = new File(srcDir, files[i]);
-
- long srcLastModified = srcFile.lastModified();
- if (srcLastModified > now) {
- log("Warning: file modified in the future: " +
- files[i], Project.MSG_WARN);
- }
-
- if (srcLastModified > destLastModified) {
- return false;
- }
- }
- return true;
+ SourceFileScanner sfs = new SourceFileScanner(this);
+ MergingMapper mm = new MergingMapper();
+ mm.setTo(destFile.getAbsolutePath());
+ return sfs.restrict(files, srcDir, null, mm).length == 0;
}
}
1.17 +32 -13 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
Index: Zip.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Zip.java 2000/10/30 13:35:42 1.16
+++ Zip.java 2000/11/16 09:57:46 1.17
@@ -56,6 +56,7 @@
import org.apache.tools.ant.*;
import org.apache.tools.ant.types.*;
+import org.apache.tools.ant.util.*;
import java.io.*;
import java.util.Enumeration;
@@ -70,6 +71,7 @@
*
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
+ * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class Zip extends MatchingTask {
@@ -96,15 +98,15 @@
* This is the base directory to look in for
* things to zip.
*/
- public void setBasedir(String baseDirname) {
- baseDir = project.resolveFile(baseDirname);
+ public void setBasedir(File baseDir) {
+ this.baseDir = baseDir;
}
/**
* Sets whether we want to compress the files or only store them.
*/
- public void setCompress(String compress) {
- doCompress = Project.toBoolean(compress);
+ public void setCompress(boolean c) {
+ doCompress = c;
}
/**
@@ -228,7 +230,8 @@
*/
protected boolean isUpToDate(FileScanner[] scanners, File zipFile) throws BuildException
{
- File[] files = grabFiles(scanners);
+ String[][] fileNames = grabFileNames(scanners);
+ File[] files = grabFiles(scanners, fileNames);
if (files.length == 0) {
if (emptyBehavior.equals("skip")) {
log("Warning: skipping "+archiveType+" archive " + zipFile +
@@ -264,10 +267,14 @@
return true;
}
} else {
- // Probably unnecessary but just for clarity:
if (!zipFile.exists()) return false;
- for (int i=0; i<files.length; i++) {
- if (files[i].lastModified() > zipFile.lastModified()) {
+
+ SourceFileScanner sfs = new SourceFileScanner(this);
+ MergingMapper mm = new MergingMapper();
+ mm.setTo(zipFile.getAbsolutePath());
+ for (int i=0; i<scanners.length; i++) {
+ if (sfs.restrict(fileNames[i], scanners[i].getBasedir(), null,
+ mm).length > 0) {
return false;
}
}
@@ -276,16 +283,28 @@
}
protected static File[] grabFiles(FileScanner[] scanners) {
- Vector files = new Vector ();
- for (int i = 0; i < scanners.length; i++) {
+ return grabFiles(scanners, grabFileNames(scanners));
+ }
+
+ protected static File[] grabFiles(FileScanner[] scanners,
+ String[][] fileNames) {
+ Vector files = new Vector();
+ for (int i = 0; i < fileNames.length; i++) {
File thisBaseDir = scanners[i].getBasedir();
- String[] ifiles = scanners[i].getIncludedFiles();
- for (int j = 0; j < ifiles.length; j++)
- files.addElement(new File(thisBaseDir, ifiles[j]));
+ for (int j = 0; j < fileNames[i].length; j++)
+ files.addElement(new File(thisBaseDir, fileNames[i][j]));
}
File[] toret = new File[files.size()];
files.copyInto(toret);
return toret;
+ }
+
+ protected static String[][] grabFileNames(FileScanner[] scanners) {
+ String[][] result = new String[scanners.length][];
+ for (int i=0; i<scanners.length; i++) {
+ result[i] = scanners[i].getIncludedFiles();
+ }
+ return result;
}
protected void zipDir(File dir, ZipOutputStream zOut, String vPath)
1.3 +9 -2 jakarta-ant/src/main/org/apache/tools/ant/util/SourceFileScanner.java
Index: SourceFileScanner.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/SourceFileScanner.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SourceFileScanner.java 2000/11/16 08:59:26 1.2
+++ SourceFileScanner.java 2000/11/16 09:57:47 1.3
@@ -87,7 +87,8 @@
*
* @param files the original set of files
* @param srcDir all files are relative to this directory
- * @param destDir target files live here
+ * @param destDir target files live here. if null file names
+ * returned by the mapper are assumed to be absolute.
* @param mapper knows how to construct a target file names from
* source file names.
*/
@@ -116,7 +117,13 @@
boolean added = false;
targetList.setLength(0);
for (int j=0; !added && j<targets.length; j++) {
- File dest = new File(destDir, targets[j]);
+ File dest = null;
+ if (destDir == null) {
+ dest = new File(targets[j]);
+ } else {
+ dest = new File(destDir, targets[j]);
+ }
+
if (!dest.exists()) {
task.log(files[i]+" added as "+dest.getAbsolutePath()+" doesn\'t exist.",
Project.MSG_VERBOSE);
1.1 jakarta-ant/src/main/org/apache/tools/ant/util/MergingMapper.java
Index: MergingMapper.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.util;
/**
* Implementation of FileNameMapper that always returns the same
* target file name.
*
* <p>This is the default FileNameMapper for the archiving tasks and
* uptodate.</p>
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class MergingMapper implements FileNameMapper {
protected String[] mergedFile = null;
/**
* Ignored.
*/
public void setFrom(String from) {}
/**
* Sets the name of the merged file.
*/
public void setTo(String to) {
mergedFile = new String[] {to};
}
/**
* Returns an one-element array containing the file name set via setTo.
*/
public String[] mapFileName(String sourceFileName) {
return mergedFile;
}
}