[jboss-svn-commits] JBoss Common SVN: r4379 - in shrinkwrap/trunk: api/src and 28 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue May 11 08:22:50 EDT 2010
Author: kenglxn
Date: 2010-05-11 08:22:44 -0400 (Tue, 11 May 2010)
New Revision: 4379
Added:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayAsset.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayIOUtil.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/EmptyAsset.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/FileAsset.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/SecurityActions.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/StringAsset.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/UrlAsset.java
shrinkwrap/trunk/api/src/test/
shrinkwrap/trunk/api/src/test/java/
shrinkwrap/trunk/api/src/test/java/org/
shrinkwrap/trunk/api/src/test/java/org/jboss/
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtils.java
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ByteArrayAssetTestCase.java
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/EmptyAssetTestCase.java
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/FileAssetTestCase.java
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/StringAssetTestCase.java
shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/UrlAssetTestCase.java
shrinkwrap/trunk/api/src/test/resources/
shrinkwrap/trunk/api/src/test/resources/org/
shrinkwrap/trunk/api/src/test/resources/org/jboss/
shrinkwrap/trunk/api/src/test/resources/org/jboss/shrinkwrap/
shrinkwrap/trunk/api/src/test/resources/org/jboss/shrinkwrap/api/
shrinkwrap/trunk/api/src/test/resources/org/jboss/shrinkwrap/api/asset/
shrinkwrap/trunk/api/src/test/resources/org/jboss/shrinkwrap/api/asset/Test.properties
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/api/
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/api/asset/
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/api/asset/IOUtilDelegator.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/api/
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/api/asset/
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtilsDelegator.java
Removed:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAsset.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAsset.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/FileAsset.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/StringAsset.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/UrlAsset.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAssetTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAssetTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/FileAssetTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/StringAssetTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/UrlAssetTestCase.java
Modified:
shrinkwrap/trunk/api/pom.xml
shrinkwrap/trunk/impl-base/pom.xml
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/EnterpriseContainerBase.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ResourceAdapterContainerBase.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/WebContainerBase.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterImpl.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImpl.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/TestUtils.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java
Log:
SHRINKWRAP-162:
Moved common assets to api module
Moved TestCases for common assets to api module
Extracted methods needed from impl-base to package private classes in api module to avoid cyclical dependencies.
Added delegator classes to make methods available from package private classes.
Updated api module pom and added generating test-jar for api module in build.
Updated impl-base pom and added dependency for api test-jar
Modified: shrinkwrap/trunk/api/pom.xml
===================================================================
--- shrinkwrap/trunk/api/pom.xml 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/api/pom.xml 2010-05-11 12:22:44 UTC (rev 4379)
@@ -37,6 +37,26 @@
</dependency>
</dependencies>
+
+ <!-- Build Configuration -->
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.2</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
<reporting>
<plugins>
Copied: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayAsset.java (from rev 4353, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAsset.java)
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayAsset.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.shrinkwrap.api.Asset;
+
+/**
+ * ByteArrayAsset
+ *
+ * Implementation of a {@link Asset} backed by a byte array
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ByteArrayAsset implements Asset
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ByteArrayAsset.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Underlying content
+ */
+ private final byte[] content;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new {@link Asset} instance backed by the specified
+ * byte array
+ *
+ * @param content
+ * @throws IllegalArgumentException If the contents were not specified
+ */
+ public ByteArrayAsset(final byte[] content) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (content == null)
+ {
+ throw new IllegalArgumentException("content must be specified");
+ }
+
+ // Defensive copy on set, SHRINKWRAP-38
+ final int length = content.length;
+ byte[] newArray = new byte[length];
+ System.arraycopy(content, 0, newArray, 0, length);
+
+ // Set
+ this.content = newArray;
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer("Created " + this + " with backing byte array of size " + length + "b");
+ }
+ }
+
+ /**
+ * Creates a new {@link Asset} instance backed by the bytes
+ * contained in the the specified {@link InputStream}
+ *
+ * @param stream
+ * @throws IllegalArgumentException If the stream is not specified
+ */
+ public ByteArrayAsset(final InputStream stream)
+ {
+ // Delegate
+ this(ByteArrayIOUtil.asByteArray(stream));
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.shrinkwrap.api.Asset#openStream()
+ */
+ @Override
+ public InputStream openStream()
+ {
+ return new ByteArrayInputStream(this.content);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return "ByteArrayAsset [content size=" + content.length + "bytes]";
+ }
+}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayIOUtil.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayIOUtil.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/ByteArrayIOUtil.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * ByteArrayIOUtil
+ *
+ * Package private class that helps get byte array from {@link InputStream}.
+ * Needed by the common assets in api.
+ *
+ * @author <a href="mailto:ken at glxn.net">Ken Gullaksen</a>
+ * @version $Revision: $
+ */
+class ByteArrayIOUtil
+{
+
+ private static final Logger log = Logger.getLogger(ByteArrayIOUtil.class.getName());
+
+ /**
+ * Obtains the contents of the specified stream
+ * as a byte array
+ *
+ * @param in InputStream
+ * @throws IllegalArgumentException If the stream was not specified
+ * @return the byte[] for the given InputStream
+ */
+ public static byte[] asByteArray(final InputStream in) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (in == null) {
+ throw new IllegalArgumentException("stream must be specified");
+ }
+
+ // Get content as an array of bytes
+ final ByteArrayOutputStream out = new ByteArrayOutputStream(8192);
+ final int len = 4096;
+ final byte[] buffer = new byte[len];
+ int read = 0;
+ try {
+ while (((read = in.read(buffer)) != -1)) {
+ out.write(buffer, 0, read);
+ }
+ }
+ catch (final IOException ioe) {
+ throw new RuntimeException("Error in obtainting bytes from " + in, ioe);
+ }
+ finally {
+ try {
+ in.close();
+ }
+ catch (final IOException ignore) {
+ if (log.isLoggable(Level.FINER)) {
+ log.finer("Could not close stream due to: " + ignore.getMessage() + "; ignoring");
+ }
+ }
+ // We don't need to close the outstream, it's a byte array out
+ }
+
+ // Represent as byte array
+ final byte[] content = out.toByteArray();
+
+ // Return
+ return content;
+ }
+}
Copied: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/EmptyAsset.java (from rev 4353, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAsset.java)
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/EmptyAsset.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/EmptyAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,40 @@
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.jboss.shrinkwrap.api.Asset;
+
+/**
+ * Implementation of a {@link Asset} having empty content.
+ *
+ * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
+ * @version $Revision: $
+ */
+public enum EmptyAsset implements Asset {
+ INSTANCE;
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.shrinkwrap.api.Asset#openStream()
+ */
+ @Override
+ public InputStream openStream()
+ {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return "EmptyAsset";
+ }
+
+}
\ No newline at end of file
Copied: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/FileAsset.java (from rev 4353, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/FileAsset.java)
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/FileAsset.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/FileAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.jboss.shrinkwrap.api.Asset;
+
+/**
+ * FileAsset
+ *
+ * Implementation of a {@link Asset} backed by a {@link File}
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ */
+public class FileAsset implements Asset
+{
+ private File file;
+
+ /**
+ * Load the specified File.
+ *
+ * @param file The file to load
+ * @throws IllegalArgumentException File can not be null
+ * @throws IllegalArgumentException File must exist
+ */
+ public FileAsset(File file)
+ {
+ // Precondition check
+ if (file == null)
+ {
+ throw new IllegalArgumentException("File must be specified");
+ }
+ if (!file.exists())
+ {
+ throw new IllegalArgumentException("File must exist: " + file.getAbsolutePath());
+ }
+ this.file = file;
+ }
+
+ /**
+ * Opens a new FileInputStream for the given File.
+ *
+ * Can throw a Runtime exception if the file has been deleted inbetween
+ * the FileResource was created and the stream is opened.
+ *
+ * @throws RuntimeException If the file is not found.
+ */
+ @Override
+ public InputStream openStream()
+ {
+ try
+ {
+ return new BufferedInputStream(new FileInputStream(file), 8192);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new RuntimeException("Could not open file " + file, e);
+ }
+ }
+}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/SecurityActions.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/SecurityActions.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/SecurityActions.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+
+package org.jboss.shrinkwrap.api.asset;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:ken at glxn.net">Ken Gullaksen</a>
+ * @version $Revision: $
+ */
+public class SecurityActions
+{
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(GetTcclAction.INSTANCE);
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Inner Classes ----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Single instance to get the TCCL
+ */
+ private enum GetTcclAction implements PrivilegedAction<ClassLoader>
+ {
+ INSTANCE;
+
+ @Override
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ }
+}
Copied: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/StringAsset.java (from rev 4353, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/StringAsset.java)
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/StringAsset.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/StringAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,85 @@
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.shrinkwrap.api.Asset;
+
+/**
+ * Implementation of a {@link Asset} backed by a String
+ *
+ * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
+ * @version $Revision: $
+ */
+public class StringAsset implements Asset
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(StringAsset.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Underlying content.
+ */
+ private final String content;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new {@link Asset} instance backed by the specified String
+ *
+ * @param content The content represented as a String
+ * @throws IllegalArgumentException If the contents were not specified
+ */
+ public StringAsset(final String content)
+ {
+ // Precondition check
+ if (content == null)
+ {
+ throw new IllegalArgumentException("content must be specified");
+ }
+ // don't need to copy since String is immutable
+ this.content = content;
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer("Created " + this + " with backing String of size " + content.length() + "b");
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.shrinkwrap.api.Asset#openStream()
+ */
+
+ @Override
+ public InputStream openStream()
+ {
+ return new ByteArrayInputStream(content.getBytes());
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return "StringAsset [content size=" + content.length() + " bytes]";
+ }
+
+}
Copied: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/UrlAsset.java (from rev 4353, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/UrlAsset.java)
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/UrlAsset.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/asset/UrlAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.shrinkwrap.api.Asset;
+
+/**
+ * UrlAsset
+ *
+ * Implementation of a {@link Asset} backed by a {@link URL}.
+ * The URL may be of any backing protocol supported by the runtime
+ * (ie. has a handler registered).
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public class UrlAsset implements Asset
+{
+ private URL url;
+
+ /**
+ * Create a new resource with a <code>URL</code> source.
+ *
+ * @param url A valid URL
+ * @throws IllegalArgumentException <Code>URL</code> can not be null
+ */
+ public UrlAsset(URL url)
+ {
+ // Precondition check
+ if (url == null)
+ {
+ throw new IllegalArgumentException("URL must be specified");
+ }
+ this.url = url;
+ }
+
+ /**
+ * Open the <code>URL</code> stream.
+ *
+ * @return A open stream with the content of the URL
+ */
+ @Override
+ public InputStream openStream()
+ {
+ try
+ {
+ return new BufferedInputStream(url.openStream(), 8192);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not open stream for url " + url.toExternalForm(), e);
+ }
+ }
+}
Added: shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtils.java
===================================================================
--- shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtils.java (rev 0)
+++ shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtils.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+/**
+ * ApiTestUtils
+ *
+ * Package private class that helps get byte array from {@link InputStream}.
+ * Needed by the TestCases for common assets in api.
+ *
+ * @author <a href="mailto:ken at glxn.net">Ken Gullaksen</a>
+ * @version $Revision: $
+ */
+class ApiTestUtils
+{
+ /**
+ * Convert a {@link InputStream} to a UTF-8 string.
+ * <br/>
+ * Helper for testing the content of loaded resources.
+ * <br/>
+ * This method will close the stream when done.
+ *
+ * @param in Open InputStream
+ * @return The InputStream as a String
+ * @throws Exception
+ */
+ static String convertToString(InputStream in) throws Exception
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ int b;
+ while ((b = in.read()) != -1)
+ {
+ out.write(b);
+ }
+ out.close();
+ in.close();
+ return new String(out.toByteArray(), "UTF-8");
+ }
+}
Copied: shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ByteArrayAssetTestCase.java (from rev 4353, shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAssetTestCase.java)
===================================================================
--- shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ByteArrayAssetTestCase.java (rev 0)
+++ shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/ByteArrayAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ * ByteArrayAssetTestCase
+ *
+ * Test Cases for the {@link ByteArrayAsset}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ByteArrayAssetTestCase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ByteArrayAssetTestCase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the contents of the asset match that which was passed in,
+ * and that the state of the asset can not be mutated from the outside
+ */
+ @Test
+ public void testRoundtripAndExternalMutationGuard() throws Exception
+ {
+ // Log
+ log.info("testRoundtrip");
+
+ // Make contents
+ final int length = 10;
+ final byte[] contents = new byte[length];
+ for (int i = 0; i < length; i++)
+ {
+ contents[i] = (byte) i;
+ }
+ log.info("Inbound contents: " + Arrays.toString(contents));
+
+ // Make Asset
+ final ByteArrayAsset asset = new ByteArrayAsset(contents);
+
+ // Change the contents passed in (so we ensure we protect against mutation, SHRINKWRAP-38)
+ contents[0] = 0x1;
+ log.info("Contents after change: " + Arrays.toString(contents));
+
+ // Get the contents back out of the asset
+ final InputStream stream = asset.openStream();
+ final ByteArrayOutputStream out = new ByteArrayOutputStream(length);
+ int read;
+ while ((read = stream.read()) != -1)
+ {
+ out.write(read);
+ }
+ byte[] roundtrip = out.toByteArray();
+ log.info("Roundtrip contents: " + Arrays.toString(roundtrip));
+
+ // Ensure the roundtrip matches the input (index number)
+ for (int i = 0; i < length; i++)
+ {
+ Assert.assertEquals("Roundtrip did not equal passed in contents", i, roundtrip[i]);
+ }
+
+ }
+}
Copied: shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/EmptyAssetTestCase.java (from rev 4353, shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAssetTestCase.java)
===================================================================
--- shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/EmptyAssetTestCase.java (rev 0)
+++ shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/EmptyAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.jboss.shrinkwrap.api.Asset;
+import org.junit.Test;
+
+/**
+ * Test Cases for the {@link EmptyAsset}
+ *
+ * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
+ * @version $Revision: $
+ */
+public class EmptyAssetTestCase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(EmptyAssetTestCase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the contents of the asset is empty.
+ */
+ @Test
+ public void testRoundtrip() throws Exception
+ {
+ // Log
+ log.info("testRoundtrip");
+
+ // Make Asset
+ final Asset asset = EmptyAsset.INSTANCE;
+
+ // Get the contents back out of the asset
+ final InputStream stream = asset.openStream();
+ final ByteArrayOutputStream out = new ByteArrayOutputStream(0);
+ int read;
+ while ((read = stream.read()) != -1)
+ {
+ out.write(read);
+ }
+
+ Assert.assertEquals("Roundtrip did not produce empty contents", 0, out.toByteArray().length);
+ }
+}
Copied: shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/FileAssetTestCase.java (from rev 4353, shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/FileAssetTestCase.java)
===================================================================
--- shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/FileAssetTestCase.java (rev 0)
+++ shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/FileAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.File;
+import java.io.InputStream;
+
+import junit.framework.Assert;
+
+import org.jboss.shrinkwrap.api.Asset;
+import org.junit.Test;
+
+/**
+ * Test to ensure that we can use a File as a resource.
+ *
+ * https://jira.jboss.org/jira/browse/TMPARCH-5
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public class FileAssetTestCase
+{
+ private static final String BASE_PATH = "src/test/resources/org/jboss/shrinkwrap/api/asset/";
+
+ private static final String EXISTING_FILE = BASE_PATH + "Test.properties";
+
+ private static final String NON_EXISTING_FILE = BASE_PATH + "NoFileShouldBePlacedHere.properties";
+
+ @Test
+ public void shouldBeAbleToReadFile() throws Exception
+ {
+ Asset asset = new FileAsset(new File(EXISTING_FILE));
+ InputStream io = asset.openStream();
+
+ Assert.assertNotNull(io);
+ Assert.assertEquals("Should be able to read the content of the resource", "shrinkwrap=true", ApiTestUtils
+ .convertToString(io));
+ }
+
+ @Test
+ public void shouldThrowExceptionOnNullFile() throws Exception
+ {
+ try
+ {
+ new FileAsset(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ }
+ catch (Exception e)
+ {
+ Assert.assertEquals("A null file argument should result in a IllegalArgumentException",
+ IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void shouldThrowExceptionOnMissingFile() throws Exception
+ {
+ try
+ {
+ new FileAsset(new File(NON_EXISTING_FILE));
+ Assert.fail("Should have thrown IllegalArgumentException");
+ }
+ catch (Exception e)
+ {
+ Assert.assertEquals("A non existing file should result in a IllegalArgumentException",
+ IllegalArgumentException.class, e.getClass());
+ }
+ }
+}
Copied: shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/StringAssetTestCase.java (from rev 4353, shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/StringAssetTestCase.java)
===================================================================
--- shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/StringAssetTestCase.java (rev 0)
+++ shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/StringAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ * Test Cases for the {@link StringAsset}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
+ * @version $Revision: $
+ */
+public class StringAssetTestCase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(StringAssetTestCase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the contents of the asset match that which was passed in.
+ */
+ @Test
+ public void testRoundtrip() throws Exception
+ {
+ // Log
+ log.info("testRoundtrip");
+
+ // Make contents
+ String contents = StringAsset.class.getSimpleName();
+
+ // Make Asset
+ final StringAsset asset = new StringAsset(contents);
+
+ // Get the contents back out of the asset
+ final InputStream stream = asset.openStream();
+ final ByteArrayOutputStream out = new ByteArrayOutputStream(contents.length());
+ int read;
+ while ((read = stream.read()) != -1)
+ {
+ out.write(read);
+ }
+ String roundtrip = new String(out.toByteArray());
+ log.info("Roundtrip contents: " + roundtrip);
+
+ Assert.assertEquals("Roundtrip did not equal passed in contents", contents, roundtrip);
+ }
+}
Copied: shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/UrlAssetTestCase.java (from rev 4353, shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/UrlAssetTestCase.java)
===================================================================
--- shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/UrlAssetTestCase.java (rev 0)
+++ shrinkwrap/trunk/api/src/test/java/org/jboss/shrinkwrap/api/asset/UrlAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.InputStream;
+
+import junit.framework.Assert;
+
+import org.jboss.shrinkwrap.api.Asset;
+import org.junit.Test;
+
+/**
+ * Test to ensure that we can use a URL as a resource.
+ *
+ * https://jira.jboss.org/jira/browse/TMPARCH-5
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ *
+ */
+public class UrlAssetTestCase
+{
+ private static final String EXISTING_RESOURCE = "org/jboss/shrinkwrap/api/asset/Test.properties";
+
+ @Test
+ public void shouldBeAbleToReadURL() throws Exception
+ {
+ Asset asset = new UrlAsset(SecurityActions.getThreadContextClassLoader().getResource(EXISTING_RESOURCE));
+
+ InputStream io = asset.openStream();
+
+ Assert.assertNotNull(io);
+ Assert.assertEquals("Should be able to read the content of the resource", "shrinkwrap=true", ApiTestUtils
+ .convertToString(io));
+ }
+
+ @Test
+ public void shouldThrowExceptionOnNullURL() throws Exception
+ {
+ try
+ {
+ new UrlAsset(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ }
+ catch (Exception e)
+ {
+ Assert.assertEquals("A null url argument should result in a IllegalArgumentException",
+ IllegalArgumentException.class, e.getClass());
+ }
+ }
+}
Copied: shrinkwrap/trunk/api/src/test/resources/org/jboss/shrinkwrap/api/asset/Test.properties (from rev 4353, shrinkwrap/trunk/impl-base/src/test/resources/org/jboss/shrinkwrap/impl/base/asset/Test.properties)
===================================================================
--- shrinkwrap/trunk/api/src/test/resources/org/jboss/shrinkwrap/api/asset/Test.properties (rev 0)
+++ shrinkwrap/trunk/api/src/test/resources/org/jboss/shrinkwrap/api/asset/Test.properties 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1 @@
+shrinkwrap=true
\ No newline at end of file
Modified: shrinkwrap/trunk/impl-base/pom.xml
===================================================================
--- shrinkwrap/trunk/impl-base/pom.xml 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/pom.xml 2010-05-11 12:22:44 UTC (rev 4379)
@@ -44,6 +44,17 @@
<version>${project.version}</version>
</dependency>
+ <!--
+ shrinkwrap-api test jar
+ -->
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-api</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
<!--
External Projects
-->
Added: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/api/asset/IOUtilDelegator.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/api/asset/IOUtilDelegator.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/api/asset/IOUtilDelegator.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.InputStream;
+
+/**
+ * IOUtilDelegator
+ *
+ * Class that helps expose package private {@link ByteArrayIOUtil}
+ *
+ * @author <a href="mailto:ken at glxn.net">Ken Gullaksen</a>
+ * @version $Revision: $
+ */
+public class IOUtilDelegator
+{
+ /**
+ * Delegates to {@link ByteArrayIOUtil#asByteArray(java.io.InputStream)}
+ * @param in
+ * @throws IllegalArgumentException If the stream was not specified
+ * @return the byte[] for the given InputStream
+ */
+ public static byte[] asByteArray(final InputStream in) throws IllegalArgumentException
+ {
+ return ByteArrayIOUtil.asByteArray(in);
+ }
+
+}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAsset.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,121 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.jboss.shrinkwrap.api.Asset;
-import org.jboss.shrinkwrap.impl.base.Validate;
-import org.jboss.shrinkwrap.impl.base.io.IOUtil;
-
-/**
- * ByteArrayAsset
- *
- * Implementation of a {@link Asset} backed by a byte array
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ByteArrayAsset implements Asset
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(ByteArrayAsset.class.getName());
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Underlying content
- */
- private final byte[] content;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a new {@link Asset} instance backed by the specified
- * byte array
- *
- * @param content
- * @throws IllegalArgumentException If the contents were not specified
- */
- public ByteArrayAsset(final byte[] content) throws IllegalArgumentException
- {
- // Precondition check
- Validate.notNull(content, "content must be specified");
-
- // Defensive copy on set, SHRINKWRAP-38
- final int length = content.length;
- byte[] newArray = new byte[length];
- System.arraycopy(content, 0, newArray, 0, length);
-
- // Set
- this.content = newArray;
- if (log.isLoggable(Level.FINER))
- {
- log.finer("Created " + this + " with backing byte array of size " + length + "b");
- }
- }
-
- /**
- * Creates a new {@link Asset} instance backed by the bytes
- * contained in the the specified {@link InputStream}
- *
- * @param stream
- * @throws IllegalArgumentException If the stream is not specified
- */
- public ByteArrayAsset(final InputStream stream)
- {
- // Delegate
- this(IOUtil.asByteArray(stream));
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @see org.jboss.shrinkwrap.api.Asset#openStream()
- */
- @Override
- public InputStream openStream()
- {
- return new ByteArrayInputStream(this.content);
- }
-
- /**
- * {@inheritDoc}
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return "ByteArrayAsset [content size=" + content.length + "bytes]";
- }
-}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAsset.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,40 +0,0 @@
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-import org.jboss.shrinkwrap.api.Asset;
-
-/**
- * Implementation of a {@link Asset} having empty content.
- *
- * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
- * @version $Revision: $
- */
-public enum EmptyAsset implements Asset {
- INSTANCE;
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @see org.jboss.shrinkwrap.api.Asset#openStream()
- */
- @Override
- public InputStream openStream()
- {
- return new ByteArrayInputStream(new byte[0]);
- }
-
- /**
- * {@inheritDoc}
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return "EmptyAsset";
- }
-
-}
\ No newline at end of file
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/FileAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/FileAsset.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/FileAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,77 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import org.jboss.shrinkwrap.api.Asset;
-import org.jboss.shrinkwrap.impl.base.Validate;
-
-/**
- * FileAsset
- *
- * Implementation of a {@link Asset} backed by a {@link File}
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- */
-public class FileAsset implements Asset
-{
- private File file;
-
- /**
- * Load the specified File.
- *
- * @param file The file to load
- * @throws IllegalArgumentException File can not be null
- * @throws IllegalArgumentException File must exist
- */
- public FileAsset(File file)
- {
- // Precondition check
- Validate.notNull(file, "File must be specified");
- if (!file.exists())
- {
- throw new IllegalArgumentException("File must exist: " + file.getAbsolutePath());
- }
- this.file = file;
- }
-
- /**
- * Opens a new FileInputStream for the given File.
- *
- * Can throw a Runtime exception if the file has been deleted inbetween
- * the FileResource was created and the stream is opened.
- *
- * @throws RuntimeException If the file is not found.
- */
- @Override
- public InputStream openStream()
- {
- try
- {
- return new BufferedInputStream(new FileInputStream(file), 8192);
- }
- catch (FileNotFoundException e)
- {
- throw new RuntimeException("Could not open file " + file, e);
- }
- }
-}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/StringAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/StringAsset.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/StringAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,83 +0,0 @@
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.jboss.shrinkwrap.api.Asset;
-import org.jboss.shrinkwrap.impl.base.Validate;
-
-/**
- * Implementation of a {@link Asset} backed by a String
- *
- * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
- * @version $Revision: $
- */
-public class StringAsset implements Asset
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(StringAsset.class.getName());
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Underlying content.
- */
- private final String content;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a new {@link Asset} instance backed by the specified String
- *
- * @param content The content represented as a String
- * @throws IllegalArgumentException If the contents were not specified
- */
- public StringAsset(final String content)
- {
- // Precondition check
- Validate.notNull(content, "content must be specified");
- // don't need to copy since String is immutable
- this.content = content;
- if (log.isLoggable(Level.FINER))
- {
- log.finer("Created " + this + " with backing String of size " + content.length() + "b");
- }
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * @see org.jboss.shrinkwrap.api.Asset#openStream()
- */
-
- @Override
- public InputStream openStream()
- {
- return new ByteArrayInputStream(content.getBytes());
- }
-
- /**
- * {@inheritDoc}
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return "StringAsset [content size=" + content.length() + " bytes]";
- }
-
-}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/UrlAsset.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/UrlAsset.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/asset/UrlAsset.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.BufferedInputStream;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.jboss.shrinkwrap.api.Asset;
-import org.jboss.shrinkwrap.impl.base.Validate;
-
-/**
- * UrlAsset
- *
- * Implementation of a {@link Asset} backed by a {@link URL}.
- * The URL may be of any backing protocol supported by the runtime
- * (ie. has a handler registered).
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- *
- */
-public class UrlAsset implements Asset
-{
- private URL url;
-
- /**
- * Create a new resource with a <code>URL</code> source.
- *
- * @param url A valid URL
- * @throws IllegalArgumentException <Code>URL</code> can not be null
- */
- public UrlAsset(URL url)
- {
- // Precondition check
- Validate.notNull(url, "URL must be specified");
- this.url = url;
- }
-
- /**
- * Open the <code>URL</code> stream.
- *
- * @return A open stream with the content of the URL
- */
- @Override
- public InputStream openStream()
- {
- try
- {
- return new BufferedInputStream(url.openStream(), 8192);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Could not open stream for url " + url.toExternalForm(), e);
- }
- }
-}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -29,6 +29,8 @@
import org.jboss.shrinkwrap.api.Filter;
import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.Node;
+import org.jboss.shrinkwrap.api.asset.FileAsset;
+import org.jboss.shrinkwrap.api.asset.UrlAsset;
import org.jboss.shrinkwrap.api.container.ClassContainer;
import org.jboss.shrinkwrap.api.container.LibraryContainer;
import org.jboss.shrinkwrap.api.container.ManifestContainer;
@@ -40,9 +42,7 @@
import org.jboss.shrinkwrap.impl.base.asset.AssetUtil;
import org.jboss.shrinkwrap.impl.base.asset.ClassAsset;
import org.jboss.shrinkwrap.impl.base.asset.ClassLoaderAsset;
-import org.jboss.shrinkwrap.impl.base.asset.FileAsset;
import org.jboss.shrinkwrap.impl.base.asset.ServiceProviderAsset;
-import org.jboss.shrinkwrap.impl.base.asset.UrlAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
/**
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/EnterpriseContainerBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/EnterpriseContainerBase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/EnterpriseContainerBase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -23,12 +23,12 @@
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.asset.FileAsset;
+import org.jboss.shrinkwrap.api.asset.UrlAsset;
import org.jboss.shrinkwrap.api.container.EnterpriseContainer;
import org.jboss.shrinkwrap.impl.base.Validate;
import org.jboss.shrinkwrap.impl.base.asset.AssetUtil;
import org.jboss.shrinkwrap.impl.base.asset.ClassLoaderAsset;
-import org.jboss.shrinkwrap.impl.base.asset.FileAsset;
-import org.jboss.shrinkwrap.impl.base.asset.UrlAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
/**
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ResourceAdapterContainerBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ResourceAdapterContainerBase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ResourceAdapterContainerBase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -21,11 +21,11 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.asset.FileAsset;
+import org.jboss.shrinkwrap.api.asset.UrlAsset;
import org.jboss.shrinkwrap.api.container.ResourceAdapterContainer;
import org.jboss.shrinkwrap.impl.base.Validate;
import org.jboss.shrinkwrap.impl.base.asset.ClassLoaderAsset;
-import org.jboss.shrinkwrap.impl.base.asset.FileAsset;
-import org.jboss.shrinkwrap.impl.base.asset.UrlAsset;
/**
* ResourceAdapterContainerBase
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/WebContainerBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/WebContainerBase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/WebContainerBase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -23,12 +23,12 @@
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.asset.FileAsset;
+import org.jboss.shrinkwrap.api.asset.UrlAsset;
import org.jboss.shrinkwrap.api.container.WebContainer;
import org.jboss.shrinkwrap.impl.base.Validate;
import org.jboss.shrinkwrap.impl.base.asset.AssetUtil;
import org.jboss.shrinkwrap.impl.base.asset.ClassLoaderAsset;
-import org.jboss.shrinkwrap.impl.base.asset.FileAsset;
-import org.jboss.shrinkwrap.impl.base.asset.UrlAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
/**
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterImpl.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterImpl.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -22,10 +22,10 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.asset.FileAsset;
import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
import org.jboss.shrinkwrap.impl.base.AssignableBase;
import org.jboss.shrinkwrap.impl.base.Validate;
-import org.jboss.shrinkwrap.impl.base.asset.FileAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
/**
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImpl.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImpl.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImpl.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -26,11 +26,11 @@
import java.util.zip.ZipInputStream;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
import org.jboss.shrinkwrap.api.importer.ArchiveImportException;
import org.jboss.shrinkwrap.api.importer.ZipImporter;
import org.jboss.shrinkwrap.impl.base.AssignableBase;
import org.jboss.shrinkwrap.impl.base.Validate;
-import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
import org.jboss.shrinkwrap.impl.base.asset.ZipFileEntryAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -17,7 +17,6 @@
package org.jboss.shrinkwrap.impl.base.io;
import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@@ -26,6 +25,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.jboss.shrinkwrap.api.asset.IOUtilDelegator;
import org.jboss.shrinkwrap.impl.base.Validate;
/**
@@ -87,49 +87,11 @@
*
* @param in
* @throws IllegalArgumentException If the stream was not specified
+ * @return the byte[] for the given InputStream
*/
public static byte[] asByteArray(final InputStream in) throws IllegalArgumentException
{
- // Precondition check
- Validate.notNull(in, "stream must be specified");
-
- // Get content as an array of bytes
- final ByteArrayOutputStream out = new ByteArrayOutputStream(8192);
- final int len = 4096;
- final byte[] buffer = new byte[len];
- int read = 0;
- try
- {
- while (((read = in.read(buffer)) != -1))
- {
- out.write(buffer, 0, read);
- }
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Error in obtainting bytes from " + in, ioe);
- }
- finally
- {
- try
- {
- in.close();
- }
- catch (final IOException ignore)
- {
- if (log.isLoggable(Level.FINER))
- {
- log.finer("Could not close stream due to: " + ignore.getMessage() + "; ignoring");
- }
- }
- // We don't need to close the outstream, it's a byte array out
- }
-
- // Represent as byte array
- final byte[] content = out.toByteArray();
-
- // Return
- return content;
+ return IOUtilDelegator.asByteArray(in);
}
/**
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtilsDelegator.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtilsDelegator.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/api/asset/ApiTestUtilsDelegator.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+
+package org.jboss.shrinkwrap.api.asset;
+
+import java.io.InputStream;
+
+/**
+ * ApiTestUtilsDelegator
+ *
+ * @author <a href="mailto:ken at glxn.net">Ken Gullaksen</a>
+ * @version $Revision: $
+ */
+public class ApiTestUtilsDelegator
+{
+ /**
+ * Delegates to {@link org.jboss.shrinkwrap.api.asset.ApiTestUtils}
+ *
+ * @param in Open InputStream
+ * @return The InputStream as a String
+ * @throws Exception
+ */
+ public static String convertToString(InputStream in) throws Exception
+ {
+ return ApiTestUtils.convertToString(in);
+ }
+}
Deleted: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAssetTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAssetTestCase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/ByteArrayAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,100 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.logging.Logger;
-
-import junit.framework.Assert;
-
-import org.junit.Test;
-
-/**
- * ByteArrayAssetTestCase
- *
- * Test Cases for the {@link ByteArrayAsset}
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ByteArrayAssetTestCase
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(ByteArrayAssetTestCase.class.getName());
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- //-------------------------------------------------------------------------------------||
- // Tests ------------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Ensures that the contents of the asset match that which was passed in,
- * and that the state of the asset can not be mutated from the outside
- */
- @Test
- public void testRoundtripAndExternalMutationGuard() throws Exception
- {
- // Log
- log.info("testRoundtrip");
-
- // Make contents
- final int length = 10;
- final byte[] contents = new byte[length];
- for (int i = 0; i < length; i++)
- {
- contents[i] = (byte) i;
- }
- log.info("Inbound contents: " + Arrays.toString(contents));
-
- // Make Asset
- final ByteArrayAsset asset = new ByteArrayAsset(contents);
-
- // Change the contents passed in (so we ensure we protect against mutation, SHRINKWRAP-38)
- contents[0] = 0x1;
- log.info("Contents after change: " + Arrays.toString(contents));
-
- // Get the contents back out of the asset
- final InputStream stream = asset.openStream();
- final ByteArrayOutputStream out = new ByteArrayOutputStream(length);
- int read;
- while ((read = stream.read()) != -1)
- {
- out.write(read);
- }
- byte[] roundtrip = out.toByteArray();
- log.info("Roundtrip contents: " + Arrays.toString(roundtrip));
-
- // Ensure the roundtrip matches the input (index number)
- for (int i = 0; i < length; i++)
- {
- Assert.assertEquals("Roundtrip did not equal passed in contents", i, roundtrip[i]);
- }
-
- }
-}
Deleted: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAssetTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAssetTestCase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/EmptyAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,77 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.util.logging.Logger;
-
-import junit.framework.Assert;
-
-import org.jboss.shrinkwrap.api.Asset;
-import org.junit.Test;
-
-/**
- * Test Cases for the {@link EmptyAsset}
- *
- * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
- * @version $Revision: $
- */
-public class EmptyAssetTestCase
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(EmptyAssetTestCase.class.getName());
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- //-------------------------------------------------------------------------------------||
- // Tests ------------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Ensures that the contents of the asset is empty.
- */
- @Test
- public void testRoundtrip() throws Exception
- {
- // Log
- log.info("testRoundtrip");
-
- // Make Asset
- final Asset asset = EmptyAsset.INSTANCE;
-
- // Get the contents back out of the asset
- final InputStream stream = asset.openStream();
- final ByteArrayOutputStream out = new ByteArrayOutputStream(0);
- int read;
- while ((read = stream.read()) != -1)
- {
- out.write(read);
- }
-
- Assert.assertEquals("Roundtrip did not produce empty contents", 0, out.toByteArray().length);
- }
-}
Deleted: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/FileAssetTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/FileAssetTestCase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/FileAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.File;
-import java.io.InputStream;
-
-import junit.framework.Assert;
-
-import org.jboss.shrinkwrap.api.Asset;
-import org.junit.Test;
-
-/**
- * Test to ensure that we can use a File as a resource.
- *
- * https://jira.jboss.org/jira/browse/TMPARCH-5
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- *
- */
-public class FileAssetTestCase
-{
- private static final String BASE_PATH = "src/test/resources/org/jboss/shrinkwrap/impl/base/asset/";
-
- private static final String EXISTING_FILE = BASE_PATH + "Test.properties";
-
- private static final String NON_EXISTING_FILE = BASE_PATH + "NoFileShouldBePlacedHere.properties";
-
- @Test
- public void shouldBeAbleToReadFile() throws Exception
- {
- Asset asset = new FileAsset(new File(EXISTING_FILE));
- InputStream io = asset.openStream();
-
- Assert.assertNotNull(io);
- Assert.assertEquals("Should be able to read the content of the resource", "shrinkwrap=true", TestUtils
- .convertToString(io));
- }
-
- @Test
- public void shouldThrowExceptionOnNullFile() throws Exception
- {
- try
- {
- new FileAsset(null);
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (Exception e)
- {
- Assert.assertEquals("A null file argument should result in a IllegalArgumentException",
- IllegalArgumentException.class, e.getClass());
- }
- }
-
- @Test
- public void shouldThrowExceptionOnMissingFile() throws Exception
- {
- try
- {
- new FileAsset(new File(NON_EXISTING_FILE));
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (Exception e)
- {
- Assert.assertEquals("A non existing file should result in a IllegalArgumentException",
- IllegalArgumentException.class, e.getClass());
- }
- }
-}
Deleted: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/StringAssetTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/StringAssetTestCase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/StringAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,78 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.util.logging.Logger;
-
-import junit.framework.Assert;
-
-import org.junit.Test;
-
-/**
- * Test Cases for the {@link StringAsset}
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @author <a href="mailto:dan.j.allen at gmail.com">Dan Allen</a>
- * @version $Revision: $
- */
-public class StringAssetTestCase
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(StringAssetTestCase.class.getName());
-
- //-------------------------------------------------------------------------------------||
- // Tests ------------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Ensures that the contents of the asset match that which was passed in.
- */
- @Test
- public void testRoundtrip() throws Exception
- {
- // Log
- log.info("testRoundtrip");
-
- // Make contents
- String contents = StringAsset.class.getSimpleName();
-
- // Make Asset
- final StringAsset asset = new StringAsset(contents);
-
- // Get the contents back out of the asset
- final InputStream stream = asset.openStream();
- final ByteArrayOutputStream out = new ByteArrayOutputStream(contents.length());
- int read;
- while ((read = stream.read()) != -1)
- {
- out.write(read);
- }
- String roundtrip = new String(out.toByteArray());
- log.info("Roundtrip contents: " + roundtrip);
-
- Assert.assertEquals("Roundtrip did not equal passed in contents", contents, roundtrip);
- }
-}
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/TestUtils.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/TestUtils.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/TestUtils.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -16,7 +16,7 @@
*/
package org.jboss.shrinkwrap.impl.base.asset;
-import java.io.ByteArrayOutputStream;
+import org.jboss.shrinkwrap.api.asset.ApiTestUtilsDelegator;
import java.io.InputStream;
/**
@@ -44,15 +44,7 @@
*/
static String convertToString(InputStream in) throws Exception
{
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- int b;
- while ((b = in.read()) != -1)
- {
- out.write(b);
- }
- out.close();
- in.close();
- return new String(out.toByteArray(), "UTF-8");
+ return ApiTestUtilsDelegator.convertToString(in);
}
/**
Deleted: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/UrlAssetTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/UrlAssetTestCase.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/asset/UrlAssetTestCase.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.impl.base.asset;
-
-import java.io.InputStream;
-
-import junit.framework.Assert;
-
-import org.jboss.shrinkwrap.api.Asset;
-import org.junit.Test;
-
-/**
- * Test to ensure that we can use a URL as a resource.
- *
- * https://jira.jboss.org/jira/browse/TMPARCH-5
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- *
- */
-public class UrlAssetTestCase
-{
- private static final String EXISTING_RESOURCE = "org/jboss/shrinkwrap/impl/base/asset/Test.properties";
-
- @Test
- public void shouldBeAbleToReadURL() throws Exception
- {
- Asset asset = new UrlAsset(SecurityActions.getThreadContextClassLoader().getResource(EXISTING_RESOURCE));
-
- InputStream io = asset.openStream();
-
- Assert.assertNotNull(io);
- Assert.assertEquals("Should be able to read the content of the resource", "shrinkwrap=true", TestUtils
- .convertToString(io));
- }
-
- @Test
- public void shouldThrowExceptionOnNullURL() throws Exception
- {
- try
- {
- new UrlAsset(null);
- Assert.fail("Should have thrown IllegalArgumentException");
- }
- catch (Exception e)
- {
- Assert.assertEquals("A null url argument should result in a IllegalArgumentException",
- IllegalArgumentException.class, e.getClass());
- }
- }
-}
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java 2010-05-10 18:50:55 UTC (rev 4378)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterStressTest.java 2010-05-11 12:22:44 UTC (rev 4379)
@@ -28,9 +28,9 @@
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
import org.jboss.shrinkwrap.impl.base.io.IOUtil;
import org.junit.Test;
More information about the jboss-svn-commits
mailing list