ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r314776 [2/2] - in /ant/core/trunk: docs/manual/ docs/manual/CoreTypes/ src/etc/testcases/types/resources/ src/main/org/apache/tools/ant/taskdefs/ src/main/org/apache/tools/ant/types/ src/main/org/apache/tools/ant/types/resources/ src/testc...
Date Wed, 12 Oct 2005 04:23:00 GMT
Added: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java?rev=314776&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java Tue
Oct 11 21:22:37 2005
@@ -0,0 +1,244 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.types.resources;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.DataType;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.ResourceCollection;
+
+/**
+ * A compressed resource.
+ *
+ * <p>Wraps around another resource, delegates all queries to that
+ * other resource but uncompresses/compresses streams on the fly.</p>
+ *
+ * @since Ant 1.7
+ */
+public abstract class CompressedResource extends Resource
+    implements ResourceCollection {
+
+    private Resource resource;
+
+    public CompressedResource() {
+    }
+
+    public CompressedResource(ResourceCollection other) {
+        addConfigured(other);
+    }
+
+    /**
+     * Sets the resource to wrap using a single-element collection.
+     * @param a the resource to wrap as a single element Resource collection.
+     */
+    public void addConfigured(ResourceCollection a) {
+        checkChildrenAllowed();
+        if (resource != null) {
+            throw new BuildException("you must not specify more than one"
+                                     + " resource");
+        }
+        if (a.size() != 1) {
+            throw new BuildException("only single argument resource collections"
+                                     + " are supported");
+        }
+        resource = (Resource) a.iterator().next();
+    }
+
+    public String getName() {
+        return getResource().getName();
+    }
+
+
+    public void setName(String name) {
+        throw new BuildException("you can't change the name of a compressed"
+                                 + " resource");
+    }
+
+    /**
+     * The exists attribute tells whether a file exists.
+     * @return true if this resource exists.
+     */
+    public boolean isExists() {
+        return getResource().isExists();
+    }
+
+    /**
+     * Set the exists attribute.
+     * @param exists if true, this resource exists.
+     */
+    public void setExists(boolean exists) {
+        throw new BuildException("you can't change the exists state of a "
+                                 + " compressed resource");
+    }
+
+    /**
+     * Tells the modification time in milliseconds since 01.01.1970 .
+     *
+     * @return 0 if the resource does not exist to mirror the behavior
+     * of {@link java.io.File File}.
+     */
+    public long getLastModified() {
+        return getResource().getLastModified();
+    }
+
+    public void setLastModified(long lastmodified) {
+        throw new BuildException("you can't change the timestamp of a "
+                                 + " compressed resource");
+    }
+
+    /**
+     * Tells if the resource is a directory.
+     * @return boolean flag indicating if the resource is a directory.
+     */
+    public boolean isDirectory() {
+        return getResource().isDirectory();
+    }
+
+    public void setDirectory(boolean directory) {
+        throw new BuildException("you can't change the directory state of a "
+                                 + " compressed resource");
+    }
+
+    /**
+     * Get the size of this Resource.
+     * @return the size, as a long, 0 if the Resource does not exist (for
+     *         compatibility with java.io.File), or UNKNOWN_SIZE if not known.
+     */
+    public long getSize() {
+        return getResource().getSize();
+    }
+
+    public void setSize(long size) {
+        throw new BuildException("you can't change the size of a "
+                                 + " compressed resource");
+    }
+
+    /**
+     * Delegates to a comparison of names.
+     * @param other the object to compare to.
+     * @return a negative integer, zero, or a positive integer as this Resource
+     *         is less than, equal to, or greater than the specified Resource.
+     */
+    public int compareTo(Object other) {
+        return getResource().compareTo(other);
+    }
+
+    /**
+     * Get the hash code for this Resource.
+     * @return hash code as int.
+     */
+    public int hashCode() {
+        return getResource().hashCode();
+    }
+
+    /**
+     * Get an InputStream for the Resource.
+     * @return an InputStream containing this Resource's content.
+     * @throws IOException if unable to provide the content of this
+     *         Resource as a stream.
+     * @throws UnsupportedOperationException if InputStreams are not
+     *         supported for this Resource type.
+     */
+    public InputStream getInputStream() throws IOException {
+        InputStream in = getResource().getInputStream();
+        if (in != null) {
+            in = wrapStream(in);
+        }
+        return in;
+    }
+
+    /**
+     * Get an OutputStream for the Resource.
+     * @return an OutputStream to which content can be written.
+     * @throws IOException if unable to provide the content of this
+     *         Resource as a stream.
+     * @throws UnsupportedOperationException if OutputStreams are not
+     *         supported for this Resource type.
+     */
+    public OutputStream getOutputStream() throws IOException {
+        OutputStream out = getResource().getOutputStream();
+        if (out != null) {
+            out = wrapStream(out);
+        }
+        return out;
+    }
+
+    /**
+     * Fulfill the ResourceCollection contract.
+     * @return whether this Resource is a FileResource.
+     */
+    public boolean isFilesystemOnly() {
+        return false;
+    }
+
+    /**
+     * Get the string representation of this Resource.
+     * @return this Resource formatted as a String.
+     * @since Ant 1.7
+     */
+    public String toString() {
+        return getCompressionName() + " compressed "
+            + getResource().toString();
+    }
+
+    /**
+     * Overrides the base version.
+     * @param r the Reference to set.
+     */
+    public void setRefid(Reference r) {
+        if (resource != null) {
+            throw noChildrenAllowed();
+        }
+        super.setRefid(r);
+    }
+
+    /**
+     * Is supposed to wrap the stream to allow decompression on the fly.
+     *
+     * @param in InputStream to wrap, will never be null.
+     */
+    protected abstract InputStream wrapStream(InputStream in)
+        throws IOException;
+
+    /**
+     * Is supposed to wrap the stream to allow compression on the fly.
+     *
+     * @param out OutputStream to wrap, will never be null.
+     */
+    protected abstract OutputStream wrapStream(OutputStream out)
+        throws IOException;
+
+    /**
+     * @return the name of the compression method.
+     */
+    protected abstract String getCompressionName();
+
+    private Resource getResource() {
+        if (isReference()) {
+            return (Resource) getCheckedRef();
+        } else if (resource == null) {
+            throw new BuildException("no resource specified");
+        }
+        return resource;
+    }
+
+}
\ No newline at end of file

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
------------------------------------------------------------------------------
    svn:executable = *

