Browse Source

Make sure <tar> resets its state.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272405 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
7efc06af49
3 changed files with 92 additions and 76 deletions
  1. +90
    -74
      src/main/org/apache/tools/ant/taskdefs/Tar.java
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Taskdef.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Typedef.java

+ 90
- 74
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -78,6 +78,8 @@ import org.apache.tools.tar.TarEntry;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
* *
* @since Ant 1.1
*
* @ant.task category="packaging" * @ant.task category="packaging"
*/ */


@@ -140,11 +142,11 @@ public class Tar extends MatchingTask {


/** /**
* Sets the destfile attribute. * Sets the destfile attribute.
* @since 1.22 ant 1.5
* @since Ant 1.5
* @param destFile The output of the tar * @param destFile The output of the tar
*/ */
public void setDestFile(File destFile) { public void setDestFile(File destFile) {
this.tarFile = destFile;
this.tarFile = destFile;
} }


/** /**
@@ -205,89 +207,101 @@ public class Tar extends MatchingTask {
location); 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);
filesets.addElement(mainFileSet);
}

if (filesets.size() == 0) {
throw new BuildException("You must supply either a basdir attribute or some nested filesets.",
location);
}
Vector savedFileSets = (Vector) filesets.clone();
try {
if (baseDir != null) {
if (!baseDir.exists()) {
throw new BuildException("basedir does not exist!",
location);
}


// 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);
// add the main fileset to the list of filesets to process.
TarFileSet mainFileSet = new TarFileSet(fileset);
mainFileSet.setDir(baseDir);
filesets.addElement(mainFileSet);
}


if (!archiveIsUpToDate(files)) {
upToDate = false;
if (filesets.size() == 0) {
throw new BuildException("You must supply either a basedir "
+ "attribute or some nested filesets.",
location);
} }
// check if tar 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);


for (int i = 0; i < files.length; ++i) {
if (tarFile.equals(new File(fs.getDir(project), files[i]))) {
throw new BuildException("A tar file cannot include itself", location);
if (!archiveIsUpToDate(files)) {
upToDate = false;
}

for (int i = 0; i < files.length; ++i) {
if (tarFile.equals(new File(fs.getDir(project),
files[i]))) {
throw new BuildException("A tar file cannot include "
+ "itself", location);
}
} }
} }
}


if (upToDate) {
log("Nothing to do: "+tarFile.getAbsolutePath()+" is up to date.",
Project.MSG_INFO);
return;
}
if (upToDate) {
log("Nothing to do: "+tarFile.getAbsolutePath()
+" is up to date.", Project.MSG_INFO);
return;
}


log("Building tar: "+ tarFile.getAbsolutePath(), Project.MSG_INFO);
log("Building tar: "+ tarFile.getAbsolutePath(), Project.MSG_INFO);


TarOutputStream tOut = null;
try {
tOut = new TarOutputStream(new FileOutputStream(tarFile));
tOut.setDebug(true);
if (longFileMode.isTruncateMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
}
else if (longFileMode.isFailMode() ||
longFileMode.isOmitMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
}
else {
// warn or GNU
tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
}
TarOutputStream tOut = null;
try {
tOut = new TarOutputStream(new FileOutputStream(tarFile));
tOut.setDebug(true);
if (longFileMode.isTruncateMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
}
else if (longFileMode.isFailMode() ||
longFileMode.isOmitMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
}
else {
// warn or GNU
tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
}


longWarningGiven = false;
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.");
longWarningGiven = false;
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,'/');
tarFile(f, tOut, name, fs);
}
} }
for (int i = 0; i < files.length; i++) {
File f = new File(fs.getDir(project), files[i]);
String name = files[i].replace(File.separatorChar,'/');
tarFile(f, tOut, name, fs);
} catch (IOException ioe) {
String msg = "Problem creating TAR: " + ioe.getMessage();
throw new BuildException(msg, ioe, location);
} finally {
if (tOut != null) {
try {
// close up
tOut.close();
}
catch (IOException e) {}
} }
} }
} catch (IOException ioe) {
String msg = "Problem creating TAR: " + ioe.getMessage();
throw new BuildException(msg, ioe, location);
} finally { } finally {
if (tOut != null) {
try {
// close up
tOut.close();
}
catch (IOException e) {}
}
filesets = savedFileSets;
} }
} }


@@ -334,10 +348,12 @@ public class Tar extends MatchingTask {
return; return;
} else if (longFileMode.isWarnMode()) { } else if (longFileMode.isWarnMode()) {
log("Entry: "+ vPath + " longer than " + log("Entry: "+ vPath + " longer than " +
TarConstants.NAMELEN + " characters.", Project.MSG_WARN);
TarConstants.NAMELEN + " characters.",
Project.MSG_WARN);
if (!longWarningGiven) { if (!longWarningGiven) {
log("Resulting tar file can only be processed successfully"
+ " by GNU compatible tar commands", Project.MSG_WARN);
log("Resulting tar file can only be processed "
+ "successfully by GNU compatible tar commands",
Project.MSG_WARN);
longWarningGiven = true; longWarningGiven = true;
} }
} else if (longFileMode.isFailMode()) { } else if (longFileMode.isFailMode()) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Taskdef.java View File

@@ -60,7 +60,7 @@ import org.apache.tools.ant.BuildException;
* Define a new task. * Define a new task.
* *
* @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a>
*
* @since Ant 1.1
* @ant.task category="internal" * @ant.task category="internal"
*/ */
public class Taskdef extends Definer { public class Taskdef extends Definer {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Typedef.java View File

@@ -60,7 +60,7 @@ import org.apache.tools.ant.BuildException;
* Define a new data type. * Define a new data type.
* *
* @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a>
*
* @since Ant 1.4
* @ant.task category="internal" * @ant.task category="internal"
*/ */
public class Typedef extends Definer { public class Typedef extends Definer {


Loading…
Cancel
Save