You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/12/06 13:39:36 UTC
svn commit: r601718 -
/directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/
Author: felixk
Date: Thu Dec 6 04:39:34 2007
New Revision: 601718
URL: http://svn.apache.org/viewvc?rev=601718&view=rev
Log:
- Use plexus archiver
- Some log beautyfying
Modified:
directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioCopyEclipseDependencyMojo.java
directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioPrepareJarPackageMojo.java
directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioReplaceFileInJarMojo.java
directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioUnpackPrefixedMojo.java
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=601718&r1=601717&r2=601718&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 04:39:34 2007
@@ -20,12 +20,9 @@
package org.apache.directory.studio.maven.plugins;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Iterator;
import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
@@ -40,6 +37,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
@@ -55,7 +53,7 @@
/**
* To look up Archiver/UnArchiver implementations
- *
+ *
* @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
* @required
* @readonly
@@ -161,83 +159,56 @@
protected boolean outputAbsoluteArtifactFilename;
/**
- * Unzip a file into a directory
+ * Unpack a file to a location
*
* @param location
- * The directory the file unzip into
+ * The location to unpack the file to
* @param file
- * The file to unzip
+ * The file to unpack
*/
- protected void unzipToDir(final File location, final File file) throws Exception {
+ protected void unpackToLocation(final File location, final File file) throws Exception {
try {
+ getLog().info("Unpacking " + file + " to\n " + location);
location.mkdirs();
- UnArchiver unArchiver = archiverManager.getUnArchiver( file );
- unArchiver.setSourceFile( file );
-
- unArchiver.setDestDirectory( location );
+ UnArchiver unArchiver = archiverManager.getUnArchiver(file);
+ unArchiver.setSourceFile(file);
+ unArchiver.setDestDirectory(location);
unArchiver.extract();
- }
- catch ( NoSuchArchiverException e )
- {
- throw new MojoExecutionException( "Unknown archiver type", e );
- }
- catch ( ArchiverException e )
- {
+ } 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 );
+ throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location + "\r\n"
+ + e.toString(), e);
}
}
/**
- * Zip a directory to given ZipOutputStream
+ * Pack a given location into a file
*
- * @param dirToZip
- * A directory to zip
- * @param zos
- * The A ZipOutputStream
+ * @param location
+ * A location to pack
+ * @param file
+ * The file to pack the location into
* @throws Exception
* If an error occurs
*/
- protected void zipFromDir(final File dirToZip, final File zipFile) throws Exception {
- final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
+ protected void packFromLocation(final File location, final File file) throws MojoExecutionException {
try {
- if (!dirToZip.isFile() && !dirToZip.isDirectory()) {
- throw new MojoExecutionException("Source file/directory " + dirToZip.getAbsolutePath() + " not found.");
- }
- zipFiles(dirToZip, zos, dirToZip.getAbsolutePath());
- } finally {
- zos.finish();
- zos.close();
- }
- }
-
- private void zipFiles(File cpFile, ZipOutputStream zos, final String dirToZip) throws Exception {
- int byteCount;
- final int DATA_BLOCK_SIZE = 2048;
-
- if (cpFile.isDirectory()) {
- File[] fList = cpFile.listFiles();
- for (File aFile : fList) {
- zipFiles(aFile, zos, dirToZip);
- }
- } else {
- String strAbsPath = cpFile.getPath();
- String strZipEntryName = strAbsPath.substring(dirToZip.length() + 1, strAbsPath.length());
-
- final FileInputStream cpFileInputStream = new FileInputStream(cpFile);
- try {
- ZipEntry cpZipEntry = new ZipEntry(strZipEntryName);
- zos.putNextEntry(cpZipEntry);
-
- final byte[] b = new byte[DATA_BLOCK_SIZE];
- while ((byteCount = cpFileInputStream.read(b, 0, DATA_BLOCK_SIZE)) != -1) {
- zos.write(b, 0, byteCount);
- }
- zos.closeEntry();
- } finally {
- cpFileInputStream.close();
- }
+ getLog().info("Packing " + location + " to\n " + file);
+ Archiver archiver = archiverManager.getArchiver(file);
+ archiver.setDestFile(file);
+ archiver.setIncludeEmptyDirs(true);
+ archiver.addDirectory(location);
+ archiver.createArchive();
+ } catch (NoSuchArchiverException e) {
+ throw new MojoExecutionException("Unknown archiver type", e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error creating archive", e);
+ } catch (ArchiverException e) {
+ e.printStackTrace();
+ throw new MojoExecutionException("Error packing file: " + file + " to: " + location + "\r\n"
+ + e.toString(), e);
}
}
@@ -459,9 +430,10 @@
}
/**
- * @param libraryPath the libraryPath to set
+ * @param libraryPath
+ * the libraryPath to set
*/
public void setLibraryPath(String pLibraryPath) {
- this.libraryPath = pLibraryPath;
+ this.libraryPath = pLibraryPath;
}
}
Modified: directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioCopyEclipseDependencyMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioCopyEclipseDependencyMojo.java?rev=601718&r1=601717&r2=601718&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioCopyEclipseDependencyMojo.java (original)
+++ directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioCopyEclipseDependencyMojo.java Thu Dec 6 04:39:34 2007
@@ -78,7 +78,7 @@
final File destFile = new File(destinationDirectory.getAbsoluteFile() + File.separator
+ item.getArtifactId() + "_" + item.getVersion() + "." + item.getType());
- getLog().info("Copying " + item.getArtifactId() + " to " + destFile.getAbsolutePath());
+ getLog().info("Copying artifact " + item.getArtifactId() + " to\n " + destFile.getAbsolutePath());
if (!destinationDirectory.exists()) {
destinationDirectory.mkdirs();
Modified: directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioPrepareJarPackageMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioPrepareJarPackageMojo.java?rev=601718&r1=601717&r2=601718&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioPrepareJarPackageMojo.java (original)
+++ directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioPrepareJarPackageMojo.java Thu Dec 6 04:39:34 2007
@@ -111,7 +111,7 @@
for (Artifact artifact : list) {
final File destFile = new File(copyDir, artifact.getFile().getName());
FileUtils.copyFile(artifact.getFile(), destFile);
- getLog().info("Copying " + artifact.getFile() + " to " + destFile);
+ getLog().info("Copying " + artifact.getFile() + " to\n " + destFile);
}
}
}
Modified: directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioReplaceFileInJarMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioReplaceFileInJarMojo.java?rev=601718&r1=601717&r2=601718&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioReplaceFileInJarMojo.java (original)
+++ directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioReplaceFileInJarMojo.java Thu Dec 6 04:39:34 2007
@@ -94,27 +94,17 @@
public void execute() throws MojoExecutionException {
completeArtifactItems(artifactItems);
- // Add file to dest jar
+ // Add file to packed file
for (Iterator<ArtifactItem> artifactItem = artifactItems.iterator(); artifactItem.hasNext();) {
ArtifactItem item = artifactItem.next();
try {
final File zipFile = new File(destinationDirectory.getAbsolutePath() + File.separator
+ item.getArtifactId() + "_" + item.getVersion() + "." + item.getType());
final File tmpDir = new File(pluginWorkDir + item.getArtifact().getArtifactId());
-
- getLog().info("Adding " + inputFile + " to " + zipFile);
-
- if (getLog().isDebugEnabled())
- getLog().debug("Unzipping " + zipFile + " into " + tmpDir);
- unzipToDir(tmpDir, zipFile);
-
- if (getLog().isDebugEnabled())
- getLog().debug("Copying " + inputFile + " into " + tmpDir);
+ unpackToLocation(tmpDir, zipFile);
+ getLog().info("Adding " + inputFile + " to\n " + zipFile);
FileUtils.copyFileToDirectory(inputFile, tmpDir);
-
- if (getLog().isDebugEnabled())
- getLog().debug("Zipping " + tmpDir + " into " + zipFile);
- zipFromDir(tmpDir, zipFile);
+ packFromLocation(tmpDir, zipFile);
} catch (Exception e) {
throw new MojoExecutionException("", e);
Modified: directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioUnpackPrefixedMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioUnpackPrefixedMojo.java?rev=601718&r1=601717&r2=601718&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioUnpackPrefixedMojo.java (original)
+++ directory/sandbox/felixk/studio-plugin/src/main/java/org/apache/directory/studio/maven/plugins/StudioUnpackPrefixedMojo.java Thu Dec 6 04:39:34 2007
@@ -68,18 +68,12 @@
public void execute() throws MojoExecutionException {
completeArtifactItems(artifactItems);
-
- // unzip it
for (Iterator<ArtifactItem> artifactItem = artifactItems.iterator(); artifactItem.hasNext();) {
ArtifactItem item = artifactItem.next();
try {
final File tmpDir = new File(outputDirectory.getAbsoluteFile() + File.separator + item.getArtifactId()
+ "_" + item.getVersion());
-
- if (getLog().isDebugEnabled())
- getLog().debug("Unzipping " + item.getArtifact().getFile() + " into " + tmpDir);
- unzipToDir(tmpDir, item.getArtifact().getFile());
-
+ unpackToLocation(tmpDir, item.getArtifact().getFile());
} catch (Exception e) {
throw new MojoExecutionException("", e);
}