Added: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/GZipResource.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/GZipResource.java?rev=314776&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/GZipResource.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/GZipResource.java Tue Oct
11 21:22:37 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.types.resources;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * A GZip compressed resource.
+ *
+ * <p>Wraps around another resource, delegates all quries to that
+ * other resource but uncompresses/compresses streams on the fly.</p>
+ *
+ * @since Ant 1.7
+ */
+public class GZipResource extends CompressedResource {
+
+    public GZipResource() {
+    }
+
+    public GZipResource(org.apache.tools.ant.types.ResourceCollection other) {
+        super(other);
+    }
+
+    protected InputStream wrapStream(InputStream in) throws IOException {
+        return new GZIPInputStream(in);
+    }
+    protected OutputStream wrapStream(OutputStream out) throws IOException {
+        return new GZIPOutputStream(out);
+    }
+    protected String getCompressionName() {
+        return "GZip";
+    }
+}
\ No newline at end of file

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/GZipResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/GZipResource.java
------------------------------------------------------------------------------
    svn:executable = *

Added: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/TarResource.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/TarResource.java?rev=314776&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/TarResource.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/TarResource.java Tue Oct
11 21:22:37 2005
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.types.resources;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.FilterInputStream;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.tar.TarEntry;
+import org.apache.tools.tar.TarInputStream;
+
+/**
+ * A Resource representation of an entry in a tar archive.
+ * @since Ant 1.7
+ */
+public class TarResource extends ArchiveResource {
+
+    /**
+     * Default constructor.
+     */
+    public TarResource() {
+    }
+
+    /**
+     * Construct a TarResource representing the specified
+     * entry in the specified archive.
+     * @param a the archive as File.
+     * @param e the TarEntry.
+     */
+    public TarResource(File a, TarEntry e) {
+        super(a, true);
+        setEntry(e);
+    }
+
+    /**
+     * Construct a TarResource representing the specified
+     * entry in the specified archive.
+     * @param a the archive as Resource.
+     * @param e the TarEntry.
+     */
+    public TarResource(Resource a, TarEntry e) {
+        super(a, true);
+        setEntry(e);
+    }
+
+    /**
+     * Return an InputStream for reading the contents of this Resource.
+     * @return an InputStream object.
+     * @throws IOException if the tar file cannot be opened,
+     *         or the entry cannot be read.
+     */
+    public InputStream getInputStream() throws IOException {
+        if (isReference()) {
+            return ((Resource) getCheckedRef()).getInputStream();
+        }
+        Resource archive = getArchive();
+        final TarInputStream i = new TarInputStream(archive.getInputStream());
+        TarEntry te = null;
+        while ((te = i.getNextEntry()) != null) {
+            if (te.getName().equals(getName())) {
+                return i;
+            }
+        }
+        
+        FileUtils.close(i);
+        throw new BuildException("no entry " + getName() + " in "
+                                 + getArchive());
+    }
+
+    /**
+     * Get an OutputStream for the Resource.
+     * @return an OutputStream to which content can be written.
+     * @throws IOException if unable to provide the content of this
+     *         Resource as a stream.
+     * @throws UnsupportedOperationException if OutputStreams are not
+     *         supported for this Resource type.
+     */
+    public OutputStream getOutputStream() throws IOException {
+        if (isReference()) {
+            return ((Resource) getCheckedRef()).getOutputStream();
+        }
+        throw new UnsupportedOperationException(
+            "Use the tar task for tar output.");
+    }
+
+    /**
+     * fetches information from the named entry inside the archive.
+     */
+    protected void fetchEntry() {
+        Resource archive = getArchive();
+        TarInputStream i = null;
+        try {
+            i = new TarInputStream(archive.getInputStream());
+            TarEntry te = null;
+            while ((te = i.getNextEntry()) != null) {
+                if (te.getName().equals(getName())) {
+                    setEntry(te);
+                    return;
+                }
+            }
+        } catch (IOException e) {
+            log(e.getMessage(), Project.MSG_DEBUG);
+            throw new BuildException(e);
+        } finally {
+            if (i != null) {
+                FileUtils.close(i);
+            }
+        }
+        setEntry(null);
+    }
+
+    private void setEntry(TarEntry e) {
+        if (e == null) {
+            super.setExists(false);
+            return;
+        }
+        super.setName(e.getName());
+        super.setExists(true);
+        super.setLastModified(e.getModTime().getTime());
+        super.setDirectory(e.isDirectory());
+        super.setSize(e.getSize());
+    }
+
+}

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/TarResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/TarResource.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java?rev=314776&r1=314775&r2=314776&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java Tue Oct
11 21:22:37 2005
@@ -25,6 +25,7 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.zip.ZipFile;
@@ -34,13 +35,9 @@
  * A Resource representation of an entry in a zipfile.
  * @since Ant 1.7
  */
