You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2009/02/02 13:22:21 UTC
svn commit: r739973 [2/3] - in /incubator/sling/trunk/scripting/scala: ./
engine/ engine/src/ engine/src/main/ engine/src/main/java/
engine/src/main/java/org/ engine/src/main/java/org/apache/
engine/src/main/java/org/apache/sling/ engine/src/main/java/...
Added: incubator/sling/trunk/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaTestBase.java?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaTestBase.java (added)
+++ incubator/sling/trunk/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaTestBase.java Mon Feb 2 12:22:19 2009
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.scripting.scala;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import javax.jcr.Node;
+import javax.script.ScriptException;
+
+import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
+import org.apache.sling.scripting.scala.engine.BacklogReporter;
+import org.apache.sling.scripting.scala.interpreter.Bindings;
+import org.apache.sling.scripting.scala.interpreter.InterpreterException;
+import org.apache.sling.scripting.scala.interpreter.JcrFS;
+import org.apache.sling.scripting.scala.interpreter.ScalaBindings;
+import org.apache.sling.scripting.scala.interpreter.ScalaInterpreter;
+import org.apache.sling.scripting.scala.interpreter.JcrFS.JcrNode;
+
+import scala.tools.nsc.Settings;
+import scala.tools.nsc.io.AbstractFile;
+import scala.tools.nsc.reporters.Reporter;
+
+public class ScalaTestBase extends RepositoryTestBase {
+ public static final String NL = System.getProperty("line.separator");
+
+ protected static final String SCRIPT_PATH = "/scripts/";
+
+ private Node appNode;
+ private ScalaInterpreter interpreter;
+ private ByteArrayOutputStream interpreterOut;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Node testRoot = getTestRootNode();
+ appNode = testRoot.addNode("app", "nt:folder");
+ getSession().save();
+
+ Settings settings = new Settings();
+ String testCp = System.getProperty("surefire.test.class.path");
+ String javaCp = System.getProperty("java.class.path");
+ settings.classpath().v_$eq(testCp != null ? testCp : javaCp);
+ JcrNode appDir = JcrFS.create(appNode);
+ AbstractFile outDir = appDir.subdirectoryNamed("outdir");
+ interpreter = new ScalaInterpreter(settings, new BacklogReporter(settings), outDir);
+ interpreterOut = new ByteArrayOutputStream();
+ }
+
+ @Override
+ protected void tearDown() {
+ interpreter = null;
+ }
+
+ protected Node getAppNode() {
+ return appNode;
+ }
+
+ protected String getScript(String scriptName) throws URISyntaxException, IOException {
+ URL url = getClass().getResource(SCRIPT_PATH + scriptName);
+ BufferedReader reader = new BufferedReader(new FileReader(new File(url.toURI())));
+
+ StringBuilder script = new StringBuilder();
+
+ String line;
+ while ((line = reader.readLine()) != null) {
+ script.append(line).append(NL);
+ }
+
+ return script.toString();
+ }
+
+ protected String evalScala(String code) throws ScriptException {
+ Bindings bindings = new ScalaBindings();
+ return evalScala(createScriptName(), code, bindings);
+ }
+
+ protected String evalScala(String code, Bindings bindings) throws ScriptException {
+ return evalScala(createScriptName(), code, bindings);
+ }
+
+ protected String evalScala(String name, String code, Bindings bindings) throws ScriptException {
+ try {
+ interpreterOut.reset();
+ Reporter result = interpreter.interprete(name, code, bindings, null, interpreterOut);
+ if (result.hasErrors()) {
+ throw new ScriptException(result.toString());
+ }
+ return interpreterOut.toString();
+ }
+ catch (InterpreterException e) {
+ throw new ScriptException(e);
+ }
+ }
+
+ protected String evalScalaScript(String scriptName) throws URISyntaxException, IOException,
+ ScriptException, InvocationTargetException {
+
+ String code = getScript(scriptName);
+ return evalScala(code);
+ }
+
+ protected String evalScalaScript(String scriptName, Bindings bindings)
+ throws URISyntaxException, IOException, ScriptException {
+
+ String code = getScript(scriptName);
+ return evalScala(scriptName, code, bindings);
+ }
+
+ protected String evalScala(String name, AbstractFile src, ScalaBindings bindings) throws ScriptException {
+ try {
+ interpreterOut.reset();
+ Reporter result = interpreter.interprete(name, src, bindings, null, interpreterOut);
+ if (result.hasErrors()) {
+ throw new ScriptException(result.toString());
+ }
+ return interpreterOut.toString();
+ }
+ catch (InterpreterException e) {
+ throw new ScriptException(e);
+ }
+ }
+
+ protected String createScriptName() {
+ return "scalaTest";
+ }
+
+}
Propchange: incubator/sling/trunk/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/scripting/scala/engine/src/test/java/org/apache/sling/scripting/scala/ScalaTestBase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url
Added: incubator/sling/trunk/scripting/scala/engine/src/test/resources/scripts/simple.scs
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/engine/src/test/resources/scripts/simple.scs?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/engine/src/test/resources/scripts/simple.scs (added)
+++ incubator/sling/trunk/scripting/scala/engine/src/test/resources/scripts/simple.scs Mon Feb 2 12:22:19 2009
@@ -0,0 +1 @@
+print(1 + 2)
\ No newline at end of file
Added: incubator/sling/trunk/scripting/scala/engine/src/test/test-config/jackrabbit-test-config.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/engine/src/test/test-config/jackrabbit-test-config.xml?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/engine/src/test/test-config/jackrabbit-test-config.xml (added)
+++ incubator/sling/trunk/scripting/scala/engine/src/test/test-config/jackrabbit-test-config.xml Mon Feb 2 12:22:19 2009
@@ -0,0 +1,112 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN"
+ "http://jackrabbit.apache.org/dtd/repository-1.2.dtd">
+<Repository>
+ <!--
+ virtual file system where the repository stores global state
+ (e.g. registered namespaces, custom node types, etc.)
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/repository"/>
+ </FileSystem>
+
+ <!--
+ security configuration
+ -->
+ <Security appName="Jackrabbit">
+ <!--
+ access manager:
+ class: FQN of class implementing the AccessManager interface
+ -->
+ <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager">
+ <!-- <param name="config" value="${rep.home}/access.xml"/> -->
+ </AccessManager>
+
+ <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
+ <!-- anonymous user name ('anonymous' is the default value) -->
+ <param name="anonymousId" value="anonymous"/>
+ </LoginModule>
+ </Security>
+
+ <!--
+ location of workspaces root directory and name of default workspace
+ -->
+ <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+ <!--
+ workspace configuration template:
+ used to create the initial workspace if there's no workspace yet
+ -->
+ <Workspace name="Jackrabbit Core">
+ <!--
+ virtual file system of the workspace:
+ class: FQN of class implementing the FileSystem interface
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${wsp.home}"/>
+ </FileSystem>
+ <!--
+ persistence manager of the workspace:
+ class: FQN of class implementing the PersistenceManager interface
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
+ <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
+ <param name="schemaObjectPrefix" value="Jackrabbit Core_"/>
+ </PersistenceManager>
+ <!--
+ Search index and the file system it uses.
+ class: FQN of class implementing the QueryHandler interface
+ -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${wsp.home}/index"/>
+ </SearchIndex>
+ </Workspace>
+
+ <!--
+ Configures the versioning
+ -->
+ <Versioning rootPath="${rep.home}/version">
+ <!--
+ Configures the filesystem to use for versioning for the respective
+ persistence manager
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/version" />
+ </FileSystem>
+
+ <!--
+ Configures the persistence manager to be used for persisting version state.
+ Please note that the current versioning implementation is based on
+ a 'normal' persistence manager, but this could change in future
+ implementations.
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
+ <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
+ <param name="schemaObjectPrefix" value="version_"/>
+ </PersistenceManager>
+ </Versioning>
+
+ <!--
+ Search index for content that is shared repository wide
+ (/jcr:system tree, contains mainly versions)
+ -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index"/>
+ </SearchIndex>
+</Repository>
+
Propchange: incubator/sling/trunk/scripting/scala/engine/src/test/test-config/jackrabbit-test-config.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/scripting/scala/interpreter/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 2 12:22:19 2009
@@ -0,0 +1,4 @@
+.classpath
+.project
+target
+.settings
Added: incubator/sling/trunk/scripting/scala/interpreter/LICENSE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/LICENSE?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/LICENSE (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/LICENSE Mon Feb 2 12:22:19 2009
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
Added: incubator/sling/trunk/scripting/scala/interpreter/NOTICE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/NOTICE?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/NOTICE (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/NOTICE Mon Feb 2 12:22:19 2009
@@ -0,0 +1,5 @@
+Apache Sling Scala Interpreter
+Copyright 2009 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
Added: incubator/sling/trunk/scripting/scala/interpreter/README.txt
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/README.txt?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/README.txt (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/README.txt Mon Feb 2 12:22:19 2009
@@ -0,0 +1,41 @@
+Apache Sling Scala Interpreter
+
+Scala interpreter with OSGi support. This module is used by the Scala
+ScriptEngineFactory to implement support scripts stored in OSGi bundles
+and JCR repositories. Due to issues with the Scala Compiler, this
+module must be separate from the Scala ScriptEngineFactory module
+but will be included in the latter.
+
+Disclaimer
+==========
+Apache Sling is an effort undergoing incubation at The Apache Software Foundation (ASF),
+sponsored by the Apache Jackrabbit PMC. Incubation is required of all newly accepted
+projects until a further review indicates that the infrastructure, communications,
+and decision making process have stabilized in a manner consistent with other
+successful ASF projects. While incubation status is not necessarily a reflection of
+the completeness or stability of the code, it does indicate that the project has yet
+to be fully endorsed by the ASF.
+
+Getting Started
+===============
+
+This component uses a Maven 2 (http://maven.apache.org/) build
+environment. It requires a Java 5 JDK (or higher) and Maven (http://maven.apache.org/)
+2.0.7 or later. We recommend to use the latest Maven version.
+
+If you have Maven 2 installed, you can compile and
+package the jar using the following command:
+
+ mvn package
+
+See the Maven 2 documentation for other build features.
+
+The latest source code for this component is available in the
+Subversion (http://subversion.tigris.org/) source repository of
+the Apache Software Foundation. If you have Subversion installed,
+you can checkout the latest source using the following command:
+
+ svn checkout http://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/velocity
+
+See the Subversion documentation for other source control features.
+
Propchange: incubator/sling/trunk/scripting/scala/interpreter/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/scripting/scala/interpreter/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/pom.xml?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/pom.xml (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/pom.xml Mon Feb 2 12:22:19 2009
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>5-incubator-SNAPSHOT</version>
+ <relativePath>../../../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.scripting.scala.interpreter</artifactId>
+ <version>0.9.0-incubator-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>Apache Sling Scala Interpreter</name>
+ <description>
+ Scala interpreter with OSGi support. This module is used by the Scala
+ ScriptEngineFactory to implement support scripts stored in OSGi bundles
+ and JCR repositories. Due to issues with the Scala Compiler, this
+ module must be separate from the Scala ScriptEngineFactory module
+ but will be included in the latter.
+ </description>
+
+ <build>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <scalaVersion>${scala.version}</scalaVersion>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ <downloadJavadocs>true</downloadJavadocs>
+ <buildcommands>
+ <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
+ </buildcommands>
+ <additionalProjectnatures>
+ <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
+ </additionalProjectnatures>
+ <classpathContainers>
+ <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+ <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
+ </classpathContainers>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.2</version>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>org.apache.jackrabbit.repository.conf</name>
+ <value>target/repository.xml</value>
+ </property>
+ <property>
+ <name>org.apache.jackrabbit.repository.home</name>
+ <value>target/repository</value>
+ </property>
+ <property>
+ <name>derby.stream.error.file</name>
+ <value>target/repository/derby.log</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>2.7.3</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-compiler</artifactId>
+ <version>2.7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ <version>1.5.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
Propchange: incubator/sling/trunk/scripting/scala/interpreter/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/DISCLAIMER
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/DISCLAIMER?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/DISCLAIMER (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/DISCLAIMER Mon Feb 2 12:22:19 2009
@@ -0,0 +1,7 @@
+Apache Sling is an effort undergoing incubation at The Apache Software Foundation (ASF),
+sponsored by the Apache Jackrabbit PMC. Incubation is required of all newly accepted
+projects until a further review indicates that the infrastructure, communications,
+and decision making process have stabilized in a manner consistent with other
+successful ASF projects. While incubation status is not necessarily a reflection of
+the completeness or stability of the code, it does indicate that the project has yet
+to be fully endorsed by the ASF.
\ No newline at end of file
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/LICENSE?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/LICENSE (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/LICENSE Mon Feb 2 12:22:19 2009
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/NOTICE?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/NOTICE (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/resources/META-INF/NOTICE Mon Feb 2 12:22:19 2009
@@ -0,0 +1,5 @@
+Apache Sling Scala Interpreter
+Copyright 2009 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/Utils.scala
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/Utils.scala?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/Utils.scala (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/Utils.scala Mon Feb 2 12:22:19 2009
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.scripting.scala
+
+/**
+ * General purpose utility functions
+ */
+object Utils {
+
+ /**
+ * Evaluate <code>f</code> on <code>s</code> if <code>s</code> is not null.
+ * @param s
+ * @param f
+ * @return <code>f(s)</code> if s is not <code>null</code>, <code>null</code> otherwise.
+ */
+ def nullOrElse[S, T](s: S)(f: S => T): T =
+ if (s == null) null.asInstanceOf[T]
+ else f(s)
+
+ /**
+ * @param t
+ * @param default
+ * @return <code>t</code> or <code>default</code> if <code>null</code>.
+ */
+ def valueOrElse[T](t: T)(default: => T) =
+ if (t == null) default
+ else t
+
+ /**
+ * Converts a value into an Option.
+ * @param value
+ * @returns <code>Some(value)</code> if value is not <code>null</code>,
+ * <code>None</code> otherwise.
+ */
+ def option[T](value: T): Option[T] =
+ if (null == value) None else Some(value)
+
+}
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala Mon Feb 2 12:22:19 2009
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+import scala.collection.Map
+import scala.collection.mutable.HashMap
+
+package org.apache.sling.scripting.scala.interpreter {
+
+/**
+ * An argument consists of a value and its type
+ */
+trait Argument[T <: AnyRef] {
+
+ /**
+ * @returns the value of this argument
+ */
+ def getValue: T
+
+ /**
+ * @returns the type of this argument
+ */
+ def getType: Class[T]
+}
+
+/**
+ * Bindings of names to {@link Argument}s
+ */
+trait Bindings extends Map[String, Argument[_]] {
+
+ /**
+ * Associate an argument with a name
+ * @param name
+ * @param argument
+ * @returns The argument which was previously associated with the
+ * given name or null if none.
+ */
+ def put(name: String, argument: Argument[_]): Argument[_]
+
+ /**
+ * Associate an argument with a name
+ * @param name
+ * @param value the value of the {@link Argument}
+ * @param tyqe the type of the {@link Argument}
+ */
+ def put[T <: AnyRef](name: String, value: T, tyqe: Class[T]): Argument[_] =
+ put(name, new Argument[T] {
+ def getValue: T = value
+ def getType: Class[T] = tyqe
+ })
+
+ /**
+ * @returns the value of the {@link Argument} associated with the given name
+ * @param name
+ */
+ def getValue(name: String): AnyRef =
+ get(name) match {
+ case Some(a) => a.getValue
+ case None => null
+ }
+
+ /**
+ * @returns the type of the {@link Argument} associated with the given name
+ * @param name
+ */
+ def getType(name: String): Class[_] =
+ get(name) match {
+ case Some(a) => a.getClass
+ case None => null
+ }
+}
+
+/**
+ * HashMap based default implementation of {@link Bindings}.
+ */
+class ScalaBindings extends Bindings {
+ private val bindings = new HashMap[String, Argument[_]]
+
+ def size: Int = bindings.size
+ def get(name: String): Option[Argument[_]] = bindings.get(name)
+ def elements: Iterator[(String, Argument[_])] = bindings.elements
+
+ def put(name: String, argument: Argument[_]): Argument[_] =
+ bindings.put(name, argument) match {
+ case Some(a) => a
+ case None => null
+ }
+}
+
+}
+
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala Mon Feb 2 12:22:19 2009
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+import scala.tools.nsc.io.AbstractFile
+import java.io.{File, InputStream, OutputStream, IOException}
+import java.net.URL
+import org.osgi.framework.Bundle
+import org.apache.sling.scripting.scala.Utils.{valueOrElse, nullOrElse}
+
+package org.apache.sling.scripting.scala.interpreter {
+
+/**
+ * Implementation of {@link AbstractFile} on top of a {@link org.osgi.framework.Bundle}
+ */
+object BundleFS {
+
+ /**
+ * Create a new {@link AbstractFile} instance representing an
+ * {@link org.osgi.framework.Bundle}
+ * @param bundle
+ */
+ def create(bundle: Bundle): AbstractFile = {
+ require(bundle != null, "bundle must not be null")
+
+ abstract class BundleEntry(url: URL, parent: DirEntry) extends AbstractFile {
+ lazy val (path: String, name: String) = getPathAndName(url)
+ lazy val fullName: String = (path::name::Nil).filter(!_.isEmpty).mkString("/")
+
+ /**
+ * @return null
+ */
+ def file: File = null
+
+ /**
+ * @return last modification time or 0 if not known
+ */
+ def lastModified: Long =
+ try { url.openConnection.getLastModified }
+ catch { case _ => 0 }
+
+ @throws(classOf[IOException])
+ def container: AbstractFile =
+ valueOrElse(parent) {
+ throw new IOException("No container")
+ }
+
+ @throws(classOf[IOException])
+ def input: InputStream = url.openStream()
+
+ /**
+ * Not supported. Always throws an IOException.
+ * @throws IOException
+ */
+ @throws(classOf[IOException])
+ def output = throw new IOException("not supported: output")
+
+ private def getPathAndName(url: URL): (String, String) = {
+ val u = url.getPath
+ var k = u.length
+ while( (k > 0) && (u(k - 1) == '/') )
+ k = k - 1
+
+ var j = k
+ while( (j > 0) && (u(j - 1) != '/') )
+ j = j - 1
+
+ (u.substring(if (j > 0) 1 else 0, if (j > 1) j - 1 else j), u.substring(j, k))
+ }
+
+ override def toString = fullName
+ }
+
+ class DirEntry(url: URL, parent: DirEntry) extends BundleEntry(url, parent) {
+
+ /**
+ * @return true
+ */
+ def isDirectory: Boolean = true
+
+ def elements: Iterator[AbstractFile] = {
+ new Iterator[AbstractFile]() {
+ val dirs = bundle.getEntryPaths(fullName)
+ def hasNext = dirs.hasMoreElements
+ def next = {
+ val entry = dirs.nextElement.asInstanceOf[String]
+ val entryUrl = bundle.getResource("/" + entry)
+ if (entry.endsWith("/"))
+ new DirEntry(entryUrl, DirEntry.this)
+ else
+ new FileEntry(entryUrl, DirEntry.this)
+ }
+ }
+ }
+
+ def lookupName(name: String, directory: Boolean): AbstractFile = {
+ val entry = bundle.getEntry(fullName + "/" + name)
+ nullOrElse(entry) { entry =>
+ if (directory)
+ new DirEntry(entry, DirEntry.this)
+ else
+ new FileEntry(entry, DirEntry.this)
+ }
+ }
+
+ }
+
+ class FileEntry(url: URL, parent: DirEntry) extends BundleEntry(url, parent) {
+
+ /**
+ * @return false
+ */
+ def isDirectory: Boolean = false
+ override def sizeOption: Option[Int] = Some(bundle.getEntry(fullName).openConnection().getContentLength())
+ def elements: Iterator[AbstractFile] = Iterator.empty
+ def lookupName(name: String, directory: Boolean): AbstractFile = null
+ }
+
+ new DirEntry(bundle.getResource("/"), null)
+ }
+
+}
+
+}
\ No newline at end of file
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala Mon Feb 2 12:22:19 2009
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.scripting.scala.interpreter
+
+/**
+ * Exception thrown by {@link ScalaInterpreter} in case of errors.
+ */
+class InterpreterException(message: String, cause: Throwable) extends Exception(message, cause) {
+ def this(cause: Throwable) = this(if (cause == null) null else cause.getMessage, cause)
+ def this(message: String) = this(message, null);
+ def this() = this(null, null)
+}
+
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/JcrFS.scala
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/JcrFS.scala?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/JcrFS.scala (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/JcrFS.scala Mon Feb 2 12:22:19 2009
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+import scala.tools.nsc.io.AbstractFile
+import java.io.{File, InputStream, OutputStream, IOException, ByteArrayOutputStream, ByteArrayInputStream}
+import javax.jcr.{Session, Node, Property}
+import org.apache.sling.scripting.scala.Utils.{nullOrElse, valueOrElse}
+
+package org.apache.sling.scripting.scala.interpreter {
+
+/**
+ * Implementation of {@link AbstractFile} on top of the {@link javax.jcr.Node}s
+ * of a JCR repositoy.
+ */
+object JcrFS {
+
+ /**
+ * Create a new {@link AbstractFile} for the given node.
+ * @param node
+ * @throws IOException if the node type is neither nt:folder nor nt:file
+ */
+ def create(node: Node): JcrNode = node.getPrimaryNodeType.getName match {
+ case "nt:file" => JcrFile(node) // todo fix: dont hc ns prefixes
+ case "nt:folder" => JcrFolder(node)
+ case _ => throw new IOException("Neither file nor folder: " + node.getPath)
+ }
+
+ /**
+ * Create a new {@link AbstractFile} for node at the given path in the given
+ * {@link javax.jcr.Session}.
+ * @param session
+ * @param path
+ * @throws IOException if the node at the given path is neither nt:folder nor
+ * nt:file or the path does not identify a node.
+ */
+ def create(session: Session, path: String): JcrNode = {
+ session.getItem(path) match {
+ case n: Node => create(n)
+ case _ => throw new IOException("Path not found: " + path)
+ }
+ }
+
+ abstract sealed class JcrNode(node: Node) extends AbstractFile {
+ require(node != null, "node must not be null")
+
+ /**
+ * @returns an empty stream
+ */
+ val emptyInputStream: InputStream = new InputStream {
+ override def read = -1
+ }
+
+ private def getIndex: String =
+ if (node.getIndex == 1) ""
+ else "[" + node.getIndex + "]"
+
+ /**
+ * @returns the name of the node covered
+ */
+ def name: String = node.getName + getIndex
+
+ /**
+ * @returns the path of the node covered
+ */
+ def path: String = node.getPath
+
+ def container: JcrNode = create(node.getParent)
+
+ /**
+ * @returns null
+ */
+ def file: File = null
+
+ /**
+ * @returns the value of the jcr:lastModified property of either the jcr:content node
+ * beneath this node or from this node itself otherwise or 0 if this node does not
+ * have a jcr:lastModified property.
+ */
+ def lastModified: Long =
+ if (node.hasProperty("jcr:content/jcr:lastModified")) node.getProperty("jcr:content/jcr:lastModified").getLong
+ else {
+ if (node.hasProperty("jcr:lastModified")) node.getProperty("jcr:lastModified").getLong
+ else 0
+ }
+
+ override def equals(other: Any): Boolean =
+ other match {
+ case that: JcrNode => this.path == that.path
+ case _ => false
+ }
+
+ override def hashCode: Int = path.hashCode
+ }
+
+ case class JcrFolder(node: Node) extends JcrNode(node) {
+
+ /**
+ * @returns true
+ */
+ def isDirectory: Boolean = true
+
+ /**
+ * Not supported. Always throws an IOException.
+ * @throws IOException
+ */
+ def input: InputStream = throw new IOException("Cannot read from directory")
+
+ /**
+ * Not supported. Always throws an IOException.
+ * @throws IOException
+ */
+ def output: OutputStream = throw new IOException("Cannot write to directory")
+
+ /**
+ * @returns the child nodes of this nodes which are either nt:file or nt:folder
+ */
+ def elements: Iterator[JcrNode] =
+ new Iterator[Node] {
+ val childs = node.getNodes
+ def hasNext = childs.hasNext
+ def next = childs.next.asInstanceOf[Node]
+ }
+ .filter((node: Node) =>
+ "nt:file" == node.getPrimaryNodeType.getName ||
+ "nt:folder" == node.getPrimaryNodeType.getName)
+ .map((node: Node) => create(node))
+
+ /**
+ * Considers only child nodes which are wither nt:file or nt:folder
+ */
+ def lookupName(name: String, directory: Boolean): AbstractFile = {
+ if (node.hasNode(name)) {
+ val n = node.getNode(name)
+ if (directory && "nt:folder" == n.getPrimaryNodeType.getName ||
+ !directory && "nt:file" == n.getPrimaryNodeType.getName)
+ create(n)
+ else
+ null
+ }
+ else
+ null
+ }
+
+ /**
+ * Creates a child node of type nt:file with the given name if such node exists.
+ * @param name
+ * @returns the (possibly newly created) child node
+ */
+ override def fileNamed(name: String): AbstractFile = {
+ valueOrElse(lookupName(name, false)) {
+ val file = node.addNode(name, "nt:file")
+ val content = file.addNode("jcr:content", "nt:resource")
+ content.setProperty("jcr:mimeType", "application/octet-stream") // todo fix: dont hc MIME
+ content.setProperty("jcr:data", emptyInputStream)
+ content.setProperty("jcr:lastModified", System.currentTimeMillis)
+ node.save()
+ create(file)
+ }
+ }
+
+ /**
+ * Creates a child node of type nt:folder with the given name if such node exists.
+ * @param name
+ * @returns the (possibly newly created) child node
+ */
+ override def subdirectoryNamed(name: String): AbstractFile = {
+ valueOrElse(lookupName(name, true)) {
+ val dir = node.addNode(name, "nt:folder")
+ node.save()
+ create(dir)
+ }
+ }
+ }
+
+ case class JcrFile(node: Node) extends JcrNode(node) {
+
+ /**
+ * @returns the jcr:content child node of this node or null if none exists
+ */
+ def contentNode: Node =
+ if (node.hasNode("jcr:content")) node.getNode("jcr:content")
+ else null
+
+ /**
+ * @returns the jcr:data property of the jcr:content child node of this node or
+ * null if none exists
+ */
+ def dataProperty: Property =
+ nullOrElse(contentNode) { node =>
+ if (node.hasProperty("jcr:data")) node.getProperty("jcr:data")
+ else null
+ }
+
+ /**
+ * @returns false
+ */
+ def isDirectory = false
+
+ /**
+ * @returns a stream for reading from {@ling #dataProperty}. The stream is empty
+ * if the property does not exist.
+ */
+ def input: InputStream = dataProperty match {
+ case prop: Property => prop.getStream
+ case null => emptyInputStream
+ }
+
+ /**
+ * @returns a stream for writing to {@ling #dataProperty}. If necessary the child
+ * jcr:content child node and its jcr:data property are created.
+ */
+ def output: OutputStream = new ByteArrayOutputStream() {
+ override def close() {
+ super.close()
+ val content = valueOrElse(contentNode) {
+ node.addNode("jcr:content", "nt:resource")
+ }
+ content.setProperty("jcr:lastModified", System.currentTimeMillis)
+ content.setProperty("jcr:data", new ByteArrayInputStream(buf, 0, size))
+ node.save()
+ }
+ }
+
+ /**
+ * @returns the size of the {@ling #dataProperty} or None if the property does not
+ * exist.
+ */
+ override def sizeOption: Option[Int] = {
+ val p = dataProperty
+ if (p == null) None
+ else Some(p.getLength.toInt)
+ }
+
+ def elements: Iterator[AbstractFile] = Iterator.empty
+ def lookupName(name: String, directory: Boolean): AbstractFile = null
+ }
+
+}
+
+}
\ No newline at end of file
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala Mon Feb 2 12:22:19 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.util.ClassPath
+
+package org.apache.sling.scripting.scala.interpreter {
+
+/**
+ * Specialized class path for the {@link ScalaCompiler} which supports {@link AbstractFile}
+ * entries.
+ */
+class ScalaClasspath(onlyPresentation: Boolean) extends ClassPath(onlyPresentation) {
+
+ class BuildClasspath(classpath: String, source: String, output: String, boot: String, extdirs: String,
+ codebase: String, classes: Array[AbstractFile])
+ extends Build(classpath, source, output, boot, extdirs, codebase) {
+
+ if (classes != null) {
+ for (file <- classes if file != null) {
+ val lib = new Library(file)
+ entries += lib
+ }
+ }
+ }
+
+}
+
+}
\ No newline at end of file
Added: incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala?rev=739973&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala (added)
+++ incubator/sling/trunk/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala Mon Feb 2 12:22:19 2009
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+import scala.tools.nsc.{Settings, Global}
+import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.reporters.Reporter
+
+package org.apache.sling.scripting.scala.interpreter {
+
+/**
+ * Extendend Scala compiler which supports a class path with {@link AbstractFile} entries.
+ * Note: this implementation does not support MSIL (.NET).
+ */
+class ScalaCompiler(settings: Settings, reporter: Reporter, classes: Array[AbstractFile])
+ extends Global(settings, reporter) {
+
+ override lazy val classPath0 = new ScalaClasspath(false && onlyPresentation)
+
+ override lazy val classPath = {
+ require(!forMSIL, "MSIL not supported")
+ new classPath0.BuildClasspath(settings.classpath.value, settings.sourcepath.value,
+ settings.outdir.value, settings.bootclasspath.value, settings.extdirs.value,
+ settings.Xcodebase.value, classes)
+ }
+
+}
+
+}
\ No newline at end of file