[jboss-cvs] JBossAS SVN: r87362 - in projects/bootstrap/trunk: spi/src/main/java/org/jboss/bootstrap/spi and 14 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 15 12:00:02 EDT 2009
Author: ALRubinger
Date: 2009-04-15 12:00:02 -0400 (Wed, 15 Apr 2009)
New Revision: 87362
Added:
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfigFactory.java
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/SecurityActions.java
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServerFactory.java
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/SecurityActions.java
projects/bootstrap/trunk/spi-test/
projects/bootstrap/trunk/spi-test/.classpath
projects/bootstrap/trunk/spi-test/.project
projects/bootstrap/trunk/spi-test/.settings/
projects/bootstrap/trunk/spi-test/.settings/org.eclipse.jdt.core.prefs
projects/bootstrap/trunk/spi-test/.settings/org.maven.ide.eclipse.prefs
projects/bootstrap/trunk/spi-test/pom.xml
projects/bootstrap/trunk/spi-test/src/
projects/bootstrap/trunk/spi-test/src/test/
projects/bootstrap/trunk/spi-test/src/test/java/
projects/bootstrap/trunk/spi-test/src/test/java/org/
projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/
projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/bootstrap/
projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/bootstrap/spi/
projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/bootstrap/spi/test/
projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/bootstrap/spi/test/ClassLoadingTestCase.java
projects/bootstrap/trunk/spi-test/src/test/resources/
projects/bootstrap/trunk/spi-test/src/test/resources/bootstrap.xml
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/GenericFactory.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/SecurityActions.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerConfigFactory.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerFactory.java
Modified:
projects/bootstrap/trunk/pom.xml
Log:
[JBBOOT-39] Provide a launch mechanism that allows SPIs only upon the application classpath
Modified: projects/bootstrap/trunk/pom.xml
===================================================================
--- projects/bootstrap/trunk/pom.xml 2009-04-15 15:59:16 UTC (rev 87361)
+++ projects/bootstrap/trunk/pom.xml 2009-04-15 16:00:02 UTC (rev 87362)
@@ -37,6 +37,7 @@
<module>legacy</module>
<module>spi</module>
<module>spi-mc</module>
+ <module>spi-test</module>
</modules>
</project>
Added: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/GenericFactory.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/GenericFactory.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/GenericFactory.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,114 @@
+/*
+ * 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.bootstrap.spi.factory;
+
+/**
+ * GenericFactory
+ *
+ * Factory for creating generic instances
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class GenericFactory
+{
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ */
+ private GenericFactory()
+ {
+ // No external creation of instances
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a instance from the specified implementation class name, using the
+ * specified ClassLoader. The returned instance will additionally be created using
+ * the ClassLoader denoted.
+ *
+ * @param <T> The expected type
+ * @param implClassName The fully-qualified name of the implementation class
+ * @param cl The ClassLoader to use
+ * @param expectedType The Class to which the resultant object should be assignable
+ * @return The newly-created instance
+ * @throws IllegalArgumentException If the expected type is null,
+ * ClassLoader is null, implementation class
+ * name is null, blank, can not be found on the ClassLoader,
+ * or is not assignable to the expected type.
+ * @throws Exception If some error occurred in constructing the instance
+ */
+ final static <T> T createInstance(final String implClassName, final ClassLoader cl, final Class<T> expectedType)
+ throws IllegalArgumentException, Exception
+ {
+ // Precondition checks
+ if (implClassName == null || implClassName.length() == 0)
+ {
+ throw new IllegalArgumentException("Implementation class must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException(ClassLoader.class.getSimpleName() + " must be specified");
+ }
+ if (expectedType == null)
+ {
+ throw new IllegalArgumentException("Expected type must be specified");
+ }
+
+ // Get the implementation class
+ Class<?> implClass = null;
+ try
+ {
+ implClass = Class.forName(implClassName, false, cl);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new IllegalArgumentException("Specified implementation class could not be found: " + implClassName
+ + " on " + ClassLoader.class.getSimpleName() + " " + cl, cnfe);
+ }
+
+ // Make a new instance
+ final Object obj = SecurityActions.newInstance(implClass, cl);
+
+ // Return
+ try
+ {
+ return expectedType.cast(obj);
+ }
+ catch (ClassCastException cce)
+ {
+ // Rethrow as new CCE with some context
+ final ClassLoader implCl = implClass.getClassLoader();
+ final ClassLoader expectedTypeCl = expectedType.getClassLoader();
+ throw new ClassCastException("Specified implementation class, " + implClassName + ", resolved to " + implClass
+ + " on " + implCl + " is not of type " + expectedType + " from " + ClassLoader.class.getSimpleName()
+ + ": " + (expectedTypeCl == null ? "[BOOTSTRAP CL]" : expectedTypeCl));
+ }
+ }
+}
Added: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/SecurityActions.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/SecurityActions.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/SecurityActions.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,125 @@
+/*
+ * 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.bootstrap.spi.factory;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * SecurityActions
+ *
+ * Utility class for security actions, so as to provide
+ * some centralization without leaking privileged actions
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * In place to prevent instanciation
+ */
+ private SecurityActions()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns a new instance of the specified class, defined in the
+ * specified ClassLoader. If the CL is null, the Thread Context CL
+ * will be used.
+ *
+ * @throws IllegalArgumentException If the class was not specified
+ * @throws PrivilegedActionException
+ */
+ static Object newInstance(final Class<?> clazz, final ClassLoader cl) throws IllegalArgumentException, Exception
+ {
+
+ // Whether to set the CL
+ final boolean setDefiningCl = cl != null;
+
+ // Make new instance
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
+ {
+
+ public Object run() throws Exception
+ {
+ // Initialize
+ Thread current = null;
+ ClassLoader oldCl = null;
+
+ // If necessary, set the TCCL
+ if (setDefiningCl)
+ {
+ current = Thread.currentThread();
+ oldCl = current.getContextClassLoader();
+ current.setContextClassLoader(cl);
+ }
+
+ try
+ {
+ // Create the instance
+ return clazz.newInstance();
+ }
+ finally
+ {
+ // Reset the TCCL if necessary
+ if (setDefiningCl)
+ {
+ current.setContextClassLoader(oldCl);
+ }
+ }
+ }
+
+ });
+ }
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ *
+ * @return
+ */
+ static ClassLoader getTccl()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+
+ public ClassLoader run()
+ {
+ // Return the TCCL
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ });
+ }
+}
Added: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerConfigFactory.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerConfigFactory.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerConfigFactory.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,86 @@
+/*
+ * 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.bootstrap.spi.factory;
+
+import org.jboss.bootstrap.spi.config.ServerConfig;
+
+/**
+ * ServerConfigFactory
+ *
+ * Factory of generic {@link ServerConfig} implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerConfigFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private ServerConfigFactory()
+ {
+ // No external access
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Factory Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a ServerConfig from the specified implementation class name, using the
+ * Thread Context ClassLoader. The returned config will additionally be created using
+ * the TCCL.
+ *
+ * @param implClassName The fully-qualified name of the implementation class
+ * @throws IllegalArgumentException If the implementation class name is null, blank,
+ * can not be found on the ClassLoader, or is not assignable to {@link ServerConfig}
+ * @throws Exception If some error occurred in constructing the config
+ * @return The newly-created config
+ */
+ public static ServerConfig<?> createServerConfig(final String implClassName) throws IllegalArgumentException,
+ Exception
+ {
+ return createServerConfig(implClassName, SecurityActions.getTccl());
+ }
+
+ /**
+ * Creates a ServerConfig from the specified implementation class name, using the
+ * specified ClassLoader. The returned config will additionally be created using
+ * the ClassLoader denoted.
+ *
+ * @param implClassName The fully-qualified name of the implementation class
+ * @param cl The ClassLoader to use
+ * @throws IllegalArgumentException If the ClassLoader is null, implementation class
+ * name is null, blank, can not be found on the ClassLoader,
+ * or is not assignable to {@link ServerConfig}.
+ * @throws Exception If some error occurred in constructing the config
+ * @return The newly-created config
+ */
+ public static ServerConfig<?> createServerConfig(final String implClassName, final ClassLoader cl)
+ throws IllegalArgumentException, Exception
+ {
+ return GenericFactory.createInstance(implClassName, cl, ServerConfig.class);
+ }
+}
Added: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerFactory.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerFactory.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/factory/ServerFactory.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,85 @@
+/*
+ * 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.bootstrap.spi.factory;
+
+import org.jboss.bootstrap.spi.server.Server;
+
+/**
+ * ServerFactory
+ *
+ * Factory of generic {@link Server} implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private ServerFactory()
+ {
+ // No external access
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Factory Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a Server from the specified implementation class name, using the
+ * Thread Context ClassLoader. The returned server will additionally be created using
+ * the TCCL.
+ *
+ * @param implClassName The fully-qualified name of the implementation class
+ * @throws IllegalArgumentException If the implementation class name is null, blank,
+ * can not be found on the ClassLoader, or is not assignable to {@link Server}
+ * @throws Exception If some error occurred in constructing the Server
+ * @return The newly-created Server
+ */
+ public static Server<?, ?> createServer(final String implClassName) throws IllegalArgumentException, Exception
+ {
+ return createServer(implClassName, SecurityActions.getTccl());
+ }
+
+ /**
+ * Creates a Server from the specified implementation class name, using the
+ * specified ClassLoader. The returned server will additionally be created using
+ * the ClassLoader denoted.
+ *
+ * @param implClassName The fully-qualified name of the implementation class
+ * @param cl The ClassLoader to use
+ * @throws IllegalArgumentException If the ClassLoader is null, implementation class
+ * name is null, blank, can not be found on the ClassLoader,
+ * or is not assignable to {@link Server}.
+ * @throws Exception If some error occurred in constructing the Server
+ * @return The newly-created Server
+ */
+ public static Server<?, ?> createServer(final String implClassName, final ClassLoader cl)
+ throws IllegalArgumentException, Exception
+ {
+ return GenericFactory.createInstance(implClassName, cl, Server.class);
+ }
+}
Added: projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfigFactory.java
===================================================================
--- projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfigFactory.java (rev 0)
+++ projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfigFactory.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,106 @@
+/*
+ * 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.bootstrap.spi.mc.config;
+
+import org.jboss.bootstrap.spi.config.ServerConfig;
+import org.jboss.bootstrap.spi.factory.ServerConfigFactory;
+
+/**
+ * MCServerConfigFactory
+ *
+ * Factory of {@link MCServerConfig} implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MCServerConfigFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The FQN of the default implementation class to create
+ */
+ public static final String DEFAULT_MC_SERVER_CONFIG_IMPL_CLASS_NAME = "org.jboss.bootstrap.impl.mc.config.BasicMCServerConfig";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private MCServerConfigFactory()
+ {
+ // No external access
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Factory Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates an MCServerConfig from the default implementation class name
+ * {@link MCServerConfigFactory#DEFAULT_MC_SERVER_CONFIG_IMPL_CLASS_NAME}, using the
+ * Thread Context ClassLoader. The returned config will additionally be created using
+ * the TCCL.
+ *
+ * @return The newly-created config
+ */
+ public static MCServerConfig createServerConfig()
+ {
+ return createServerConfig(SecurityActions.getTccl());
+ }
+
+ /**
+ * Creates an MCServerConfig from the default implementation class name
+ * {@link MCServerConfigFactory#DEFAULT_MC_SERVER_CONFIG_IMPL_CLASS_NAME}, using the
+ * specified ClassLoader. The returned config will additionally be created using
+ * the ClassLoader denoted.
+ *
+ * @throws IllegalArgumentException If the ClassLoader is null
+ * @return The newly-created config
+ */
+ public static MCServerConfig createServerConfig(final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException(ClassLoader.class.getSimpleName() + " is required.");
+ }
+
+ // Get the config
+ ServerConfig<?> config = null;
+ try
+ {
+ config = ServerConfigFactory.createServerConfig(DEFAULT_MC_SERVER_CONFIG_IMPL_CLASS_NAME, cl);
+ }
+ catch (Exception e)
+ {
+ // An exception here is likely our fault, so throw a RuntimeException
+ throw new RuntimeException("Error in creating the configuration", e);
+ }
+
+ // Cast
+ return MCServerConfig.class.cast(config);
+ }
+}
Added: projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/SecurityActions.java
===================================================================
--- projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/SecurityActions.java (rev 0)
+++ projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/SecurityActions.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,73 @@
+/*
+ * 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.bootstrap.spi.mc.config;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * Utility class for security actions, so as to provide
+ * some centralization without leaking privileged actions
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * In place to prevent instanciation
+ */
+ private SecurityActions()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ *
+ * @return
+ */
+ static ClassLoader getTccl()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+
+ public ClassLoader run()
+ {
+ // Return the TCCL
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ });
+ }
+}
Added: projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServerFactory.java
===================================================================
--- projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServerFactory.java (rev 0)
+++ projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServerFactory.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,215 @@
+/*
+ * 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.bootstrap.spi.mc.server;
+
+import org.jboss.bootstrap.spi.factory.ServerFactory;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfigFactory;
+import org.jboss.bootstrap.spi.server.Server;
+
+/**
+ * MCServerFactory
+ *
+ * Factory of {@link MCServer} implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MCServerFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The FQN of the default server implementation class to create
+ */
+ public static final String DEFAULT_MC_SERVER_IMPL_CLASS_NAME = "org.jboss.bootstrap.impl.mc.server.MCServerImpl";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private MCServerFactory()
+ {
+ // No external access
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Factory Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates an MCServer from the default implementation class name
+ * {@link MCServerFactory#DEFAULT_MC_SERVER_IMPL_CLASS_NAME}, using the
+ * Thread Context ClassLoader. The returned server will additionally be created using
+ * the TCCL.
+ *
+ * @return The newly-created Server
+ */
+ public static MCServer createServer()
+ {
+ return createServer(SecurityActions.getTccl());
+ }
+
+ /**
+ * Creates an MCServer from the default implementation class name
+ * {@link MCServerFactory#DEFAULT_MC_SERVER_IMPL_CLASS_NAME}, using the
+ * Thread Context ClassLoader. The returned server will additionally be created using
+ * the TCCL. As a convenience, the server will contain a default configuration.
+ *
+ * @return The newly-created Server populated with a default configuration
+ */
+ public static MCServer createServerWithDefaultConfiguration()
+ {
+ return createServerWithDefaultConfiguration(SecurityActions.getTccl());
+ }
+
+ /**
+ * Creates an MCServer from the default implementation class name
+ * {@link MCServerFactory#DEFAULT_MC_SERVER_IMPL_CLASS_NAME}, using the
+ * specified ClassLoader. The returned server will additionally be created using
+ * the ClassLoader denoted.
+ *
+ * @throws IllegalArgumentException If the ClassLoader is null
+ * @return The newly-created Server
+ */
+ public static MCServer createServer(final ClassLoader cl) throws IllegalArgumentException
+ {
+ try
+ {
+ return createServer(DEFAULT_MC_SERVER_IMPL_CLASS_NAME, cl);
+ }
+ catch (Exception e)
+ {
+ // An exception here is likely our fault, so throw a RuntimeException
+ throw new RuntimeException("Error in creating the Server", e);
+ }
+ }
+
+ /**
+ * Creates an MCServer from the default implementation class name
+ * {@link MCServerFactory#DEFAULT_MC_SERVER_IMPL_CLASS_NAME}, using the
+ * specified ClassLoader. The returned server will additionally be created using
+ * the ClassLoader denoted. As a convenience, the server will contain a
+ * default configuration.
+ *
+ * @throws IllegalArgumentException If the ClassLoader is null
+ * @return The newly-created Server populated with a default configuration
+ */
+ public static MCServer createServerWithDefaultConfiguration(final ClassLoader cl) throws IllegalArgumentException
+ {
+ try
+ {
+ return createServerWithDefaultConfiguration(DEFAULT_MC_SERVER_IMPL_CLASS_NAME, cl);
+ }
+ catch (Exception e)
+ {
+ // An exception here is likely our fault, so throw a RuntimeException
+ throw new RuntimeException("Error in creating the Server", e);
+ }
+ }
+
+ /**
+ * Creates an MCServer from the specified implementation class name
+ * using the specified ClassLoader. The returned server will additionally
+ * be created using the ClassLoader denoted.
+ *
+ * @throws IllegalArgumentException If the ClassLoader or server implementation class is null
+ * @throws Exception If there was an error in creating the Server
+ * @return The newly-created Server
+ */
+ public static MCServer createServer(final String implClassName, final ClassLoader cl)
+ throws IllegalArgumentException, Exception
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException(ClassLoader.class.getSimpleName() + " is required.");
+ }
+ if (implClassName == null || implClassName.length() == 0)
+ {
+ throw new IllegalArgumentException("Implementation class name must be specified");
+ }
+
+ // Get the server
+ final Server<?, ?> server = ServerFactory.createServer(implClassName, cl);
+
+ // Cast
+ MCServer mcServer = null;
+ try
+ {
+ mcServer = MCServer.class.cast(server);
+ }
+ catch (ClassCastException cce)
+ {
+ // Catch, explain giving some context, throw new
+ throw new ClassCastException("Specified server implementation class, " + implClassName
+ + " must be assignable to " + MCServer.class.getName());
+ }
+
+ // Set a default config
+ final MCServerConfig config = MCServerConfigFactory.createServerConfig(cl);
+ mcServer.setConfiguration(config);
+
+ // Return
+ return mcServer;
+ }
+
+ /**
+ * Creates an MCServer from the specified implementation class name
+ * using the specified ClassLoader. The returned server will additionally
+ * be created using the ClassLoader denoted. As a convenience, the server
+ * will contain a default configuration.
+ *
+ * @throws IllegalArgumentException If the ClassLoader or server implementation class is null
+ * @throws Exception If there was an error in creating the Server
+ * @return The newly-created Server populated with a default configuration
+ */
+ public static MCServer createServerWithDefaultConfiguration(final String implClassName, final ClassLoader cl)
+ throws IllegalArgumentException, Exception
+ {
+ // Make the server, applying a default config
+ return applyDefaultConfiguration(createServer(implClassName, cl), cl);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Sets a new, default configuration upon the specified server
+ *
+ * @param server The server upon which we'll set a new config
+ * @param cl The ClassLoader used to create the new config
+ * @return The same server instance passed in, with a set config
+ */
+ private static MCServer applyDefaultConfiguration(final MCServer server, final ClassLoader cl)
+ {
+ // Set a default config
+ final MCServerConfig config = MCServerConfigFactory.createServerConfig(cl);
+ server.setConfiguration(config);
+ return server;
+ }
+}
Added: projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/SecurityActions.java
===================================================================
--- projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/SecurityActions.java (rev 0)
+++ projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/SecurityActions.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,73 @@
+/*
+ * 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.bootstrap.spi.mc.server;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * Utility class for security actions, so as to provide
+ * some centralization without leaking privileged actions
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * In place to prevent instanciation
+ */
+ private SecurityActions()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ *
+ * @return
+ */
+ static ClassLoader getTccl()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+
+ public ClassLoader run()
+ {
+ // Return the TCCL
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ });
+ }
+}
Property changes on: projects/bootstrap/trunk/spi-test
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
Added: projects/bootstrap/trunk/spi-test/.classpath
===================================================================
--- projects/bootstrap/trunk/spi-test/.classpath (rev 0)
+++ projects/bootstrap/trunk/spi-test/.classpath 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,7 @@
+<classpath>
+ <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
+ <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
+ <classpathentry kind="output" path="eclipse-target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+</classpath>
\ No newline at end of file
Added: projects/bootstrap/trunk/spi-test/.project
===================================================================
--- projects/bootstrap/trunk/spi-test/.project (rev 0)
+++ projects/bootstrap/trunk/spi-test/.project 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,17 @@
+<projectDescription>
+ <name>jboss-bootstrap-spi-test</name>
+ <comment>SPI Testing for JBoss Bootstrap</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Added: projects/bootstrap/trunk/spi-test/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/bootstrap/trunk/spi-test/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ projects/bootstrap/trunk/spi-test/.settings/org.eclipse.jdt.core.prefs 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,5 @@
+#Wed Apr 15 10:48:46 GMT-05:00 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
Added: projects/bootstrap/trunk/spi-test/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/bootstrap/trunk/spi-test/.settings/org.maven.ide.eclipse.prefs (rev 0)
+++ projects/bootstrap/trunk/spi-test/.settings/org.maven.ide.eclipse.prefs 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,8 @@
+#Tue Apr 14 10:33:13 GMT-05:00 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+version=1
Added: projects/bootstrap/trunk/spi-test/pom.xml
===================================================================
--- projects/bootstrap/trunk/spi-test/pom.xml (rev 0)
+++ projects/bootstrap/trunk/spi-test/pom.xml 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,206 @@
+<?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.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-build</artifactId>
+ <version>0.1.0</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>jboss-bootstrap-spi-test</artifactId>
+ <name>JBoss Bootstrap SPI Test</name>
+ <version>0.1.1-SNAPSHOT</version>
+ <description>SPI Testing for JBoss Bootstrap</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.bootstrap_jboss.bootstrap.impl.base>0.1.1-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.impl.base>
+ <version.org.jboss.bootstrap_jboss.bootstrap.impl.mc>0.1.1-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.impl.mc>
+ <version.org.jboss.bootstrap_jboss.bootstrap.spi>0.1.1-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.spi>
+ <version.org.jboss.bootstrap_jboss.bootstrap.spi.mc>0.1.1-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.spi.mc>
+ <version.org.jboss.logging_jboss.logging.log4j>2.0.6.GA</version.org.jboss.logging_jboss.logging.log4j>
+ <version.org.jboss.logging_jboss.logging.spi>2.0.5.GA</version.org.jboss.logging_jboss.logging.spi>
+ <version.org.jboss.microcontainer_jboss.kernel>2.0.4.GA</version.org.jboss.microcontainer_jboss.kernel>
+ <version.org.jboss_jbossxb>2.0.0.GA</version.org.jboss_jbossxb>
+
+ <version.org.jboss_jboss.common.core>2.2.8.GA</version.org.jboss_jboss.common.core>
+ <version.org.jboss_jboss.reflect>2.0.0.GA</version.org.jboss_jboss.reflect>
+ <version.apache_xerces_xml.apis>2.9.1</version.apache_xerces_xml.apis>
+ <version.apache_xerces_xercesImpl>2.9.1</version.apache_xerces_xercesImpl>
+ <version.wutka_dtdparser_dtdparser121>1.2.1</version.wutka_dtdparser_dtdparser121>
+ <version.javax.activation_activation>1.1.1</version.javax.activation_activation>
+ <version.log4j_log4j>1.2.14</version.log4j_log4j>
+ <version.org.jboss.man_jboss.managed>2.0.0.GA</version.org.jboss.man_jboss.managed>
+ <version.org.jboss.man_jboss.metatype>2.0.0.GA</version.org.jboss.man_jboss.metatype>
+ <version.org.jboss_jboss.mdr>2.0.1.GA</version.org.jboss_jboss.mdr>
+ <version.sun_jaxb_jaxb_api>2.1.4</version.sun_jaxb_jaxb_api>
+ <version.org.jboss.microcontainer_jboss.dependency>2.0.4.GA</version.org.jboss.microcontainer_jboss.dependency>
+
+ </properties>
+
+ <!-- Build -->
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <includeScope>runtime</includeScope>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ <stripVersion>true</stripVersion>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-spi</artifactId>
+ <version>${version.org.jboss.bootstrap_jboss.bootstrap.spi}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-spi-mc</artifactId>
+ <version>${version.org.jboss.bootstrap_jboss.bootstrap.spi.mc}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-impl-base</artifactId>
+ <version>${version.org.jboss.bootstrap_jboss.bootstrap.impl.base}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-impl-mc</artifactId>
+ <version>${version.org.jboss.bootstrap_jboss.bootstrap.impl.mc}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <version>${version.org.jboss.logging_jboss.logging.spi}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <version>${version.org.jboss.logging_jboss.logging.log4j}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ <version>${version.org.jboss.microcontainer_jboss.kernel}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossxb</artifactId>
+ <version>${version.org.jboss_jbossxb}</version>
+ </artifactItem>
+
+
+ <artifactItem>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <version>${version.org.jboss_jboss.common.core}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ <version>${version.org.jboss_jboss.reflect}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>apache-xerces</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>${version.apache_xerces_xml.apis}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>apache-xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>${version.apache_xerces_xercesImpl}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>wutka-dtdparser</groupId>
+ <artifactId>dtdparser121</artifactId>
+ <version>${version.wutka_dtdparser_dtdparser121}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>${version.javax.activation_activation}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${version.log4j_log4j}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>${version.org.jboss.man_jboss.managed}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ <version>${version.org.jboss.man_jboss.metatype}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-mdr</artifactId>
+ <version>${version.org.jboss_jboss.mdr}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>sun-jaxb</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>${version.sun_jaxb_jaxb_api}</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-dependency</artifactId>
+ <version>${version.org.jboss.microcontainer_jboss.dependency}</version>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+
+ The ONLY dependencies allowed in this section are upon the
+ Bootstrap SPIs and JUnit. Anything else will either fail the tests
+ or render them invalid. The purpose of this project is to ensure
+ that the Server may be launched with *only* the bootstrap SPIs
+ upon the application classpath. Other dependencies must be added
+ to the dependency plugin configuration to be placed in target/lib.
+ -->
+
+ <dependency>
+ <groupId>org.jboss.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-spi-mc</artifactId>
+ <version>${version.org.jboss.bootstrap_jboss.bootstrap.spi.mc}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+</project>
Added: projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/bootstrap/spi/test/ClassLoadingTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/bootstrap/spi/test/ClassLoadingTestCase.java (rev 0)
+++ projects/bootstrap/trunk/spi-test/src/test/java/org/jboss/bootstrap/spi/test/ClassLoadingTestCase.java 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,306 @@
+/*
+ * 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.bootstrap.spi.test;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.bootstrap.spi.mc.server.MCServer;
+import org.jboss.bootstrap.spi.mc.server.MCServerFactory;
+import org.junit.Test;
+
+/**
+ * ClassLoadingTestCase
+ *
+ * Tests to ensure that the Server may be started with nothing but
+ * the SPIs on the application classpath (==extension ClassLoader).
+ * The runtime libraries required for start may be added
+ * by the caller, and this asserts that ClassLoader
+ * visibility/accessibility is intact.
+ *
+ * The build for this project will have declared dependencies *only*
+ * upon the Bootstrap SPIs (and JUnit), and places runtime dependencies
+ * in target/lib.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ClassLoadingTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Location of the lib directory relative to the compile target
+ */
+ private static final String LOCATION_LIB = "../lib/";
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the Server may be created and started when its runtime
+ * dependencies are *not* available upon the application classpath. Must
+ * create a new ClassLoader to add the appropriate libs.
+ *
+ * This method intentionally throws no Exceptions to be self-documenting
+ * as to the usage of the SPI Factories.
+ */
+ @Test
+ public void testServerStart()
+ {
+ // Log
+ getOut().println("In testServerStart");
+
+ // First ensure we can't see the server impl class
+ final Thread currentThread = Thread.currentThread();
+ final ClassLoader appCl = currentThread.getContextClassLoader();
+ this.assertServerImplNotVisibleFromClassLoader(appCl);
+
+ // Construct a new CL with the runtime deps visible
+ final ClassLoader runtimeCl = this.getRuntimeDepsCl(appCl);
+
+ // Set the runtimeCL
+ currentThread.setContextClassLoader(runtimeCl);
+
+ // Everything here in a "try" so we may reset the TCCL in "finally"
+ try
+ {
+
+ // Create the server
+ final MCServer server = MCServerFactory.createServerWithDefaultConfiguration(runtimeCl);
+ getOut().println("Got Server: " + server);
+
+ // Configure it
+ final URL bootstrapHome = this.getTarget();
+ server.getConfiguration().bootstrapHome(bootstrapHome);
+ getOut().println("Configured bootstrap home: " + bootstrapHome);
+
+ // Ensure not started
+ if (!server.getState().equals(LifecycleState.PRE_INIT))
+ {
+ TestCase.fail("Test has server reporting the wrong state before started");
+ }
+
+ /*
+ * Start the server
+ */
+ getOut().println("Starting server...");
+ final long start = System.currentTimeMillis();
+ long end = 0;
+ try
+ {
+ // Start
+ server.start();
+ end = System.currentTimeMillis();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not start server", e);
+ }
+ final long time = end - start;
+ getOut().println("Server started in " + time + "ms");
+
+ // Ensure started
+ if (!server.getState().equals(LifecycleState.STARTED))
+ {
+ TestCase.fail("Server is not reporting as started");
+ }
+
+ }
+ finally
+ {
+ // Reset TCCL
+ currentThread.setContextClassLoader(appCl);
+ }
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the MC Server Implementation Class
+ * is not visibile from the specified ClassLoader
+ *
+ * @param cl
+ */
+ private void assertServerImplNotVisibleFromClassLoader(final ClassLoader cl)
+ {
+ // Initialize
+ boolean gotExpectedCnfe = false;
+
+ // Get the class impl name
+ final String serverImplClassName = MCServerFactory.DEFAULT_MC_SERVER_IMPL_CLASS_NAME;
+
+ // Log
+ getOut().println("Attempting to obtain " + serverImplClassName + " from " + cl + "...");
+
+ // Try to load
+ Class<?> serverImplClass = null;
+ try
+ {
+ serverImplClass = Class.forName(serverImplClassName, false, cl);
+ }
+ catch (ClassNotFoundException e)
+ {
+ gotExpectedCnfe = true;
+ getOut().println("Failed as expected");
+ }
+
+ // Test
+ final ClassLoader loadingCl = serverImplClass != null ? serverImplClass.getClassLoader() : null;
+ TestCase.assertTrue("Error in test setup, server implementation class was obtained via " + cl
+ + " and had loading CL " + loadingCl + ": " + serverImplClass, gotExpectedCnfe);
+ }
+
+ /**
+ * Returns a ClassLoader with the runtime dependencies
+ * visible
+ *
+ * @return
+ */
+ private ClassLoader getRuntimeDepsCl(final ClassLoader parent)
+ {
+ // Make Set of URLs to add to CP
+ final Set<URL> urls = new HashSet<URL>();
+
+ // Get libs to add
+ final File[] libs = this.getLibs();
+
+ // Add all
+ if (libs != null)
+ {
+ for (File lib : libs)
+ {
+ try
+ {
+ URL url = lib.toURL();
+ getOut().println("Adding to CP: " + url);
+ urls.add(url);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ getOut().println("All Runtime Dependencies for new CL: " + this.getTargetLib());
+ getOut().println(urls);
+ URL[] urlArray = urls.toArray(new URL[]
+ {});
+
+ // Construct the new CL
+ final ClassLoader urlCl = new URLClassLoader(urlArray, parent);
+
+ // Return
+ return urlCl;
+ }
+
+ /**
+ * Obtains the home of this test's CP (target)
+ */
+ private URL getTarget()
+ {
+ return this.getClass().getProtectionDomain().getCodeSource().getLocation();
+ }
+
+ /**
+ * Obtains the location in which the runtime libs (JARs) are placed by
+ * the build
+ *
+ * @return
+ */
+ private URL getTargetLib()
+ {
+ // Get the target base
+ final URL base = this.getTarget();
+
+ try
+ {
+ // Return the lib location relative to the target
+ return new URL(base, LOCATION_LIB);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("Error in test setup, could not get lib location", e);
+ }
+
+ }
+
+ /**
+ * Obtains all runtime dependency libraries
+ *
+ * @return
+ */
+ private File[] getLibs()
+ {
+ // Get the location of the libs
+ final URL libUrl = this.getTargetLib();
+
+ // Make a File from the lib directory
+ File libDir = null;
+ try
+ {
+ libDir = new File(libUrl.toURI());
+ }
+ catch (URISyntaxException e)
+ {
+ throw new RuntimeException("Error in test setup", e);
+ }
+
+ // Ensure it's a directory
+ TestCase.assertNotNull("Problem in test setup, lib directory is null", libDir);
+ TestCase.assertTrue("Problem in test setup, lib dir is not a directory: " + libDir, libDir.isDirectory());
+
+ // Return all contents
+ return libDir.listFiles();
+ }
+
+ /**
+ * Returns the stream to which we'll print logging messages
+ * (as jboss-logging and log4j is not permitted as a dependency
+ * of this project).
+ *
+ * Maven or Eclipse IDE will capture this output and put it somewhere
+ * appropriate
+ *
+ * @return
+ */
+ private static PrintStream getOut()
+ {
+ return System.out;
+ }
+}
Added: projects/bootstrap/trunk/spi-test/src/test/resources/bootstrap.xml
===================================================================
--- projects/bootstrap/trunk/spi-test/src/test/resources/bootstrap.xml (rev 0)
+++ projects/bootstrap/trunk/spi-test/src/test/resources/bootstrap.xml 2009-04-15 16:00:02 UTC (rev 87362)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bootstrap xmlns="urn:jboss:bootstrap:1.0">
+
+
+ <!--
+ Dummy file for testing, would ordinarily contain:
+
+ <url>something.xml</url>
+ -->
+
+</bootstrap>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list