[jboss-svn-commits] JBoss Common SVN: r3455 - in declarchive/trunk: impl-base/src/main/java/org/jboss/declarchive/impl/base/jar and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 17 06:20:11 EDT 2009
Author: ALRubinger
Date: 2009-08-17 06:20:09 -0400 (Mon, 17 Aug 2009)
New Revision: 3455
Modified:
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java
Log:
[TMPARCH-10] Comment out and make compilation happy as new APIs are introduced; we will build up again as needed
Modified: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java 2009-08-17 10:12:40 UTC (rev 3454)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java 2009-08-17 10:20:09 UTC (rev 3455)
@@ -34,7 +34,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public abstract class ArchiveBase<T extends Archive<T>> implements Archive<T>
+public abstract class ArchiveBase<T extends Archive<T>>
{
//-------------------------------------------------------------------------------------||
@@ -114,152 +114,152 @@
this.classLoader = cl;
}
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+// // Required Implementations -----------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * @see org.jboss.declarchive.api.Archive#addClass(java.lang.Class)
+// */
+// @Override
+// public T addClass(final Class<?> clazz) throws IllegalArgumentException
+// {
+// // Precondition check
+// if (clazz == null)
+// {
+// throw new IllegalArgumentException("Class must be specified");
+// }
+//
+// // Get the resource name of the class
+// final String name = this.getResourceNameOfClass(clazz);
+//
+// // Get the CL of the Class
+// final ClassLoader cl = clazz.getClassLoader();
+//
+// // Add it as a resource
+// if (log.isLoggable(Level.FINER))
+// {
+// log.log(Level.FINER, "Adding class as resource: " + clazz);
+// }
+// return this.addResource(name, cl);
+// }
+//
+// /**
+// * @see org.jboss.declarchive.api.Archive#addClasses(java.lang.Class<?>[])
+// */
+// @Override
+// public T addClasses(final Class<?>... classes) throws IllegalArgumentException
+// {
+// // Precondition check
+// if (classes == null || classes.length == 0)
+// {
+// throw new IllegalArgumentException("At least one class must be specified");
+// }
+//
+// // For each class
+// for (final Class<?> clazz : classes)
+// {
+// this.addClass(clazz);
+// }
+//
+// // Return
+// return this.covarientReturn();
+// }
+//
+// /**
+// * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
+// */
+// @Override
+// public T addResource(final String name) throws IllegalArgumentException
+// {
+// return this.addResource(name, this.getClassLoader());
+// }
+//
+// /**
+// * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
+// */
+// @Override
+// public T addResource(final URL location) throws IllegalArgumentException
+// {
+// // Delegate to the other implementation
+// return this.addResource(location, null);
+// }
+//
+// /**
+// * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String, java.lang.ClassLoader)
+// */
+// @Override
+// public final T addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
+// {
+// // Precondition check
+// if (name == null || name.length() == 0)
+// {
+// throw new IllegalArgumentException("name must be specified");
+// }
+// if (cl == null)
+// {
+// throw new IllegalArgumentException("ClassLoader must be specified");
+// }
+//
+// // Get the content of the resource
+// byte[] content = null;
+// try
+// {
+// content = this.getBytesOfResource(name, cl);
+// }
+// catch (final IOException ioe)
+// {
+// throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
+// }
+//
+// // Add
+// this.addContent(content, name);
+//
+// // Return
+// return this.covarientReturn();
+// }
+//
+// /**
+// * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
+// */
+// @Override
+// public T addResource(final URL location, final String newPath) throws IllegalArgumentException
+// {
+// // Precondition check
+// if (location == null)
+// {
+// throw new IllegalArgumentException("location must be specified");
+// }
+//
+// // Get the content of the location
+// byte[] content = null;
+// try
+// {
+// content = this.getBytesOfResource(location);
+// }
+// catch (final IOException ioe)
+// {
+// throw new RuntimeException("Could not add location \"" + location + "\" to " + this, ioe);
+// }
+//
+// // Adjust the path if not explicitly defined
+// String path = newPath;
+// if (path == null)
+// {
+// path = location.getPath();
+// if (log.isLoggable(Level.FINER))
+// {
+// log.log(Level.FINER, "Implicitly set new path to \"" + path + "\" while adding: " + location);
+// }
+// }
+//
+// // Add
+// this.addContent(content, path);
+//
+// // Return
+// return this.covarientReturn();
+// }
- /**
- * @see org.jboss.declarchive.api.Archive#addClass(java.lang.Class)
- */
- @Override
- public T addClass(final Class<?> clazz) throws IllegalArgumentException
- {
- // Precondition check
- if (clazz == null)
- {
- throw new IllegalArgumentException("Class must be specified");
- }
-
- // Get the resource name of the class
- final String name = this.getResourceNameOfClass(clazz);
-
- // Get the CL of the Class
- final ClassLoader cl = clazz.getClassLoader();
-
- // Add it as a resource
- if (log.isLoggable(Level.FINER))
- {
- log.log(Level.FINER, "Adding class as resource: " + clazz);
- }
- return this.addResource(name, cl);
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#addClasses(java.lang.Class<?>[])
- */
- @Override
- public T addClasses(final Class<?>... classes) throws IllegalArgumentException
- {
- // Precondition check
- if (classes == null || classes.length == 0)
- {
- throw new IllegalArgumentException("At least one class must be specified");
- }
-
- // For each class
- for (final Class<?> clazz : classes)
- {
- this.addClass(clazz);
- }
-
- // Return
- return this.covarientReturn();
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
- */
- @Override
- public T addResource(final String name) throws IllegalArgumentException
- {
- return this.addResource(name, this.getClassLoader());
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
- */
- @Override
- public T addResource(final URL location) throws IllegalArgumentException
- {
- // Delegate to the other implementation
- return this.addResource(location, null);
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String, java.lang.ClassLoader)
- */
- @Override
- public final T addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
- {
- // Precondition check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
- if (cl == null)
- {
- throw new IllegalArgumentException("ClassLoader must be specified");
- }
-
- // Get the content of the resource
- byte[] content = null;
- try
- {
- content = this.getBytesOfResource(name, cl);
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
- }
-
- // Add
- this.addContent(content, name);
-
- // Return
- return this.covarientReturn();
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
- */
- @Override
- public T addResource(final URL location, final String newPath) throws IllegalArgumentException
- {
- // Precondition check
- if (location == null)
- {
- throw new IllegalArgumentException("location must be specified");
- }
-
- // Get the content of the location
- byte[] content = null;
- try
- {
- content = this.getBytesOfResource(location);
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Could not add location \"" + location + "\" to " + this, ioe);
- }
-
- // Adjust the path if not explicitly defined
- String path = newPath;
- if (path == null)
- {
- path = location.getPath();
- if (log.isLoggable(Level.FINER))
- {
- log.log(Level.FINER, "Implicitly set new path to \"" + path + "\" while adding: " + location);
- }
- }
-
- // Add
- this.addContent(content, path);
-
- // Return
- return this.covarientReturn();
- }
-
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java 2009-08-17 10:12:40 UTC (rev 3454)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/jar/JavaArchiveImpl.java 2009-08-17 10:20:09 UTC (rev 3455)
@@ -33,212 +33,61 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public final class JavaArchiveImpl implements JavaArchive
+public final class JavaArchiveImpl
{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+// // Class Members ----------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Logger
+// */
+// private static final Logger log = Logger.getLogger(JavaArchiveImpl.class.getName());
+//
+// /**
+// * Path to the manifest inside of a JAR
+// */
+// private static final String PATH_MANIFEST = "META-INF/MANIFEST.MF";
+//
+// //-------------------------------------------------------------------------------------||
+// // Instance Members -------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Underlying delegate
+// */
+// private final Archive<?> delegate;
+//
+// //-------------------------------------------------------------------------------------||
+// // Constructor ------------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Constructor
+// *
+// * @param The underlying archive storage implementation
+// * to which the convenience methods of this archive
+// * will delegate
+// * @throws IllegalArgumentException If the delegate is not specified
+// */
+// public JavaArchiveImpl(final Archive<?> delegate)
+// {
+// // Precondition check
+// if (delegate == null)
+// {
+// throw new IllegalArgumentException("delegate must be specified");
+// }
+//
+// // Set properties
+// this.delegate = delegate;
+//
+// // Log
+// log.fine("Created new Java Archive from backing delegate: " + delegate);
+// }
+//
+// //-------------------------------------------------------------------------------------||
+// // Required Implementations -----------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(JavaArchiveImpl.class.getName());
-
- /**
- * Path to the manifest inside of a JAR
- */
- private static final String PATH_MANIFEST = "META-INF/MANIFEST.MF";
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Underlying delegate
- */
- private final Archive<?> delegate;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Constructor
- *
- * @param The underlying archive storage implementation
- * to which the convenience methods of this archive
- * will delegate
- * @throws IllegalArgumentException If the delegate is not specified
- */
- public JavaArchiveImpl(final Archive<?> delegate)
- {
- // Precondition check
- if (delegate == null)
- {
- throw new IllegalArgumentException("delegate must be specified");
- }
-
- // Set properties
- this.delegate = delegate;
-
- // Log
- log.fine("Created new Java Archive from backing delegate: " + delegate);
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @param clazz
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.api.Archive#addClass(java.lang.Class)
- */
- public JavaArchive addClass(final Class<?> clazz) throws IllegalArgumentException
- {
- delegate.addClass(clazz);
- return this;
- }
-
- /**
- * @param classes
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.api.Archive#addClasses(java.lang.Class<?>[])
- */
- public JavaArchive addClasses(final Class<?>... classes) throws IllegalArgumentException
- {
- delegate.addClasses(classes);
- return this;
- }
-
- /**
- * @param name
- * @param cl
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String, java.lang.ClassLoader)
- */
- public JavaArchive addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
- {
- delegate.addResource(name, cl);
- return this;
- }
-
- /**
- * @param name
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
- */
- public JavaArchive addResource(final String name) throws IllegalArgumentException
- {
- delegate.addResource(name);
- return this;
- }
-
- /**
- * @param location
- * @param newPath
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
- */
- public JavaArchive addResource(final URL location, final String newPath) throws IllegalArgumentException
- {
- delegate.addResource(location, newPath);
- return this;
- }
-
- /**
- * @param location
- * @return
- * @throws IllegalArgumentException
- * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
- */
- public JavaArchive addResource(final URL location) throws IllegalArgumentException
- {
- delegate.addResource(location);
- return this;
- }
-
- /**
- * @param verbose
- * @return
- * @see org.jboss.declarchive.api.Archive#toString(boolean)
- */
- public String toString(final boolean verbose)
- {
- return "Java Archive (JAR): " + delegate.toString(verbose);
- }
-
- /**
- * @throws MalformedURLException
- * @see org.jboss.declarchive.api.jar.JavaArchive#addManifest(java.io.File)
- */
- @Override
- public JavaArchive addManifest(final File manifestFile) throws IllegalArgumentException
- {
- // Precondition checks
- if (manifestFile == null)
- {
- throw new IllegalArgumentException("Manifest file must be specified");
- }
- if (!manifestFile.exists())
- {
- throw new IllegalArgumentException("Specified manifest file does not exist: " + manifestFile.getAbsolutePath());
- }
-
- // Get a URL
- final URL url;
- try
- {
- url = manifestFile.toURI().toURL();
- }
- catch (final MalformedURLException murle)
- {
- throw new RuntimeException("Unexpected error in obtaining URL from File reference: "
- + manifestFile.getAbsolutePath(), murle);
- }
-
- // Return
- return this.addManifest(url);
- }
-
- /**
- * @see org.jboss.declarchive.api.jar.JavaArchive#addManifest(java.lang.String)
- */
- @Override
- public JavaArchive addManifest(final String manifestFilePath) throws IllegalArgumentException
- {
- // Precondition check
- if (manifestFilePath == null || manifestFilePath.length() == 0)
- {
- throw new IllegalArgumentException("path must be specified");
- }
-
- // Get a File
- final File file = new File(manifestFilePath);
-
- // Return
- return this.addManifest(file);
- }
-
- /**
- * @see org.jboss.declarchive.api.jar.JavaArchive#addManifest(java.net.URL)
- */
- @Override
- public JavaArchive addManifest(final URL manifestFile) throws IllegalArgumentException
- {
- // Precondition checks
- if (manifestFile == null)
- {
- throw new IllegalArgumentException("Manifest file must be specified");
- }
-
- // Add the resource and return
- return this.addResource(manifestFile, PATH_MANIFEST);
- }
}
Modified: declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java 2009-08-17 10:12:40 UTC (rev 3454)
+++ declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java 2009-08-17 10:20:09 UTC (rev 3455)
@@ -25,8 +25,6 @@
import java.util.logging.Logger;
import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.impl.base.ArchiveBase;
-import org.jboss.declarchive.spi.jdk.file.FileArchive;
/**
* TempFileArchiveImpl
@@ -37,273 +35,257 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class TempFileArchiveImpl extends ArchiveBase<FileArchive> implements FileArchive
+public class TempFileArchiveImpl
{
+//
+// //-------------------------------------------------------------------------------------||
+// // Class Members ----------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Logger
+// */
+// private static final Logger log = Logger.getLogger(TempFileArchiveImpl.class.getName());
+//
+// /**
+// * Prefix to be applied to the archive temp directory
+// */
+// private static final String PREFIX_TEMP = "archive";
+//
+// /**
+// * Empty String
+// */
+// private static final String EMPTY_STRING = "";
+//
+// /**
+// * Root of all virtual archives
+// */
+// private static final File archivesRoot;
+//
+// /*
+// * Initialize the temp directory location once on load/init
+// */
+// static
+// {
+// try
+// {
+//
+// // Make a new temp file to get unique namespace
+// final File tempStub = File.createTempFile(PREFIX_TEMP, EMPTY_STRING);
+// // Delete it
+// tempStub.delete();
+// // Make a new directory in the place of the temp file
+// final File temp = new File(tempStub.getAbsolutePath());
+// if (!temp.mkdir())
+// {
+// throw new RuntimeException("Could not create the temp virtual archive location at: "
+// + temp.getAbsolutePath());
+// }
+// // Mark the archives to delete on exit
+// temp.deleteOnExit();
+// log.log(Level.FINE, "Archives root: " + temp.getAbsolutePath());
+// // Set the archives root
+// archivesRoot = temp;
+// }
+// catch (final IOException ioe)
+// {
+// throw new RuntimeException("Could not create the temp location for virtual archives", ioe);
+// }
+// }
+//
+// //-------------------------------------------------------------------------------------||
+// // Instance Members -------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Root of the archive
+// */
+// private final File root;
+//
+// //-------------------------------------------------------------------------------------||
+// // Constructors -----------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Constructor
+// *
+// * Creates a new instance using the Thread Context
+// * ClassLoader.
+// *
+// * @param name Unique name for the deployment
+// * @throws IllegalArgumentException If the name was not specified
+// */
+// public TempFileArchiveImpl(final String name) throws IllegalArgumentException
+// {
+// this(name, SecurityActions.getThreadContextClassLoader());
+// }
+//
+// /**
+// * Constructor
+// *
+// * @param name Unique name for the deployment
+// * @param cl ClassLoader to be used in loading resources and classes
+// * @throws IllegalArgumentException If the name or ClassLoader was not specified
+// */
+// public TempFileArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
+// {
+// // Invoke super
+// super(cl);
+//
+// // Precondition Check
+// if (name == null || name.length() == 0)
+// {
+// throw new IllegalArgumentException("name must be specified");
+// }
+// if (cl == null)
+// {
+// throw new IllegalArgumentException("ClassLoader must be specified");
+// }
+//
+// /*
+// * Set root
+// */
+//
+// // Make pointer
+// final File root = new File(archivesRoot, name);
+// if (!root.mkdir())
+// {
+// throw new RuntimeException("Could not create new temp file virtual archive root: " + root.getAbsolutePath());
+// }
+//
+// // Set
+// this.root = root;
+//
+// // Delete it on exit
+// this.deleteOnExit(root);
+// }
+//
+// //-------------------------------------------------------------------------------------||
+// // Required Implementations -----------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
+// */
+// @Override
+// protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
+// {
+// // Make the new pointer
+// final File newFile = new File(this.getRoot(), location);
+// this.deleteOnExit(newFile);
+// final String newPath = newFile.getAbsolutePath();
+//
+// // Ensure the parent location exists, or we can make it
+// final File parent = newFile.getParentFile();
+// if (!parent.exists() && !parent.mkdirs())
+// {
+// throw new RuntimeException("Could not make " + parent.getAbsolutePath());
+// }
+//
+// // Get an OutputStream to write into the buffer
+// final BufferedOutputStream out;
+// try
+// {
+// out = new BufferedOutputStream(new FileOutputStream(newFile));
+// }
+// catch (final FileNotFoundException e)
+// {
+// throw new RuntimeException("Could not obtain file: " + newPath, e);
+// }
+//
+// // Write
+// try
+// {
+// out.write(content);
+// log.log(Level.FINE, "Wrote " + content.length + " bytes to " + newPath);
+// }
+// catch (final IOException ioe)
+// {
+// throw new RuntimeException("Error in writing to file " + newPath, ioe);
+// }
+// // Close
+// finally
+// {
+// try
+// {
+// out.close();
+// }
+// catch (final IOException e)
+// {
+// // Ignore
+// }
+// }
+// }
+//
+// /**
+// * @see org.jboss.declarchive.api.Archive#toString(boolean)
+// */
+// @Override
+// public String toString(final boolean verbose)
+// {
+// // Short form
+// if (!verbose)
+// {
+// return this.toString();
+// }
+// // Verbose
+// else
+// {
+// //TODO
+// log.log(Level.WARNING, "Must implement the verbose form of toString()");
+// return this.toString();
+// }
+// }
+//
+// /**
+// * @see java.lang.Object#toString()
+// */
+// @Override
+// public String toString()
+// {
+// //return super.toString() + ": " + this.getRoot().getAbsolutePath();
+// }
+//
+//
+//
+// //-------------------------------------------------------------------------------------||
+// // Internal Helper Methods ------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Marks the specified File, and all parents of that file up to the
+// * root of this archive, to delete upon JVM normal exit as documented by
+// * {@link File#deleteOnExit()}
+// *
+// * @param File the File, and parents to to the root, to delete
+// * @throws IllegalArgumentException If the specified file is null
+// * @throws IllegalStateException If the root is not yet set
+// */
+// private void deleteOnExit(final File file) throws IllegalArgumentException, IllegalStateException
+// {
+// // Precondition check
+// assert file != null : "file was null";
+//
+// // Get the root
+// final File root = archivesRoot;
+// if (root == null)
+// {
+// throw new IllegalStateException("root must first be set");
+// }
+//
+// // If this is the root, exit
+// if (file.equals(root))
+// {
+// return;
+// }
+//
+// // Delete the parent (if not the root)
+// final File parent = file.getParentFile();
+// this.deleteOnExit(parent);
+//
+// // Mark to delete
+// file.deleteOnExit();
+// log.log(Level.FINE, "Going to delete on exit: " + file.getAbsolutePath());
+// }
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(TempFileArchiveImpl.class.getName());
-
- /**
- * Prefix to be applied to the archive temp directory
- */
- private static final String PREFIX_TEMP = "archive";
-
- /**
- * Empty String
- */
- private static final String EMPTY_STRING = "";
-
- /**
- * Root of all virtual archives
- */
- private static final File archivesRoot;
-
- /*
- * Initialize the temp directory location once on load/init
- */
- static
- {
- try
- {
-
- // Make a new temp file to get unique namespace
- final File tempStub = File.createTempFile(PREFIX_TEMP, EMPTY_STRING);
- // Delete it
- tempStub.delete();
- // Make a new directory in the place of the temp file
- final File temp = new File(tempStub.getAbsolutePath());
- if (!temp.mkdir())
- {
- throw new RuntimeException("Could not create the temp virtual archive location at: "
- + temp.getAbsolutePath());
- }
- // Mark the archives to delete on exit
- temp.deleteOnExit();
- log.log(Level.FINE, "Archives root: " + temp.getAbsolutePath());
- // Set the archives root
- archivesRoot = temp;
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Could not create the temp location for virtual archives", ioe);
- }
- }
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Root of the archive
- */
- private final File root;
-
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Constructor
- *
- * Creates a new instance using the Thread Context
- * ClassLoader.
- *
- * @param name Unique name for the deployment
- * @throws IllegalArgumentException If the name was not specified
- */
- public TempFileArchiveImpl(final String name) throws IllegalArgumentException
- {
- this(name, SecurityActions.getThreadContextClassLoader());
- }
-
- /**
- * Constructor
- *
- * @param name Unique name for the deployment
- * @param cl ClassLoader to be used in loading resources and classes
- * @throws IllegalArgumentException If the name or ClassLoader was not specified
- */
- public TempFileArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
- {
- // Invoke super
- super(cl);
-
- // Precondition Check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
- if (cl == null)
- {
- throw new IllegalArgumentException("ClassLoader must be specified");
- }
-
- /*
- * Set root
- */
-
- // Make pointer
- final File root = new File(archivesRoot, name);
- if (!root.mkdir())
- {
- throw new RuntimeException("Could not create new temp file virtual archive root: " + root.getAbsolutePath());
- }
-
- // Set
- this.root = root;
-
- // Delete it on exit
- this.deleteOnExit(root);
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
- */
- @Override
- protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
- {
- // Make the new pointer
- final File newFile = new File(this.getRoot(), location);
- this.deleteOnExit(newFile);
- final String newPath = newFile.getAbsolutePath();
-
- // Ensure the parent location exists, or we can make it
- final File parent = newFile.getParentFile();
- if (!parent.exists() && !parent.mkdirs())
- {
- throw new RuntimeException("Could not make " + parent.getAbsolutePath());
- }
-
- // Get an OutputStream to write into the buffer
- final BufferedOutputStream out;
- try
- {
- out = new BufferedOutputStream(new FileOutputStream(newFile));
- }
- catch (final FileNotFoundException e)
- {
- throw new RuntimeException("Could not obtain file: " + newPath, e);
- }
-
- // Write
- try
- {
- out.write(content);
- log.log(Level.FINE, "Wrote " + content.length + " bytes to " + newPath);
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Error in writing to file " + newPath, ioe);
- }
- // Close
- finally
- {
- try
- {
- out.close();
- }
- catch (final IOException e)
- {
- // Ignore
- }
- }
- }
-
- /**
- * @see org.jboss.declarchive.api.Archive#toString(boolean)
- */
- @Override
- public String toString(final boolean verbose)
- {
- // Short form
- if (!verbose)
- {
- return this.toString();
- }
- // Verbose
- else
- {
- //TODO
- log.log(Level.WARNING, "Must implement the verbose form of toString()");
- return this.toString();
- }
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return super.toString() + ": " + this.getRoot().getAbsolutePath();
- }
-
- /**
- * @see org.jboss.declarchive.spi.jdk.file.FileArchive#getRoot()
- */
- @Override
- public File getRoot()
- {
- return this.root;
- }
-
- /**
- * @see org.jboss.declarchive.impl.base.ArchiveBase#getActualClass()
- */
- @Override
- protected Class<FileArchive> getActualClass()
- {
- return FileArchive.class;
- }
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Marks the specified File, and all parents of that file up to the
- * root of this archive, to delete upon JVM normal exit as documented by
- * {@link File#deleteOnExit()}
- *
- * @param File the File, and parents to to the root, to delete
- * @throws IllegalArgumentException If the specified file is null
- * @throws IllegalStateException If the root is not yet set
- */
- private void deleteOnExit(final File file) throws IllegalArgumentException, IllegalStateException
- {
- // Precondition check
- assert file != null : "file was null";
-
- // Get the root
- final File root = archivesRoot;
- if (root == null)
- {
- throw new IllegalStateException("root must first be set");
- }
-
- // If this is the root, exit
- if (file.equals(root))
- {
- return;
- }
-
- // Delete the parent (if not the root)
- final File parent = file.getParentFile();
- this.deleteOnExit(parent);
-
- // Mark to delete
- file.deleteOnExit();
- log.log(Level.FINE, "Going to delete on exit: " + file.getAbsolutePath());
- }
-
}
Modified: declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java 2009-08-17 10:12:40 UTC (rev 3454)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java 2009-08-17 10:20:09 UTC (rev 3455)
@@ -35,167 +35,167 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class MemoryArchiveImpl extends VfsArchiveBase implements VfsArchive
+public class MemoryArchiveImpl
{
+//
+// //-------------------------------------------------------------------------------------||
+// // Class Members ----------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Logger
+// */
+// private static final Logger log = Logger.getLogger(MemoryArchiveImpl.class);
+//
+// /**
+// * Protocol of VFS in-memory
+// */
+// private static final String PROTOCOL_VFS_MEMORY = "vfsmemory";
+//
+// /**
+// * Empty String
+// */
+// private static final String EMPTY_STRING = "";
+//
+// /**
+// * Separator
+// */
+// private static final char SEPARATOR = '/';
+//
+// //-------------------------------------------------------------------------------------||
+// // Constructors -----------------------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Constructor
+// *
+// * Creates a new instance using the Thread Context
+// * ClassLoader.
+// *
+// * @param name Unique name for the deployment
+// * @throws IllegalArgumentException If the name was not specified
+// */
+// public MemoryArchiveImpl(final String name) throws IllegalArgumentException
+// {
+// this(name, SecurityActions.getThreadContextClassLoader());
+// }
+//
+// /**
+// * Constructor
+// *
+// * @param name Unique name for the deployment
+// * @param cl ClassLoader to be used in loading resources and classes
+// * @throws IllegalArgumentException If the name or ClassLoader was not specified
+// */
+// public MemoryArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
+// {
+// // Invoke super
+// super(cl);
+//
+// // Precondition Check
+// if (name == null || name.length() == 0)
+// {
+// throw new IllegalArgumentException("name must be specified");
+// }
+// if (cl == null)
+// {
+// throw new IllegalArgumentException("ClassLoader must be specified");
+// }
+//
+// // Create the root for the archive
+// VirtualFile file = null;
+// URL url = null;
+// try
+// {
+// final URL memoryRootUrl = new URL(PROTOCOL_VFS_MEMORY, name, EMPTY_STRING);
+// MemoryFileFactory.createRoot(memoryRootUrl);
+// final URL stubUrl = new URL(memoryRootUrl, name);
+// MemoryFileFactory.createDirectory(stubUrl);
+// url = stubUrl;
+// file = VFS.getRoot(memoryRootUrl);
+// }
+// catch (final IOException ioe)
+// {
+// throw new RuntimeException("Error in creating the root for virtual deployment \"" + name + "\"", ioe);
+// }
+//
+// // Set properties for the root
+// this.initialize(file, url);
+// }
+//
+// //-------------------------------------------------------------------------------------||
+// // Required Implementations -----------------------------------------------------------||
+// //-------------------------------------------------------------------------------------||
+//
+// /**
+// * Puts the specified content at the specified location as a memory file
+// * @param content
+// * @param location
+// * @throws IllegalArgumentException
+// */
+// void addContent(final byte[] content, final URL location) throws IllegalArgumentException
+// {
+// // Precondition check
+// if (content == null)
+// {
+// throw new IllegalArgumentException("content must be specified");
+// }
+// if (location == null)
+// {
+// throw new IllegalArgumentException("location must be specified");
+// }
+//
+// // Put the new memory file in place
+// MemoryFileFactory.putFile(location, content);
+// log.debug("Added: " + location);
+//
+// }
+//
+// /**
+// * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
+// */
+// @Override
+// protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
+// {
+// // Precondition check
+// if (content == null)
+// {
+// throw new IllegalArgumentException("content must be specified");
+// }
+// if (location == null || location.length() == 0)
+// {
+// throw new IllegalArgumentException("location must be specified");
+// }
+//
+// // Get the root URL of the memory file
+// final URL rootUrl = this.getRootUrl();
+//
+// // Construct a new URL for this new memoryfile
+// URL url = null;
+// try
+// {
+// final StringBuilder sb = new StringBuilder();
+// sb.append(rootUrl.toExternalForm());
+// sb.append(SEPARATOR);
+// sb.append(location);
+// url = new URL(sb.toString());
+// }
+// catch (final MalformedURLException murle)
+// {
+// throw new RuntimeException("Could not form URL for new resource \"" + location + "\" in " + this, murle);
+// }
+//
+// // Add the content
+// this.addContent(content, url);
+// }
+//
+// /**
+// * @see org.jboss.declarchive.impl.base.ArchiveBase#getActualClass()
+// */
+// @Override
+// protected Class<VfsArchive> getActualClass()
+// {
+// return VfsArchive.class;
+// }
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(MemoryArchiveImpl.class);
-
- /**
- * Protocol of VFS in-memory
- */
- private static final String PROTOCOL_VFS_MEMORY = "vfsmemory";
-
- /**
- * Empty String
- */
- private static final String EMPTY_STRING = "";
-
- /**
- * Separator
- */
- private static final char SEPARATOR = '/';
-
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Constructor
- *
- * Creates a new instance using the Thread Context
- * ClassLoader.
- *
- * @param name Unique name for the deployment
- * @throws IllegalArgumentException If the name was not specified
- */
- public MemoryArchiveImpl(final String name) throws IllegalArgumentException
- {
- this(name, SecurityActions.getThreadContextClassLoader());
- }
-
- /**
- * Constructor
- *
- * @param name Unique name for the deployment
- * @param cl ClassLoader to be used in loading resources and classes
- * @throws IllegalArgumentException If the name or ClassLoader was not specified
- */
- public MemoryArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
- {
- // Invoke super
- super(cl);
-
- // Precondition Check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
- if (cl == null)
- {
- throw new IllegalArgumentException("ClassLoader must be specified");
- }
-
- // Create the root for the archive
- VirtualFile file = null;
- URL url = null;
- try
- {
- final URL memoryRootUrl = new URL(PROTOCOL_VFS_MEMORY, name, EMPTY_STRING);
- MemoryFileFactory.createRoot(memoryRootUrl);
- final URL stubUrl = new URL(memoryRootUrl, name);
- MemoryFileFactory.createDirectory(stubUrl);
- url = stubUrl;
- file = VFS.getRoot(memoryRootUrl);
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Error in creating the root for virtual deployment \"" + name + "\"", ioe);
- }
-
- // Set properties for the root
- this.initialize(file, url);
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Puts the specified content at the specified location as a memory file
- * @param content
- * @param location
- * @throws IllegalArgumentException
- */
- void addContent(final byte[] content, final URL location) throws IllegalArgumentException
- {
- // Precondition check
- if (content == null)
- {
- throw new IllegalArgumentException("content must be specified");
- }
- if (location == null)
- {
- throw new IllegalArgumentException("location must be specified");
- }
-
- // Put the new memory file in place
- MemoryFileFactory.putFile(location, content);
- log.debug("Added: " + location);
-
- }
-
- /**
- * @see org.jboss.declarchive.impl.base.ArchiveBase#addContent(byte[], java.lang.String)
- */
- @Override
- protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
- {
- // Precondition check
- if (content == null)
- {
- throw new IllegalArgumentException("content must be specified");
- }
- if (location == null || location.length() == 0)
- {
- throw new IllegalArgumentException("location must be specified");
- }
-
- // Get the root URL of the memory file
- final URL rootUrl = this.getRootUrl();
-
- // Construct a new URL for this new memoryfile
- URL url = null;
- try
- {
- final StringBuilder sb = new StringBuilder();
- sb.append(rootUrl.toExternalForm());
- sb.append(SEPARATOR);
- sb.append(location);
- url = new URL(sb.toString());
- }
- catch (final MalformedURLException murle)
- {
- throw new RuntimeException("Could not form URL for new resource \"" + location + "\" in " + this, murle);
- }
-
- // Add the content
- this.addContent(content, url);
- }
-
- /**
- * @see org.jboss.declarchive.impl.base.ArchiveBase#getActualClass()
- */
- @Override
- protected Class<VfsArchive> getActualClass()
- {
- return VfsArchive.class;
- }
-
}
Modified: declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java 2009-08-17 10:12:40 UTC (rev 3454)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java 2009-08-17 10:20:09 UTC (rev 3455)
@@ -87,24 +87,24 @@
//-------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
+//
+// /* (non-Javadoc)
+// * @see org.jboss.embedded.core.deployment.ExtensibleVirtualDeployment#toString(boolean)
+// */
+// @Override
+// public String toString(final boolean verbose)
+// {
+// // If we want verbose output
+// if (verbose)
+// {
+// // Describe the root
+// return this.describe(this.getRoot());
+// }
+//
+// // Fall back on toString
+// return this.toString();
+// }
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.ExtensibleVirtualDeployment#toString(boolean)
- */
- @Override
- public String toString(final boolean verbose)
- {
- // If we want verbose output
- if (verbose)
- {
- // Describe the root
- return this.describe(this.getRoot());
- }
-
- // Fall back on toString
- return this.toString();
- }
-
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java 2009-08-17 10:12:40 UTC (rev 3454)
+++ declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java 2009-08-17 10:20:09 UTC (rev 3455)
@@ -74,15 +74,15 @@
{
// Log
log.info("testVirtualArchiveFactory");
-
- // Make an archive
- final VfsArchive archive = VfsMemoryArchiveFactory.createArchive("testArchive.jar", VfsArchive.class);
- archive.addClass(VfsMemoryArchiveFactory.class);
- log.info("Archive: " + archive.toString(true));
-
- // Ensure exists
- Assert.assertNotNull("Archive was not created/null", archive);
- // Ensure of expected type
- Assert.assertTrue("Created archive was not of expected type", archive instanceof VfsArchive);
+//
+// // Make an archive
+// final VfsArchive archive = VfsMemoryArchiveFactory.createArchive("testArchive.jar", VfsArchive.class);
+// archive.addClass(VfsMemoryArchiveFactory.class);
+// log.info("Archive: " + archive.toString(true));
+//
+// // Ensure exists
+// Assert.assertNotNull("Archive was not created/null", archive);
+// // Ensure of expected type
+// Assert.assertTrue("Created archive was not of expected type", archive instanceof VfsArchive);
}
}
Modified: declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java
===================================================================
--- declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java 2009-08-17 10:12:40 UTC (rev 3454)
+++ declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveTestCase.java 2009-08-17 10:20:09 UTC (rev 3455)
@@ -98,22 +98,22 @@
@Test
public void testAddResourceExplicitPathNameMemory() throws Exception
{
- // Log
- log.info("testAddResourceExplicitPathNameMemory");
+// // Log
+// log.info("testAddResourceExplicitPathNameMemory");
+//
+// // Get the base
+// final URL base = this.getBase();
+//
+// // Get the path to the test XML file
+// final URL location = new URL(base, PATH_SOMETHING_XML);
+//
+// // Define the new path
+// final String newPath = PATH_WEB_INF + SEPARATOR + FILENAME_WEB_XML;
+//
+// // Make a virtual archive
+// final Archive archive = new MemoryArchiveImpl("something.war").addResource(location, newPath);
+// log.info(archive.toString(true));
- // Get the base
- final URL base = this.getBase();
-
- // Get the path to the test XML file
- final URL location = new URL(base, PATH_SOMETHING_XML);
-
- // Define the new path
- final String newPath = PATH_WEB_INF + SEPARATOR + FILENAME_WEB_XML;
-
- // Make a virtual archive
- final Archive archive = new MemoryArchiveImpl("something.war").addResource(location, newPath);
- log.info(archive.toString(true));
-
//TODO Actually test something when we have better hooks to examine archive contents
}
More information about the jboss-svn-commits
mailing list