-public class ZipResource extends Resource {
-    private static final int NULL_ZIPFILE
-        = Resource.getMagicNumber("null zipfile".getBytes());
+public class ZipResource extends ArchiveResource {
 
     private String encoding;
-    private File zipfile;
-    private boolean haveEntry = false;
 
     /**
      * Default constructor.
@@ -56,9 +53,9 @@
      * @param e the ZipEntry.
      */
     public ZipResource(File z, String enc, ZipEntry e) {
-        setEntry(e);
-        setZipfile(z);
+        super(z, true);
         setEncoding(enc);
+        setEntry(e);
     }
 
     /**
@@ -66,8 +63,7 @@
      * @param z the zipfile as a File.
      */
     public void setZipfile(File z) {
-        checkAttributesAllowed();
-        zipfile = z;
+        setArchive(z);
     }
 
     /**
@@ -75,8 +71,20 @@
      * @return the zipfile as a File.
      */
     public File getZipfile() {
-        return isReference()
-            ? ((ZipResource) getCheckedRef()).getZipfile() : zipfile;
+        FileResource r = (FileResource) getArchive();
+        return r.getFile();
+    }
+
+    /**
+     * Sets the archive that holds this as a single element Resource
+     * collection.
+     * @param a the archive as a single element Resource collection.
+     */
+    public void addConfigured(ResourceCollection a) {
+        super.addConfigured(a);
+        if (!a.isFilesystemOnly()) {
+            throw new BuildException("only filesystem resources are supported");
+        }
     }
 
     /**
@@ -98,59 +106,11 @@
     }
 
     /**
-     * Get the last modified date of this ZipResource.
-     * @return the last modification date.
-     */
-    public long getLastModified() {
-        if (isReference()) {
-            return ((Resource) getCheckedRef()).getLastModified();
-        }
-        checkEntry();
-        return super.getLastModified();
-    }
-
-    /**
-     * Get the size of this ZipResource.
-     * @return the long size of this ZipResource.
-     */
-    public long getSize() {
-        if (isReference()) {
-            return ((Resource) getCheckedRef()).getSize();
-        }
-        checkEntry();
-        return super.getSize();
-    }
-
-    /**
-     * Learn whether this ZipResource represents a directory.
-     * @return boolean flag indicating whether the zip entry is a directory.
-     */
-    public boolean isDirectory() {
-        if (isReference()) {
-            return ((Resource) getCheckedRef()).isDirectory();
-        }
-        checkEntry();
-        return super.isDirectory();
-    }
-
-    /**
-     * Find out whether this ZipResource represents an existing Resource.
-     * @return boolean existence flag.
-     */
-    public boolean isExists() {
-        if (isReference()) {
-            return ((Resource) getCheckedRef()).isExists();
-        }
-        checkEntry();
-        return super.isExists();
-    }
-
-    /**
      * Overrides the super version.
      * @param r the Reference to set.
      */
     public void setRefid(Reference r) {
-        if (encoding != null || zipfile != null) {
+        if (encoding != null) {
             throw tooManyAttributes();
         }
         super.setRefid(r);
@@ -199,76 +159,13 @@
     }
 
     /**
-     * Compare this ZipResource to another Resource.
-     * @param another the other Resource against which to compare.
-     * @return a negative integer, zero, or a positive integer as this ZipResource
-     *         is less than, equal to, or greater than the specified Resource.
-     */
-    public int compareTo(Object another) {
-        return this.equals(another) ? 0 : super.compareTo(another);
-    }
-
-    /**
-     * Compare another Object to this ZipResource for equality.
-     * @param another the other Object to compare.
-     * @return true if another is a ZipResource representing
-     *              the same entry in the same zipfile.
-     */
-    public boolean equals(Object another) {
-        if (this == another) {
-            return true;
-        }
-        if (isReference()) {
-            return getCheckedRef().equals(another);
-        }
-        if (!(another.getClass().equals(getClass()))) {
-            return false;
-        }
-        ZipResource r = (ZipResource) another;
-        return getZipfile().equals(r.getZipfile())
-            && getName().equals(r.getName());
-    }
-
-    /**
-     * Get the hash code for this Resource.
-     * @return hash code as int.
-     */
-    public int hashCode() {
-        return super.hashCode()
-            * (getZipfile() == null ? NULL_ZIPFILE : getZipfile().hashCode());
-    }
-
-    /**
-     * Format this ZipResource as a String.
-     * @return String representatation of this ZipResource.
+     * fetches information from the named entry inside the archive.
      */
-    public String toString() {
-        return isReference() ? getCheckedRef().toString()
-            : getZipfile().toString() + ':' + getName();
-    }
-
-    private synchronized void checkEntry() throws BuildException {
-        if (haveEntry) {
-            return;
-        }
-        String name = getName();
-        if (name == null) {
-            throw new BuildException("zip entry name not set");
-        }
-        File f = getZipfile();
-        if (f == null) {
-            throw new BuildException("zipfile attribute not set");
-        }
-        if (!f.exists()) {
-            throw new BuildException(f.getAbsolutePath() + " does not exist.");
-        }
-        if (f.isDirectory()) {
-            throw new BuildException(f + " denotes a directory.");
-        }
+    protected void fetchEntry() {
         ZipFile z = null;
         try {
-            z = new ZipFile(f, getEncoding());
-            setEntry(z.getEntry(name));
+            z = new ZipFile(getZipfile(), getEncoding());
+            setEntry(z.getEntry(getName()));
         } catch (IOException e) {
             log(e.getMessage(), Project.MSG_DEBUG);
             throw new BuildException(e);
@@ -283,8 +180,7 @@
         }
     }
 
-    private synchronized void setEntry(ZipEntry e) {
-        haveEntry = true;
+    private void setEntry(ZipEntry e) {
         if (e == null) {
             super.setExists(false);
             return;

Added: ant/core/trunk/src/testcases/org/apache/tools/ant/types/TarFileSetTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/types/TarFileSetTest.java?rev=314776&view=auto
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/types/TarFileSetTest.java (added)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/types/TarFileSetTest.java Tue Oct 11
21:22:37 2005
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+import junit.framework.TestCase;
+import junit.framework.AssertionFailedError;
+
+import java.io.File;
+
+/**
+ * JUnit 3 testcases for org.apache.tools.ant.types.TarFileSet.
+ *
+ * <p>This doesn't actually test much, mainly reference handling.
+ *
+ */
+
+public class TarFileSetTest extends AbstractFileSetTest {
+
+    public TarFileSetTest(String name) {
+        super(name);
+    }
+
+    protected AbstractFileSet getInstance() {
+        return new TarFileSet();
+    }
+    public final void testAttributes() {
+        TarFileSet f = (TarFileSet)getInstance();
+        //check that dir and src are incompatible
+        f.setSrc(new File("example.tar"));
+        try {
+            f.setDir(new File("examples"));
+            fail("can add dir to "
+                    + f.getDataTypeName()
+                    + " when a src is already present");
+        } catch (BuildException be) {
+            assertEquals("Cannot set both dir and src attributes",be.getMessage());
+        }
+        f = (TarFileSet)getInstance();
+        //check that dir and src are incompatible
+        f.setDir(new File("examples"));
+        try {
+            f.setSrc(new File("example.tar"));
+            fail("can add src to "
+                    + f.getDataTypeName()
+                    + " when a dir is already present");
+        } catch (BuildException be) {
+            assertEquals("Cannot set both dir and src attributes",be.getMessage());
+        }
+        //check that fullpath and prefix are incompatible
+        f = (TarFileSet)getInstance();
+        f.setSrc(new File("example.tar"));
+        f.setPrefix("/examples");
+        try {
+            f.setFullpath("/doc/manual/index.html");
+            fail("Can add fullpath to "
+                    + f.getDataTypeName()
+                    + " when a prefix is already present");
+        } catch (BuildException be) {
+            assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
+        }
+        f = (TarFileSet)getInstance();
+        f.setSrc(new File("example.tar"));
+        f.setFullpath("/doc/manual/index.html");
+        try {
+            f.setPrefix("/examples");
+            fail("Can add prefix to "
+                    + f.getDataTypeName()
+                    + " when a fullpath is already present");
+        } catch (BuildException be) {
+            assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
+        }
+        // check that reference tarfilesets cannot have specific attributes
+        f = (TarFileSet)getInstance();
+        f.setRefid(new Reference("test"));
+        try {
+            f.setSrc(new File("example.tar"));
+            fail("Can add src to "
+                    + f.getDataTypeName()
+                    + " when a refid is already present");
+        } catch (BuildException be) {
+            assertEquals("You must not specify more than one "
+            + "attribute when using refid", be.getMessage());
+        }
+        // check that a reference tarfileset gets the same attributes as the original
+        f = (TarFileSet)getInstance();
+        f.setSrc(new File("example.tar"));
+        f.setPrefix("/examples");
+        f.setFileMode("600");
+        f.setDirMode("530");
+        getProject().addReference("test",f);
+        TarFileSet zid=(TarFileSet)getInstance();
+        zid.setRefid(new Reference("test"));
+        assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject())));
+        assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject())));
+        assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject()));
+        assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));
+      }
+
+
+}

