[jboss-svn-commits] JBoss Common SVN: r3941 - in shrinkwrap/trunk/impl-base/src: main/java/org/jboss/shrinkwrap/impl/base/exporter and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 20 19:10:32 EST 2010
Author: ALRubinger
Date: 2010-01-20 19:10:32 -0500 (Wed, 20 Jan 2010)
New Revision: 3941
Modified:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/DirectoryAsset.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterDelegate.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java
Log:
[SHRINKWRAP-104] Refine the contract of Asset to account for directory types and adjust the implementation to rely upon that contract, not a particular implementation
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/DirectoryAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/DirectoryAsset.java 2010-01-20 23:21:42 UTC (rev 3940)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/DirectoryAsset.java 2010-01-21 00:10:32 UTC (rev 3941)
@@ -19,8 +19,8 @@
import java.io.InputStream;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Asset;
-import org.jboss.shrinkwrap.api.ArchivePath;
/**
* {@link Asset} implementation used to denote no backing
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterDelegate.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterDelegate.java 2010-01-20 23:21:42 UTC (rev 3940)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterDelegate.java 2010-01-21 00:10:32 UTC (rev 3941)
@@ -24,12 +24,11 @@
import java.util.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Asset;
-import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
import org.jboss.shrinkwrap.api.exporter.ExplodedExporter;
import org.jboss.shrinkwrap.impl.base.asset.ArchiveAsset;
-import org.jboss.shrinkwrap.impl.base.asset.DirectoryAsset;
import org.jboss.shrinkwrap.impl.base.io.IOUtil;
/**
@@ -108,44 +107,53 @@
processArchiveAsset(assetParent, nesteArchiveAsset);
return;
}
-
+
// Handle directory assets separately
- final boolean isDirectory = asset instanceof DirectoryAsset;
- if (isDirectory)
+ try
{
- // If doesn't already exist
- if (!assetFile.exists())
+ final boolean isDirectory = (asset.openStream() == null);
+ if (isDirectory)
{
- // Attempt a create
- if (!assetFile.mkdirs())
+ // If doesn't already exist
+ if (!assetFile.exists())
{
- // Some error in writing
- throw new ArchiveExportException("Failed to write directory: " + assetFile.getAbsolutePath());
+ // Attempt a create
+ if (!assetFile.mkdirs())
+ {
+ // Some error in writing
+ throw new ArchiveExportException("Failed to write directory: " + assetFile.getAbsolutePath());
+ }
}
}
- }
- // Only handle non-directory assets, otherwise the path is handled above
- else
- {
- try
+ // Only handle non-directory assets, otherwise the path is handled above
+ else
{
- if (log.isLoggable(Level.FINE))
+ try
{
- log.fine("Writing asset " + path.get() + " to " + assetFile.getAbsolutePath());
+ if (log.isLoggable(Level.FINE))
+ {
+ log.fine("Writing asset " + path.get() + " to " + assetFile.getAbsolutePath());
+ }
+ // Get the asset streams
+ final InputStream assetInputStream = asset.openStream();
+ final FileOutputStream assetFileOutputStream = new FileOutputStream(assetFile);
+ final BufferedOutputStream assetBufferedOutputStream = new BufferedOutputStream(assetFileOutputStream,
+ 8192);
+
+ // Write contents
+ IOUtil.copyWithClose(assetInputStream, assetBufferedOutputStream);
}
- // Get the asset streams
- final InputStream assetInputStream = asset.openStream();
- final FileOutputStream assetFileOutputStream = new FileOutputStream(assetFile);
- final BufferedOutputStream assetBufferedOutputStream = new BufferedOutputStream(assetFileOutputStream, 8192);
-
- // Write contents
- IOUtil.copyWithClose(assetInputStream, assetBufferedOutputStream);
+ catch (final Exception e)
+ {
+ // Provide a more detailed exception than the outer block
+ throw new ArchiveExportException("Failed to write asset " + path + " to " + assetFile, e);
+ }
}
- catch (Throwable t)
- {
- throw new ArchiveExportException("Failed to write asset " + path + " to " + assetFile);
- }
}
+ catch (final Exception e)
+ {
+ throw new ArchiveExportException("Unexpected error encountered in export of " + asset, e);
+ }
}
/**
@@ -191,11 +199,10 @@
{
throw new ArchiveExportException("Unable to create archive output directory - " + outputDirectory);
}
- if(outputDirectory.isFile())
+ if (outputDirectory.isFile())
{
- throw new IllegalArgumentException(
- "Unable to export exploded directory to " + outputDirectory.getAbsolutePath() +
- ", it points to a existing file");
+ throw new IllegalArgumentException("Unable to export exploded directory to "
+ + outputDirectory.getAbsolutePath() + ", it points to a existing file");
}
return outputDirectory;
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java 2010-01-20 23:21:42 UTC (rev 3940)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java 2010-01-21 00:10:32 UTC (rev 3941)
@@ -117,6 +117,13 @@
{
ZipExportDelegate.super.export();
}
+ catch (final Exception e)
+ {
+ // Log this and rethrow; otherwise if we go into deadlock we won't ever
+ // be able to get the underlying cause from the Future
+ log.log(Level.WARNING, "Exception encountered during export of archive", e);
+ throw e;
+ }
finally
{
try
@@ -174,6 +181,10 @@
{
throw new IllegalArgumentException("Path must be specified");
}
+ if (asset == null)
+ {
+ throw new IllegalArgumentException("asset must be specified");
+ }
if (isParentOfAnyPathsExported(path))
{
@@ -195,18 +206,19 @@
final boolean isRoot = grandParent == null;
if (!isRoot)
{
- // Process the parent without any asset (it's a directory)
- this.processAsset(parent, null);
+ // Process the parent as directory
+ this.processAsset(parent, DirectoryAsset.INSTANCE);
}
}
- // Mark if we're writing a directory
- final boolean isDirectory = ((asset == null) || (asset instanceof DirectoryAsset));
// Get Asset InputStream if the asset is specified (else it's a directory so use null)
- final InputStream assetStream = !isDirectory ? asset.openStream() : null;
- final String pathName = PathUtil.optionallyRemovePrecedingSlash(path.get());
+ final InputStream assetStream = asset.openStream();
+ // Mark if we're writing a directory
+ final boolean isDirectory = assetStream == null;
+
// If we haven't already written this path
+ final String pathName = PathUtil.optionallyRemovePrecedingSlash(path.get());
if (!this.pathsExported.contains(path))
{
// Make a task for this stream and close when done
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java 2010-01-20 23:21:42 UTC (rev 3940)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java 2010-01-21 00:10:32 UTC (rev 3941)
@@ -26,9 +26,9 @@
import java.util.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.Asset;
-import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
import org.jboss.shrinkwrap.api.exporter.ExplodedExporter;
import org.jboss.shrinkwrap.impl.base.TestIOUtil;
@@ -196,7 +196,7 @@
@Override
public InputStream openStream()
{
- throw new RuntimeException("Mock Esception getting Stream");
+ throw new RuntimeException("Mock Exception getting Stream");
}
}, new BasicPath("badAsset"));
More information about the jboss-svn-commits
mailing list