Author: cziegeler
Date: Wed Mar 28 18:42:58 2012
New Revision: 1306533
URL: http://svn.apache.org/viewvc?rev=1306533&view=rev
Log:
SLING-2447 : ClassLoaderWriter should provide class loader for loading written
classes/resources
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=1306533&r1=1306532&r2=1306533&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Wed Mar 28 18:42:58 2012
@@ -46,6 +46,7 @@ import org.apache.sling.api.scripting.Sl
import org.apache.sling.api.scripting.SlingScriptConstants;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.commons.classloader.ClassLoaderWriter;
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
import org.apache.sling.scripting.jsp.jasper.JasperException;
@@ -94,6 +95,11 @@ public class JspScriptEngineFactory
@Reference
private ClassLoaderWriter classLoaderWriter;
+ @Reference
+ private DynamicClassLoaderManager dynamicClassLoaderManager;
+
+ private ClassLoader dynamicClassLoader;
+
/** The io provider for reading and writing. */
private SlingIOProvider ioProvider;
@@ -277,7 +283,7 @@ public class JspScriptEngineFactory
// set the current class loader as the thread context loader for
// the setup of the JspRuntimeContext
final ClassLoader old = Thread.currentThread().getContextClassLoader();
-
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ Thread.currentThread().setContextClassLoader(this.dynamicClassLoader);
try {
this.jspFactoryHandler = JspRuntimeContext.initFactoryHandler();
@@ -382,6 +388,44 @@ public class JspScriptEngineFactory
}
}
+ /**
+ * Bind the class load provider.
+ *
+ * @param repositoryClassLoaderProvider the new provider
+ */
+ protected void bindDynamicClassLoaderManager(final
DynamicClassLoaderManager rclp) {
+ if ( this.dynamicClassLoader != null ) {
+ this.ungetClassLoader();
+ }
+ this.getClassLoader(rclp);
+ }
+
+ /**
+ * Unbind the class loader provider.
+ * @param repositoryClassLoaderProvider the old provider
+ */
+ protected void unbindDynamicClassLoaderManager(final
DynamicClassLoaderManager rclp) {
+ if ( this.dynamicClassLoaderManager == rclp ) {
+ this.ungetClassLoader();
+ }
+ }
+
+ /**
+ * Get the class loader
+ */
+ private void getClassLoader(final DynamicClassLoaderManager rclp) {
+ this.dynamicClassLoaderManager = rclp;
+ this.dynamicClassLoader = rclp.getDynamicClassLoader();
+ }
+
+ /**
+ * Unget the class loader
+ */
+ private void ungetClassLoader() {
+ this.dynamicClassLoader = null;
+ this.dynamicClassLoaderManager = null;
+ }
+
// ---------- Internal
-----------------------------------------------------
private class JspScriptEngine extends AbstractSlingScriptEngine {
@@ -399,7 +443,7 @@ public class JspScriptEngineFactory
// set the current class loader as the thread context loader
for
// the compilation and execution of the JSP script
ClassLoader old =
Thread.currentThread().getContextClassLoader();
-
Thread.currentThread().setContextClassLoader(classLoaderWriter.getClassLoader());
+
Thread.currentThread().setContextClassLoader(dynamicClassLoader);
try {
callJsp(props, scriptHelper, context);
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java?rev=1306533&r1=1306532&r2=1306533&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
Wed Mar 28 18:42:58 2012
@@ -20,7 +20,6 @@ package org.apache.sling.scripting.jsp.j
import java.io.File;
import java.io.FilePermission;
import java.net.URL;
-import java.net.URLClassLoader;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.security.Policy;
@@ -215,7 +214,7 @@ public final class JspRuntimeContext {
this.context = context;
this.options = options;
this.ioProvider = ioProvider;
-
+/*
// Get the parent class loader
parentClassLoader = Thread.currentThread().getContextClassLoader();
if (parentClassLoader == null) {
@@ -233,7 +232,7 @@ public final class JspRuntimeContext {
}
initClassPath();
-
+*/
if (context instanceof
org.apache.sling.scripting.jsp.jasper.servlet.JspCServletContext) {
return;
}
@@ -250,10 +249,10 @@ public final class JspRuntimeContext {
*/
private ServletContext context;
private Options options;
- private ClassLoader parentClassLoader;
+// private ClassLoader parentClassLoader;
private PermissionCollection permissionCollection;
private CodeSource codeSource;
- private String classpath;
+ // private String classpath;
/**
* Maps JSP pages to their JspServletWrapper's
@@ -388,10 +387,10 @@ public final class JspRuntimeContext {
* Get the parent URLClassLoader.
*
* @return URLClassLoader parent
- */
public ClassLoader getParentClassLoader() {
return parentClassLoader;
}
+ */
/**
* Get the SecurityManager PermissionCollection for this
@@ -440,10 +439,10 @@ public final class JspRuntimeContext {
/**
* The classpath that is passed off to the Java compiler.
- */
public String getClassPath() {
return classpath;
}
+ */
/**
* Returns the current {@link IOProvider} of this context.
@@ -457,7 +456,6 @@ public final class JspRuntimeContext {
/**
* Method used to initialize classpath for compiles.
- */
private void initClassPath() {
StringBuffer cpath = new StringBuffer();
@@ -488,6 +486,7 @@ public final class JspRuntimeContext {
log.debug("Compilation classpath initialized: " + getClassPath());
}
}
+ */
/**
* Method used to initialize SecurityManager data.
@@ -542,7 +541,7 @@ public final class JspRuntimeContext {
// Allow the JSP to access
org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase
permissionCollection.add( new RuntimePermission(
"accessClassInPackage.org.apache.jasper.runtime") );
-
+/*
if (parentClassLoader instanceof URLClassLoader) {
URL [] urls = ((URLClassLoader)
parentClassLoader).getURLs();
String jarUrl = null;
@@ -571,6 +570,7 @@ public final class JspRuntimeContext {
permissionCollection.add(
new FilePermission(jndiUrl,"read") );
}
+ */
} catch(Exception e) {
context.log("Security Init for context failed",e);
}