Index: src/main/org/apache/tools/ant/taskdefs/Expand.java
===================================================================
RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/Expand.java,v
retrieving revision 1.42
diff -b -u -r1.42 Expand.java
--- src/main/org/apache/tools/ant/taskdefs/Expand.java 24 Apr 2003 13:02:56 -0000 1.42
+++ src/main/org/apache/tools/ant/taskdefs/Expand.java 18 May 2003 01:27:13 -0000
@@ -72,7 +72,11 @@
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.PatternSet;
+import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.util.FileNameMapper;
+import org.apache.tools.ant.util.FlatFileNameMapper;
+import org.apache.tools.ant.util.IdentityMapper;
/**
* Unzip a file.
@@ -81,6 +85,7 @@
* @author Stefan Bodewig
* @author Magesh Umasankar
* @author Jason Salter
+ * @author Mark Crocker
*
* @since Ant 1.1
*
@@ -98,6 +103,7 @@
private static final byte[] ZIPMARKER = {0x50, 0x4b, 0x03, 0x04};
private static final int MARKER_SIZE = ZIPMARKER.length;
private static final int MAX_LOOKAHEAD = 50 * 1024; // 50K.
+ protected Mapper mapperElement = null;
/**
* Do the work.
@@ -152,6 +158,21 @@
* This method is to be overridden by extending unarchival tasks.
*/
protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
+ if (mapperElement != null) {
+ FileNameMapper mapper = mapperElement.getImplementation();
+ String[] newDirs = mapper.mapFileName(srcF.getName());
+ if (newDirs != null && newDirs.length > 0) {
+ dir = new File(dir, newDirs[0]);
+ if (newDirs.length > 1) {
+ log("Expand: " + srcF + " produces multiple mapper matches! " +
+ "Only first match used.", Project.MSG_WARN);
+ }
+ } else {
+ log("Expand: " + srcF + " not matched by mapper. " +
+ "Not being expanded.", Project.MSG_INFO);
+ return;
+ }
+ }
log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
ZipInputStream zis = null;
FileInputStream fis = null;
@@ -338,6 +359,18 @@
*/
public void addFileset(FileSet set) {
filesets.addElement(set);
+ }
+
+ /**
+ * Defines the mapper to map source to destination files.
+ */
+ public Mapper createMapper() throws BuildException {
+ if (mapperElement != null) {
+ throw new BuildException("Cannot define more than one mapper",
+ getLocation());
+ }
+ mapperElement = new Mapper(getProject());
+ return mapperElement;
}
}