diff --git a/build.xml b/build.xml
index 4ff5ee6bd..a793a7ff9 100644
--- a/build.xml
+++ b/build.xml
@@ -68,10 +68,11 @@
-->
+
-
+
@@ -397,10 +398,18 @@
includes="${dist.name}/**"
excludes="${dist.name}/lib/optional.jar"/>
+ tarfile="${dist.base}/${dist.name}-bin.tar">
+
+
+
+
+
+
+
+
+
+
+
@@ -415,9 +424,17 @@
basedir="${dist.name}/.."
includes="${dist.name}/**"/>
+ tarfile="${dist.base}/${dist.name}-src.tar" >
+
+
+
+
+
+
+
+
+
+
@@ -432,6 +449,7 @@
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java
index 06adde55b..b8db73abc 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Tar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java
@@ -55,9 +55,11 @@
package org.apache.tools.ant.taskdefs;
import java.io.*;
+import java.util.*;
import org.apache.tools.ant.*;
import org.apache.tools.ant.util.*;
import org.apache.tools.tar.*;
+import org.apache.tools.ant.types.*;
/**
* Creates a TAR archive.
@@ -76,6 +78,16 @@ public class Tar extends MatchingTask {
String longFileMode = null;
+ Vector filesets = new Vector();
+ Vector fileSetFiles = new Vector();
+
+ public TarFileSet createFileSet() {
+ TarFileSet fileset = new TarFileSet();
+ filesets.addElement(fileset);
+ return fileset;
+ }
+
+
/**
* This is the name/location of where to create the tar file.
*/
@@ -107,19 +119,32 @@ public class Tar extends MatchingTask {
location);
}
- if (baseDir == null) {
- throw new BuildException("basedir attribute must be set!",
- location);
- }
- if (!baseDir.exists()) {
- throw new BuildException("basedir does not exist!", location);
+ if (baseDir != null) {
+ if (!baseDir.exists()) {
+ throw new BuildException("basedir does not exist!", location);
+ }
+
+ // add the main fileset to the list of filesets to process.
+ TarFileSet mainFileSet = new TarFileSet(fileset);
+ mainFileSet.setDir(baseDir);
+ mainFileSet.setDefaultexcludes(useDefaultExcludes);
+ filesets.addElement(mainFileSet);
}
- DirectoryScanner ds = super.getDirectoryScanner(baseDir);
-
- String[] files = ds.getIncludedFiles();
+ // check if tr is out of date with respect to each
+ // fileset
+ boolean upToDate = true;
+ for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
+ TarFileSet fs = (TarFileSet)e.nextElement();
+ String[] files = fs.getFiles(project);
+
+ if (!archiveIsUpToDate(files)) {
+ upToDate = false;
+ break;
+ }
+ }
- if (archiveIsUpToDate(files)) {
+ if (upToDate) {
log("Nothing to do: "+tarFile.getAbsolutePath()+" is up to date.",
Project.MSG_INFO);
return;
@@ -140,11 +165,15 @@ public class Tar extends MatchingTask {
else if (longFileMode.equalsIgnoreCase(GNU)) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
}
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir,files[i]);
- String name = files[i].replace(File.separatorChar,'/');
- tarFile(f, tOut, name);
+
+ for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
+ TarFileSet fs = (TarFileSet)e.nextElement();
+ String[] files = fs.getFiles(project);
+ for (int i = 0; i < files.length; i++) {
+ File f = new File(baseDir,files[i]);
+ String name = files[i].replace(File.separatorChar,'/');
+ tarFile(f, tOut, name, fs);
+ }
}
} catch (IOException ioe) {
String msg = "Problem creating TAR: " + ioe.getMessage();
@@ -160,7 +189,8 @@ public class Tar extends MatchingTask {
}
}
- protected void tarFile(File file, TarOutputStream tOut, String vPath)
+ protected void tarFile(File file, TarOutputStream tOut, String vPath,
+ TarFileSet tarFileSet)
throws IOException
{
FileInputStream fIn = new FileInputStream(file);
@@ -169,6 +199,12 @@ public class Tar extends MatchingTask {
TarEntry te = new TarEntry(vPath);
te.setSize(file.length());
te.setModTime(file.lastModified());
+ if (!file.isDirectory()) {
+ te.setMode(tarFileSet.getMode());
+ }
+ te.setUserName(tarFileSet.getUserName());
+ te.setGroupName(tarFileSet.getGroup());
+
tOut.putNextEntry(te);
byte[] buffer = new byte[8 * 1024];
@@ -190,4 +226,56 @@ public class Tar extends MatchingTask {
mm.setTo(tarFile.getAbsolutePath());
return sfs.restrict(files, baseDir, null, mm).length == 0;
}
+
+ static public class TarFileSet extends FileSet {
+ private String[] files = null;
+
+ private int mode = 0100644;
+
+ private String userName = "";
+ private String groupName = "";
+
+
+ public TarFileSet(FileSet fileset) {
+ super(fileset);
+ }
+
+ public TarFileSet() {
+ super();
+ }
+
+ public String[] getFiles(Project p) {
+ if (files == null) {
+ DirectoryScanner ds = getDirectoryScanner(p);
+ files = ds.getIncludedFiles();
+ }
+
+ return files;
+ }
+
+ public void setMode(String octalString) {
+ this.mode = 0100000 | Integer.parseInt(octalString, 8);
+ }
+
+ public int getMode() {
+ return mode;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setGroup(String groupName) {
+ this.groupName = groupName;
+ }
+
+ public String getGroup() {
+ return groupName;
+ }
+
+ }
}
diff --git a/src/main/org/apache/tools/ant/types/FileSet.java b/src/main/org/apache/tools/ant/types/FileSet.java
index b7f1f27b7..da2f23259 100644
--- a/src/main/org/apache/tools/ant/types/FileSet.java
+++ b/src/main/org/apache/tools/ant/types/FileSet.java
@@ -85,6 +85,15 @@ public class FileSet extends DataType {
super();
}
+ protected FileSet(FileSet fileset) {
+ this.dir = fileset.dir;
+ this.defaultPatterns = fileset.defaultPatterns;
+ this.additionalPatterns = fileset.additionalPatterns;
+ this.useDefaultExcludes = fileset.useDefaultExcludes;
+ }
+
+
+
/**
* Makes this instance in effect a reference to another PatternSet
* instance.
diff --git a/src/main/org/apache/tools/tar/TarEntry.java b/src/main/org/apache/tools/tar/TarEntry.java
index 91da76f9b..451def973 100644
--- a/src/main/org/apache/tools/tar/TarEntry.java
+++ b/src/main/org/apache/tools/tar/TarEntry.java
@@ -305,6 +305,14 @@ public class TarEntry implements TarConstants {
public void setName(String name) {
this.name = new StringBuffer(name);
}
+
+ /**
+ * Set the mode for this entry
+ */
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
+
/**
* Get this entry's user id.
@@ -580,5 +588,5 @@ public class TarEntry implements TarConstants {
this.devMajor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
offset += DEVLEN;
this.devMinor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
- }
+ }
}