Propchange: ant/core/trunk/src/testcases/org/apache/tools/ant/types/TarFileSetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/testcases/org/apache/tools/ant/types/TarFileSetTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: ant/core/trunk/src/testcases/org/apache/tools/ant/types/resources/TarResourceTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/types/resources/TarResourceTest.java?rev=314776&view=auto
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/types/resources/TarResourceTest.java
(added)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/types/resources/TarResourceTest.java
Tue Oct 11 21:22:37 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright  2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.types.resources;
+
+import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.util.FileUtils;
+
+public class TarResourceTest extends BuildFileTest {
+
+    private static final FileUtils FU = FileUtils.getFileUtils();
+
+    public TarResourceTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        configureProject("src/etc/testcases/types/resources/tarentry.xml");
+    }
+
+    protected void tearDown() throws Exception {
+        executeTarget("tearDown");
+    }
+
+    public void testUncompressSource() throws java.io.IOException {
+        executeTarget("uncompressSource");
+        assertTrue(FU.contentEquals(project.resolveFile("../../asf-logo.gif"),
+                                    project.resolveFile("testout/asf-logo.gif")));
+    }
+}
\ No newline at end of file

Propchange: ant/core/trunk/src/testcases/org/apache/tools/ant/types/resources/TarResourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/testcases/org/apache/tools/ant/types/resources/TarResourceTest.java
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message