Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-2980 Improved Modularization
Browse files Browse the repository at this point in the history
- move third-party libraries out of org.gatein.lib
- don't export any dependencies from org.gatein.lib
- reintroduce the necessary TCCL resources to portal.war by using jboss-deployment-structure.xml instead of MANIFEST.MF
- introduce 'bom' modules org.gatein.portal.container-dependencies, and org.gatein.portal.container-dependencies-basic
  • Loading branch information
mstruk committed May 7, 2013
1 parent da7dfa2 commit ec04ced
Show file tree
Hide file tree
Showing 48 changed files with 1,368 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public DelegatingClassLoader(ClassLoader... delegates) {
}

@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class cl;

for (ClassLoader delegate : delegates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.cache.CacheService;
import org.exoplatform.services.database.impl.HibernateServiceImpl;
import org.gatein.common.classloader.DelegatingClassLoader;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.cfg.Configuration;
Expand Down Expand Up @@ -82,7 +83,33 @@ public void sessionFactoryClosed(SessionFactory factory) {
((StandardServiceRegistryImpl) serviceRegistry).destroy();
}
});
return conf.buildSessionFactory(serviceRegistry);

final ClassLoader old = SecurityHelper.doPrivilegedAction(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});

try {
SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>() {
public Void run() {
DelegatingClassLoader cl = new DelegatingClassLoader(old,
org.picketlink.idm.api.IdentitySessionFactory.class.getClassLoader());
Thread.currentThread().setContextClassLoader(cl);
return null;
}
});
return conf.buildSessionFactory(serviceRegistry);
} finally {
if (old != null) {
SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>() {
public Void run() {
Thread.currentThread().setContextClassLoader(old);
return null;
}
});
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -32,6 +33,8 @@

import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyCodeSource;
import org.exoplatform.commons.utils.SecurityHelper;
import org.gatein.common.classloader.DelegatingClassLoader;

/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
Expand Down Expand Up @@ -178,7 +181,7 @@ public GroovyScript build() throws TemplateCompilationException {
//
InputStream in = new ByteArrayInputStream(bytes);
GroovyCodeSource gcs = new GroovyCodeSource(in, templateName, "/groovy/shell");
GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), config);
GroovyClassLoader loader = new GroovyClassLoader(prepareClassLoader(), config);
Class<?> scriptClass;
try {
scriptClass = loader.parseClass(gcs, false);
Expand All @@ -192,6 +195,18 @@ public GroovyScript build() throws TemplateCompilationException {
Collections.unmodifiableMap(new HashMap<Integer, TextItem>(script.positionTable)));
}

private ClassLoader prepareClassLoader() {
final ClassLoader tccl = SecurityHelper.doPrivilegedAction(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});

return new DelegatingClassLoader(tccl,
GroovyClassLoader.class.getClassLoader(),
javax.portlet.PortletConfig.class.getClassLoader());
}

/**
* Internal representation of a script
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ public static boolean isGateInArchive(DeploymentUnit du) {
return du.hasAttachment(GateInEarKey.KEY) || du.hasAttachment(GateInExtKey.KEY);
}

public static boolean isGateInArchiveOrSubDeployment(DeploymentUnit du) {
boolean ret = du.hasAttachment(GateInEarKey.KEY) || du.hasAttachment(GateInExtKey.KEY);
if (ret) {
return true;
}
if (du.getParent() != null) {
return isGateInArchive(du.getParent());
}
return false;
}

public static boolean isPortletArchive(DeploymentUnit du) {
return du.hasAttachment(PortletWarKey.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,42 @@
*/
package org.gatein.integration.jboss.as7.deployment;

import java.util.List;

import org.gatein.integration.jboss.as7.GateInConfiguration;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ModuleDependency;
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.as.server.moduleservice.ServiceModuleLoader;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoader;

