From 0fce1960afecacee4b489ab8c403653e3171ac01 Mon Sep 17 00:00:00 2001 From: "Arnout J. Kuiper" Date: Sat, 17 Jun 2000 12:57:48 +0000 Subject: [PATCH] Fix for Tar-time Submitted by: Stefan Bodewig git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267679 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Tar.java | 2 +- .../org/apache/tools/ant/taskdefs/Untar.java | 37 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index ae6340777..df9243f9b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -122,7 +122,7 @@ public class Tar extends MatchingTask { TarEntry te = new TarEntry(vPath); te.setSize(file.length()); - te.setModTime(file.lastModified() / 1000); + te.setModTime(file.lastModified()); tOut.putNextEntry(te); byte[] buffer = new byte[8 * 1024]; diff --git a/src/main/org/apache/tools/ant/taskdefs/Untar.java b/src/main/org/apache/tools/ant/taskdefs/Untar.java index 9b870402d..ce197bdb3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Untar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Untar.java @@ -57,6 +57,9 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.*; import org.apache.tools.tar.*; import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + /** * Untar a file. * @@ -74,6 +77,23 @@ public class Untar extends Task { * @exception BuildException Thrown in unrecoverable error. */ public void execute() throws BuildException { + + Method setLastModified = null; + Long[] times = null; + // 1.0 is ruled out anyway, so this ensures 1.2 or above + if (project.getJavaVersion() != Project.JAVA_1_1) { + try { + setLastModified = + java.io.File.class.getMethod("setLastModified", + new Class[] {Long.TYPE}); + + times = new Long[1]; + } catch (Exception e) { + project.log("File.setLastModified(long) not found", + Project.MSG_VERBOSE); + } + } + try { if (source == null) { throw new BuildException("No source specified"); @@ -115,8 +135,21 @@ public class Untar extends Task { fos.close(); } - } catch( FileNotFoundException ex ) { - System.out.println("FileNotFoundException: " + te.getName() ); + + if (setLastModified != null) { + times[0] = new Long(te.getModTime().getTime()); + try { + setLastModified.invoke(f, times); + } catch (Exception e) { + project.log("cannot invoke File.setLastModified(long)", + Project.MSG_VERBOSE); + setLastModified = null; + } + } + + } catch(FileNotFoundException ex) { + project.log("FileNotFoundException: " + te.getName(), + Project.MSG_WARN); } } } catch (IOException ioe) {