Author: reinhard
Date: Sun Oct 9 05:17:33 2005
New Revision: 307410
URL: http://svn.apache.org/viewcvs?rev=307410&view=rev
Log:
rework classloading:
- add all [block]/COB-INF/classes directories to the classpath
(information is read out from wiring.xml)
- do classloading in CoreUtil only (remove it from environment)
open tasks:
- use ReloadingClassloader instead of URLClassLoader
- make it possible to use packaged blocks too
- StatusGenerator doesn't show the context classloader information
Added:
cocoon/trunk/src/java/org/apache/cocoon/core/WiringNotFoundException.java (with props)
cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGICoreUtil.java (with props)
Modified:
cocoon/trunk/src/java/org/apache/cocoon/Constants.java
cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java
cocoon/trunk/src/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java
cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java
cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java
cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
cocoon/trunk/src/test/org/apache/cocoon/test/SitemapTestCase.java
cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java
cocoon/trunk/src/test/org/apache/cocoon/test/core/TestCoreUtil.java
Modified: cocoon/trunk/src/java/org/apache/cocoon/Constants.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/Constants.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/Constants.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/Constants.java Sun Oct 9 05:17:33 2005
@@ -211,6 +211,11 @@
/** Application <code>Context</code> key prefix for the current sitemap virtual
components */
public static final String CONTEXT_VPC_PREFIX = "vpc-";
+ /** Path to the wiring.xml relative to the context root directory */
+ public static final String WIRING = "wiring.xml";
+
+ public static final String BLOCK_META_DIR = "COB-INF";
+
/**
* Application <code>Context</code> Key for the URL to the configuration
file
* (usually named cocoon.xconf)
@@ -222,16 +227,5 @@
* @deprecated Use {@link org.apache.cocoon.core.Settings#getFormEncoding()}. */
public static final String CONTEXT_DEFAULT_ENCODING = "default-encoding";
-}
-
-
-
-
-
-
-
-
-
-
-
-
+
+}
\ No newline at end of file
Modified: cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java Sun Oct 9 05:17:33 2005
@@ -41,7 +41,6 @@
import org.apache.cocoon.core.BootstrapEnvironment;
import org.apache.cocoon.core.CoreUtil;
import org.apache.cocoon.core.MutableSettings;
-import org.apache.cocoon.core.Settings;
import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.commandline.CommandLineContext;
@@ -671,13 +670,6 @@
}
/**
- * @see org.apache.cocoon.core.BootstrapEnvironment#getClassPath(org.apache.cocoon.core.Settings)
- */
- public String getClassPath(Settings settings) {
- return null;
- }
-
- /**
* @see org.apache.cocoon.core.BootstrapEnvironment#getConfigFile(java.lang.String)
*/
public URL getConfigFile(String configFileName) throws Exception {
@@ -707,13 +699,6 @@
*/
public Context getEnvironmentContext() {
return this.environmentContext;
- }
-
- /**
- * @see org.apache.cocoon.core.BootstrapEnvironment#getInitClassLoader()
- */
- public ClassLoader getInitClassLoader() {
- return CocoonWrapper.class.getClassLoader();
}
/**
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
Sun Oct 9 05:17:33 2005
@@ -157,11 +157,11 @@
public void addResourceStore(final ResourceStore pStore) {
- final int n = stores.length;
+ final int n = this.stores.length;
final ResourceStore[] newStores = new ResourceStore[n + 1];
- System.arraycopy(stores, 0, newStores, 0, n);
+ System.arraycopy(this.stores, 0, newStores, 0, n);
newStores[n] = pStore;
- stores = newStores;
+ this.stores = newStores;
if (getLogger().isDebugEnabled()) {
getLogger().debug("added store " + stores);
}
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
Sun Oct 9 05:17:33 2005
@@ -417,7 +417,8 @@
// We need to setup the FOM_Cocoon object according to the current
// request. Everything else remains the same.
- thrScope.setupPackages(Thread.currentThread().getContextClassLoader());
+ ClassLoader contextClassloader = Thread.currentThread().getContextClassLoader();
+ thrScope.setupPackages(contextClassloader);
cocoon.pushCallContext(this, redirector, manager,
avalonContext, getLogger(), null);
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java Sun Oct 9 05:17:33
2005
@@ -127,8 +127,6 @@
*/
void configure(DefaultContext context);
- ClassLoader getInitClassLoader();
-
org.apache.cocoon.environment.Context getEnvironmentContext();
/**
@@ -152,6 +150,5 @@
*/
URL getConfigFile(String configFileName)
throws Exception;
-
- String getClassPath(Settings settings);
+
}
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java Sun Oct 9 05:17:33 2005
@@ -23,8 +23,11 @@
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -34,6 +37,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
@@ -94,6 +98,8 @@
/** Is this a per request logger manager */
protected boolean isPerRequestLoggerManager = false;
+
+ protected ClassLoader classloader;
/**
* Setup a new instance.
@@ -104,6 +110,7 @@
throws Exception {
this.env = environment;
this.init();
+ this.createClassloader();
}
protected void init()
@@ -129,16 +136,6 @@
// create settings
this.settings = this.createSettings();
- if (this.settings.isInitClassloader()) {
- // Force context classloader so that JAXP can work correctly
- // (see javax.xml.parsers.FactoryFinder.findClassLoader())
- try {
- Thread.currentThread().setContextClassLoader(this.env.getInitClassLoader());
- } catch (Exception e) {
- // ignore this
- }
- }
-
// first init the work-directory for the logger.
// this is required if we are running inside a war file!
final String workDirParam = this.settings.getWorkDirectory();
@@ -251,7 +248,7 @@
this.appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, settings.getFormEncoding());
// set class loader
- this.appContext.put(Constants.CONTEXT_CLASS_LOADER, this.env.getInitClassLoader());
+ this.appContext.put(Constants.CONTEXT_CLASS_LOADER, this.classloader);
// create the Core object
final Core core = this.createCore();
@@ -649,16 +646,6 @@
public synchronized Cocoon createCocoon()
throws Exception {
- /* HACK for reducing class loader problems. */
- /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */
- if (this.settings.isInitClassloader()) {
- try {
- Thread.currentThread().setContextClassLoader(this.env.getInitClassLoader());
- } catch (Exception e) {
- // ignore
- }
- }
-
this.updateEnvironment();
this.forceLoad();
this.forceProperty();
@@ -689,11 +676,66 @@
}
/**
+ * Create the classloader that inlcudes all the [block]/BLOCK-INF/classes directories.
+ * @throws Exception
+ */
+ protected void createClassloader() throws Exception {
+ // get the wiring
+ final SourceResolver resolver = this.createSourceResolver(this.log);
+ Source wiringSource = null;
+ final Configuration wiring;
+ try {
+ wiringSource = resolver.resolveURI(Constants.WIRING);
+ DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+ wiring = builder.build( wiringSource.getInputStream() );
+ } catch(org.apache.excalibur.source.SourceNotFoundException snfe) {
+ throw new WiringNotFoundException("wiring.xml not found in the root directory
of your Cocoon application.");
+ } finally {
+ resolver.release(wiringSource);
+ }
+
+ // get all wired blocks and add their classed directory to the classloader
+ List urlList = new ArrayList();
+ Configuration[] blocks = wiring.getChildren("block");
+ for(int i = 0; i < blocks.length; i++) {
+ String location = blocks[i].getAttribute("location");
+ if(this.log.isDebugEnabled()) {
+ this.log.debug("Found block " + blocks[i].getAttribute("id") + " at " + location);
+ }
+ Source classesDir = null;
+ try {
+ classesDir = resolver.resolveURI(location + "/" + Constants.BLOCK_META_DIR
+ "/classes");
+ if(classesDir.exists()) {
+ String classesDirURI = classesDir.getURI();
+ urlList.add(new URL(classesDirURI));
+ if(this.log.isDebugEnabled()) {
+ this.log.debug("added " + classesDir.getURI());
+ }
+ }
+ } finally {
+ resolver.release(classesDir);
+ }
+ }
+
+ // setup the classloader using the current classloader as parent
+ ClassLoader parentClassloader = Thread.currentThread().getContextClassLoader();
+ URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]);
+ URLClassLoader classloader = new URLClassLoader(urls, parentClassloader);
+ Thread.currentThread().setContextClassLoader(classloader);
+ this.classloader = Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
* Gets the current cocoon object.
* Reload cocoon if configuration changed or we are reloading.
+ * Ensure that the correct classloader is set.
*/
public Cocoon getCocoon(final String pathInfo, final String reloadParam)
throws Exception {
+
+ // set the blocks classloader for this thread
+ Thread.currentThread().setContextClassLoader(this.classloader);
+
if (this.settings.isAllowReload()) {
boolean reload = false;
@@ -812,33 +854,26 @@
* of this class (eg. Cocoon Context).
*/
protected void updateEnvironment() throws Exception {
- // concatenate the class path and the extra class path
- String classPath = this.env.getClassPath(this.settings);
- StringBuffer buffer = new StringBuffer();
- if ( classPath != null && classPath.length() > 0 ) {
- buffer.append(classPath);
- }
- classPath = this.getExtraClassPath();
- if ( classPath != null && classPath.length() > 0 ) {
- if ( buffer.length() > 0 ) {
- buffer.append(File.pathSeparatorChar);
- }
- buffer.append(classPath);
- }
- this.appContext.put(Constants.CONTEXT_CLASSPATH, buffer.toString());
+// // concatenate the class path and the extra class path
+// String classPath = this.env.getClassPath(this.settings);
+// StringBuffer buffer = new StringBuffer();
+// if ( classPath != null && classPath.length() > 0 ) {
+// buffer.append(classPath);
+// }
+// classPath = this.getExtraClassPath();
+// if ( classPath != null && classPath.length() > 0 ) {
+// if ( buffer.length() > 0 ) {
+// buffer.append(File.pathSeparatorChar);
+// }
+// buffer.append(classPath);
+// }
+// this.appContext.put(Constants.CONTEXT_CLASSPATH, buffer.toString());
}
/**
* Dispose Cocoon when environment is destroyed
*/
public void destroy() {
- if (this.settings.isInitClassloader()) {
- try {
- Thread.currentThread().setContextClassLoader(this.env.getInitClassLoader());
- } catch (Exception e) {
- // ignore this
- }
- }
this.disposeCocoon();
}
Added: cocoon/trunk/src/java/org/apache/cocoon/core/WiringNotFoundException.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/WiringNotFoundException.java?rev=307410&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/WiringNotFoundException.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/WiringNotFoundException.java Sun Oct 9 05:17:33
2005
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core;
+
+/**
+ * Throw this exception in the case that the wiring.xml is not found.
+ *
+ * @version SVN $Id$
+ */
+public class WiringNotFoundException extends RuntimeException {
+
+ public WiringNotFoundException(String message) {
+ super(message);
+ }
+
+}
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/WiringNotFoundException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/WiringNotFoundException.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/CoreBlockActivator.java Sun Oct 9 05:17:33
2005
@@ -34,10 +34,10 @@
private Processor processor;
public void start(final BundleContext ctx) throws Exception {
-
+ Thread.currentThread().setContextClassLoader(CoreBlockActivator.class.getClassLoader());
BootstrapEnvironment env = new OSGiBootstrapEnvironment(this.classLoader, ctx);
env.log("OSGiBootstrapEnvironment created");
- CoreUtil coreUtil = new CoreUtil(env);
+ OSGICoreUtil coreUtil = new OSGICoreUtil(env);
env.log("CoreUtil created");
this.core = coreUtil.getCore();
this.processor = coreUtil.createCocoon();
Added: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGICoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGICoreUtil.java?rev=307410&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGICoreUtil.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGICoreUtil.java Sun Oct 9 05:17:33
2005
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.osgi;
+
+import org.apache.cocoon.core.BootstrapEnvironment;
+import org.apache.cocoon.core.CoreUtil;
+
+public class OSGICoreUtil extends CoreUtil {
+
+ public OSGICoreUtil(BootstrapEnvironment environment) throws Exception {
+ super(environment);
+ }
+
+ protected void createClassloader() throws Exception {
+ this.classloader = OSGICoreUtil.class.getClassLoader();
+ }
+
+}
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGICoreUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGICoreUtil.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java Sun Oct
9 05:17:33 2005
@@ -176,10 +176,6 @@
return new URL(this.contextPath + configFileName);
}
- public String getClassPath(Settings settings) {
- return null;
- }
-
public class OSGiContext extends AbstractContext {
private Bundle bundle;
Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java Sun Oct 9 05:17:33
2005
@@ -107,9 +107,6 @@
protected ServletContext servletContext;
- /** The classloader that will be set as the context classloader if init-classloader is
true */
- protected ClassLoader classLoader = getClass().getClassLoader();
-
/**
* This is the path to the servlet context (or the result
* of calling getRealPath('/') on the ServletContext.
@@ -203,7 +200,7 @@
}
// initialize settings
- ServletBootstrapEnvironment env = new ServletBootstrapEnvironment(conf, this.classLoader,
this.servletContextPath, this.servletContextURL);
+ ServletBootstrapEnvironment env = new ServletBootstrapEnvironment(conf, this.servletContextPath,
this.servletContextURL);
try {
this.coreUtil = new CoreUtil(env);
@@ -235,7 +232,7 @@
try {
this.exception = null;
- this.cocoon = this.coreUtil.createCocoon();
+ this.cocoon = this.coreUtil.createCocoon();
} catch (Exception e) {
this.exception = e;
}
@@ -262,7 +259,6 @@
this.requestFactory = null;
this.servletContext = null;
this.environmentContext = null;
- this.classLoader = null;
this.log = null;
super.destroy();
}
@@ -273,17 +269,7 @@
*/
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
-
- /* HACK for reducing class loader problems. */
- /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */
- if (this.coreUtil.getSettings().isInitClassloader()) {
- try {
- Thread.currentThread().setContextClassLoader(this.classLoader);
- } catch (Exception e) {
- // ignore
- }
- }
-
+
// used for timing the processing
StopWatch stopWatch = new StopWatch();
stopWatch.start();
@@ -632,21 +618,18 @@
}
protected static final class ServletBootstrapEnvironment
- implements BootstrapEnvironment {
+ implements BootstrapEnvironment {
private final ServletConfig config;
- private final ClassLoader classLoader;
- private final File writeableContextPath;
- private final String contextPath;
+ private final File writeableContextPath;
+ private final String contextPath;
public Logger logger;
- private final HttpContext environmentContext;
+ private final HttpContext environmentContext;
- public ServletBootstrapEnvironment(ServletConfig config,
- ClassLoader cl,
- String writeablePath,
- String path) {
+ public ServletBootstrapEnvironment(ServletConfig config,
+ String writeablePath,
+ String path) {
this.config = config;
- this.classLoader = cl;
if ( writeablePath == null ) {
this.writeableContextPath = null;
} else {
@@ -700,13 +683,6 @@
}
/**
- * @see org.apache.cocoon.core.BootstrapEnvironment#getInitClassLoader()
- */
- public ClassLoader getInitClassLoader() {
- return this.classLoader;
- }
-
- /**
* @see org.apache.cocoon.core.BootstrapEnvironment#getEnvironmentContext()
*/
public Context getEnvironmentContext() {
@@ -797,164 +773,166 @@
return result;
}
- /**
- * This builds the important ClassPath used by this Servlet. It
- * does so in a Servlet Engine neutral way. It uses the
- * <code>ServletContext</code>'s <code>getRealPath</code>
method
- * to get the Servlet 2.2 identified classes and lib directories.
- * It iterates in alphabetical order through every file in the
- * lib directory and adds it to the classpath.
- *
- * Also, we add the files to the ClassLoader for the Cocoon system.
- * In order to protect ourselves from skitzofrantic classloaders,
- * we need to work with a known one.
- *
- * We need to get this to work properly when Cocoon is in a war.
- *
- */
- public String getClassPath(Settings settings) {
- StringBuffer buildClassPath = new StringBuffer();
-
- File root = null;
- if (this.getContextForWriting() != null) {
- // Old method. There *MUST* be a better method than this...
-
- String classDir = this.config.getServletContext().getRealPath("/WEB-INF/classes");
- String libDir = this.config.getServletContext().getRealPath("/WEB-INF/lib");
-
- if (libDir != null) {
- root = new File(libDir);
- }
-
- if (classDir != null) {
- buildClassPath.append(classDir);
- }
- } else {
- // New(ish) method for war'd deployments
- URL classDirURL = null;
- URL libDirURL = null;
-
- try {
- classDirURL = this.config.getServletContext().getResource("/WEB-INF/classes");
- } catch (MalformedURLException me) {
- this.logger.warn("Unable to add WEB-INF/classes to the classpath", me);
- }
-
- try {
- libDirURL = this.config.getServletContext().getResource("/WEB-INF/lib");
- } catch (MalformedURLException me) {
- this.logger.warn("Unable to add WEB-INF/lib to the classpath", me);
- }
-
- if (libDirURL != null && libDirURL.toExternalForm().startsWith("file:"))
{
- root = new File(libDirURL.toExternalForm().substring("file:".length()));
- }
-
- if (classDirURL != null) {
- buildClassPath.append(classDirURL.toExternalForm());
- }
- }
-
- // Unable to find lib directory. Going the hard way.
- if (root == null) {
- root = this.extractLibraries(settings);
- }
-
- if (root != null && root.isDirectory()) {
- File[] libraries = root.listFiles();
- Arrays.sort(libraries);
- for (int i = 0; i < libraries.length; i++) {
- String fullName = IOUtils.getFullFilename(libraries[i]);
- buildClassPath.append(File.pathSeparatorChar).append(fullName);
- }
- }
-
- buildClassPath.append(File.pathSeparatorChar)
- .append(SystemUtils.JAVA_CLASS_PATH);
-
- return buildClassPath.toString();
- }
-
- private File extractLibraries(Settings settings) {
- try {
- URL manifestURL = this.config.getServletContext().getResource("/META-INF/MANIFEST.MF");
- if (manifestURL == null) {
- this.logger.fatalError("Unable to get Manifest");
- return null;
- }
-
- Manifest mf = new Manifest(manifestURL.openStream());
- Attributes attr = mf.getMainAttributes();
- String libValue = attr.getValue("Cocoon-Libs");
- if (libValue == null) {
- this.logger.fatalError("Unable to get 'Cocoon-Libs' attribute from the
Manifest");
- return null;
- }
-
- List libList = new ArrayList();
- for (StringTokenizer st = new StringTokenizer(libValue, " "); st.hasMoreTokens();)
{
- libList.add(st.nextToken());
- }
-
- File root = new File(settings.getWorkDirectory(), "lib");
- root.mkdirs();
-
- File[] oldLibs = root.listFiles();
- for (int i = 0; i < oldLibs.length; i++) {
- String oldLib = oldLibs[i].getName();
- if (!libList.contains(oldLib)) {
- this.logger.debug("Removing old library " + oldLibs[i]);
- oldLibs[i].delete();
- }
- }
-
- this.logger.warn("Extracting libraries into " + root);
- byte[] buffer = new byte[65536];
- for (Iterator i = libList.iterator(); i.hasNext();) {
- String libName = (String) i.next();
-
- long lastModified = -1;
- try {
- lastModified = Long.parseLong(attr.getValue("Cocoon-Lib-" + libName.replace('.',
'_')));
- } catch (Exception e) {
- this.logger.debug("Failed to parse lastModified: " + attr.getValue("Cocoon-Lib-"
+ libName.replace('.', '_')));
- }
-
- File lib = new File(root, libName);
- if (lib.exists() && lib.lastModified() != lastModified) {
- this.logger.debug("Removing modified library " + lib);
- lib.delete();
- }
-
- InputStream is = this.config.getServletContext().getResourceAsStream("/WEB-INF/lib/"
+ libName);
- if (is == null) {
- this.logger.warn("Skipping " + libName);
- } else {
- this.logger.debug("Extracting " + libName);
- OutputStream os = null;
- try {
- os = new FileOutputStream(lib);
- int count;
- while ((count = is.read(buffer)) > 0) {
- os.write(buffer, 0, count);
- }
- } finally {
- if (is != null) is.close();
- if (os != null) os.close();
- }
- }
-
- if (lastModified != -1) {
- lib.setLastModified(lastModified);
- }
- }
-
- return root;
- } catch (IOException e) {
- this.logger.fatalError("Exception while processing Manifest file", e);
- return null;
- }
- }
-
+// (RP) comment this stuff out as it isn't used any more except in the StatusGenerator and
I also think it returns wrong information
+// under some circumstances.
+// /**
+// * This builds the important ClassPath used by this Servlet. It
+// * does so in a Servlet Engine neutral way. It uses the
+// * <code>ServletContext</code>'s <code>getRealPath</code>
method
+// * to get the Servlet 2.2 identified classes and lib directories.
+// * It iterates in alphabetical order through every file in the
+// * lib directory and adds it to the classpath.
+// *
+// * Also, we add the files to the ClassLoader for the Cocoon system.
+// * In order to protect ourselves from skitzofrantic classloaders,
+// * we need to work with a known one.
+// *
+// * We need to get this to work properly when Cocoon is in a war.
+// *
+// */
+// public String getClassPath(Settings settings) {
+// StringBuffer buildClassPath = new StringBuffer();
+//
+// File root = null;
+// if (this.getContextForWriting() != null) {
+// // Old method. There *MUST* be a better method than this...
+//
+// String classDir = this.config.getServletContext().getRealPath("/WEB-INF/classes");
+// String libDir = this.config.getServletContext().getRealPath("/WEB-INF/lib");
+//
+// if (libDir != null) {
+// root = new File(libDir);
+// }
+//
+// if (classDir != null) {
+// buildClassPath.append(classDir);
+// }
+// } else {
+// // New(ish) method for war'd deployments
+// URL classDirURL = null;
+// URL libDirURL = null;
+//
+// try {
+// classDirURL = this.config.getServletContext().getResource("/WEB-INF/classes");
+// } catch (MalformedURLException me) {
+// this.logger.warn("Unable to add WEB-INF/classes to the classpath",
me);
+// }
+//
+// try {
+// libDirURL = this.config.getServletContext().getResource("/WEB-INF/lib");
+// } catch (MalformedURLException me) {
+// this.logger.warn("Unable to add WEB-INF/lib to the classpath", me);
+// }
+//
+// if (libDirURL != null && libDirURL.toExternalForm().startsWith("file:"))
{
+// root = new File(libDirURL.toExternalForm().substring("file:".length()));
+// }
+//
+// if (classDirURL != null) {
+// buildClassPath.append(classDirURL.toExternalForm());
+// }
+// }
+//
+// // Unable to find lib directory. Going the hard way.
+// if (root == null) {
+// root = this.extractLibraries(settings);
+// }
+//
+// if (root != null && root.isDirectory()) {
+// File[] libraries = root.listFiles();
+// Arrays.sort(libraries);
+// for (int i = 0; i < libraries.length; i++) {
+// String fullName = IOUtils.getFullFilename(libraries[i]);
+// buildClassPath.append(File.pathSeparatorChar).append(fullName);
+// }
+// }
+//
+// buildClassPath.append(File.pathSeparatorChar)
+// .append(SystemUtils.JAVA_CLASS_PATH);
+//
+// return buildClassPath.toString();
+// }
+//
+// private File extractLibraries(Settings settings) {
+// try {
+// URL manifestURL = this.config.getServletContext().getResource("/META-INF/MANIFEST.MF");
+// if (manifestURL == null) {
+// this.logger.fatalError("Unable to get Manifest");
+// return null;
+// }
+//
+// Manifest mf = new Manifest(manifestURL.openStream());
+// Attributes attr = mf.getMainAttributes();
+// String libValue = attr.getValue("Cocoon-Libs");
+// if (libValue == null) {
+// this.logger.fatalError("Unable to get 'Cocoon-Libs' attribute from
the Manifest");
+// return null;
+// }
+//
+// List libList = new ArrayList();
+// for (StringTokenizer st = new StringTokenizer(libValue, " "); st.hasMoreTokens();)
{
+// libList.add(st.nextToken());
+// }
+//
+// File root = new File(settings.getWorkDirectory(), "lib");
+// root.mkdirs();
+//
+// File[] oldLibs = root.listFiles();
+// for (int i = 0; i < oldLibs.length; i++) {
+// String oldLib = oldLibs[i].getName();
+// if (!libList.contains(oldLib)) {
+// this.logger.debug("Removing old library " + oldLibs[i]);
+// oldLibs[i].delete();
+// }
+// }
+//
+// this.logger.warn("Extracting libraries into " + root);
+// byte[] buffer = new byte[65536];
+// for (Iterator i = libList.iterator(); i.hasNext();) {
+// String libName = (String) i.next();
+//
+// long lastModified = -1;
+// try {
+// lastModified = Long.parseLong(attr.getValue("Cocoon-Lib-" + libName.replace('.',
'_')));
+// } catch (Exception e) {
+// this.logger.debug("Failed to parse lastModified: " + attr.getValue("Cocoon-Lib-"
+ libName.replace('.', '_')));
+// }
+//
+// File lib = new File(root, libName);
+// if (lib.exists() && lib.lastModified() != lastModified) {
+// this.logger.debug("Removing modified library " + lib);
+// lib.delete();
+// }
+//
+// InputStream is = this.config.getServletContext().getResourceAsStream("/WEB-INF/lib/"
+ libName);
+// if (is == null) {
+// this.logger.warn("Skipping " + libName);
+// } else {
+// this.logger.debug("Extracting " + libName);
+// OutputStream os = null;
+// try {
+// os = new FileOutputStream(lib);
+// int count;
+// while ((count = is.read(buffer)) > 0) {
+// os.write(buffer, 0, count);
+// }
+// } finally {
+// if (is != null) is.close();
+// if (os != null) os.close();
+// }
+// }
+//
+// if (lastModified != -1) {
+// lib.setLastModified(lastModified);
+// }
+// }
+//
+// return root;
+// } catch (IOException e) {
+// this.logger.fatalError("Exception while processing Manifest file", e);
+// return null;
+// }
+// }
+//
}
}
Modified: cocoon/trunk/src/test/org/apache/cocoon/test/SitemapTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/test/SitemapTestCase.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/test/org/apache/cocoon/test/SitemapTestCase.java (original)
+++ cocoon/trunk/src/test/org/apache/cocoon/test/SitemapTestCase.java Sun Oct 9 05:17:33
2005
@@ -72,7 +72,6 @@
this.classDir = this.getClassDirURL().toExternalForm();
BootstrapEnvironment env =
new TestBootstrapEnvironment(className.substring(className.lastIndexOf('.') +
1) + ".xconf",
- this.getClass().getClassLoader(),
this.classDir,
environmentContext,
this.logger);
@@ -91,8 +90,7 @@
return this.logger;
}
- protected final Object lookup( final String key )
- throws ServiceException {
+ protected final Object lookup( final String key ) throws ServiceException {
return this.cocoon.getServiceManager().lookup( key );
}
Modified: cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java (original)
+++ cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java Sun Oct
9 05:17:33 2005
@@ -31,18 +31,15 @@
implements BootstrapEnvironment {
private final String configuration;
- private final ClassLoader classLoader;
private final String contextPath;
public Logger logger;
private final Context environmentContext;
public TestBootstrapEnvironment(String configuration,
- ClassLoader classLoader,
String contextPath,
Context environmentContext,
Logger logger) {
this.configuration = configuration;
- this.classLoader = classLoader;
this.contextPath = contextPath;
this.environmentContext = environmentContext;
@@ -98,10 +95,6 @@
public void configure(DefaultContext context) {
}
- public ClassLoader getInitClassLoader() {
- return this.classLoader;
- }
-
public Context getEnvironmentContext() {
return this.environmentContext;
}
@@ -133,7 +126,4 @@
return new URL(this.contextPath + configFileName);
}
- public String getClassPath(Settings settings) {
- return null;
- }
}
Modified: cocoon/trunk/src/test/org/apache/cocoon/test/core/TestCoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/test/core/TestCoreUtil.java?rev=307410&r1=307409&r2=307410&view=diff
==============================================================================
--- cocoon/trunk/src/test/org/apache/cocoon/test/core/TestCoreUtil.java (original)
+++ cocoon/trunk/src/test/org/apache/cocoon/test/core/TestCoreUtil.java Sun Oct 9 05:17:33
2005
@@ -23,6 +23,7 @@
public class TestCoreUtil extends CoreUtil {
public TestCoreUtil(BootstrapEnvironment env) throws Exception {
super(env);
+ this.classloader = TestCoreUtil.class.getClassLoader();
}
// Simplified logging
|