Browse Source

New attributes to tarfileset to allow equivalent of tar -P option

PR: 5874

Submitted by: Stefan Heimann (mail@stefanheimann.net)


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271139 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
8fa296bb51
4 changed files with 73 additions and 13 deletions
  1. +3
    -0
      WHATSNEW
  2. +11
    -0
      src/etc/testcases/taskdefs/tar.xml
  3. +50
    -13
      src/main/org/apache/tools/ant/taskdefs/Tar.java
  4. +9
    -0
      src/testcases/org/apache/tools/ant/taskdefs/TarTest.java

+ 3
- 0
WHATSNEW View File

@@ -70,6 +70,9 @@ Fixed bugs:

Other changes:
--------------
* TarFileset takes in three new attributes - fullpath, prefix
and preserveLeadingSlashes.

* <move> attempts to rename the directory, if everything inside it is
included, before performing file-by-file moves. This attempt will
be done only if filtering is off and if mappers are not used. This


+ 11
- 0
src/etc/testcases/taskdefs/tar.xml View File

@@ -44,6 +44,15 @@
<untar src="test7.tar" dest="."/>
</target>

<target name="test8">
<tar destfile="test8.tar">
<tarfileset dir="." fullpath="/test8.xml">
<include name="tar.xml"/>
</tarfileset>
</tar>
<untar src="test8.tar" dest="."/>
</target>

<target name="cleanup">
<delete file="test4.tar"/>
<delete file="test5.tar"/>
@@ -52,6 +61,8 @@
<delete dir="test7dir"/>
<delete dir="test7-prefix"/>
<delete file="test7.tar"/>
<delete file="test8.tar"/>
<delete file="test8.xml"/>
</target>

<target name="feather">


+ 50
- 13
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -265,6 +265,10 @@ public class Tar extends MatchingTask {
for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
TarFileSet fs = (TarFileSet)e.nextElement();
String[] files = fs.getFiles(project);
if (files.length > 1 && fs.getFullpath().length() > 0) {
throw new BuildException("fullpath attribute may only be specified for " +
"filesets that specify a single file.");
}
for (int i = 0; i < files.length; i++) {
File f = new File(fs.getDir(project), files[i]);
String name = files[i].replace(File.separatorChar,'/');
@@ -291,13 +295,34 @@ public class Tar extends MatchingTask {
{
FileInputStream fIn = null;

// don't add "" to the archive
if (vPath.length() <= 0) {
return;
String fullpath = tarFileSet.getFullpath();
if (fullpath.length() > 0) {
vPath = fullpath;
} else {
// don't add "" to the archive
if (vPath.length() <= 0) {
return;
}
if (file.isDirectory() && !vPath.endsWith("/")) {
vPath += "/";
}
String prefix = tarFileSet.getPrefix();
// '/' is appended for compatibility with the zip task.
if (prefix.length() > 0 && !prefix.endsWith("/")) {
prefix = prefix + "/";
}
vPath = prefix + vPath;
}

if (file.isDirectory() && !vPath.endsWith("/")) {
vPath += "/";
if (vPath.startsWith("/") && !tarFileSet.getPreserveLeadingSlashes()) {
int l = vPath.length();
if (l <= 1) {
// we would end up adding "" to the archive
return;
}
vPath = vPath.substring(1, l);
}

try {
@@ -320,13 +345,7 @@ public class Tar extends MatchingTask {
}
}

String prefix = tarFileSet.getPrefix();
// '/' is appended for compatibility with the zip task.
if(prefix.length() > 0 && !prefix.endsWith("/")) {
prefix = prefix + "/";
}

TarEntry te = new TarEntry(prefix + vPath);
TarEntry te = new TarEntry(vPath);
te.setModTime(file.lastModified());
if (!file.isDirectory()) {
te.setSize(file.length());
@@ -371,7 +390,9 @@ public class Tar extends MatchingTask {
private String userName = "";
private String groupName = "";
private String prefix = "";

private String fullpath = "";
private boolean preserveLeadingSlashes = false;
public TarFileSet(FileSet fileset) {
super(fileset);
}
@@ -430,6 +451,22 @@ public class Tar extends MatchingTask {
public String getPrefix() {
return prefix;
}

public void setFullpath(String fullpath) {
this.fullpath = fullpath;
}

public String getFullpath() {
return fullpath;
}

public void setPreserveLeadingSlashes(boolean b) {
this.preserveLeadingSlashes = b;
}

public boolean getPreserveLeadingSlashes() {
return preserveLeadingSlashes;
}
}

/**


+ 9
- 0
src/testcases/org/apache/tools/ant/taskdefs/TarTest.java View File

@@ -115,6 +115,15 @@ public class TarTest extends BuildFileTest {
}
}

public void test8() {
executeTarget("test8");
java.io.File f1
= new java.io.File("src/etc/testcases/taskdefs/test8.xml");
if (! f1.exists()) {
fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly");
}
}

public void tearDown() {
executeTarget("cleanup");
}


Loading…
Cancel
Save