You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/08/06 16:18:53 UTC

svn commit: r1154525 - in /maven/sandbox/trunk/plexus-utils-commons-bridge: plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Expand.java plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java

Author: struberg
Date: Sat Aug  6 14:18:52 2011
New Revision: 1154525

URL: http://svn.apache.org/viewvc?rev=1154525&view=rev
Log:
MSANDBOX-51 more Expand tests + initial implementation skelleton.

Added:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Expand.java
Modified:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java

Added: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Expand.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Expand.java?rev=1154525&view=auto
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Expand.java (added)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Expand.java Sat Aug  6 14:18:52 2011
@@ -0,0 +1,92 @@
+package org.codehaus.plexus.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.File;
+
+/**
+ * Expand will unpack the given zip archive.
+ *
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class Expand
+{
+    /**
+     * Source file which should get expanded
+     */
+    private File source;
+
+    /**
+     * destination directory
+     */
+    private File dest;
+
+    /**
+     * if the unpackaging should get performed if the destination already exists.
+     */
+    private boolean overwrite = false;
+
+
+    /**
+     * The zip archive which should get expanded.
+     *
+     * @param sourceArchive
+     */
+    public void setSrc( File sourceArchive )
+    {
+        this.source = sourceArchive;
+    }
+
+    /**
+     * Set the destination directory into which the archive should get expanded.
+     * The directory will get created if it doesn't yet exist
+     * while executing the expand.
+     *
+     * @param destinationDirectory
+     */
+    public void setDest( File destinationDirectory )
+    {
+        this.dest = destinationDirectory;
+    }
+
+    /**
+     * If the destination directory should get overwritten if the content
+     * already exists.
+     * @param overwrite
+     */
+    public void setOverwrite( boolean overwrite )
+    {
+        this.overwrite = overwrite;
+    }
+
+    /**
+     * Actually perform the unpacking of the source archive
+     * into the destination directory.
+     *
+     * @throws Exception
+     */
+    public void execute() throws Exception
+    {
+        //X TODO implement
+        throw new RuntimeException( "not yet implemented!" );
+    }
+
+
+}

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java?rev=1154525&r1=1154524&r2=1154525&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/ExpandTest.java Sat Aug  6 14:18:52 2011
@@ -118,7 +118,7 @@ public class ExpandTest extends Assert
 
         expand.execute();
 
-        verifyExpandedFileAndContent( targetDir,  TEST_UNZIPPED_CONTENT );
+        verifyExpandedFileAndContent(targetDir, TEST_UNZIPPED_CONTENT);
     }
 
     @Test
@@ -140,7 +140,7 @@ public class ExpandTest extends Assert
 
         expand.execute();
 
-        verifyExpandedFileAndContent( nonexisingDir,  TEST_UNZIPPED_CONTENT );
+        verifyExpandedFileAndContent(nonexisingDir, TEST_UNZIPPED_CONTENT);
     }
 
     @Test
@@ -169,6 +169,48 @@ public class ExpandTest extends Assert
 
     }
 
+    @Test( expected = NullPointerException.class )
+    public void testExecute_NullSource()
+            throws Exception
+    {
+        Expand expand = new Expand();
+        expand.setSrc( null );
+
+        File targetDir = getTestTargetDir();
+        expand.setDest( targetDir );
+
+        expand.execute();
+    }
+
+    @Test
+    public void testExecute_NullDest()
+            throws Exception
+    {
+        Expand expand = new Expand();
+        expand.setSrc( getSourceFile() );
+
+        // execute without a dest directory seems to
+        // expand all the archive into the current working directory
+        expand.setDest( null );
+
+        String oldWorkingDirectory = System.getProperty( "user.dir" );
+
+        try
+        {
+            File targetDir = getTestTargetDir();
+            System.setProperty( "user.dir", targetDir.getAbsolutePath() );
+
+            expand.execute();
+
+            verifyExpandedFileAndContent( targetDir, TEST_UNZIPPED_CONTENT );
+        }
+        finally
+        {
+            System.setProperty( "user.dir", oldWorkingDirectory );
+        }
+    }
+
+
     private File verifyExpandedFile( File targetDir )
     {
         assertThat( "target directory must exist"