directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r601684 - in /directory/sandbox/felixk/studio-plugin: pom.xml src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
Date Thu, 06 Dec 2007 10:36:24 GMT
Author: felixk
Date: Thu Dec  6 02:36:24 2007
New Revision: 601684

URL: http://svn.apache.org/viewvc?rev=601684&view=rev
Log:
Use plexus unarchiver

Modified:
    directory/sandbox/felixk/studio-plugin/pom.xml
    directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java

Modified: directory/sandbox/felixk/studio-plugin/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-plugin/pom.xml?rev=601684&r1=601683&r2=601684&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-plugin/pom.xml (original)
+++ directory/sandbox/felixk/studio-plugin/pom.xml Thu Dec  6 02:36:24 2007
@@ -68,6 +68,36 @@
             <artifactId>maven-model</artifactId>
             <version>2.0.7</version>
         </dependency>
+        <dependency>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-archiver</artifactId>
+          <version>1.0-alpha-9</version>
+          <exclusions>
+            <exclusion>
+              <groupId>org.codehaus.plexus</groupId>
+              <artifactId>plexus-container-default</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>org.codehaus.plexus</groupId>
+              <artifactId>plexus-component-api</artifactId>
+            </exclusion>
+          </exclusions>
+        </dependency>
+        <dependency>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-io</artifactId>
+          <version>1.0-alpha-1</version>
+          <exclusions>
+            <exclusion>
+              <groupId>org.codehaus.plexus</groupId>
+              <artifactId>plexus-container-default</artifactId>
+            </exclusion>
+            <exclusion>
+              <groupId>org.codehaus.plexus</groupId>
+              <artifactId>plexus-component-api</artifactId>
+            </exclusion>
+          </exclusions>
+        </dependency>
     </dependencies>
 
     <reporting>

Modified: directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java?rev=601684&r1=601683&r2=601684&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
(original)
+++ directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
Thu Dec  6 02:36:24 2007
@@ -22,12 +22,9 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
 import java.util.zip.ZipOutputStream;
 
 import org.apache.commons.lang.StringUtils;
@@ -43,6 +40,10 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 
 /**
  * The abstract studio mojo
@@ -53,6 +54,15 @@
 public abstract class AbstractStudioMojo extends AbstractMojo {
 
     /**
+     * To look up Archiver/UnArchiver implementations
+     *
+     * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
+     * @required
+     * @readonly
+     */
+    protected ArchiverManager archiverManager;
+
+    /**
      * Location of the file.
      * 
      * @parameter expression="${project.build.directory}"
@@ -153,40 +163,29 @@
     /**
      * Unzip a file into a directory
      * 
-     * @param unzipDir
+     * @param location
      *            The directory the file unzip into
-     * @param zipFile
+     * @param file
      *            The file to unzip
      */
-    protected void unzipToDir(final File unzipDir, final File zipFile) throws Exception {
-        final ZipFile zf = new ZipFile(zipFile);
-
+    protected void unzipToDir(final File location, final File file) throws Exception {
         try {
-            final Enumeration<? extends ZipEntry> zipEnum = zf.entries();
-            while (zipEnum.hasMoreElements()) {
-                final ZipEntry item = zipEnum.nextElement();
-
-                if (item.isDirectory()) {
-                    final File newdir = new File(unzipDir.getAbsoluteFile() + File.separator
+ item.getName());
-                    newdir.mkdirs();
-                } else {
-                    final String newfile = unzipDir.getAbsoluteFile() + File.separator +
item.getName();
-                    final InputStream is = zf.getInputStream(item);
-                    final FileOutputStream fos = new FileOutputStream(newfile);
-                    try {
-                        int ch;
-                        while ((ch = is.read()) != -1) {
-                            fos.write(ch);
-                        }
-                    } finally {
-                        is.close();
-                        fos.flush();
-                        fos.close();
-                    }
-                }
+            location.mkdirs();
+            UnArchiver unArchiver =  archiverManager.getUnArchiver( file );
+            unArchiver.setSourceFile( file );
+    
+            unArchiver.setDestDirectory( location );
+            unArchiver.extract();
             }
-        } finally {
-            zf.close();
+        catch ( NoSuchArchiverException e )
+        {
+            throw new MojoExecutionException( "Unknown archiver type", e );
+        }
+        catch ( ArchiverException e )
+        {
+            e.printStackTrace();
+            throw new MojoExecutionException( "Error unpacking file: " + file + " to: " +
location + "\r\n"
+                + e.toString(), e );
         }
     }
 



Mime
View raw message