Author: cziegeler
Date: Sun Jun 10 18:52:11 2012
New Revision: 1348643
URL: http://svn.apache.org/viewvc?rev=1348643&view=rev
Log:
SLING-2505 : Don't load class for dependency check
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/SlingIOProvider.java
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.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=1348643&r1=1348642&r2=1348643&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
Sun Jun 10 18:52:11 2012
@@ -165,6 +165,7 @@ public class JspScriptEngineFactory
* @param scriptHelper
* @param context
*/
+ @SuppressWarnings("unchecked")
private void callErrorPageJsp(final Bindings bindings,
final SlingScriptHelper scriptHelper,
final ScriptContext context,
@@ -178,7 +179,7 @@ public class JspScriptEngineFactory
resolver =
scriptHelper.getScript().getScriptResource().getResourceResolver();
}
final SlingIOProvider io = this.ioProvider;
- io.setRequestResourceResolver(resolver);
+ final ResourceResolver oldResolver =
io.setRequestResourceResolver(resolver);
jspFactoryHandler.incUsage();
try {
final JspServletWrapper errorJsp =
getJspWrapper(scriptName, slingBindings);
@@ -203,7 +204,7 @@ public class JspScriptEngineFactory
request.removeAttribute("javax.servlet.jsp.jspException");
} finally {
jspFactoryHandler.decUsage();
- io.resetRequestResourceResolver();
+ io.resetRequestResourceResolver(oldResolver);
}
}
@@ -212,6 +213,7 @@ public class JspScriptEngineFactory
* @throws SlingServletException
* @throws SlingIOException
*/
+ @SuppressWarnings("unchecked")
private void callJsp(final Bindings bindings,
final SlingScriptHelper scriptHelper,
final ScriptContext context) {
@@ -222,7 +224,7 @@ public class JspScriptEngineFactory
resolver =
scriptHelper.getScript().getScriptResource().getResourceResolver();
}
final SlingIOProvider io = this.ioProvider;
- io.setRequestResourceResolver(resolver);
+ final ResourceResolver oldResolver =
io.setRequestResourceResolver(resolver);
jspFactoryHandler.incUsage();
try {
final SlingBindings slingBindings = new SlingBindings();
@@ -233,7 +235,7 @@ public class JspScriptEngineFactory
jsp.service(slingBindings);
} finally {
jspFactoryHandler.decUsage();
- io.resetRequestResourceResolver();
+ io.resetRequestResourceResolver(oldResolver);
}
}
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java?rev=1348643&r1=1348642&r2=1348643&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
Sun Jun 10 18:52:11 2012
@@ -54,12 +54,20 @@ class SlingIOProvider implements IOProvi
this.classLoaderWriter = classLoaderWriter;
}
- void setRequestResourceResolver(ResourceResolver resolver) {
+ /**
+ * Set the thread context resource resolver.
+ */
+ ResourceResolver setRequestResourceResolver(final ResourceResolver
resolver) {
+ final ResourceResolver old = requestResourceResolver.get();
requestResourceResolver.set(resolver);
+ return old;
}
- void resetRequestResourceResolver() {
- requestResourceResolver.remove();
+ /**
+ * Reset the thread context resource resolver.
+ */
+ void resetRequestResourceResolver(final ResourceResolver resolver) {
+ requestResourceResolver.set(resolver);
}
// ---------- IOProvider interface
-----------------------------------------
@@ -69,29 +77,27 @@ class SlingIOProvider implements IOProvi
* ResourceProvider and retrieved from the Resource if the StreamProvider
* interface is implemented.
*/
- public InputStream getInputStream(String fileName)
+ public InputStream getInputStream(final String path)
throws FileNotFoundException, IOException {
- if ( fileName.startsWith(":") ) {
- return
this.classLoaderWriter.getInputStream(fileName.substring(1));
+ if ( path.startsWith(":") ) {
+ return this.classLoaderWriter.getInputStream(path.substring(1));
}
- try {
-
- Resource resource = getResourceInternal(fileName);
- if (resource == null) {
- throw new FileNotFoundException("Cannot find " + fileName);
- }
-
- InputStream stream = resource.adaptTo(InputStream.class);
- if (stream == null) {
- throw new FileNotFoundException("Cannot find " + fileName);
+ ResourceResolver resolver = requestResourceResolver.get();
+ if (resolver != null) {
+ try {
+ final Resource resource = resolver.getResource(cleanPath(path,
true));
+ if (resource != null) {
+ final InputStream stream =
resource.adaptTo(InputStream.class);
+ if (stream != null) {
+ return stream;
+ }
+ }
+ } catch (final SlingException se) {
+ throw (IOException) new IOException(
+ "Failed to get InputStream for " + path).initCause(se);
}
-
- return stream;
-
- } catch (SlingException se) {
- throw (IOException) new IOException(
- "Failed to get InputStream for " + fileName).initCause(se);
}
+ throw new FileNotFoundException("Cannot find " + path);
}
/**
@@ -100,22 +106,23 @@ class SlingIOProvider implements IOProvi
* resource does not exist or an error occurrs finding the resource, -1 is
* returned.
*/
- public long lastModified(String fileName) {
- if ( fileName.startsWith(":") ) {
- return
this.classLoaderWriter.getLastModified(fileName.substring(1));
- }
- try {
- Resource resource = getResourceInternal(fileName);
- if (resource != null) {
- ResourceMetadata meta = resource.getResourceMetadata();
- long modTime = meta.getModificationTime();
- return (modTime > 0) ? modTime : 0;
+ public long lastModified(final String path) {
+ if ( path.startsWith(":") ) {
+ return this.classLoaderWriter.getLastModified(path.substring(1));
+ }
+ ResourceResolver resolver = requestResourceResolver.get();
+ if (resolver != null) {
+ try {
+ final Resource resource = resolver.getResource(cleanPath(path,
true));
+ if (resource != null) {
+ ResourceMetadata meta = resource.getResourceMetadata();
+ long modTime = meta.getModificationTime();
+ return (modTime > 0) ? modTime : 0;
+ }
+ } catch (final SlingException se) {
+ log.error("Cannot get last modification time for " + path, se);
}
-
- } catch (SlingException se) {
- log.error("Cannot get last modification time for " + fileName, se);
}
-
// fallback to "non-existant" in case of problems
return -1;
}
@@ -123,28 +130,28 @@ class SlingIOProvider implements IOProvi
/**
* Removes the named item from the repository.
*/
- public boolean delete(String fileName) {
- return this.classLoaderWriter.delete(fileName.substring(1));
+ public boolean delete(final String path) {
+ return this.classLoaderWriter.delete(path.substring(1));
}
/**
* Returns an output stream to write to the repository.
*/
- public OutputStream getOutputStream(String fileName) {
- return this.classLoaderWriter.getOutputStream(fileName.substring(1));
+ public OutputStream getOutputStream(final String path) {
+ return this.classLoaderWriter.getOutputStream(path.substring(1));
}
/**
* Renames a node in the repository.
*/
- public boolean rename(String oldFileName, String newFileName) {
+ public boolean rename(final String oldFileName, final String newFileName) {
return this.classLoaderWriter.rename(oldFileName.substring(1),
newFileName.substring(1));
}
/**
* Creates a folder hierarchy in the repository.
*/
- public boolean mkdirs(String path) {
+ public boolean mkdirs(final String path) {
// we just do nothing
return true;
}
@@ -159,18 +166,22 @@ class SlingIOProvider implements IOProvi
// ---------- Helper Methods for JspServletContext
-------------------------
- /* package */URL getURL(String path) throws MalformedURLException {
- try {
- Resource resource = getResourceInternal(path);
- return (resource != null) ? resource.adaptTo(URL.class) : null;
- } catch (SlingException se) {
- throw (MalformedURLException) new MalformedURLException(
- "Cannot get URL for " + path).initCause(se);
+ URL getURL(final String path) throws MalformedURLException {
+ ResourceResolver resolver = requestResourceResolver.get();
+ if (resolver != null) {
+ try {
+ final Resource resource = resolver.getResource(cleanPath(path,
true));
+ return (resource != null) ? resource.adaptTo(URL.class) : null;
+ } catch (final SlingException se) {
+ throw (MalformedURLException) new MalformedURLException(
+ "Cannot get URL for " + path).initCause(se);
+ }
}
+ return null;
}
- /* package */Set<String> getResourcePaths(String path) {
- Set<String> paths = new HashSet<String>();
+ Set<String> getResourcePaths(final String path) {
+ final Set<String> paths = new HashSet<String>();
ResourceResolver resolver = requestResourceResolver.get();
if (resolver != null) {
@@ -190,7 +201,7 @@ class SlingIOProvider implements IOProvi
}
}
}
- } catch (SlingException se) {
+ } catch (final SlingException se) {
log.warn("getResourcePaths: Cannot list children of " + path,
se);
}
@@ -199,18 +210,9 @@ class SlingIOProvider implements IOProvi
return paths.isEmpty() ? null : paths;
}
- private Resource getResourceInternal(String path) throws SlingException {
- ResourceResolver resolver = requestResourceResolver.get();
- if (resolver != null) {
- return resolver.getResource(cleanPath(path, true));
- }
-
- return null;
- }
-
// ---------- internal
-----------------------------------------------------
- private String cleanPath(String path, boolean removeWebInfTags) {
+ private String cleanPath(String path, final boolean removeWebInfTags) {
// replace backslash by slash
path = path.replace('\\', '/');
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=1348643&r1=1348642&r2=1348643&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
Sun Jun 10 18:52:11 2012
@@ -231,7 +231,7 @@ public final class JspRuntimeContext {
// ------------------------------------------------------ Public Methods
- public void addJspDependencies(final JspServletWrapper jsw, List<String>
deps) {
+ public void addJspDependencies(final JspServletWrapper jsw, final
List<String> deps) {
if ( deps != null ) {
final String jspUri = jsw.getJspUri();
synchronized ( depToJsp ) {
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java?rev=1348643&r1=1348642&r2=1348643&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
Sun Jun 10 18:52:11 2012
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.sling.scripting.jsp.jasper.servlet;
import java.io.IOException;
@@ -278,7 +277,6 @@ public class JspServletWrapper {
if ( !equals(oldDeps, this.dependents) ) {
this.persistDependencies();
}
- this.persistDependencies();
} catch (final Throwable t) {
// ignore
}
@@ -308,34 +306,39 @@ public class JspServletWrapper {
*/
public List<String> getDependants() {
if ( this.dependents == null ) {
- // we load the deps file
- final String path = this.getDependencyFilePath();
- InputStream is = null;
- try {
- is =
this.ctxt.getRuntimeContext().getIOProvider().getInputStream(path);
- if ( is != null ) {
- if ( log.isDebugEnabled() ) {
- log.debug("Loading dependencies for " + jspUri);
+ synchronized ( this ) {
+ if ( this.dependents == null ) {
+ // we load the deps file
+ final String path = this.getDependencyFilePath();
+ InputStream is = null;
+ try {
+ is =
this.ctxt.getRuntimeContext().getIOProvider().getInputStream(path);
+ if ( is != null ) {
+ if ( log.isDebugEnabled() ) {
+ log.debug("Loading dependencies for " +
jspUri);
+ }
+ final List<String> deps = new ArrayList<String>();
+ final InputStreamReader reader = new
InputStreamReader(is, "UTF-8");
+ final LineNumberReader lnr = new
LineNumberReader(reader);
+ String line;
+ while ( (line = lnr.readLine()) != null ) {
+ deps.add(line.trim());
+ }
+ this.dependents = deps;
+ }
+ } catch ( final IOException ignore ) {
+ // excepted
+ } finally {
+ if ( is != null ) {
+ try { is.close(); } catch ( final IOException ioe
) {}
+ }
}
- this.dependents = new ArrayList<String>();
- final InputStreamReader reader = new InputStreamReader(is,
"UTF-8");
- final LineNumberReader lnr = new LineNumberReader(reader);
- String line;
- while ( (line = lnr.readLine()) != null ) {
- this.dependents.add(line.trim());
+
+ // use empty list, until servlet is compiled and loaded
+ if ( this.dependents == null ) {
+ this.dependents = Collections.emptyList();
}
}
- } catch ( final IOException ignore ) {
- // excepted
- } finally {
- if ( is != null ) {
- try { is.close(); } catch ( final IOException ioe ) {}
- }
- }
-
- // use empty list, until servlet is compiled and loaded
- if ( this.dependents == null ) {
- this.dependents = Collections.emptyList();
}
}
return this.dependents;
@@ -357,19 +360,20 @@ public class JspServletWrapper {
return jspUri;
}
+ /**
+ * Check if the compiled class is still current
+ */
private boolean isOutDated() {
- final String jsp = ctxt.getJspFile();
-
- long jspRealLastModified =
ctxt.getRuntimeContext().getIOProvider().lastModified(jsp);
-
- long targetLastModified = 0;
+ // check if class file exists
final String targetFile = ctxt.getClassFileName();
-
- targetLastModified =
ctxt.getRuntimeContext().getIOProvider().lastModified(targetFile);
+ final long targetLastModified =
ctxt.getRuntimeContext().getIOProvider().lastModified(targetFile);
if (targetLastModified < 0) {
return true;
}
+ // compare jsp time stamp with class file time stamp
+ final String jsp = ctxt.getJspFile();
+ final long jspRealLastModified =
ctxt.getRuntimeContext().getIOProvider().lastModified(jsp);
if (targetLastModified < jspRealLastModified) {
if (log.isDebugEnabled()) {
log.debug("Compiler: outdated: " + targetFile + " "
@@ -378,26 +382,25 @@ public class JspServletWrapper {
return true;
}
+ // check includes
final List<String> depends = this.getDependants();
- if (depends == null) {
- return false;
- }
-
- final Iterator<String> it = depends.iterator();
- while (it.hasNext()) {
- final String include = it.next();
- // ignore tag libs, we are reloaded if a taglib changes anyway
- if ( include.startsWith("tld:") ) {
- continue;
- }
- final long includeLastModified =
ctxt.getRuntimeContext().getIOProvider().lastModified(include);
-
- if (includeLastModified > targetLastModified) {
- if (log.isDebugEnabled()) {
- log.debug("Compiler: outdated: " + targetFile + " because
of dependency " + include + " : "
- + targetLastModified + " - " +
includeLastModified);
+ if (depends != null) {
+ final Iterator<String> it = depends.iterator();
+ while (it.hasNext()) {
+ final String include = it.next();
+ // ignore tag libs, we are reloaded if a taglib changes anyway
+ if ( include.startsWith("tld:") ) {
+ continue;
+ }
+ final long includeLastModified =
ctxt.getRuntimeContext().getIOProvider().lastModified(include);
+
+ if (includeLastModified > targetLastModified) {
+ if (log.isDebugEnabled()) {
+ log.debug("Compiler: outdated: " + targetFile + "
because of dependency " + include + " : "
+ + targetLastModified + " - " +
includeLastModified);
+ }
+ return true;
}
- return true;
}
}