Author: sohil.shah(a)jboss.com
Date: 2010-06-05 12:09:30 -0400 (Sat, 05 Jun 2010)
New Revision: 1125
Added:
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java
authz/gatein/authz-plugin/trunk/tools/
authz/gatein/authz-plugin/trunk/tools/pom.xml
authz/gatein/authz-plugin/trunk/tools/src/
authz/gatein/authz-plugin/trunk/tools/src/main/
authz/gatein/authz-plugin/trunk/tools/src/main/java/
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/gatein/
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/gatein/authz/
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/gatein/authz/tools/
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/gatein/authz/tools/ContainerBuilder.java
Removed:
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/ContainerBuilder.java
Modified:
authz/gatein/authz-plugin/trunk/.classpath
authz/gatein/authz-plugin/trunk/pom.xml
authz/gatein/authz-plugin/trunk/service/pom.xml
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java
Log:
Tools component for kernel bootstrapping and other common utilities
Modified: authz/gatein/authz-plugin/trunk/.classpath
===================================================================
--- authz/gatein/authz-plugin/trunk/.classpath 2010-06-05 15:25:52 UTC (rev 1124)
+++ authz/gatein/authz-plugin/trunk/.classpath 2010-06-05 16:09:30 UTC (rev 1125)
@@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="src" path="service/src/main/java"/>
<classpathentry kind="src" path="service/src/test/java"/>
+ <classpathentry kind="src" path="tools/src/main/java"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con"
path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
Modified: authz/gatein/authz-plugin/trunk/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/pom.xml 2010-06-05 15:25:52 UTC (rev 1124)
+++ authz/gatein/authz-plugin/trunk/pom.xml 2010-06-05 16:09:30 UTC (rev 1125)
@@ -10,6 +10,7 @@
<modules>
<module>service</module>
+ <module>tools</module>
</modules>
<properties>
Modified: authz/gatein/authz-plugin/trunk/service/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/service/pom.xml 2010-06-05 15:25:52 UTC (rev 1124)
+++ authz/gatein/authz-plugin/trunk/service/pom.xml 2010-06-05 16:09:30 UTC (rev 1125)
@@ -16,6 +16,12 @@
<dependencies>
<dependency>
+ <groupId>org.jboss.gatein.authz.tools</groupId>
+ <artifactId>tools</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.exoplatform.kernel</groupId>
<artifactId>exo.kernel.commons</artifactId>
</dependency>
Added:
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java
===================================================================
---
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java
(rev 0)
+++
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java 2010-06-05
16:09:30 UTC (rev 1125)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt 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.gatein.authz.service;
+
+import java.net.URL;
+
+import org.exoplatform.container.PortalContainer;
+import org.jboss.gatein.authz.tools.ContainerBuilder;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public final class SecurityService
+{
+ public SecurityService()
+ {
+
+ }
+
+ public void start()
+ {
+ //TODO: log message using GateIn Logging Framework
+ URL rootURL =
getClass().getResource("/conf/gatein-authz-configuration.xml");
+ URL portalURL =
getClass().getResource("/conf/portal/gatein-authz-configuration.xml");
+ new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
+ }
+
+ public void stop()
+ {
+
+ }
+
+ public PortalContainer getContainer()
+ {
+ return PortalContainer.getInstance();
+ }
+}
Deleted:
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/ContainerBuilder.java
===================================================================
---
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/ContainerBuilder.java 2010-06-05
15:25:52 UTC (rev 1124)
+++
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/ContainerBuilder.java 2010-06-05
16:09:30 UTC (rev 1125)
@@ -1,258 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.gatein.authz.service;
-
-import junit.framework.AssertionFailedError;
-import org.exoplatform.commons.utils.PropertyManager;
-import org.exoplatform.commons.utils.Tools;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.container.RootContainer;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * <p>An helper for building a root container and a portal container. I have done
several attempt to make easily
- * and safe root/portal container boot for unit test. This one is my best attempt so
far.</p>
- *
- * <p>Note that the portal container are booted in the order they are declared
first.</p>
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public class ContainerBuilder
-{
-
- /** A hack used during the boot of a portal container. */
- private final ThreadLocal<String> bootedPortalName = new
ThreadLocal<String>();
-
- /** . */
- private ClassLoader loader;
-
- /** . */
- private List<URL> configURLs;
-
- /** . */
- private LinkedHashMap<String, List<URL>> portalConfigURLs;
-
- /** . */
- private Set<String> profiles;
-
- public ContainerBuilder()
- {
- this.loader = Thread.currentThread().getContextClassLoader();
- this.configURLs = new ArrayList<URL>();
- this.portalConfigURLs = new LinkedHashMap<String, List<URL>>();
- }
-
- public ContainerBuilder withRoot(String configPath)
- {
- configURLs.addAll(urls(configPath));
- return this;
- }
-
- public ContainerBuilder withRoot(URL configURL)
- {
- configURLs.add(configURL);
- return this;
- }
-
- public ContainerBuilder withPortal(String configPath)
- {
- return withPortal("portal", configPath);
- }
-
- public ContainerBuilder withPortal(String portalName, String configPath)
- {
- for (URL configURL : urls(configPath))
- {
- withPortal(portalName, configURL);
- }
- return this;
- }
-
- public ContainerBuilder withPortal(URL configURL)
- {
- return withPortal("portal", configURL);
- }
-
- public ContainerBuilder withPortal(String portalName, URL configURL)
- {
- List<URL> urls = portalConfigURLs.get(portalName);
- if (urls == null)
- {
- urls = new ArrayList<URL>();
- portalConfigURLs.put(portalName, urls);
- }
- urls.add(configURL);
- return this;
- }
-
- public ContainerBuilder withLoader(ClassLoader loader)
- {
- this.loader = loader;
- return this;
- }
-
-
- private List<URL> urls(String path)
- {
- try
- {
- return Collections.list(loader.getResources(path));
- }
- catch (IOException e)
- {
- AssertionFailedError err = new AssertionFailedError();
- err.initCause(e);
- throw err;
- }
- }
-
- public RootContainer build()
- {
- try
- {
- return _build();
- }
- catch (Exception e)
- {
- AssertionFailedError err = new AssertionFailedError();
- err.initCause(e);
- throw err;
- }
- }
-
- private RootContainer _build() throws Exception
- {
- //
- if (configURLs.size() == 0)
- {
- throw new IllegalStateException("Must provide at least one URL for building
the root container");
- }
-
- // Must clear the top container first otherwise it's not going to work well
- // it's a big ugly but I don't want to change anything in the
ExoContainerContext class for now
- // and this is for unit testing
- Field topContainerField =
ExoContainerContext.class.getDeclaredField("topContainer");
- topContainerField.setAccessible(true);
- topContainerField.set(null, null);
-
- // Same remark than above
- Field singletonField =
RootContainer.class.getDeclaredField("singleton_");
- singletonField.setAccessible(true);
- singletonField.set(null, null);
-
- // Setup profiles
- if (profiles == null)
- {
- PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES, "");
- }
- else
- {
- StringBuilder builder = new StringBuilder();
- for (Iterator<String> i = profiles.iterator();i.hasNext();)
- {
- builder.append(i.next());
- if (i.hasNext())
- {
- builder.append(',');
- }
- }
- PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES,
builder.toString());
- }
-
- //
- ClassLoader rootCL = new ClassLoader(loader)
- {
- @Override
- public Enumeration<URL> getResources(String name) throws IOException
- {
- if ("conf/configuration.xml".equals(name))
- {
- return Collections.enumeration(configURLs);
- }
- else if ("conf/portal/configuration.xml".equals(name))
- {
- String portalName = bootedPortalName.get();
- return Collections.enumeration(portalConfigURLs.get(portalName));
- }
- else if ("conf/portal/test-configuration.xml".equals(name))
- {
- return Collections.enumeration(Collections.<URL>emptyList());
- }
- else
- {
- return super.getResources(name);
- }
- }
- };
-
- //
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
-
- // Boot root container
- RootContainer root;
- try
- {
- Thread.currentThread().setContextClassLoader(rootCL);
-
- //
- root = RootContainer.getInstance();
-
- //
- for (String portalName : portalConfigURLs.keySet())
- {
- try
- {
- bootedPortalName.set(portalName);
- root.getPortalContainer(portalName);
- }
- finally
- {
- bootedPortalName.set(null);
- }
- }
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
-
- //
- return root;
- }
-
- public static RootContainer bootstrap(URL configurationURL, String... profiles)
- {
- ContainerBuilder builder = new ContainerBuilder();
- builder.withRoot(configurationURL);
- return builder.build();
- }
-}
Modified:
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java
===================================================================
---
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java 2010-06-05
15:25:52 UTC (rev 1124)
+++
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java 2010-06-05
16:09:30 UTC (rev 1125)
@@ -22,21 +22,22 @@
******************************************************************************/
package org.jboss.gatein.authz.service;
-import java.net.URL;
+import org.exoplatform.container.PortalContainer;
-import org.exoplatform.container.PortalContainer;
import org.jboss.security.authz.policy.server.event.LocalEventBus;
import org.jboss.security.authz.policy.server.tools.HibernateService;
import org.jboss.security.authz.policy.server.provisioning.RelationalDBPolicyStore;
import org.jboss.security.authz.policy.server.plugin.DroolsRuleManager;
import org.jboss.security.authz.policy.server.decision.PolicyDecisionPoint;
+import org.jboss.security.authz.policy.server.PolicyServer;
+
+import org.jboss.gatein.authz.service.SecurityService;
import org.jboss.gatein.authz.service.PolicyServerComponent;
import org.jboss.gatein.authz.service.decision.PolicyDecisionPointComponent;
import org.jboss.gatein.authz.service.event.LocalEventBusComponent;
import org.jboss.gatein.authz.service.plugin.DroolsRuleManagerComponent;
import org.jboss.gatein.authz.service.provisioning.RelationalDBPolicyStoreComponent;
import org.jboss.gatein.authz.service.tools.HibernateServiceComponent;
-import org.jboss.security.authz.policy.server.PolicyServer;
import junit.framework.TestCase;
@@ -45,14 +46,26 @@
*
*/
public class TestKernelStartup extends TestCase
-{
+{
+ private SecurityService securityService;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ this.securityService = new SecurityService();
+ this.securityService.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ this.securityService.stop();
+ }
+
+
public void testStartup() throws Exception
- {
- URL rootURL =
getClass().getResource("/conf/gatein-authz-configuration.xml");
- URL portalURL =
getClass().getResource("/conf/portal/gatein-authz-configuration.xml");
- new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
-
- PortalContainer portal = PortalContainer.getInstance();
+ {
+ PortalContainer portal = this.securityService.getContainer();
//Integrating the EventBus service
LocalEventBusComponent eventBusComponent =
(LocalEventBusComponent)portal.getComponentInstanceOfType(LocalEventBusComponent.class);
Added: authz/gatein/authz-plugin/trunk/tools/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/tools/pom.xml (rev 0)
+++ authz/gatein/authz-plugin/trunk/tools/pom.xml 2010-06-05 16:09:30 UTC (rev 1125)
@@ -0,0 +1,53 @@
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.gatein.authz</groupId>
+ <artifactId>gatein-authz-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.jboss.gatein.authz.tools</groupId>
+ <artifactId>tools</artifactId>
+ <name>tools</name>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.cache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.command</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.ext.cache.impl.jboss.v3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>picocontainer</groupId>
+ <artifactId>picocontainer</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added:
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/gatein/authz/tools/ContainerBuilder.java
===================================================================
---
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/gatein/authz/tools/ContainerBuilder.java
(rev 0)
+++
authz/gatein/authz-plugin/trunk/tools/src/main/java/org/jboss/gatein/authz/tools/ContainerBuilder.java 2010-06-05
16:09:30 UTC (rev 1125)
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.gatein.authz.tools;
+
+import junit.framework.AssertionFailedError;
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.Tools;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.RootContainer;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * <p>An helper for building a root container and a portal container. I have done
several attempt to make easily
+ * and safe root/portal container boot for unit test. This one is my best attempt so
far.</p>
+ *
+ * <p>Note that the portal container are booted in the order they are declared
first.</p>
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ContainerBuilder
+{
+
+ /** A hack used during the boot of a portal container. */
+ private final ThreadLocal<String> bootedPortalName = new
ThreadLocal<String>();
+
+ /** . */
+ private ClassLoader loader;
+
+ /** . */
+ private List<URL> configURLs;
+
+ /** . */
+ private LinkedHashMap<String, List<URL>> portalConfigURLs;
+
+ /** . */
+ private Set<String> profiles;
+
+ public ContainerBuilder()
+ {
+ this.loader = Thread.currentThread().getContextClassLoader();
+ this.configURLs = new ArrayList<URL>();
+ this.portalConfigURLs = new LinkedHashMap<String, List<URL>>();
+ }
+
+ public ContainerBuilder withRoot(String configPath)
+ {
+ configURLs.addAll(urls(configPath));
+ return this;
+ }
+
+ public ContainerBuilder withRoot(URL configURL)
+ {
+ configURLs.add(configURL);
+ return this;
+ }
+
+ public ContainerBuilder withPortal(String configPath)
+ {
+ return withPortal("portal", configPath);
+ }
+
+ public ContainerBuilder withPortal(String portalName, String configPath)
+ {
+ for (URL configURL : urls(configPath))
+ {
+ withPortal(portalName, configURL);
+ }
+ return this;
+ }
+
+ public ContainerBuilder withPortal(URL configURL)
+ {
+ return withPortal("portal", configURL);
+ }
+
+ public ContainerBuilder withPortal(String portalName, URL configURL)
+ {
+ List<URL> urls = portalConfigURLs.get(portalName);
+ if (urls == null)
+ {
+ urls = new ArrayList<URL>();
+ portalConfigURLs.put(portalName, urls);
+ }
+ urls.add(configURL);
+ return this;
+ }
+
+ public ContainerBuilder withLoader(ClassLoader loader)
+ {
+ this.loader = loader;
+ return this;
+ }
+
+
+ private List<URL> urls(String path)
+ {
+ try
+ {
+ return Collections.list(loader.getResources(path));
+ }
+ catch (IOException e)
+ {
+ AssertionFailedError err = new AssertionFailedError();
+ err.initCause(e);
+ throw err;
+ }
+ }
+
+ public RootContainer build()
+ {
+ try
+ {
+ return _build();
+ }
+ catch (Exception e)
+ {
+ AssertionFailedError err = new AssertionFailedError();
+ err.initCause(e);
+ throw err;
+ }
+ }
+
+ private RootContainer _build() throws Exception
+ {
+ //
+ if (configURLs.size() == 0)
+ {
+ throw new IllegalStateException("Must provide at least one URL for building
the root container");
+ }
+
+ // Must clear the top container first otherwise it's not going to work well
+ // it's a big ugly but I don't want to change anything in the
ExoContainerContext class for now
+ // and this is for unit testing
+ Field topContainerField =
ExoContainerContext.class.getDeclaredField("topContainer");
+ topContainerField.setAccessible(true);
+ topContainerField.set(null, null);
+
+ // Same remark than above
+ Field singletonField =
RootContainer.class.getDeclaredField("singleton_");
+ singletonField.setAccessible(true);
+ singletonField.set(null, null);
+
+ // Setup profiles
+ if (profiles == null)
+ {
+ PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES, "");
+ }
+ else
+ {
+ StringBuilder builder = new StringBuilder();
+ for (Iterator<String> i = profiles.iterator();i.hasNext();)
+ {
+ builder.append(i.next());
+ if (i.hasNext())
+ {
+ builder.append(',');
+ }
+ }
+ PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES,
builder.toString());
+ }
+
+ //
+ ClassLoader rootCL = new ClassLoader(loader)
+ {
+ @Override
+ public Enumeration<URL> getResources(String name) throws IOException
+ {
+ if ("conf/configuration.xml".equals(name))
+ {
+ return Collections.enumeration(configURLs);
+ }
+ else if ("conf/portal/configuration.xml".equals(name))
+ {
+ String portalName = bootedPortalName.get();
+ return Collections.enumeration(portalConfigURLs.get(portalName));
+ }
+ else if ("conf/portal/test-configuration.xml".equals(name))
+ {
+ return Collections.enumeration(Collections.<URL>emptyList());
+ }
+ else
+ {
+ return super.getResources(name);
+ }
+ }
+ };
+
+ //
+ ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+
+ // Boot root container
+ RootContainer root;
+ try
+ {
+ Thread.currentThread().setContextClassLoader(rootCL);
+
+ //
+ root = RootContainer.getInstance();
+
+ //
+ for (String portalName : portalConfigURLs.keySet())
+ {
+ try
+ {
+ bootedPortalName.set(portalName);
+ root.getPortalContainer(portalName);
+ }
+ finally
+ {
+ bootedPortalName.set(null);
+ }
+ }
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ }
+
+ //
+ return root;
+ }
+
+ public static RootContainer bootstrap(URL configurationURL, String... profiles)
+ {
+ ContainerBuilder builder = new ContainerBuilder();
+ builder.withRoot(configurationURL);
+ return builder.build();
+ }
+}