You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/02/01 20:37:26 UTC
svn commit: r905388 [2/3] - in /sling/trunk/contrib/scripting/scala: config/
config/src/ config/src/main/ config/src/main/java/
config/src/main/java/org/ config/src/main/java/org/apache/
config/src/main/java/org/apache/sling/ config/src/main/java/org/a...
Added: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/LICENSE?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/LICENSE (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/LICENSE Mon Feb 1 19:37:24 2010
@@ -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.
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/LICENSE
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/NOTICE?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/NOTICE (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/NOTICE Mon Feb 1 19:37:24 2010
@@ -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/).
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/NOTICE
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/SCALA-LICENSE.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/SCALA-LICENSE.txt?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/SCALA-LICENSE.txt (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/SCALA-LICENSE.txt Mon Feb 1 19:37:24 2010
@@ -0,0 +1,35 @@
+SCALA LICENSE
+
+Copyright (c) 2002-2008 EPFL, Lausanne, unless otherwise specified.
+All rights reserved.
+
+This software was developed by the Programming Methods Laboratory of the
+Swiss Federal Institute of Technology (EPFL), Lausanne, Switzerland.
+
+Permission to use, copy, modify, and distribute this software in source
+or binary form for any purpose with or without fee is hereby granted,
+provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of the EPFL nor the names of its contributors
+ may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/SCALA-LICENSE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/SCALA-LICENSE.txt
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/SCALA-LICENSE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory Mon Feb 1 19:37:24 2010
@@ -0,0 +1,15 @@
+# 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.
+org.apache.sling.scripting.scala.ScalaScriptEngineFactory
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/resources/OSGI-INF/serviceComponents.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/resources/OSGI-INF/serviceComponents.xml?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/resources/OSGI-INF/serviceComponents.xml (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/resources/OSGI-INF/serviceComponents.xml Mon Feb 1 19:37:24 2010
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+ <scr:component enabled="true" name="org.apache.sling.scripting.scala.ScalaScriptEngineFactory">
+ <implementation class="org.apache.sling.scripting.scala.ScalaScriptEngineFactory"/>
+ <service servicefactory="false">
+ <provide interface="javax.script.ScriptEngineFactory"/>
+ </service>
+ <property name="service.pid" value="org.apache.sling.scripting.scala.ScalaScriptEngineFactory"/>
+ <reference name="settingsProvider" interface="org.apache.sling.scripting.scala.SettingsProvider" cardinality="0..1" policy="dynamic" bind="setSettingsProvider" unbind="unsetSettingsProvider"/>
+ <reference name="scriptInfo" interface="org.apache.sling.scripting.scala.ScriptInfo" cardinality="0..1" policy="dynamic" bind="setScriptInfo" unbind="unsetScriptInfo"/>
+ </scr:component>
+</components>
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/OSGI-INF/serviceComponents.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/OSGI-INF/serviceComponents.xml
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: sling/trunk/contrib/scripting/scala/script/src/main/resources/OSGI-INF/serviceComponents.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractScriptInfo.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractScriptInfo.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractScriptInfo.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractScriptInfo.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,56 @@
+/*
+ * 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 javax.script.{ScriptContext, ScriptException}
+
+package org.apache.sling.scripting.scala {
+
+object AbstractScriptInfo {
+ val SCALA_SCRIPT_CLASS = "scala.script.class"
+ val DEFAULT_SCALA_SCRIPT_CLASS = "org.apache.sling.scripting.scala.Script"
+}
+
+/**
+ * Abstract base implementation of {@link ScriptInfo}.
+ */
+abstract class AbstractScriptInfo(protected var defaultScriptClass: String) extends ScriptInfo {
+
+ def this() {
+ this(AbstractScriptInfo.DEFAULT_SCALA_SCRIPT_CLASS)
+ }
+
+ /**
+ * @return {@link #DEFAULT_SCALA_SCRIPT_CLASS}
+ */
+ def getDefaultScriptClass = defaultScriptClass
+
+ /**
+ * @return the value of the {@link AbstractScriptInfo.SCALA_SCRIPT_CLASS} attribute
+ * in the <code>context</code>.
+ */
+ @throws(classOf[ScriptException])
+ def getScriptClass(script: String, context: ScriptContext) = {
+ val value = context.getAttribute(AbstractScriptInfo.SCALA_SCRIPT_CLASS);
+
+ value match {
+ case v: String => v
+ case _ => defaultScriptClass
+ }
+ }
+
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractSettingsProvider.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractSettingsProvider.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractSettingsProvider.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/AbstractSettingsProvider.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,99 @@
+/*
+ * 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 javax.script.ScriptException;
+
+import org.apache.sling.scripting.scala.interpreter.ScalaInterpreter
+import org.slf4j.LoggerFactory
+
+import scala.tools.nsc.Settings
+import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.reporters.Reporter
+
+package org.apache.sling.scripting.scala {
+
+/**
+ * Abstract base implementation of a {@link SettingsProvider}.
+ */
+abstract class AbstractSettingsProvider extends SettingsProvider {
+ protected var settings: Settings = new Settings
+ protected var reporter: Reporter = createReporter(settings)
+ protected var classpathX: Array[AbstractFile] = null
+ protected var outDir: AbstractFile = null
+
+ @throws(classOf[ScriptException])
+ def setScalaSettings(settings: Settings): Boolean = {
+ if (settings == null) {
+ throw new IllegalArgumentException(ScalaScriptEngineFactory.SCALA_SETTINGS + " must not be null");
+ }
+
+ if (this.settings != settings) {
+ this.settings = settings
+ reporter = createReporter(settings)
+ true
+ }
+ else false
+ }
+
+ @throws(classOf[ScriptException])
+ def getSettings: Settings = settings
+
+ @throws(classOf[ScriptException])
+ def setReporter(reporter: Reporter): Boolean = {
+ if (reporter == null) {
+ throw new IllegalArgumentException(ScalaScriptEngineFactory.SCALA_REPORTER + " must not be null");
+ }
+
+ if (this.reporter != null) {
+ this.reporter = reporter
+ true
+ }
+ else false
+ }
+
+ @throws(classOf[ScriptException])
+ def getReporter: Reporter = reporter
+
+ @throws(classOf[ScriptException])
+ def setClasspathX(classpathX: Array[AbstractFile]): Boolean = {
+ if (this.classpathX != classpathX) {
+ this.classpathX = classpathX
+ true
+ }
+ else false
+ }
+
+ @throws(classOf[ScriptException])
+ def getClasspathX: Array[AbstractFile] = classpathX
+
+ @throws(classOf[ScriptException])
+ def setOutDir(outDir: AbstractFile): Boolean = {
+ if (this.outDir != outDir) {
+ this.outDir = outDir
+ true
+ }
+ else false
+ }
+
+ @throws(classOf[ScriptException])
+ def getOutDir: AbstractFile = outDir
+
+ protected def createReporter(settings: Settings) =
+ new LogReporter(LoggerFactory.getLogger(classOf[ScalaInterpreter]), settings);
+
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BacklogReporter.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BacklogReporter.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BacklogReporter.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BacklogReporter.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,82 @@
+/*
+ * 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;
+import scala.tools.nsc.reporters.AbstractReporter;
+import scala.tools.nsc.util.Position;
+
+package org.apache.sling.scripting.scala {
+
+object BacklogReporter {
+ val DEFAULT_SIZE = 50
+}
+
+class BacklogReporter(val settings: Settings, size: Int) extends AbstractReporter {
+ private var backLog: List[Info] = Nil
+
+ def this(settings: Settings) {
+ this(settings, BacklogReporter.DEFAULT_SIZE)
+ }
+
+ override def reset() {
+ super.reset
+ backLog = Nil
+ }
+
+ override def display(pos: Position, msg: String, severity: Severity) {
+ severity.count += 1
+ if (size > 0) {
+ backLog = backLog:::List(new Info(pos, msg, severity))
+ if (backLog.length > size) {
+ backLog = backLog.tail
+ }
+ }
+ }
+
+ override def displayPrompt() {
+ // empty
+ }
+
+ override def toString =
+ backLog.map(_.toString).mkString("\n")
+
+ private class Info(pos: Position, msg: String, severity: Severity) {
+
+ override def toString = {
+ val level = severity match {
+ case INFO => "INFO "
+ case WARNING => "WARNING "
+ case _ => "ERROR "
+ }
+
+ val source = pos.source match {
+ case Some(s) => s + " "
+ case _ => ""
+ }
+
+ val line = pos.line match {
+ case Some(l) => "line " + l + " "
+ case _ => ""
+ }
+
+ level + source + line + ": " + msg
+ }
+
+ }
+
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BundleFS.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BundleFS.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BundleFS.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BundleFS.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,183 @@
+/*
+ * 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 java.net.URL
+import java.io.{File, IOException, InputStream}
+
+import org.apache.sling.scripting.scala.Utils.{valueOrElse, nullOrElse}
+
+import org.osgi.framework.Bundle
+
+import scala.tools.nsc.io.AbstractFile
+
+package org.apache.sling.scripting.scala {
+
+/**
+ * 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 {
+ require(url != null, "url must not be null")
+ 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)
+ var nextEntry = prefetch()
+
+ def hasNext() = {
+ if (nextEntry == null)
+ nextEntry = prefetch()
+
+ nextEntry != null
+ }
+
+ def next() = {
+ if (hasNext()) {
+ val entry = nextEntry
+ nextEntry = null
+ entry
+ }
+ else {
+ throw new NoSuchElementException()
+ }
+ }
+
+ private def prefetch() = {
+ if (dirs.hasMoreElements) {
+ val entry = dirs.nextElement.asInstanceOf[String]
+ var entryUrl = bundle.getResource("/" + entry)
+
+ // Bundle.getResource seems to be inconsistent with respect to requiring
+ // a trailing slash
+ if (entryUrl == null)
+ entryUrl = bundle.getResource("/" + removeTralingSlash(entry))
+
+ // If still null OSGi wont let use load that resource for some reason
+ if (entryUrl == null) {
+ null
+ }
+ else {
+ if (entry.endsWith(".class"))
+ new FileEntry(entryUrl, DirEntry.this)
+ else
+ new DirEntry(entryUrl, DirEntry.this)
+ }
+ }
+ else
+ null
+ }
+
+ private def removeTralingSlash(s: String): String =
+ if (s == null || s.length == 0)
+ s
+ else if (s.last == '/')
+ removeTralingSlash(s.substring(0, s.length - 1))
+ else
+ s
+ }
+ }
+
+ 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: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/JcrFS.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/JcrFS.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/JcrFS.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/JcrFS.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,254 @@
+/*
+ * 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 {
+
+/**
+ * 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 "sling: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
+ }
+
+}
+
+}
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/LogReporter.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/LogReporter.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/LogReporter.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/LogReporter.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,38 @@
+/*
+ * 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 org.slf4j.Logger
+
+import scala.tools.nsc.Settings
+import scala.tools.nsc.util.Position
+
+package org.apache.sling.scripting.scala {
+
+class LogReporter(logger: Logger, settings: Settings) extends BacklogReporter(settings) {
+
+ override def display(pos: Position, msg: String, severity: Severity) {
+ super.display(pos, msg, severity)
+
+ severity match {
+ case INFO => logger.info("{}: {}", msg, pos);
+ case WARNING => logger.warn("{}: {}", msg, pos);
+ case _ => logger.error("{}: {}", msg, pos);
+ }
+ }
+
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngine.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngine.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngine.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngine.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,181 @@
+/*
+ * 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 java.io.{BufferedReader, Reader, IOException, OutputStream, InputStream}
+import java.util.concurrent.locks.{ReadWriteLock, ReentrantReadWriteLock}
+
+import javax.script.{AbstractScriptEngine, Bindings, SimpleBindings, ScriptEngineFactory,
+ ScriptException, ScriptContext}
+
+import org.apache.sling.scripting.scala.interpreter.{Bindings => ScalaBindings}
+import org.apache.sling.scripting.scala.Utils.makeIdentifier
+
+import org.slf4j.LoggerFactory
+
+import scala.tools.nsc.reporters.Reporter
+
+package org.apache.sling.scripting.scala {
+
+object ScalaScriptEngine {
+ private val log = LoggerFactory.getLogger(classOf[ScalaScriptEngine]);
+ private val NL = System.getProperty("line.separator");
+}
+
+/**
+ * JSR 223 compliant {@link ScriptEngine} for Scala.
+ * Scripts must be of the following form:
+ *
+ * <pre>
+ * package my.cool.script
+ * class foo(vars: fooVars) {
+ * import vars._ // import the bindings
+ *
+ * println("bar:" + bar)
+ * }
+ * </pre>
+ *
+ * Here it is assumed that the {@Bindings} passed for script evaluation contains a
+ * value for the name <em>bar</em>.
+ *
+ * The parameter <code>vars</code> contains statically typed bindings generated from the
+ * <code>Bindings</code> passed to the script engine. The individual values in
+ * <code>vars</code> appear to be of all visible types. This is achieved using implicit
+ * conversion when necessary: for a value v of type T let S be the smallest super type of T
+ * which is accessible (i.e. class loading succeeds). Then v is exposed with static type
+ * S in <code>vars</code>. Let further be J the set of interface implemented by T which
+ * are not implemented by S already. For each interface I in J which has no super type
+ * I' of I in J an implicit conversion from S to I is included in <code>vars</code>.
+ */
+class ScalaScriptEngine(factory: ScalaScriptEngineFactory, scriptInfo: ScriptInfo)
+ extends AbstractScriptEngine {
+
+ import ScalaScriptEngine._
+
+ private def rwLock = new ReentrantReadWriteLock();
+
+ // -----------------------------------------------------< AbstractScriptEngine >---
+
+ def createBindings: Bindings =
+ new SimpleBindings
+
+ def getFactory: ScriptEngineFactory =
+ factory;
+
+ @throws(classOf[ScriptException])
+ def eval(reader: Reader, context: ScriptContext) = {
+ val script = new StringBuilder;
+ try {
+ val bufferedScript = new BufferedReader(reader);
+
+ var nextLine = bufferedScript.readLine
+ while (nextLine != null) {
+ script.append(nextLine)
+ script.append(NL)
+ nextLine = bufferedScript.readLine
+ }
+ }
+ catch {
+ case e: IOException => throw new ScriptException(e)
+ }
+
+ eval(script.toString, context)
+ }
+
+ @throws(classOf[ScriptException])
+ def eval(script: String, context: ScriptContext) = {
+ try {
+ val bindings = context.getBindings(ScriptContext.ENGINE_SCOPE)
+ val scalaBindings = ScalaBindings()
+
+ import _root_.scala.collection.jcl.Conversions._
+ for (val key <- bindings.keySet) key match {
+ case name: String => {
+ val value = bindings.get(name)
+ if (value == null) log.debug("{} has null value. skipping", name)
+ else scalaBindings.putValue(makeIdentifier(name), value)
+ }
+ case x => log.debug("Bindings contain invalid key {}. skipping", x)
+ }
+
+ val scriptClass = scriptInfo.getScriptClass(script, context)
+
+ // xxx: Scripts need to be compiled everytime.
+ // The preamble for injecting the bindings into the script
+ // dependes on the actual types of the bindings. So effectively
+ // there is a specific script generated for each type of bindings.
+ val interpreter = factory.getScalaInterpreter(context)
+ var result: Reporter = writeLocked(rwLock) {
+ interpreter.compile(scriptClass, script, scalaBindings)
+ }
+
+ if (result != null && result.hasErrors)
+ throw new ScriptException(result.toString)
+
+ result = readLocked(rwLock) {
+ val outputStream = new OutputStream {
+ val writer = context.getWriter
+
+ @throws(classOf[IOException])
+ def write(b: Int) {
+ writer.write(b)
+ }
+ }
+
+ val inputStream = new InputStream {
+ val reader = context.getReader
+
+ @throws(classOf[IOException])
+ def read() = reader.read();
+ }
+
+ val result = interpreter.execute(scriptClass, scalaBindings, inputStream, outputStream)
+ outputStream.flush()
+ result
+ }
+ if (result.hasErrors)
+ throw new ScriptException(result.toString)
+ }
+ catch {
+ case e: ScriptException => throw e
+ case e: Exception => throw new ScriptException("Error executing script").initCause(e)
+ }
+ }
+
+ // -----------------------------------------------------< private >---
+
+ private def readLocked[T](lock: ReadWriteLock)(thunk: => T) = {
+ lock.readLock.lock()
+ try {
+ thunk
+ }
+ finally {
+ lock.readLock.unlock()
+ }
+ }
+
+ private def writeLocked[T](lock: ReadWriteLock)(thunk: => T) = {
+ lock.writeLock.lock()
+ try {
+ thunk
+ }
+ finally {
+ lock.writeLock.unlock()
+ }
+ }
+
+}
+
+}
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngineFactory.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngineFactory.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngineFactory.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScalaScriptEngineFactory.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,200 @@
+/*
+ * 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 java.util.Collections
+import java.util.List
+
+import javax.script.{ScriptException, ScriptEngine, ScriptEngineFactory, ScriptContext}
+
+import org.apache.sling.scripting.scala.interpreter.ScalaInterpreter
+import org.slf4j.LoggerFactory
+
+import scala.tools.nsc.Settings
+import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.reporters.Reporter
+
+package org.apache.sling.scripting.scala {
+
+object ScalaScriptEngineFactory {
+ private val log = LoggerFactory.getLogger(classOf[ScalaScriptEngineFactory]);
+ private val NL = System.getProperty("line.separator");
+
+ val SCALA_SETTINGS = "scala.settings"
+ val SCALA_REPORTER = "scala.reporter"
+ val SCALA_CLASSPATH_X = "scala.classpath.x"
+ val SCALA_CLASS_DIR = "scala.classdir"
+
+ val ENGINE_NAME = "Scala Scripting Engine"
+ val LANGUAGE_VERSION = "2.7.7"
+ val ENGINE_VERSION = "0.9/scala " + LANGUAGE_VERSION
+ val EXTENSIONS = Collections.singletonList("scala")
+ val LANGUAGE_NAME = "Scala"
+ val MIME_TYPES = Collections.singletonList("application/x-scala")
+ val NAMES = Collections.singletonList("scala")
+}
+
+/**
+ * JSR 223 compliant {@link ScriptEngineFactory} for Scala.
+ * {@link ScriptInfo} and {@link SettingsProvider} may be used to parametrize
+ * this factory. When running inside an OSGi container, ScriptInfo and
+ * SettingsProvider are looked up and injected by the Service Component Runtime.
+ */
+class ScalaScriptEngineFactory extends ScriptEngineFactory {
+ import ScalaScriptEngineFactory._
+
+ @volatile
+ private var scriptInfo: ScriptInfo =
+ new AbstractScriptInfo{}
+
+ @volatile
+ private var settingsProvider: SettingsProvider =
+ new AbstractSettingsProvider{}
+
+ private var scalaInterpreter: ScalaInterpreter = null;
+
+ // -----------------------------------------------------< ScriptEngineFactory >---
+
+ def getEngineName: String = ENGINE_NAME
+ def getEngineVersion: String = ENGINE_VERSION
+ def getExtensions: List[String] = EXTENSIONS
+ def getLanguageName: String = LANGUAGE_NAME
+ def getLanguageVersion: String = LANGUAGE_VERSION
+ def getMimeTypes: List[String] = MIME_TYPES
+ def getNames: List[String] = NAMES
+
+ def getParameter(key: String): String = key.toUpperCase match {
+ case ScriptEngine.ENGINE => getEngineName
+ case ScriptEngine.ENGINE_VERSION => getEngineVersion
+ case ScriptEngine.NAME => getNames.get(0)
+ case ScriptEngine.LANGUAGE => getLanguageName
+ case ScriptEngine.LANGUAGE_VERSION => getLanguageVersion
+ case "threading" => "multithreaded"
+ case _ => null
+ }
+
+ def getMethodCallSyntax(obj: String, method: String, args: Array[String]): String =
+ obj + "." + method + "(" + args.mkString(",") + ")"
+
+ def getOutputStatement(toDisplay: String): String =
+ "println(\""+ toDisplay+ "\")"
+
+ def getProgram(statements: Array[String]): String = {
+ def packageOf(className: String ) = {
+ val i = className.lastIndexOf('.')
+ if (i >= 0) className.substring(0, i)
+ else null
+ }
+
+ def classOf(className: String) = {
+ val i = className.lastIndexOf('.')
+ if (i == className.length()) ""
+ else className.substring(i + 1)
+ }
+
+ val qClassName = scriptInfo.getDefaultScriptClass
+ val packageName = packageOf(qClassName);
+ val className = classOf(qClassName);
+
+ "package " + packageName + " {" + NL +
+ " class " + className + "(vars: " + className + "Vars) {" + NL +
+ statements.mkString(NL) +
+ " }" + NL +
+ "}" + NL;
+ }
+
+ def getScriptEngine: ScriptEngine =
+ new ScalaScriptEngine(this, scriptInfo)
+
+ // -----------------------------------------------------< SCR integration >---
+
+ def setScriptInfo(scriptInfo: ScriptInfo) {
+ if (scriptInfo == null)
+ throw new IllegalArgumentException("ScriptInfo may not be null")
+
+ if (scriptInfo != this.scriptInfo)
+ this.scriptInfo = scriptInfo
+ }
+
+ protected def unsetScriptInfo(scriptInfo: ScriptInfo) {
+ this.scriptInfo = new AbstractScriptInfo{}
+ }
+
+ def getScriptInfoProvider: ScriptInfo = scriptInfo
+
+ def setSettingsProvider(settingsProvider: SettingsProvider) {
+ if (settingsProvider == null)
+ throw new IllegalArgumentException("SettingsProvider may not be null")
+
+ if (this.settingsProvider != settingsProvider) {
+ this.settingsProvider = settingsProvider
+ scalaInterpreter = null
+ }
+ }
+
+ protected def unsetSettingsProvider(settingsProvider: SettingsProvider) {
+ this.settingsProvider = new AbstractSettingsProvider{}
+ }
+
+ def getSettingsProvider: SettingsProvider = settingsProvider
+
+ // -----------------------------------------------------< private >---
+
+ @throws(classOf[ScriptException])
+ def getScalaInterpreter(context: ScriptContext): ScalaInterpreter = {
+ context.getAttribute(SCALA_SETTINGS) match {
+ case settings: Settings =>
+ if (settingsProvider.setScalaSettings(settings)) scalaInterpreter = null
+
+ case x => if (x != null) log.warn("Invalid settings: {}", x);
+ }
+
+ context.getAttribute(SCALA_REPORTER) match {
+ case reporter: Reporter =>
+ if (settingsProvider.setReporter(reporter)) scalaInterpreter = null
+
+ case x => if (x != null) log.warn("Invalid reporter: {}", x);
+ }
+
+ context.getAttribute(SCALA_CLASSPATH_X) match {
+ case classpath: Array[AbstractFile] =>
+ if (settingsProvider.setClasspathX(classpath)) scalaInterpreter = null
+
+ case x => if (x != null) log.warn("Invalid classpathx: {}", x);
+ }
+
+ context.getAttribute(SCALA_CLASS_DIR) match {
+ case outDir: AbstractFile =>
+ if (settingsProvider.setOutDir(outDir)) scalaInterpreter = null
+
+ case x => if (x != null) log.warn("Invalid output directory: {}", x);
+ }
+
+ if (scalaInterpreter == null) {
+ log.debug("Creating Scala script engine from settings {}", settingsProvider);
+
+ scalaInterpreter = new ScalaInterpreter(
+ settingsProvider.getSettings,
+ settingsProvider.getReporter,
+ settingsProvider.getClasspathX,
+ settingsProvider.getOutDir);
+ }
+
+ return scalaInterpreter;
+ }
+
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScriptInfo.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScriptInfo.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScriptInfo.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/ScriptInfo.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,38 @@
+/*
+ * 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 javax.script.{ScriptException, ScriptContext}
+
+package org.apache.sling.scripting.scala {
+
+/**
+ * A ScriptInfo instance provides information about Scala scripts.
+ */
+trait ScriptInfo {
+ /**
+ * @return the default name of the script class
+ */
+ def getDefaultScriptClass: String
+
+ /**
+ * @return the name of the script class ofr the passed <code>script</code> in
+ * the given <code>context</code>.
+ */
+ @throws(classOf[ScriptException])
+ def getScriptClass(script: String, context: ScriptContext): String
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/SettingsProvider.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/SettingsProvider.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/SettingsProvider.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/SettingsProvider.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,67 @@
+/*
+ * 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 javax.script.ScriptException
+
+import scala.tools.nsc.Settings
+import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.reporters.Reporter
+
+package org.apache.sling.scripting.scala {
+
+/**
+ * Provides compiler settings to the {@link ScalaScriptEngineFactory}.
+ */
+trait SettingsProvider {
+
+ /**
+ * @return true if the passed value differes from the current value
+ */
+ @throws(classOf[ScriptException])
+ def setScalaSettings(value: Settings): Boolean
+
+ @throws(classOf[ScriptException])
+ def getSettings: Settings
+
+ /**
+ * @return true if the passed value differes from the current value
+ */
+ @throws(classOf[ScriptException])
+ def setReporter(reporter: Reporter): Boolean
+
+ @throws(classOf[ScriptException])
+ def getReporter: Reporter
+
+ /**
+ * @return true if the passed value differes from the current value
+ */
+ @throws(classOf[ScriptException])
+ def setClasspathX(classpath: Array[AbstractFile]): Boolean
+
+ @throws(classOf[ScriptException])
+ def getClasspathX: Array[AbstractFile]
+
+ /**
+ * @return true if the passed value differes from the current value
+ */
+ @throws(classOf[ScriptException])
+ def setOutDir(outDir: AbstractFile): Boolean
+
+ @throws(classOf[ScriptException])
+ def getOutDir: AbstractFile
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/Utils.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/Utils.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/Utils.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/Utils.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,106 @@
+/*
+ * 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)
+
+ /**
+ * Converts the given identifier to a legal Java/Scala identifier
+ * @param identifier Identifier to convert
+ * @return Legal Java/Scala identifier corresponding to the given identifier
+ */
+ def makeIdentifier(identifier: String) = {
+ val id = new StringBuilder(identifier.length);
+ if (!Character.isJavaIdentifierStart(identifier.charAt(0)))
+ id.append('_');
+
+ for (val ch <- identifier) {
+ if (Character.isJavaIdentifierPart(ch) && ch != '_') id.append(ch)
+ else if (ch == '.') id.append('_')
+ else id.append(mangleChar(ch))
+ }
+
+ if (isKeyword(id.toString))
+ id.append('_')
+
+ id.toString
+ }
+
+ /**
+ * Mangle the specified character to create a legal Java/Scala class name.
+ */
+ def mangleChar(ch: Char) = {
+ val result = new StringBuilder("01234")
+ result(0) = '_'
+ result(1) = Character.forDigit((ch >> 12) & 0xf, 16)
+ result(2) = Character.forDigit((ch >> 8) & 0xf, 16)
+ result(3) = Character.forDigit((ch >> 4) & 0xf, 16)
+ result(4) = Character.forDigit(ch & 0xf, 16)
+ result
+ }
+
+ /**
+ * Test whether the argument is a Scala/Java keyword
+ */
+ def isKeyword(token: String) =
+ Set (
+ "abstract", "assert", "boolean", "break", "byte", "case", "catch",
+ "char", "class", "const", "continue", "default", "do", "double",
+ "else", "enum", "extends", "final", "finally", "float", "for",
+ "goto", "if", "implements", "import", "instanceof", "int",
+ "interface", "long", "native", "new", "package", "private",
+ "protected", "public", "return", "short", "static", "strictfp",
+ "super", "switch", "synchronized", "this", "throws", "transient",
+ "try", "void", "volatile", "while", "true", "false", "null",
+ "forSome", "type", "var", "val", "def", "with", "yield", "match",
+ "implicit", "lazy", "override", "sealed", "trait", "object"
+ ).contains(token)
+
+}
+
+}
\ No newline at end of file
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/Bindings.scala Mon Feb 1 19:37:24 2010
@@ -0,0 +1,121 @@
+/*
+ * 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._
+
+package org.apache.sling.scripting.scala.interpreter {
+
+/**
+ * Bindings of names to Values
+ */
+trait Bindings extends Map[String, AnyRef] {
+
+ /**
+ * Associate a value with a name
+ * @param name
+ * @param value
+ * @returns The value which was previously associated with the
+ * given name or null if none.
+ */
+ def putValue(name: String, value: AnyRef): AnyRef
+
+ /**
+ * @returns the value associated with the given name
+ * @param name
+ */
+ def getValue(name: String): AnyRef =
+ get(name) match {
+ case Some(a) => a
+ case None => null
+ }
+
+ /**
+ * Calculates the views of a class.
+ * Let <code>clazz</code> be of type <code>Clazz[T]</code> for some type T. Let S be the
+ * smallest super type of T which is accessible. Then <code>Class[S]</code> is the head
+ * of the result list of classes. Let further be J the set of interface implemented by
+ * T which are not implemented by S already. For each interface I in J which has no super
+ * type I' of I in J <code>Class[I]</code> is included in the tail of the result list of
+ * classes.
+ *
+ * @param clazz the class whos view to calculate
+ * @return a list of Class[_] instances representing the views of <code>clazz</code>.
+ */
+ def getViews(clazz: Class[_]) = {
+ def findLeastAccessibleClass(clazz: Class[_]): Class[_] = {
+ if (accessible(clazz)) clazz
+ else findLeastAccessibleClass(clazz.getSuperclass)
+ }
+
+ def getInterfacesUpTo(clazz: Class[_], bound: Class[_]) = {
+ def getInterfacesUpTo(intfs: mutable.Set[Class[_]], clazz: Class[_], bound: Class[_]): mutable.Set[Class[_]] =
+ if (clazz == bound) intfs
+ else getInterfacesUpTo(intfs ++ clazz.getInterfaces, clazz.getSuperclass, bound)
+
+ getInterfacesUpTo(mutable.Set.empty, clazz, bound)
+ }
+
+ def accessible(clazz: Class[_]) = {
+ try {
+ Class.forName(clazz.getName)
+ true
+ }
+ catch { case _ => false }
+ }
+
+ val l = findLeastAccessibleClass(clazz)
+ var o = getInterfacesUpTo(clazz, l)
+ var v = Set.empty ++ o
+
+ while (!v.isEmpty) {
+ val w = v.find(_ => true).get
+ val p = w.getInterfaces.filter(accessible)
+ o = o -- p
+ v = v - w ++ p
+ }
+
+ l::o.toList
+ }
+}
+
+/**
+ * Default implementation of {@link Bindings} backed by a mutable Map
+ */
+private class BindingsWrapper(map: mutable.Map[String, AnyRef]) extends Bindings {
+ def size: Int = map.size
+ def get(name: String) = map.get(name)
+ def elements: Iterator[(String, AnyRef)] = map.elements
+
+ def putValue(name: String, value: AnyRef) =
+ map.put(name, value) match {
+ case Some(a) => a
+ case None => null
+ }
+
+}
+
+object Bindings {
+ import _root_.scala.collection.jcl.Conversions.convertMap
+
+ def apply(): Bindings = new BindingsWrapper(new mutable.HashMap)
+ def apply(map: mutable.Map[String, AnyRef]): Bindings = new BindingsWrapper(map)
+ def apply(map: java.util.Map[String, AnyRef]): Bindings = new BindingsWrapper(map)
+}
+
+}
+
+
+
Added: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/InterpreterException.scala Mon Feb 1 19:37:24 2010
@@ -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: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaClasspath.scala Mon Feb 1 19:37:24 2010
@@ -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: sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala?rev=905388&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala (added)
+++ sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/interpreter/ScalaCompiler.scala Mon Feb 1 19:37:24 2010
@@ -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