zip package. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268962 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -48,7 +48,7 @@ if not exist build\classes mkdir build\classes | |||
| echo. | |||
| echo ... Compiling Ant Classes | |||
| %JAVAC% -d %CLASSDIR% %TOOLS%\tar\*.java %TOOLS%\ant\*.java %TOOLS%\ant\types\*.java %TOOLS%\ant\taskdefs\*.java %TOOLS%\ant\util\*.java %TOOLS%\ant\util\regexp\RegexpMatcher.java %TOOLS%\ant\util\regexp\RegexpMatcherFactory.java | |||
| %JAVAC% -d %CLASSDIR% %TOOLS%\tar\*.java %TOOLS%\zip\*.java %TOOLS%\ant\*.java %TOOLS%\ant\types\*.java %TOOLS%\ant\taskdefs\*.java %TOOLS%\ant\util\*.java %TOOLS%\ant\util\regexp\RegexpMatcher.java %TOOLS%\ant\util\regexp\RegexpMatcherFactory.java | |||
| echo. | |||
| echo ... Copying Required Files | |||
| @@ -74,7 +74,7 @@ mkdir -p build | |||
| echo ... Compiling Ant Classes | |||
| ${JAVAC} -d ${CLASSDIR} ${TOOLS}/tar/*.java \ | |||
| ${JAVAC} -d ${CLASSDIR} ${TOOLS}/tar/*.java ${TOOLS}/zip/*.java \ | |||
| ${TOOLS}/ant/util/regexp/RegexpMatcher.java \ | |||
| ${TOOLS}/ant/util/regexp/RegexpMatcherFactory.java \ | |||
| ${TOOLS}/ant/util/*.java ${TOOLS}/ant/types/*.java \ | |||
| @@ -93,7 +93,7 @@ public class Recorder extends Task { | |||
| /** What level to log? -1 means not initialized yet. */ | |||
| private int loglevel = -1; | |||
| /** The list of recorder entries. */ | |||
| private static HashMap recorderEntries = new HashMap(); | |||
| private static Hashtable recorderEntries = new Hashtable(); | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // CONSTRUCTORS / INITIALIZERS | |||
| @@ -203,7 +203,7 @@ public class RecorderEntry implements BuildLogger { | |||
| } | |||
| public void setEmacsMode(boolean emacsMode) { | |||
| throw new java.lang.UnsupportedOperationException("Method setEmacsMode() not yet implemented."); | |||
| throw new java.lang.RuntimeException("Method setEmacsMode() not yet implemented."); | |||
| } | |||
| public void setErrorPrintStream(PrintStream err) { | |||
| @@ -59,6 +59,7 @@ package org.apache.tools.ant.taskdefs.optional; | |||
| import java.io.*; | |||
| import java.text.*; | |||
| import java.util.Random; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.Execute; | |||
| @@ -150,9 +151,9 @@ public class Pvcs extends org.apache.tools.ant.Task { | |||
| if(getPvcsproject()!=null) | |||
| commandLine.createArgument().setValue(getPvcsproject()); | |||
| File tmp; | |||
| File tmp = null; | |||
| try { | |||
| tmp = File.createTempFile("pvcs_ant_",".log"); | |||
| tmp = new File("pvcs_ant_"+(new Random(System.currentTimeMillis())).nextLong()+".log"); | |||
| result = runCmd(commandLine, new PumpStreamHandler(new FileOutputStream(tmp), new LogOutputStream(this,Project.MSG_WARN))); | |||
| if ( result != 0 && !ignorerc) { | |||
| String msg = "Failed executing: " + commandLine.toString(); | |||
| @@ -196,6 +197,10 @@ public class Pvcs extends org.apache.tools.ant.Task { | |||
| } catch(ParseException e) { | |||
| String msg = "Failed executing: " + commandLine.toString(); | |||
| throw new BuildException(e.getMessage(),location); | |||
| } finally { | |||
| if (tmp != null) { | |||
| tmp.delete(); | |||
| } | |||
| } | |||
| } | |||
| @@ -58,7 +58,6 @@ package org.apache.tools.ant.taskdefs.optional.ejb; | |||
| import java.io.*; | |||
| import java.net.*; | |||
| import java.util.*; | |||
| import java.util.jar.*; | |||
| import javax.xml.parsers.*; | |||
| import org.apache.tools.ant.*; | |||
| @@ -260,7 +260,7 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { | |||
| niceSourceList.append(" to be compiled:"); | |||
| for (int i=0; i < compileList.size(); i++) { | |||
| String arg = (String)compileList.get(i); | |||
| String arg = (String)compileList.elementAt(i); | |||
| cmd.createArgument().setValue(arg); | |||
| niceSourceList.append(" " + arg); | |||
| } | |||
| @@ -54,6 +54,8 @@ | |||
| package org.apache.tools.zip; | |||
| import java.lang.reflect.InvocationTargetException; | |||
| import java.lang.reflect.Method; | |||
| import java.util.Vector; | |||
| import java.util.zip.ZipException; | |||
| @@ -85,7 +87,29 @@ public class ZipEntry extends java.util.zip.ZipEntry { | |||
| * @since 1.1 | |||
| */ | |||
| public ZipEntry(java.util.zip.ZipEntry entry) throws ZipException { | |||
| super(entry); | |||
| /* | |||
| * REVISIT: call super(entry) instead of this stuff in Ant2, | |||
| * "copy constructor" has not been available in JDK 1.1 | |||
| */ | |||
| super(entry.getName()); | |||
| setComment(entry.getComment()); | |||
| setMethod(entry.getMethod()); | |||
| setTime(entry.getTime()); | |||
| long size = entry.getSize(); | |||
| if (size > 0) { | |||
| setSize(size); | |||
| } | |||
| long cSize = entry.getCompressedSize(); | |||
| if (cSize > 0) { | |||
| setComprSize(cSize); | |||
| } | |||
| long crc = entry.getCrc(); | |||
| if (crc > 0) { | |||
| setCrc(crc); | |||
| } | |||
| byte[] extra = entry.getExtra(); | |||
| if (extra != null) { | |||
| setExtraFields(ExtraFieldUtils.parse(extra)); | |||
| @@ -100,8 +124,8 @@ public class ZipEntry extends java.util.zip.ZipEntry { | |||
| * | |||
| * @since 1.1 | |||
| */ | |||
| public ZipEntry(ZipEntry entry) { | |||
| super(entry); | |||
| public ZipEntry(ZipEntry entry) throws ZipException { | |||
| this((java.util.zip.ZipEntry) entry); | |||
| setInternalAttributes(entry.getInternalAttributes()); | |||
| setExternalAttributes(entry.getExternalAttributes()); | |||
| setExtraFields(entry.getExtraFields()); | |||
| @@ -269,4 +293,110 @@ public class ZipEntry extends java.util.zip.ZipEntry { | |||
| public byte[] getCentralDirectoryExtra() { | |||
| return ExtraFieldUtils.mergeCentralDirectoryData(getExtraFields()); | |||
| } | |||
| /** | |||
| * Helper for JDK 1.1 <-> 1.2 incompatibility. | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| private Long compressedSize = null; | |||
| /** | |||
| * Make this class work in JDK 1.1 like a 1.2 class. | |||
| * | |||
| * <p>This either stores the size for later usage or invokes | |||
| * setCompressedSize via reflection.</p> | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| public void setComprSize(long size) { | |||
| if (haveSetCompressedSize()) { | |||
| performSetCompressedSize(this, size); | |||
| } else { | |||
| compressedSize = new Long(size); | |||
| } | |||
| } | |||
| /** | |||
| * Override to make this class work in JDK 1.1 like a 1.2 class. | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| public long getCompressedSize() { | |||
| if (compressedSize != null) { | |||
| // has been set explicitly and we are running in a 1.1 VM | |||
| return compressedSize.longValue(); | |||
| } | |||
| return super.getCompressedSize(); | |||
| } | |||
| /** | |||
| * Helper for JDK 1.1 | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| private static Method setCompressedSizeMethod = null; | |||
| /** | |||
| * Helper for JDK 1.1 | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| private static Object lockReflection = new Object(); | |||
| /** | |||
| * Helper for JDK 1.1 | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| private static boolean triedToGetMethod = false; | |||
| /** | |||
| * Are we running JDK 1.2 or higher? | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| private static boolean haveSetCompressedSize() { | |||
| checkSCS(); | |||
| return setCompressedSizeMethod != null; | |||
| } | |||
| /** | |||
| * Invoke setCompressedSize via reflection. | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| private static void performSetCompressedSize(ZipEntry ze, long size) { | |||
| Long[] s = {new Long(size)}; | |||
| try { | |||
| setCompressedSizeMethod.invoke(ze, s); | |||
| } catch (InvocationTargetException ite) { | |||
| Throwable nested = ite.getTargetException(); | |||
| throw new RuntimeException("Exception setting the compressed size " | |||
| + "of " + ze + ": " | |||
| + nested.getMessage()); | |||
| } catch (Throwable other) { | |||
| throw new RuntimeException("Exception setting the compressed size " | |||
| + "of " + ze + ": " | |||
| + other.getMessage()); | |||
| } | |||
| } | |||
| /** | |||
| * Try to get a handle to the setCompressedSize method. | |||
| * | |||
| * @since 1.2 | |||
| */ | |||
| private static void checkSCS() { | |||
| if (!triedToGetMethod) { | |||
| synchronized (lockReflection) { | |||
| triedToGetMethod = true; | |||
| try { | |||
| setCompressedSizeMethod = | |||
| java.util.zip.ZipEntry.class.getMethod("setCompressedSize", | |||
| new Class[] {Long.TYPE}); | |||
| } catch (NoSuchMethodException nse) { | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -240,7 +240,7 @@ public class ZipOutputStream extends DeflaterOutputStream { | |||
| } | |||
| entry.setSize(def.getTotalIn()); | |||
| entry.setCompressedSize(def.getTotalOut()); | |||
| entry.setComprSize(def.getTotalOut()); | |||
| entry.setCrc(realCrc); | |||
| def.reset(); | |||
| @@ -295,7 +295,7 @@ public class ZipOutputStream extends DeflaterOutputStream { | |||
| if (entry.getCrc() == -1) { | |||
| throw new ZipException("crc checksum is required for STORED method"); | |||
| } | |||
| entry.setCompressedSize(entry.getSize()); | |||
| entry.setComprSize(entry.getSize()); | |||
| } else { | |||
| def.setLevel(level); | |||
| } | |||
| @@ -54,6 +54,8 @@ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import org.apache.tools.ant.Project; | |||
| import java.net.*; | |||
| import junit.framework.*; | |||
| import java.io.*; | |||
| @@ -89,6 +91,15 @@ public class ExecuteWatchdogTest extends TestCase { | |||
| System.err.println("WARNING: 'build.tests' property is not available !"); | |||
| classpath = System.getProperty("java.class.path"); | |||
| } | |||
| // JDK 1.1 needs classes.zip in -classpath argument | |||
| if (Project.getJavaVersion() == Project.JAVA_1_1) { | |||
| classpath += File.pathSeparator | |||
| + System.getProperty("java.home") | |||
| + File.separator + "lib" | |||
| + File.separator + "classes.zip"; | |||
| } | |||
| return classpath; | |||
| } | |||