[jboss-svn-commits] JBoss Common SVN: r3423 - declarchive and 65 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Aug 4 23:56:36 EDT 2009
Author: ALRubinger
Date: 2009-08-04 23:56:35 -0400 (Tue, 04 Aug 2009)
New Revision: 3423
Added:
declarchive/
declarchive/tags/
declarchive/trunk/
declarchive/trunk/api/
declarchive/trunk/api/pom.xml
declarchive/trunk/api/src/
declarchive/trunk/api/src/main/
declarchive/trunk/api/src/main/java/
declarchive/trunk/api/src/main/java/org/
declarchive/trunk/api/src/main/java/org/jboss/
declarchive/trunk/api/src/main/java/org/jboss/declarchive/
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/SecurityActions.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java
declarchive/trunk/build/
declarchive/trunk/build/pom.xml
declarchive/trunk/impl-base/
declarchive/trunk/impl-base/pom.xml
declarchive/trunk/impl-base/src/
declarchive/trunk/impl-base/src/main/
declarchive/trunk/impl-base/src/main/java/
declarchive/trunk/impl-base/src/main/java/org/
declarchive/trunk/impl-base/src/main/java/org/jboss/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/
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/ResourceNotFoundException.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/SecurityActions.java
declarchive/trunk/impl-base/src/main/resources/
declarchive/trunk/impl-base/src/test/
declarchive/trunk/impl-base/src/test/java/
declarchive/trunk/impl-base/src/test/resources/
declarchive/trunk/impl-jdkfile/
declarchive/trunk/impl-jdkfile/pom.xml
declarchive/trunk/impl-jdkfile/src/
declarchive/trunk/impl-jdkfile/src/main/
declarchive/trunk/impl-jdkfile/src/main/java/
declarchive/trunk/impl-jdkfile/src/main/java/org/
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/SecurityActions.java
declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java
declarchive/trunk/impl-jdkfile/src/main/resources/
declarchive/trunk/impl-jdkfile/src/test/
declarchive/trunk/impl-jdkfile/src/test/java/
declarchive/trunk/impl-jdkfile/src/test/resources/
declarchive/trunk/impl-vfs/
declarchive/trunk/impl-vfs/pom.xml
declarchive/trunk/impl-vfs/src/
declarchive/trunk/impl-vfs/src/main/
declarchive/trunk/impl-vfs/src/main/java/
declarchive/trunk/impl-vfs/src/main/java/org/
declarchive/trunk/impl-vfs/src/main/java/org/jboss/
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/
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/SecurityActions.java
declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java
declarchive/trunk/impl-vfs/src/main/resources/
declarchive/trunk/impl-vfs/src/test/
declarchive/trunk/impl-vfs/src/test/java/
declarchive/trunk/impl-vfs/src/test/java/org/
declarchive/trunk/impl-vfs/src/test/java/org/jboss/
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/
declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java
declarchive/trunk/impl-vfs/src/test/resources/
declarchive/trunk/pom.xml
declarchive/trunk/spi-jdkfile/
declarchive/trunk/spi-jdkfile/pom.xml
declarchive/trunk/spi-jdkfile/src/
declarchive/trunk/spi-jdkfile/src/main/
declarchive/trunk/spi-jdkfile/src/main/java/
declarchive/trunk/spi-jdkfile/src/main/java/org/
declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/
declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/
declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/
declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/
declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/
declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java
declarchive/trunk/spi-vfs/
declarchive/trunk/spi-vfs/pom.xml
declarchive/trunk/spi-vfs/src/
declarchive/trunk/spi-vfs/src/main/
declarchive/trunk/spi-vfs/src/main/java/
declarchive/trunk/spi-vfs/src/main/java/org/
declarchive/trunk/spi-vfs/src/main/java/org/jboss/
declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/
declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/
declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/
declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java
Log:
[EMB-32] Start to move out Virtual Archives into a new repo/project location, temporarily called "declarchive"
Property changes on: declarchive/trunk
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Property changes on: declarchive/trunk/api
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Added: declarchive/trunk/api/pom.xml
===================================================================
--- declarchive/trunk/api/pom.xml (rev 0)
+++ declarchive/trunk/api/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>declarchive-api</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Declarchive API</name>
+ <description>Client View of the Declarchive Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+
+ </properties>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ </dependencies>
+
+</project>
+
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/Archive.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.api;
+
+import java.net.URL;
+
+/**
+ * Archive
+ *
+ * Represents a collection of resources which may
+ * be constructed declaratively / programmatically.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Archive
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Adds the specified Class to the archive
+ *
+ * @param The class to add
+ * @return This virtual deployment
+ * @throws IllegalArgumentException If no class was specified
+ */
+ Archive addClass(Class<?> clazz) throws IllegalArgumentException;
+
+ /**
+ * Adds the specified Classes to the archive.
+ *
+ * @param classes
+ * @return This virtual deployment
+ * @throws IllegalArgumentException If no classes were specified
+ */
+ Archive addClasses(Class<?>... classes) throws IllegalArgumentException;
+
+ /**
+ * Adds the resource with the specified name to the
+ * deployment. The resource name must be visible to the ClassLoader
+ * of the archive
+ *
+ * @param name
+ * @return
+ * @throws IllegalArgumentException If the name was not specified
+ */
+ Archive addResource(String name) throws IllegalArgumentException;
+
+ /**
+ * Adds the specified resource to the archive, using the specified ClassLoader
+ * to load the resource
+ *
+ * @param name
+ * @param cl
+ * @return
+ * @throws IllegalArgumentException If either the name or ClassLoader is not specified
+ */
+ Archive addResource(String name, ClassLoader cl) throws IllegalArgumentException;
+
+ /**
+ * Adds the resource located at the specified URL to the archive. The
+ * location within the archive will be equal to the path portion of the
+ * specified URL.
+ *
+ * @param location
+ * @return
+ * @throws IllegalArgumentException If the location is not specified
+ */
+ Archive addResource(URL location) throws IllegalArgumentException;
+
+ /**
+ * Adds the resource located at the specified URL to
+ * the archive at the specified path.
+ *
+ * @param location
+ * @param newPath The new path to assign, or null if
+ * the path portion of the location should be used
+ * @return
+ * @throws IllegalArgumentException If the location is not specified
+ */
+ Archive addResource(URL location, String newPath) throws IllegalArgumentException;
+
+ /**
+ * Returns a multiline "ls -l"-equse output of the contents of
+ * this deployment and (recursively) its children if the verbosity
+ * flag is set to "true". Otherwise the no-arg version is invoked
+ *
+ * @return
+ */
+ String toString(boolean verbose);
+
+}
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/SecurityActions.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/SecurityActions.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/SecurityActions.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,108 @@
+package org.jboss.declarchive.api;
+
+import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instantiation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+
+ /**
+ * Obtains the constructor for the specified class with the specified param types
+ * according to the contract of {@link Class#getConstructor(Class...)}
+ *
+ * @param clazz
+ * @param paramTypes
+ * @return
+ * @throws NoSuchMethodException
+ * @throws SecurityException
+ * @throws IllegalArgumentException If the class or param types were not specified
+ */
+ static Constructor<?> getConstructor(final Class<?> clazz, final Class<?>... paramTypes)
+ throws NoSuchMethodException, SecurityException, IllegalArgumentException
+ {
+ // Precondition checks
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("class must be specified");
+ }
+ if (paramTypes == null)
+ {
+ throw new IllegalArgumentException("param types must be specified");
+ }
+
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>()
+ {
+
+ @Override
+ public Constructor<?> run() throws Exception
+ {
+ return clazz.getConstructor(paramTypes);
+ }
+ });
+ }
+ catch (final PrivilegedActionException pae)
+ {
+ // Throw nsme and se
+ final Throwable unwrapped = pae.getCause();
+ if (unwrapped instanceof NoSuchMethodException)
+ {
+ final NoSuchMethodException nsme = (NoSuchMethodException) unwrapped;
+ throw nsme;
+ }
+ if (unwrapped instanceof SecurityException)
+ {
+ final SecurityException se = (SecurityException) unwrapped;
+ throw se;
+ }
+
+ // Throw the cause as encountered
+ throw new RuntimeException("Error in obtaining constructor", unwrapped);
+
+ }
+ }
+
+}
Property changes on: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/VfsMemoryArchiveFactory.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,204 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.api;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * VfsMemoryArchiveFactory
+ *
+ * Factory to create {@link Archive} instances, backed
+ * by a VFS in-memory implementation.
+ * This removes the API dependency upon internals for the
+ * client view and additionally acts as a convenience mechanism.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+/*
+ * TODO
+ *
+ * Break this up into a much more generic approach, then
+ * make factories for each underlying implementation type
+ */
+public class VfsMemoryArchiveFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VfsMemoryArchiveFactory.class.getName());
+
+ /**
+ * FQN of implementation Class used in creating new archives
+ */
+ private static final String CLASS_NAME_ARCHIVE_IMPL = "org.jboss.declarchive.impl.vfs.MemoryArchiveImpl";
+
+ /**
+ * FQNs of type of parameters to implementation class constructor
+ */
+ private static final String[] CLASS_NAMES_CTOR_PARAMETERS =
+ {String.class.getName()};
+
+ /**
+ * Constructor used in creating new {@link Archive} instances
+ */
+ private static Constructor<?> constructor;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Internal Constructor to prohibit external
+ * instantiation
+ */
+ private VfsMemoryArchiveFactory()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new {@link Archive} with the specified name.
+ *
+ * @param name
+ * @throws IllegalArgumentException If the name is not specified
+ */
+ public static Archive createVirtualArchive(final String name) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+
+ // Get constructor
+ final Constructor<?> ctor = getConstructor();
+
+ // Create new instance
+ final Object obj;
+ try
+ {
+ obj = ctor.newInstance(name);
+ }
+ catch (final InstantiationException e)
+ {
+ throw new RuntimeException("Error in creating new " + Archive.class.getName(), e);
+ }
+ catch (final IllegalAccessException e)
+ {
+ throw new RuntimeException("Error in creating new " + Archive.class.getName(), e);
+ }
+ catch (final InvocationTargetException e)
+ {
+ throw new RuntimeException("Error in creating new " + Archive.class.getName(), e);
+ }
+
+ // Cast
+ final Archive archive;
+ try
+ {
+ archive = Archive.class.cast(obj);
+ }
+ catch (final ClassCastException cce)
+ {
+ throw new RuntimeException("New instance should be of type " + Archive.class.getName(), cce);
+ }
+
+ // Return
+ return archive;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the constructor used in creating new archive instances.
+ * Uses a cached copy unless not yet initialized.
+ */
+ private synchronized static Constructor<?> getConstructor()
+ {
+ // If we haven't yet cached the ctor
+ if (constructor == null)
+ {
+ // Load the impl class
+ final String implClassName = CLASS_NAME_ARCHIVE_IMPL;
+ final Class<?> implClass = getClass(implClassName);
+
+ // Load the ctor param classes
+ final List<Class<?>> paramClasses = new ArrayList<Class<?>>();
+ for (final String paramClassName : CLASS_NAMES_CTOR_PARAMETERS)
+ {
+ paramClasses.add(getClass(paramClassName));
+ }
+ final Class<?>[] paramClassesArray = paramClasses.toArray(new Class<?>[]
+ {});
+
+ // Get and set the ctor
+ try
+ {
+ constructor = SecurityActions.getConstructor(implClass, paramClassesArray);
+ log.log(Level.FINE, "Set the " + Archive.class.getName() + " type constructor: " + constructor);
+ }
+ catch (final NoSuchMethodException nsme)
+ {
+ throw new RuntimeException("Could not find constructor to be used in factory creation of a new "
+ + Archive.class.getSimpleName(), nsme);
+ }
+ }
+
+ // Return
+ return constructor;
+ }
+
+ /**
+ * Obtains the class with the specified name from the TCCL
+ *
+ * @param className
+ * @return
+ */
+ private static Class<?> getClass(final String className)
+ {
+ final ClassLoader cl = SecurityActions.getThreadContextClassLoader();
+ try
+ {
+ return Class.forName(className, false, cl);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RuntimeException("Could not find implementation class \"" + className + "\" in " + cl, cnfe);
+ }
+ }
+}
Property changes on: declarchive/trunk/build
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Added: declarchive/trunk/build/pom.xml
===================================================================
--- declarchive/trunk/build/pom.xml (rev 0)
+++ declarchive/trunk/build/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Declarchive Build</name>
+ <description>Declarchive Build Configuration</description>
+ <packaging>pom</packaging>
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.junit_junit>4.6</version.junit_junit>
+
+ </properties>
+
+ <!-- SCM -->
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/common/declarchive/trunk</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/common/declarchive/trunk</developerConnection>
+ <url>http://anonsvn.jboss.org/repos/common/declarchive/trunk</url>
+ </scm>
+
+ <!--
+ Issues TODO: Update this when we have a JIRA Key <issueManagement>
+ <system>jira</system>
+ <url>http://jira.jboss.com/jira/browse/EMB</url> </issueManagement>
+ -->
+
+ <!-- Build -->
+ <build>
+
+ <plugins>
+
+ <!-- JBoss-specific Packaging -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jboss-packaging-maven-plugin</artifactId>
+ <version>2.0-beta-1</version>
+ <extensions>true</extensions>
+ </plugin>
+
+ <!-- Compiler -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <inherited>true</inherited>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <showDeprecation>false</showDeprecation>
+ <showWarnings>true</showWarnings>
+ <optimize>true</optimize>
+ <compilerVersion>1.6</compilerVersion>
+ <fork>true</fork>
+ <argLine>-Xmx512M</argLine>
+ <executable>${JAVA_HOME}/bin/javac</executable>
+ </configuration>
+ </plugin>
+
+ <!-- Surefire -->
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <trimStackTrace>false</trimStackTrace>
+ <printSummary>true</printSummary>
+ <includes>
+ <include>**/*TestCase.java</include>
+ <include>**/*TestSuite.java</include>
+ </includes>
+ <forkMode>always</forkMode>
+ </configuration>
+ </plugin>
+
+ <!-- Maven Release Plugin Configuration -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <tagBase>https://svn.jboss.org/repos/common/declarchive/tags</tagBase>
+ </configuration>
+ </plugin>
+
+ <!-- Enforce Maven Environment -->
+ <plugin>
+ <artifactId>maven-enforcer-plugin
+ </artifactId>
+ <executions>
+ <execution>
+ <id>enforce-maven-environment</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <rules>
+ <requireMavenVersion>
+ <version>[2.0.9,2.1)</version> <!-- Must be Maven 2.0.9 >= x > 2.1 -->
+ </requireMavenVersion>
+ <requireJavaVersion>
+ <version>1.6.0</version> <!-- Must be JDK6 -->
+ </requireJavaVersion>
+ </rules>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+ <!-- Dependency Management -->
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${version.junit_junit}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+</project>
+
Property changes on: declarchive/trunk/impl-base
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Added: declarchive/trunk/impl-base/pom.xml
===================================================================
--- declarchive/trunk/impl-base/pom.xml (rev 0)
+++ declarchive/trunk/impl-base/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>jboss-declarchive-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>declarchive-impl-base</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Declarchive VFS Implementation Base</name>
+ <description>Common Base for Implementations of the Declarchive Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.declarchive_declarchive.api>0.1.0-SNAPSHOT</version.org.jboss.declarchive_declarchive.api>
+
+ </properties>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.declarchive
+ -->
+ <dependency>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-api</artifactId>
+ <version>${version.org.jboss.declarchive_declarchive.api}</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
+
Added: 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 (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ArchiveBase.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,468 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.impl.base;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+
+/**
+ * ArchiveBase
+ *
+ * Base implementation of {@link Archive}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class ArchiveBase implements Archive
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ArchiveBase.class.getName());
+
+ /**
+ * Extension for Java Archives
+ */
+ public static final String EXTENSION_JAR = ".jar";
+
+ /**
+ * Delimiter for paths while looking for resources
+ */
+ private static final char DELIMITER_RESOURCE_PATH = '/';
+
+ /**
+ * Delimiter for paths in fully-qualified class names
+ */
+ private static final char DELIMITER_CLASS_NAME_PATH = '.';
+
+ /**
+ * The filename extension appended to classes
+ */
+ private static final String EXTENSION_CLASS = ".class";
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The ClassLoader used in loading resources and classes into the virtual deployment
+ */
+ private final ClassLoader classLoader;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance using the Thread Context ClassLoader
+ * from which we'll load resources by default
+ */
+ protected ArchiveBase()
+ {
+ // Use the TCCL
+ this(SecurityActions.getThreadContextClassLoader());
+ }
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance using the specified ClassLoader
+ * from which we'll load resources by default
+ *
+ * @param The ClassLoader to use by default
+ */
+ protected ArchiveBase(final ClassLoader cl)
+ {
+ // Invoke super
+ super();
+
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Set properties
+ this.classLoader = cl;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addClass(java.lang.Class)
+ */
+ @Override
+ public Archive 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 Archive 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;
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addResource(java.lang.String)
+ */
+ @Override
+ public Archive addResource(final String name) throws IllegalArgumentException
+ {
+ return this.addResource(name, this.getClassLoader());
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL)
+ */
+ @Override
+ public Archive 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 Archive 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;
+ }
+
+ /**
+ * @see org.jboss.declarchive.api.Archive#addResource(java.net.URL, java.lang.String)
+ */
+ @Override
+ public Archive 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;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Adds the specified content to the archive at the specified location
+ *
+ * @param content
+ * @param location
+ * @throws IllegalArgumentException
+ */
+ protected abstract void addContent(final byte[] content, final String location) throws IllegalArgumentException;
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns the name of the class such that it may be accessed via ClassLoader.getResource()
+ *
+ * @param clazz The class
+ * @throws IllegalArgumentException If the class was not specified
+ */
+ private String getResourceNameOfClass(final Class<?> clazz) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("Class must be specified");
+ }
+
+ // Build the name
+ final String fqn = clazz.getName();
+ final String nameAsResourcePath = fqn.replace(DELIMITER_CLASS_NAME_PATH, DELIMITER_RESOURCE_PATH);
+ final String resourceName = nameAsResourcePath + EXTENSION_CLASS;
+
+ // Return
+ return resourceName;
+ }
+
+ /**
+ * Copies and returns the specified URL. Used
+ * to ensure we don't export mutable URLs
+ *
+ * @param url
+ * @return
+ */
+ protected final URL copyURL(final URL url)
+ {
+ // If null, return
+ if (url == null)
+ {
+ return url;
+ }
+
+ try
+ {
+ // Copy
+ return new URL(url.toExternalForm());
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("Error in copying URL", e);
+ }
+ }
+
+ /**
+ * Obtains the contents (bytes) of the specified location
+ *
+ * @param location
+ * @return
+ * @throws IOException
+ * @throws IllegalArgumentException If the location is not specified
+ */
+ private byte[] getBytesOfResource(final URL location) throws IOException, IllegalArgumentException
+ {
+ // Precondition check
+ if (location == null)
+ {
+ throw new IllegalArgumentException("location must be specified");
+ }
+
+ // Open a connection and read in all the bytes
+ final URLConnection connection = location.openConnection();
+ final int length = connection.getContentLength();
+ assert length > -1 : "Content length is not known";
+ byte contents[] = new byte[length];
+ final InputStream in = connection.getInputStream();
+ int read = 0;
+ int currentLocation = 0;
+ int bytesToRead = 1024;
+ // Avoid ArrayIndexOutOfBounds by adjusting back the bytes we read in
+ if (bytesToRead + currentLocation > length)
+ {
+ bytesToRead = length;
+ }
+
+ // Read into the byte array
+ while ((read = (in.read(contents, currentLocation, bytesToRead))) > 0)
+ {
+ // Mark our new offset
+ currentLocation += read;
+
+ // Avoid ArrayIndexOutOfBounds
+ if (bytesToRead + currentLocation > length)
+ {
+ bytesToRead = length - currentLocation;
+ }
+ }
+
+ // Close up the stream
+ in.close();
+
+ // Return the byte array
+ if (log.isLoggable(Level.FINER))
+ {
+ log.log(Level.FINER, "Read " + contents.length + " bytes for: " + location);
+ }
+ return contents;
+ }
+
+ /**
+ * Obtains the contents (bytes) of the specified resource using the
+ * specified ClassLoader
+ *
+ * @param name
+ * @param cl
+ * @return
+ * @throws IOException
+ * @throws IllegalArgumentException If the name or ClassLoader is not specified
+ */
+ private byte[] getBytesOfResource(final String name, final ClassLoader cl) throws IOException,
+ 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 URL
+ final URL resourceUrl = this.getResourceUrl(name, cl);
+
+ // Return
+ return this.getBytesOfResource(resourceUrl);
+ }
+
+ /**
+ * Obtains the URL of the resource with the requested name.
+ * The search order is described by {@link ClassLoader#getResource(String)}
+ *
+ * @param name
+ * @return
+ * @throws IllegalArgumentException If name is not specified or could not be found,
+ * or if the ClassLoader is not specified
+ */
+ private URL getResourceUrl(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");
+ }
+
+ // Find
+ final URL url = cl.getResource(name);
+
+ // Ensure found
+ if (url == null)
+ {
+ throw new ResourceNotFoundException("Could not find resource with name \"" + name + "\" in: " + cl);
+ }
+
+ // Return
+ return url;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns the ClassLoader used to load classes
+ * and resources into this virtual deployment
+ *
+ * @return
+ */
+ protected final ClassLoader getClassLoader()
+ {
+ return this.classLoader;
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ResourceNotFoundException.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.impl.base;
+
+/**
+ * ResourceNotFoundException
+ *
+ * Thrown when a resource is requested, but could not be found
+ * within the context of the given ClassLoader
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ResourceNotFoundException extends IllegalArgumentException
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public ResourceNotFoundException()
+ {
+ super();
+ }
+
+ public ResourceNotFoundException(final String message, final Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public ResourceNotFoundException(final String s)
+ {
+ super(s);
+ }
+
+ public ResourceNotFoundException(final Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/SecurityActions.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/SecurityActions.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/SecurityActions.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,47 @@
+package org.jboss.declarchive.impl.base;
+
+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:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instanciation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
Property changes on: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Property changes on: declarchive/trunk/impl-jdkfile
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Added: declarchive/trunk/impl-jdkfile/pom.xml
===================================================================
--- declarchive/trunk/impl-jdkfile/pom.xml (rev 0)
+++ declarchive/trunk/impl-jdkfile/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>jboss-declarchive-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>declarchive-impl-jdkfile</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Declarchive JDK File-based Implementations</name>
+ <description>JDK File-based Implementations of the Declarchive Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.declarchive_declarchive.impl.base>0.1.0-SNAPSHOT</version.org.jboss.declarchive_declarchive.impl.base>
+ <version.org.jboss.declarchive_declarchive.spi.jdkfile>0.1.0-SNAPSHOT</version.org.jboss.declarchive_declarchive.spi.jdkfile>
+
+ </properties>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.declarchive
+ -->
+ <dependency>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-impl-base</artifactId>
+ <version>${version.org.jboss.declarchive_declarchive.impl.base}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-spi-jdkfile</artifactId>
+ <version>${version.org.jboss.declarchive_declarchive.spi.jdkfile}</version>
+ </dependency>
+
+ <!--
+ External Projects
+ -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
+
Added: declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/SecurityActions.java
===================================================================
--- declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/SecurityActions.java (rev 0)
+++ declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/SecurityActions.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,47 @@
+package org.jboss.declarchive.impl.jdkfile;
+
+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:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instanciation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
Property changes on: declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Added: 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 (rev 0)
+++ declarchive/trunk/impl-jdkfile/src/main/java/org/jboss/declarchive/impl/jdkfile/TempFileArchiveImpl.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,308 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.impl.jdkfile;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.logging.Level;
+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
+ *
+ * Concrete implementation of an {@link Archive} which
+ * stores contents in a directory structure in the temp directory
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class TempFileArchiveImpl extends ArchiveBase implements FileArchive
+{
+
+ //-------------------------------------------------------------------------------------||
+ // 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 -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.incubation.virtual.impl.base.AbstractVirtualArchive#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
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.incubation.virtual.api.VirtualArchive#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();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return super.toString() + ": " + this.getRoot().getAbsolutePath();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.incubation.virtual.spi.jdk.VirtualJdkArchive#getRoot()
+ */
+ @Override
+ public File getRoot()
+ {
+ return this.root;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // 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());
+ }
+
+}
Property changes on: declarchive/trunk/impl-vfs
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Added: declarchive/trunk/impl-vfs/pom.xml
===================================================================
--- declarchive/trunk/impl-vfs/pom.xml (rev 0)
+++ declarchive/trunk/impl-vfs/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>jboss-declarchive-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>declarchive-impl-vfs</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Declarchive VFS Implementations</name>
+ <description>VFS Implementations of the Declarchive Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.declarchive_declarchive.impl.base>0.1.0-SNAPSHOT</version.org.jboss.declarchive_declarchive.impl.base>
+ <version.org.jboss.declarchive_declarchive.spi.vfs>0.1.0-SNAPSHOT</version.org.jboss.declarchive_declarchive.spi.vfs>
+
+ </properties>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.declarchive
+ -->
+ <dependency>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-impl-base</artifactId>
+ <version>${version.org.jboss.declarchive_declarchive.impl.base}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-spi-vfs</artifactId>
+ <version>${version.org.jboss.declarchive_declarchive.spi.vfs}</version>
+ </dependency>
+
+ <!--
+ External Projects
+ -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
+
Added: 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 (rev 0)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/MemoryArchiveImpl.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,198 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.impl.vfs;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.declarchive.spi.vfs.VfsArchive;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.MemoryFileFactory;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * MemoryArchiveImpl
+ *
+ * Concrete implementation of a VFS-backed virtual archive which
+ * stores contents in-memory
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MemoryArchiveImpl extends VfsArchiveBase implements VfsArchive
+{
+
+ //-------------------------------------------------------------------------------------||
+ // 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);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.incubation.virtual.impl.base.AbstractVirtualArchive#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);
+ }
+
+}
Added: declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/SecurityActions.java
===================================================================
--- declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/SecurityActions.java (rev 0)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/SecurityActions.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,47 @@
+package org.jboss.declarchive.impl.vfs;
+
+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:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instanciation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
Property changes on: declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Added: 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 (rev 0)
+++ declarchive/trunk/impl-vfs/src/main/java/org/jboss/declarchive/impl/vfs/VfsArchiveBase.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,257 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.impl.vfs;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.impl.base.ArchiveBase;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VfsArchiveBase
+ *
+ * Support for VFS-backed implementations of an {@link Archive}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+abstract class VfsArchiveBase extends ArchiveBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VfsArchiveBase.class.getName());
+
+ /**
+ * Newline character
+ */
+ private static final char NEWLINE = '\n';
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The root of the deployment
+ */
+ private VirtualFile root;
+
+ /**
+ * The URL to the root deployment
+ */
+ private URL rootUrl;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance with the specified root and rootURL
+ *
+ * @param root
+ * @param rootUrl
+ * @param cl
+ */
+ public VfsArchiveBase(final ClassLoader cl)
+ {
+ // Invoke super
+ super(cl);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // 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();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Initializes the archive with the specified root and root URL
+ *
+ * @param root
+ * @param rootUrl
+ * @throws IllegalArgumentException If either the root or root URL is not specified
+ */
+ void initialize(final VirtualFile root, final URL rootUrl) throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (root == null)
+ {
+ throw new IllegalArgumentException("root is null");
+ }
+ if (rootUrl == null)
+ {
+ throw new IllegalArgumentException("rootUrl is null");
+ }
+
+ // Set properties
+ this.root = root;
+ this.rootUrl = rootUrl;
+ }
+
+ /**
+ * Describes this file in form:
+ *
+ * "/path/resource.ext - x bytes"
+ *
+ * In addition to all children of the given file root.
+ *
+ * @param file The root to describe
+ * @return
+ * @throws IllegalArgumentException If either the file or builder are not specified
+ */
+ private String describe(final VirtualFile file)
+ {
+ // Precondition checks
+ if (file == null)
+ {
+ throw new IllegalArgumentException("file must be specified");
+ }
+
+ // Make a StringBuilder
+ final StringBuilder sb = new StringBuilder();
+
+ // Start the output
+ sb.append(file);
+ sb.append(NEWLINE);
+
+ // Describe in depth
+ return this.describe(file, sb);
+ }
+
+ /**
+ * Describes this file in form:
+ *
+ * "/path/resource.ext - x bytes"
+ *
+ * In addition to all children of the given file root.
+ *
+ * @param file The root to describe
+ * @param sb The builder to which the description will be appended
+ * @return
+ * @throws IllegalArgumentException If either the file or builder are not specified
+ */
+ private String describe(final VirtualFile file, final StringBuilder sb) throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (file == null)
+ {
+ throw new IllegalArgumentException("file must be specified");
+ }
+ if (sb == null)
+ {
+ throw new IllegalArgumentException("builder must be specified");
+ }
+
+ // Get information for this root
+ final String path = file.getPathName();
+ final long size;
+ try
+ {
+ size = file.getSize();
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not get size for: " + file, ioe);
+ }
+
+ // Append this information
+ sb.append(path);
+ sb.append(" - ");
+ sb.append(size);
+ sb.append(" bytes");
+ sb.append(NEWLINE);
+
+ // Recurse into any children
+ final List<VirtualFile> children;
+ try
+ {
+ children = file.getChildren();
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not obtain children for: " + file, ioe);
+ }
+ if (children != null && children.size() > 0)
+ {
+ for (final VirtualFile child : children)
+ {
+ this.describe(child, sb);
+ }
+ }
+
+ // Return
+ return sb.toString();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the root
+ */
+ public final VirtualFile getRoot()
+ {
+ return root;
+ }
+
+ /**
+ * Returns a copy of this root's URL (not the
+ * actual reference as we want to protect internal
+ * state from mutation)
+ * @return
+ */
+ final URL getRootUrl()
+ {
+ return this.copyURL(this.rootUrl);
+ }
+}
Added: 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 (rev 0)
+++ declarchive/trunk/impl-vfs/src/test/java/org/jboss/declarchive/impl/vfs/VfsMemoryArchiveFactoryTestCase.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.impl.vfs;
+
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.VfsMemoryArchiveFactory;
+import org.jboss.declarchive.spi.vfs.VfsArchive;
+import org.jboss.virtual.VFS;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * VfsMemoryArchiveFactoryTestCase
+ *
+ * Test Cases to assert that the {@link VfsMemoryArchiveFactory} is
+ * working correctly
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VfsMemoryArchiveFactoryTestCase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VfsMemoryArchiveFactoryTestCase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Initializes the virtual file system
+ */
+ @BeforeClass
+ public static void initVfs() throws Exception
+ {
+ // Init VFS
+ VFS.init();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Tests that using a {@link testVirtualArchiveFactory} to create
+ * an archive results in a new type backed by VFS
+ */
+ @Test
+ public void testVirtualArchiveFactory() throws Exception
+ {
+ // Log
+ log.info("testVirtualArchiveFactory");
+
+ // Make an archive
+ final Archive archive = VfsMemoryArchiveFactory.createVirtualArchive("testArchive.jar");
+ 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);
+ }
+}
Added: declarchive/trunk/pom.xml
===================================================================
--- declarchive/trunk/pom.xml (rev 0)
+++ declarchive/trunk/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+
+ <!-- Model Information -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Information -->
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Declarchive Aggregator</name>
+ <url>http://www.jboss.org</url>
+ <description>Declarchive Aggregator</description>
+
+ <!-- Aggregate Modules -->
+ <modules>
+ <module>api</module>
+ <module>build</module>
+ <module>impl-base</module>
+ <module>impl-jdkfile</module>
+ <module>impl-vfs</module>
+ <module>spi-jdkfile</module>
+ <module>spi-vfs</module>
+ </modules>
+
+</project>
Property changes on: declarchive/trunk/spi-jdkfile
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Added: declarchive/trunk/spi-jdkfile/pom.xml
===================================================================
--- declarchive/trunk/spi-jdkfile/pom.xml (rev 0)
+++ declarchive/trunk/spi-jdkfile/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>jboss-declarchive-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>declarchive-spi-jdkfile</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Declarchive SPI for JDK File I/O</name>
+ <description>Service Provider Contract for JDK File I/O Implementations of the Declarchive Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.declarchive_declarchive.api>0.1.0-SNAPSHOT</version.org.jboss.declarchive_declarchive.api>
+
+ </properties>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.declarchive
+ -->
+ <dependency>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-api</artifactId>
+ <version>${version.org.jboss.declarchive_declarchive.api}</version>
+ </dependency>
+
+ <!--
+ External Projects
+ -->
+ </dependencies>
+
+</project>
+
Added: declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java
===================================================================
--- declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java (rev 0)
+++ declarchive/trunk/spi-jdkfile/src/main/java/org/jboss/declarchive/spi/jdk/file/FileArchive.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.spi.jdk.file;
+
+import java.io.File;
+
+import org.jboss.declarchive.api.Archive;
+
+/**
+ * FileArchive
+ *
+ * Represents a single collection
+ * of resources which may
+ * be constructed declaratively / programmatically. Adds
+ * the constraint to providers that this is backed by a plain
+ * File via JDK I/O.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface FileArchive extends Archive
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the File which is the root level
+ * of this archive
+ *
+ * @return
+ */
+ File getRoot();
+}
Property changes on: declarchive/trunk/spi-vfs
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
bin
.settings
.classpath
.project
Added: declarchive/trunk/spi-vfs/pom.xml
===================================================================
--- declarchive/trunk/spi-vfs/pom.xml (rev 0)
+++ declarchive/trunk/spi-vfs/pom.xml 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>jboss-declarchive-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>declarchive-spi-vfs</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Declarchive SPI for VFS</name>
+ <description>Service Provider Contract for VFS Implementations of the Declarchive Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.declarchive_declarchive.api>0.1.0-SNAPSHOT</version.org.jboss.declarchive_declarchive.api>
+ <version.org.jboss_jboss.vfs>2.2.0.M4</version.org.jboss_jboss.vfs>
+
+ </properties>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.declarchive
+ -->
+ <dependency>
+ <groupId>org.jboss.declarchive</groupId>
+ <artifactId>declarchive-api</artifactId>
+ <version>${version.org.jboss.declarchive_declarchive.api}</version>
+ </dependency>
+
+ <!--
+ External Projects
+ -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ <version>${version.org.jboss_jboss.vfs}</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
+
Added: declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java
===================================================================
--- declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java (rev 0)
+++ declarchive/trunk/spi-vfs/src/main/java/org/jboss/declarchive/spi/vfs/VfsArchive.java 2009-08-05 03:56:35 UTC (rev 3423)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.declarchive.spi.vfs;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VfsArchive
+ *
+ * Represents a single collection
+ * of resources which may be constructed declaratively / programmatically.
+ * Adds the constraint to providers that this is backed by the
+ * JBoss Virtual File System
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface VfsArchive extends Archive
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the VFS file which is the root level
+ * of this archive
+ *
+ * @return
+ */
+ VirtualFile getRoot();
+}
More information about the jboss-svn-commits
mailing list