/**
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class GateInDependenciesDeploymentProcessor implements DeploymentUnitProcessor {

final ModuleIdentifier gateInLibId = ModuleIdentifier.fromString("org.gatein.lib");
private static final ModuleDependency GATEIN_LIB;
private static final ModuleDependency GATEIN_WCI;

static {
ModuleLoader loader = Module.getBootModuleLoader();

GATEIN_LIB = new ModuleDependency(loader, ModuleIdentifier.fromString("org.gatein.lib"), false, false, true, false);
GATEIN_WCI = new ModuleDependency(loader, ModuleIdentifier.fromString("org.gatein.wci"), false, false, true, false);
}

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit du = phaseContext.getDeploymentUnit();

if (GateInConfiguration.isGateInOrPortletArchive(du)) {
if (GateInConfiguration.isGateInArchiveOrSubDeployment(du) || GateInConfiguration.isPortletArchive(du)) {
// add dependency on org.gatein.lib
List<ModuleDependency> dependencies = du.getAttachmentList(Attachments.MANIFEST_DEPENDENCIES);

if (!containsDependency(dependencies, gateInLibId)) {
du.addToAttachmentList(Attachments.MANIFEST_DEPENDENCIES, new ModuleDependency(Module.getBootModuleLoader(),
gateInLibId, false, false, true, false));
}
ModuleSpecification moduleSpec = du.getAttachment(Attachments.MODULE_SPECIFICATION);
moduleSpec.addSystemDependency(GATEIN_LIB);
moduleSpec.addSystemDependency(GATEIN_WCI);

// add gatein deployment modules cross-dependencies
ModuleIdentifier moduleId = du.getAttachment(Attachments.MODULE_IDENTIFIER);
Expand All @@ -61,35 +66,20 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
final ServiceModuleLoader deploymentModuleLoader = du.getAttachment(Attachments.SERVICE_MODULE_LOADER);

if (!moduleId.equals(config.getGateInEarModule())) {
if (!containsDependency(dependencies, config.getGateInEarModule())) {
du.addToAttachmentList(Attachments.MANIFEST_DEPENDENCIES, new ModuleDependency(deploymentModuleLoader,
config.getGateInEarModule(), false, false, false, false));
}
moduleSpec.addSystemDependency(new ModuleDependency(deploymentModuleLoader,
config.getGateInEarModule(), false, false, false, false));
}

for (ModuleIdentifier id : config.getGateInExtModules()) {
if (!moduleId.equals(id)) {
if (!containsDependency(dependencies, id)) {
du.addToAttachmentList(Attachments.MANIFEST_DEPENDENCIES, new ModuleDependency(
deploymentModuleLoader, id, false, false, false, false));
}
moduleSpec.addSystemDependency(new ModuleDependency(deploymentModuleLoader,
id, false, false, false, false));
}
}
}
}
}

private boolean containsDependency(List<ModuleDependency> dependencies, ModuleIdentifier moduleId) {
boolean exists = false;
for (ModuleDependency dep : dependencies) {
if (dep.getIdentifier().equals(moduleId)) {
exists = true;
break;
}
}
return exists;
}

public void undeploy(DeploymentUnit context) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PortletBridgeDependencyProcessor implements DeploymentUnitProcessor

private static final ModuleIdentifier CDI_PORTLET_INTEGRATION = ModuleIdentifier
.create("org.gatein.cdi-portlet-integration");
private static final ModuleIdentifier COMMONS_FILEUPLOAD = ModuleIdentifier.create("org.apache.commons-fileupload");
private static final ModuleIdentifier COMMONS_FILEUPLOAD = ModuleIdentifier.create("org.apache.commons.fileupload");
private static final ModuleIdentifier JSF_API = ModuleIdentifier.create("javax.faces.api");
private static final ModuleIdentifier JSF_IMPL = ModuleIdentifier.create("com.sun.jsf-impl");
private static final ModuleIdentifier PORTLETBRIDGE_API = ModuleIdentifier.create("org.jboss.portletbridge.api");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,10 @@ public class StartupService implements Service<StartupService> {

@Override
public void start(StartContext context) throws StartException {
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
// set TCCL to this module's CL
Thread.currentThread().setContextClassLoader(module.getClassLoader());

// Trigger startup
RootContainer rootContainer = RootContainer.getInstance();
rootContainer.createPortalContainers();
RootContainer.getInstance().createPortalContainers();
} finally {
if (Thread.currentThread().getContextClassLoader() != oldCl) {
Thread.currentThread().setContextClassLoader(oldCl);
}

// Startup message
log.info(Version.prettyVersion + " started.");
}
Expand Down

0 comments on commit ec04ced

Please sign in to comment.