Author: cziegeler
Date: Fri Jul 17 06:18:00 2009
New Revision: 794979
URL: http://svn.apache.org/viewvc?rev=794979&view=rev
Log:
Use new class loader writer.
Modified:
sling/trunk/contrib/scripting/java/pom.xml
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/CompilationContext.java
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/Options.java
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
sling/trunk/contrib/scripting/java/src/main/resources/OSGI-INF/metatype/metatype.properties
Modified: sling/trunk/contrib/scripting/java/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/pom.xml?rev=794979&r1=794978&r2=794979&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/pom.xml (original)
+++ sling/trunk/contrib/scripting/java/pom.xml Fri Jul 17 06:18:00 2009
@@ -100,11 +100,6 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.jcr.api</artifactId>
- <version>2.0.2-incubator</version>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.classloader</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
Modified:
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/CompilationContext.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/CompilationContext.java?rev=794979&r1=794978&r2=794979&view=diff
==============================================================================
---
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/CompilationContext.java
(original)
+++
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/CompilationContext.java
Fri Jul 17 06:18:00 2009
@@ -55,7 +55,7 @@
private long lastModificationTest = 0L;
private int removed = 0;
- private Class servletClass;
+ private Class<?> servletClass;
private final ServletWrapper wrapper;
@@ -194,7 +194,7 @@
/**
* Load the class.
*/
- public Class load()
+ public Class<?> load()
throws ServletException, FileNotFoundException {
final String name = this.getClassFilePath().substring(1).replace('/',
'.');
try {
Modified:
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java?rev=794979&r1=794978&r2=794979&view=diff
==============================================================================
---
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
(original)
+++
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
Fri Jul 17 06:18:00 2009
@@ -33,6 +33,7 @@
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScript;
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;
@@ -52,7 +53,6 @@
* @scr.property name="java.compilerSourceVM" value="1.5"
* @scr.property name="java.compilerTargetVM" value="1.5"
* @scr.property name="java.development" value="true"
- * @scr.property name="java.outputPath" value="/var/classes"
* @scr.property name="java.modificationTestInterval" value="-1"
* @scr.property name="java.classdebuginfo" value="true"
*/
@@ -74,6 +74,9 @@
/** @scr.reference */
private ServletContext slingServletContext;
+ /** @scr.reference */
+ private ClassLoaderWriter classLoaderWriter;
+
private SlingIOProvider ioProvider;
private JavaServletContext javaServletContext;
@@ -120,7 +123,7 @@
* @param componentContext
*/
protected void activate(ComponentContext componentContext) {
- this.ioProvider = new SlingIOProvider();
+ this.ioProvider = new SlingIOProvider(this.classLoaderWriter);
this.servletCache = new ServletCache();
this.javaServletContext = new JavaServletContext(ioProvider,
@@ -157,6 +160,7 @@
* @throws SlingServletException
* @throws SlingIOException
*/
+ @SuppressWarnings("unchecked")
private void callServlet(Bindings bindings, SlingScriptHelper
scriptHelper) {
ioProvider.setRequestResourceResolver(scriptHelper.getScript().getScriptResource().getResourceResolver());
Modified:
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/Options.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/Options.java?rev=794979&r1=794978&r2=794979&view=diff
==============================================================================
---
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/Options.java
(original)
+++
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/Options.java
Fri Jul 17 06:18:00 2009
@@ -36,8 +36,6 @@
private static final String PROPERTY_DEVELOPMENT = "development";
- private static final String PROPERTY_OUTPUT_PATH = "outputPath";
-
private static final String PROPERTY_MODIFICATION_TEST_INTERVAL =
"modificationTestInterval";
private static final String PROPERTY_CLASSDEBUGINFO = "classdebuginfo";
@@ -80,8 +78,6 @@
*/
private final ClassLoader classLoader;
- private final String destinationDir;
-
/**
* Create an compiler options object using data available from
* the component configuration.
@@ -100,7 +96,6 @@
properties.put(PROPERTY_COMPILER_TARGET_V_M, DEFAULT_VM_VERSION);
properties.put(PROPERTY_COMPILER_SOURCE_V_M, DEFAULT_VM_VERSION);
properties.put(PROPERTY_JAVA_ENCODING, "UTF-8");
- properties.put(PROPERTY_OUTPUT_PATH, "/var/classes");
// now check component properties
Dictionary<?, ?> config = componentContext.getProperties();
@@ -116,7 +111,6 @@
}
}
- this.destinationDir = properties.get(PROPERTY_OUTPUT_PATH).toString();
this.classDebugInfo =
Boolean.valueOf(properties.get(PROPERTY_CLASSDEBUGINFO).toString());
this.modificationTestInterval =
Integer.valueOf(properties.get(PROPERTY_MODIFICATION_TEST_INTERVAL).toString());
this.development =
Boolean.valueOf(properties.get(PROPERTY_DEVELOPMENT).toString());
@@ -129,7 +123,7 @@
* Return the destination directory.
*/
public String getDestinationPath() {
- return this.destinationDir;
+ return ":";
}
/**
Modified:
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java?rev=794979&r1=794978&r2=794979&view=diff
==============================================================================
---
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java
(original)
+++
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java
Fri Jul 17 06:18:00 2009
@@ -102,7 +102,7 @@
Servlet servlet = null;
try {
- final Class servletClass = ctxt.load();
+ final Class<?> servletClass = ctxt.load();
servlet = (Servlet) servletClass.newInstance();
} catch (IllegalAccessException e) {
throw new ServletException(e);
Modified:
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java?rev=794979&r1=794978&r2=794979&view=diff
==============================================================================
---
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
(original)
+++
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
Fri Jul 17 06:18:00 2009
@@ -16,8 +16,6 @@
*/
package org.apache.sling.scripting.java;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -27,32 +25,30 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import java.util.StringTokenizer;
-
-import javax.jcr.Item;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
import org.apache.sling.api.SlingException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The <code>SlingIOProvider</code> TODO
+ * The <code>SlingIOProvider</code>
*/
public class SlingIOProvider {
/** default log */
- private static final Logger log =
LoggerFactory.getLogger(SlingIOProvider.class);
+ private final Logger log = LoggerFactory.getLogger(SlingIOProvider.class);
private ThreadLocal<ResourceResolver> requestResourceResolver;
- SlingIOProvider() {
+ private final ClassLoaderWriter classLoaderWriter;
+
+ SlingIOProvider(final ClassLoaderWriter classLoaderWriter) {
this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
+ this.classLoaderWriter = classLoaderWriter;
}
void setRequestResourceResolver(ResourceResolver resolver) {
@@ -72,7 +68,9 @@
*/
public InputStream getInputStream(String fileName)
throws FileNotFoundException, IOException {
-
+ if ( fileName.startsWith(":") ) {
+ return
this.classLoaderWriter.getInputStream(fileName.substring(1));
+ }
try {
Resource resource = getResourceInternal(fileName);
@@ -100,6 +98,9 @@
* returned.
*/
public long lastModified(String fileName) {
+ if ( fileName.startsWith(":") ) {
+ return
this.classLoaderWriter.getLastModified(fileName.substring(1));
+ }
try {
Resource resource = getResourceInternal(fileName);
if (resource != null) {
@@ -117,36 +118,10 @@
}
/**
- * Removes the named item from the repository.
- */
- public boolean delete(String fileName) {
- Node parentNode = null;
- try {
- fileName = cleanPath(fileName);
- Session session = getPrivateSession();
- if (session.itemExists(fileName)) {
- Item fileItem = session.getItem(fileName);
- parentNode = fileItem.getParent();
- fileItem.remove();
- parentNode.save();
- return true;
- }
- } catch (RepositoryException re) {
- log.error("Cannot remove " + fileName, re);
- } finally {
- checkNode(parentNode, fileName);
- }
-
- // fall back to false if item does not exist or in case of error
- return false;
- }
-
- /**
* Returns an output stream to write to the repository.
*/
public OutputStream getOutputStream(String fileName) {
- fileName = cleanPath(fileName);
- return new RepositoryOutputStream(this, fileName);
+ return this.classLoaderWriter.getOutputStream(fileName.substring(1));
}
/* package */URL getURL(String path) throws MalformedURLException {
@@ -192,21 +167,6 @@
// ---------- internal
-----------------------------------------------------
- private Session getPrivateSession() throws RepositoryException {
- return requestResourceResolver.get().adaptTo(Session.class);
- }
-
- private static void checkNode(Node node, String path) {
- if (node != null && node.isModified()) {
- try {
- node.refresh(false);
- } catch (RepositoryException re) {
- log.error("Cannot refresh node for " + path
- + " after failed save", re);
- }
- }
- }
-
private String cleanPath(String path) {
// replace backslash by slash
path = path.replace('\\', '/');
@@ -218,129 +178,4 @@
return path;
}
-
- private static class RepositoryOutputStream extends ByteArrayOutputStream {
-
- private final SlingIOProvider repositoryOutputProvider;
-
- private final String fileName;
-
- RepositoryOutputStream(SlingIOProvider repositoryOutputProvider,
- String fileName) {
- this.repositoryOutputProvider = repositoryOutputProvider;
- this.fileName = fileName;
- }
-
- public void close() throws IOException {
- super.close();
-
- Node parentNode = null;
- try {
- Session session = repositoryOutputProvider.getPrivateSession();
- Node fileNode = null;
- Node contentNode = null;
- if (session.itemExists(fileName)) {
- Item item = session.getItem(fileName);
- if (item.isNode()) {
- Node node = item.isNode()
- ? (Node) item
- : item.getParent();
- if ("jcr:content".equals(node.getName())) {
- // replace the content properties of the
jcr:content
- // node
- parentNode = node;
- contentNode = node;
- } else if (node.isNodeType("nt:file")) {
- // try to set the content properties of jcr:content
- // node
- parentNode = node;
- contentNode = node.getNode("jcr:content");
- } else { // fileName is a node
- // try to set the content properties of the node
- parentNode = node;
- contentNode = node;
- }
- } else {
- // replace property with an nt:file node (if possible)
- parentNode = item.getParent();
- String name = item.getName();
- fileNode = parentNode.addNode(name, "nt:file");
- item.remove();
- }
- } else {
- fileNode = createPath(fileName, "nt:folder", "nt:file",
session);
- parentNode = session.getRootNode();
- }
-
- // if we have a file node, create the contentNode
- if (fileNode != null) {
- contentNode = fileNode.addNode("jcr:content",
"nt:resource");
- }
-
- contentNode.setProperty("jcr:lastModified",
- System.currentTimeMillis());
- contentNode.setProperty("jcr:data", new ByteArrayInputStream(
- buf, 0, size()));
- contentNode.setProperty("jcr:mimeType",
- "application/octet-stream");
-
- parentNode.save();
- } catch (RepositoryException re) {
- log.error("Cannot write file " + fileName, re);
- throw new IOException("Cannot write file " + fileName
- + ", reason: " + re.toString());
- } finally {
- checkNode(parentNode, fileName);
- }
- }
- }
-
- /**
- * Creates or gets the {...@link javax.jcr.Node Node} at the given Path.
- * In case it has to create the Node all non-existent intermediate
path-elements
- * will be create with the given intermediate node type and the returned
node
- * will be created with the given nodeType
- *
- * @param path to create
- * @param intermediateNodeType to use for creation of intermediate nodes
- * @param nodeType to use for creation of the final node
- * @param session to use
- * @return the Node at path
- * @throws RepositoryException in case of exception accessing the
Repository
- */
- private static Node createPath(String path,
- String intermediateNodeType,
- String nodeType,
- Session session)
- throws RepositoryException {
- if (path == null || path.length() == 0 || "/".equals(path)) {
- return session.getRootNode();
- } else if (!session.itemExists(path)) {
- Node node = session.getRootNode();
- path = path.substring(1);
- int pos = path.lastIndexOf('/');
- if ( pos != -1 ) {
- final StringTokenizer st = new
StringTokenizer(path.substring(0, pos), "/");
- while ( st.hasMoreTokens() ) {
- final String token = st.nextToken();
- if ( !node.hasNode(token) ) {
- try {
- node.addNode(token, intermediateNodeType);
- } catch (RepositoryException re) {
- // we ignore this as this folder might be created
from a different task
- node.refresh(false);
- }
- }
- node = node.getNode(token);
- }
- path = path.substring(pos + 1);
- }
- if ( !node.hasNode(path) ) {
- node.addNode(path, nodeType);
- }
- return node.getNode(path);
- } else {
- return (Node) session.getItem(path);
- }
- }
}
Modified:
sling/trunk/contrib/scripting/java/src/main/resources/OSGI-INF/metatype/metatype.properties
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=794979&r1=794978&r2=794979&view=diff
==============================================================================
---
sling/trunk/contrib/scripting/java/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++
sling/trunk/contrib/scripting/java/src/main/resources/OSGI-INF/metatype/metatype.properties
Fri Jul 17 06:18:00 2009
@@ -51,8 +51,3 @@
java.compilerTargetVM.name = Target VM
java.compilerTargetVM.description = Java Specification to be used to generate \
the compiled output.
-
-java.outputPath.name = Compilation Location
-java.outputPath.description = What directory should we use when \
- compiling Java files? Default is /var/classes.
-