You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2016/09/14 16:21:06 UTC

[1/5] jclouds-karaf git commit: JCLOUDS-1156: Shade the jsch-agentproxy-jsch bundle [Forced Update!]

Repository: jclouds-karaf
Updated Branches:
  refs/heads/fix-script-engine 6c0c7e6e8 -> 31190dabc (forced update)


JCLOUDS-1156: Shade the jsch-agentproxy-jsch bundle

Create a shaded bundle from the jsch-agentproxy-jsch to remove
the export that exposes core classes already exported by other
bundles.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/commit/00ff5d21
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/tree/00ff5d21
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/diff/00ff5d21

Branch: refs/heads/fix-script-engine
Commit: 00ff5d211a3f1b41ee2853ee527818ffd7beba2d
Parents: 960a9c7
Author: Ignasi Barrera <na...@apache.org>
Authored: Thu Sep 1 16:07:03 2016 +0200
Committer: Ignasi Barrera <na...@apache.org>
Committed: Thu Sep 8 10:32:23 2016 +0200

----------------------------------------------------------------------
 bundles/jsch-agentproxy-jsch/pom.xml   | 94 +++++++++++++++++++++++++++++
 bundles/pom.xml                        | 36 +++++++++++
 feature/src/main/resources/feature.xml |  2 +-
 pom.xml                                |  6 +-
 4 files changed, 132 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/00ff5d21/bundles/jsch-agentproxy-jsch/pom.xml
----------------------------------------------------------------------
diff --git a/bundles/jsch-agentproxy-jsch/pom.xml b/bundles/jsch-agentproxy-jsch/pom.xml
new file mode 100644
index 0000000..7a858cb
--- /dev/null
+++ b/bundles/jsch-agentproxy-jsch/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.jclouds.karaf</groupId>
+    <artifactId>bundles</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>org.apache.jclouds.karaf.bundles</groupId>
+  <artifactId>jsch-agentproxy-jsch</artifactId>
+  <name>jclouds :: Karaf :: JSch Agentproxy for JSch (shaded bundle)</name>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicemix.bundles</groupId>
+      <artifactId>org.apache.servicemix.bundles.jsch-agentproxy-jsch</artifactId>
+      <version>${jsch.agentproxy.bundle.version}</version>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <import.packages>
+      ft.jzlib;resolution:=optional;version="[1.1,2)",
+      keypairgen;resolution:=optional,
+      signature;resolution:=optional,
+      userauth;resolution:=optional,
+      org.ietf.jgss;resolution:=optional,
+      javax.crypto,
+      javax.crypto.interfaces,
+      javax.crypto.spec,
+      javax.naming, 
+      javax.naming.directory, 
+      javax.net, 
+      javax.security.auth.x500
+    </import.packages>
+  </properties>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
+        <configuration>
+          <instructions>
+            <Import-Package>${import.packages}</Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>2.4.3</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <!-- the RAT plugin complains if we use the default location and we don't want it in the SCM -->
+              <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
+              <artifactSet>
+                <includes>
+                  <include>org.apache.servicemix.bundles:org.apache.servicemix.bundles.jsch-agentproxy-jsch</include>
+                </includes>
+              </artifactSet>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/00ff5d21/bundles/pom.xml
----------------------------------------------------------------------
diff --git a/bundles/pom.xml b/bundles/pom.xml
new file mode 100644
index 0000000..087d08b
--- /dev/null
+++ b/bundles/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.jclouds</groupId>
+    <artifactId>jclouds-karaf</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>org.apache.jclouds.karaf</groupId>
+  <artifactId>bundles</artifactId>
+  <name>jclouds :: Karaf :: Bundles</name>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>jsch-agentproxy-jsch</module>
+  </modules>
+
+</project>

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/00ff5d21/feature/src/main/resources/feature.xml
----------------------------------------------------------------------
diff --git a/feature/src/main/resources/feature.xml b/feature/src/main/resources/feature.xml
index 44c536d..fb361a6 100644
--- a/feature/src/main/resources/feature.xml
+++ b/feature/src/main/resources/feature.xml
@@ -398,7 +398,7 @@ limitations under the License.
         <feature version='${project.version}'>jclouds-compute</feature>
         <feature version='${project.version}'>jclouds-blobstore</feature>
         <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jsch/${jsch.bundle.version}</bundle>
-        <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jsch-agentproxy-jsch/${jsch.agentproxy.bundle.version}</bundle>
+        <bundle dependency='true'>mvn:org.apache.jclouds.karaf.bundles/jsch-agentproxy-jsch/${project.version}</bundle>
         <bundle dependency='true'>mvn:com.jcraft/jsch.agentproxy.connector-factory/${jsch.agentproxy.version}</bundle>
         <bundle dependency='true'>mvn:com.jcraft/jsch.agentproxy.usocket-nc/${jsch.agentproxy.version}</bundle>
         <bundle dependency='true'>mvn:com.jcraft/jsch.agentproxy.sshagent/${jsch.agentproxy.version}</bundle>

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/00ff5d21/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index feeb07c..e207e52 100644
--- a/pom.xml
+++ b/pom.xml
@@ -169,6 +169,7 @@ limitations under the License.
 
   <modules>
     <module>core</module>
+    <module>bundles</module>
     <module>utils</module>
     <module>cache</module>
     <module>commands</module>
@@ -468,11 +469,6 @@ limitations under the License.
 
       <!-- JSch agentproxy -->
       <dependency>
-        <groupId>org.apache.servicemix.bundles</groupId>
-        <artifactId>org.apache.servicemix.bundles.jsch-agentproxy-jsch</artifactId>
-        <version>${jsch.agentproxy.bundle.version}</version>
-      </dependency>
-      <dependency>
         <groupId>com.jcraft</groupId>
         <artifactId>jsch.agentproxy.connector-factory</artifactId>
         <version>${jsch.agentproxy.version}</version>


[4/5] jclouds-karaf git commit: Align the version of org.apache.felix.configadmin with jclouds-cli

Posted by an...@apache.org.
Align the version of org.apache.felix.configadmin with jclouds-cli


Project: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/commit/4fe7b32d
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/tree/4fe7b32d
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/diff/4fe7b32d

Branch: refs/heads/fix-script-engine
Commit: 4fe7b32d042674ed678d96bec09bd6753bd14591
Parents: 522e245
Author: Andrew Phillips <an...@apache.org>
Authored: Tue Sep 6 23:52:25 2016 -0400
Committer: Andrew Phillips <an...@apache.org>
Committed: Wed Sep 14 17:14:26 2016 +0100

----------------------------------------------------------------------
 pom.xml | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/4fe7b32d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e207e52..f5bf069 100644
--- a/pom.xml
+++ b/pom.xml
@@ -184,9 +184,8 @@ limitations under the License.
   <properties>
     <aopalliance.bundle.version>1.0_5</aopalliance.bundle.version>
     <bcprov.version>1.51</bcprov.version>
-    <configadmin.version>1.2.8</configadmin.version>
     <easymock.version>3.0</easymock.version>
-    <felix.configadmin.version>1.2.8</felix.configadmin.version>
+    <felix.configadmin.version>1.8.0</felix.configadmin.version>
     <groovy.version>2.4.4</groovy.version>
     <gson.version>2.5</gson.version>
     <guava.version>16.0.1</guava.version>
@@ -310,7 +309,7 @@ limitations under the License.
       <dependency>
         <groupId>org.apache.felix</groupId>
         <artifactId>org.apache.felix.configadmin</artifactId>
-        <version>${configadmin.version}</version>
+        <version>${felix.configadmin.version}</version>
       </dependency>
 
       <!-- Pax Url -->


[5/5] jclouds-karaf git commit: Use an OSGi-compliant way of loading JSR 223 script engines

Posted by an...@apache.org.
Use an OSGi-compliant way of loading JSR 223 script engines


Project: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/commit/31190dab
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/tree/31190dab
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/diff/31190dab

Branch: refs/heads/fix-script-engine
Commit: 31190dabc5ba8ba2696ca30da0e089023024782e
Parents: 4fe7b32
Author: Andrew Phillips <de...@yahoo.co.uk>
Authored: Tue Sep 6 23:28:19 2016 -0400
Committer: Andrew Phillips <an...@apache.org>
Committed: Wed Sep 14 17:17:07 2016 +0100

----------------------------------------------------------------------
 .../commands/table/BasicShellTableFactory.java  |   9 +-
 .../table/internal/ScriptEngineShellTable.java  |  19 +-
 .../table/internal/osgi/OSGiScriptEngine.java   |  95 ++++++
 .../internal/osgi/OSGiScriptEngineFactory.java  |  98 ++++++
 .../internal/osgi/OSGiScriptEngineManager.java  | 296 +++++++++++++++++++
 .../OSGI-INF/blueprint/jclouds-commands.xml     |   8 +-
 feature/src/main/resources/feature.xml          |   1 -
 pom.xml                                         |   7 -
 8 files changed, 516 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/commands/src/main/java/org/jclouds/karaf/commands/table/BasicShellTableFactory.java
----------------------------------------------------------------------
diff --git a/commands/src/main/java/org/jclouds/karaf/commands/table/BasicShellTableFactory.java b/commands/src/main/java/org/jclouds/karaf/commands/table/BasicShellTableFactory.java
index 1769c7f..afb368a 100644
--- a/commands/src/main/java/org/jclouds/karaf/commands/table/BasicShellTableFactory.java
+++ b/commands/src/main/java/org/jclouds/karaf/commands/table/BasicShellTableFactory.java
@@ -24,10 +24,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.script.ScriptEngineManager;
+
 /**
  * A basic {@link org.jclouds.karaf.commands.table.ShellTableFactory} implementation which is backed by a {@link Map}.
  */
 public class BasicShellTableFactory implements ShellTableFactory {
+   private ScriptEngineManager scriptEngineManager;
 
    private final Map properties = new HashMap();
   /**
@@ -49,7 +52,7 @@ public class BasicShellTableFactory implements ShellTableFactory {
       List<String> headers =  Arrays.asList(headersValue.split(delimiter));
       List<String> expressions =  Arrays.asList(expressionsValue.split(delimiter));
       List<String> alignments =  Arrays.asList(alignValue.split(delimiter));
-      ShellTable shellTable = new ScriptEngineShellTable(engine);
+      ShellTable shellTable = new ScriptEngineShellTable(scriptEngineManager, engine);
 
       shellTable.setType(type);
       shellTable.setHeaders(headers);
@@ -63,4 +66,8 @@ public class BasicShellTableFactory implements ShellTableFactory {
   public Map getProperties() {
     return properties;
   }
+
+  public void setScriptEngineManager(ScriptEngineManager scriptEngineManager) {
+    this.scriptEngineManager = scriptEngineManager;
+  }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/commands/src/main/java/org/jclouds/karaf/commands/table/internal/ScriptEngineShellTable.java
----------------------------------------------------------------------
diff --git a/commands/src/main/java/org/jclouds/karaf/commands/table/internal/ScriptEngineShellTable.java b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/ScriptEngineShellTable.java
index 9bce9e6..e3a3ac9 100644
--- a/commands/src/main/java/org/jclouds/karaf/commands/table/internal/ScriptEngineShellTable.java
+++ b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/ScriptEngineShellTable.java
@@ -18,6 +18,8 @@
 package org.jclouds.karaf.commands.table.internal;
 
 import org.jclouds.karaf.commands.table.BasicShellTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
@@ -26,18 +28,19 @@ import javax.script.ScriptEngineManager;
  * A shell table implementation that works with groovy expressions.
  */
 public class ScriptEngineShellTable<D extends Object> extends BasicShellTable<D> {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ScriptEngineShellTable.class);
 
-  private final String engine;
-  private final ScriptEngineManager scriptEngineFactory = new ScriptEngineManager();
   private final ScriptEngine scriptEngine;
 
   /**
    * Constructor
    * @param engine
    */
-  public ScriptEngineShellTable(String engine) {
-    this.engine = engine;
-    this.scriptEngine = scriptEngineFactory.getEngineByName(engine);
+  public ScriptEngineShellTable(ScriptEngineManager scriptEngineManager, String engine) {
+    this.scriptEngine = scriptEngineManager.getEngineByName(engine);
+    if (scriptEngine == null) {
+       throw new IllegalStateException("Unable to load script engine " + engine);
+    }
   }
 
   /**
@@ -51,8 +54,10 @@ public class ScriptEngineShellTable<D extends Object> extends BasicShellTable<D>
     try {
       scriptEngine.put(getType(), obj);
       result = String.valueOf(scriptEngine.eval(expression));
-    } catch (Exception ex) {
-      //Ignore
+    } catch (Exception exception) {
+       LOGGER.warn("Unable to evaluate expression %s due to: %s. Please check your shell confugration",
+             expression, exception.getMessage());
+       result = "<evalution error - see log>";
     }
     return result;
   }

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngine.java
----------------------------------------------------------------------
diff --git a/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngine.java b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngine.java
new file mode 100644
index 0000000..8f7f7a2
--- /dev/null
+++ b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngine.java
@@ -0,0 +1,95 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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.
+ *
+ */
+
+package org.jclouds.karaf.commands.table.internal.osgi;
+
+import java.io.Reader;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+
+// modified version of http://svn.apache.org/repos/asf/felix/trunk/mishell/src/main/java/org/apache/felix/mishell/OSGiScriptEngine.java
+public class OSGiScriptEngine implements ScriptEngine {
+   private ScriptEngine engine;
+   private OSGiScriptEngineFactory factory;
+
+   public OSGiScriptEngine(ScriptEngine engine, OSGiScriptEngineFactory factory) {
+      this.engine = engine;
+      this.factory = factory;
+   }
+
+   public Bindings createBindings() {
+      return engine.createBindings();
+   }
+
+   public Object eval(Reader reader, Bindings n) throws ScriptException {
+      return engine.eval(reader, n);
+   }
+
+   public Object eval(Reader reader, ScriptContext context)
+         throws ScriptException {
+      return engine.eval(reader, context);
+   }
+
+   public Object eval(Reader reader) throws ScriptException {
+      return engine.eval(reader);
+   }
+
+   public Object eval(String script, Bindings n) throws ScriptException {
+      return engine.eval(script, n);
+   }
+
+   public Object eval(String script, ScriptContext context)
+         throws ScriptException {
+      return engine.eval(script, context);
+   }
+
+   public Object eval(String script) throws ScriptException {
+      return engine.eval(script);
+   }
+
+   public Object get(String key) {
+      return engine.get(key);
+   }
+
+   public Bindings getBindings(int scope) {
+      return engine.getBindings(scope);
+   }
+
+   public ScriptContext getContext() {
+      return engine.getContext();
+   }
+
+   public ScriptEngineFactory getFactory() {
+      return factory;
+   }
+
+   public void put(String key, Object value) {
+      engine.put(key, value);
+   }
+
+   public void setBindings(Bindings bindings, int scope) {
+      engine.setBindings(bindings, scope);
+   }
+
+   public void setContext(ScriptContext context) {
+      engine.setContext(context);
+   }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineFactory.java
----------------------------------------------------------------------
diff --git a/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineFactory.java b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineFactory.java
new file mode 100644
index 0000000..08d80c4
--- /dev/null
+++ b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineFactory.java
@@ -0,0 +1,98 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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.
+ *
+ */
+package org.jclouds.karaf.commands.table.internal.osgi;
+
+import java.util.List;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+/**
+ * This is a wrapper class for the ScriptEngineFactory class that deals with
+ * context class loader issues It is necessary because engines (at least ruby)
+ * use the context classloader to find their resources (i.e., their "native"
+ * classes)
+ */
+
+// modified version of http://svn.apache.org/repos/asf/felix/trunk/mishell/src/main/java/org/apache/felix/mishell/OSGiScriptEngineFactory.java
+public class OSGiScriptEngineFactory implements ScriptEngineFactory {
+   private ScriptEngineFactory factory;
+   private ClassLoader contextClassLoader;
+
+   public OSGiScriptEngineFactory(ScriptEngineFactory factory,
+         ClassLoader contextClassLoader) {
+      this.factory = factory;
+      this.contextClassLoader = contextClassLoader;
+   }
+
+   public String getEngineName() {
+      return factory.getEngineName();
+   }
+
+   public String getEngineVersion() {
+      return factory.getEngineVersion();
+   }
+
+   public List<String> getExtensions() {
+      return factory.getExtensions();
+   }
+
+   public String getLanguageName() {
+      return factory.getLanguageName();
+   }
+
+   public String getLanguageVersion() {
+      return factory.getLanguageVersion();
+   }
+
+   public String getMethodCallSyntax(String obj, String m, String... args) {
+      return factory.getMethodCallSyntax(obj, m, args);
+   }
+
+   public List<String> getMimeTypes() {
+      return factory.getMimeTypes();
+   }
+
+   public List<String> getNames() {
+      return factory.getNames();
+   }
+
+   public String getOutputStatement(String toDisplay) {
+      return factory.getOutputStatement(toDisplay);
+   }
+
+   public Object getParameter(String key) {
+      return factory.getParameter(key);
+   }
+
+   public String getProgram(String... statements) {
+      return factory.getProgram(statements);
+   }
+
+   public ScriptEngine getScriptEngine() {
+      ScriptEngine engine = null;
+      if (contextClassLoader != null) {
+         ClassLoader old = Thread.currentThread().getContextClassLoader();
+         Thread.currentThread().setContextClassLoader(contextClassLoader);
+         engine = factory.getScriptEngine();
+         Thread.currentThread().setContextClassLoader(old);
+      } else
+         engine = factory.getScriptEngine();
+      return engine;
+   }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineManager.java
----------------------------------------------------------------------
diff --git a/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineManager.java b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineManager.java
new file mode 100644
index 0000000..0190ecd
--- /dev/null
+++ b/commands/src/main/java/org/jclouds/karaf/commands/table/internal/osgi/OSGiScriptEngineManager.java
@@ -0,0 +1,296 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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.
+ *
+ */
+
+package org.jclouds.karaf.commands.table.internal.osgi;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.script.Bindings;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+import javax.script.SimpleBindings;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class acts as a delegate for all the available ScriptEngineManagers.
+ * Unluckily, the standard did not define it as an interface, so we need to
+ * extend it to allow polymorphism. However, no calls to super are used. It
+ * wraps all available ScriptEngineManagers in the OSGi ServicePlatform into a
+ * merged ScriptEngineManager.
+ *
+ * Internally, what this class does is creating ScriptEngineManagers for each
+ * bundle that contains a ScriptEngineFactory and includes a
+ * META-INF/services/javax.script.ScriptEngineFactory file. It assumes that the
+ * file contains a list of @link ScriptEngineFactory classes. For each bundle,
+ * it creates a ScriptEngineManager, then merges them. @link ScriptEngineFactory
+ * objects are wrapped into @link OSGiScriptEngineFactory objects to deal with
+ * problems of context class loader: Those scripting engines that rely on the
+ * ContextClassloader for finding resources need to use this wrapper and the @link
+ * OSGiScriptFactory. Mainly, jruby does.
+ *
+ * Note that even if no context classloader issues arose, it would still be
+ * needed to search manually for the factories and either use them directly
+ * (losing the mimeType/extension/shortName mechanisms for finding engines or
+ * manually registering them) or still use this class, which would be smarter.
+ * In the latter case, it would only be needed to remove the hack that
+ * temporarily sets the context classloader to the appropriate, bundle-related,
+ * class loader.
+ *
+ * Caveats:
+ * <ul>
+ * <li>
+ * All factories are wrapped with an {@link OSGiScriptEngineFactory}. As Engines
+ * are not wrapped, calls like <code>
+ * ScriptEngineManager osgiManager=new OSGiScriptEngineManager(context);<br>
+ * ScriptEngine engine=osgiManager.getEngineByName("ruby");
+ * ScriptEngineFactory factory=engine.getFactory() //this does not return the OSGiFactory wrapper
+ * factory.getScriptEngine(); //this might fail, as it does not use OSGiScriptEngineFactory wrapper
+ * </code>
+ * might result in unexpected errors. Future versions may wrap the ScriptEngine
+ * with a OSGiScriptEngine to solve this issue, but for the moment it is not
+ * needed.</li>
+ */
+
+// modified version of http://svn.apache.org/repos/asf/felix/trunk/mishell/src/main/java/org/apache/felix/mishell/OSGiScriptEngineManager.java
+public class OSGiScriptEngineManager extends ScriptEngineManager {
+   private static final Logger LOGGER = LoggerFactory.getLogger(OSGiScriptEngineManager.class);
+
+   private Bindings bindings;
+   private Map<ScriptEngineManager, ClassLoader> classLoaders;
+   private BundleContext context;
+
+   public OSGiScriptEngineManager(BundleContext context) {
+      this.context = context;
+      bindings = new SimpleBindings();
+      this.classLoaders = findManagers(context);
+   }
+
+   /**
+    * This method is the only one that is visible and not part of the
+    * ScriptEngineManager class. Its purpose is to find new managers that
+    * weren't available before, but keeping the globalScope bindings set. If you
+    * want to clean the bindings you can either get a fresh instance of
+    * OSGiScriptManager or setting up a new bindings object. This can be done
+    * with: <code>
+    * ScriptEngineManager manager=new OSGiScriptEngineManager(context);
+    * (...) //do stuff
+    * osgiManager=(OSGiScriptEngineManager)manager; //cast to ease reading
+    * osgiManager.reloadManagers();
+    *
+    * manager.setBindings(new OSGiBindings()); //or you can use your own bindings implementation
+    * </code>
+    */
+   public void reloadManagers() {
+      this.classLoaders = findManagers(context);
+   }
+
+   public Object get(String key) {
+      return bindings.get(key);
+   }
+
+   public Bindings getBindings() {
+      return bindings;
+   }
+
+   public ScriptEngine getEngineByExtension(String extension) {
+      // TODO this is a hack to deal with context class loader issues
+      ScriptEngine engine = null;
+      for (ScriptEngineManager manager : classLoaders.keySet()) {
+         ClassLoader old = Thread.currentThread().getContextClassLoader();
+         Thread.currentThread()
+               .setContextClassLoader(classLoaders.get(manager));
+         engine = manager.getEngineByExtension(extension);
+         Thread.currentThread().setContextClassLoader(old);
+         if (engine != null)
+            break;
+      }
+      return engine;
+   }
+
+   public ScriptEngine getEngineByMimeType(String mimeType) {
+      // TODO this is a hack to deal with context class loader issues
+      ScriptEngine engine = null;
+      for (ScriptEngineManager manager : classLoaders.keySet()) {
+         ClassLoader old = Thread.currentThread().getContextClassLoader();
+         Thread.currentThread()
+               .setContextClassLoader(classLoaders.get(manager));
+         engine = manager.getEngineByMimeType(mimeType);
+         Thread.currentThread().setContextClassLoader(old);
+         if (engine != null)
+            break;
+      }
+      return engine;
+   }
+
+   public ScriptEngine getEngineByName(String shortName) {
+      // TODO this is a hack to deal with context class loader issues
+      for (ScriptEngineManager manager : classLoaders.keySet()) {
+         ClassLoader old = Thread.currentThread().getContextClassLoader();
+         Thread.currentThread()
+               .setContextClassLoader(classLoaders.get(manager));
+         ScriptEngine engine = manager.getEngineByName(shortName);
+         Thread.currentThread().setContextClassLoader(old);
+         if (engine != null) {
+            return new OSGiScriptEngine(engine, new OSGiScriptEngineFactory(
+                  engine.getFactory(), classLoaders.get(manager)));
+         }
+      }
+      return null;
+   }
+
+   public List<ScriptEngineFactory> getEngineFactories() {
+      List<ScriptEngineFactory> osgiFactories = new ArrayList<ScriptEngineFactory>();
+      for (ScriptEngineManager engineManager : classLoaders.keySet()) {
+         for (ScriptEngineFactory factory : engineManager.getEngineFactories()) {
+            osgiFactories.add(new OSGiScriptEngineFactory(factory, classLoaders
+                  .get(engineManager)));
+         }
+      }
+      return osgiFactories;
+   }
+
+   public void put(String key, Object value) {
+      bindings.put(key, value);
+   }
+
+   public void registerEngineExtension(String extension,
+         ScriptEngineFactory factory) {
+      for (ScriptEngineManager engineManager : classLoaders.keySet())
+         engineManager.registerEngineExtension(extension, factory);
+   }
+
+   public void registerEngineMimeType(String type, ScriptEngineFactory factory) {
+      for (ScriptEngineManager engineManager : classLoaders.keySet())
+         engineManager.registerEngineMimeType(type, factory);
+   }
+
+   public void registerEngineName(String name, ScriptEngineFactory factory) {
+      for (ScriptEngineManager engineManager : classLoaders.keySet())
+         engineManager.registerEngineName(name, factory);
+   }
+
+   /**
+    * Follows the same behavior of @link
+    * javax.script.ScriptEngineManager#setBindings(Bindings) This means that the
+    * same bindings are applied to all the underlying managers.
+    * 
+    * @param bindings
+    */
+   public void setBindings(Bindings bindings) {
+      this.bindings = bindings;
+      for (ScriptEngineManager manager : classLoaders.keySet()) {
+         manager.setBindings(bindings);
+      }
+   }
+
+   private Map<ScriptEngineManager, ClassLoader> findManagers(
+         BundleContext context) {
+      Map<ScriptEngineManager, ClassLoader> managers = new HashMap<ScriptEngineManager, ClassLoader>();
+      for (String factoryName : findFactoryCandidates(context)) {
+         // we do not really need the class, but we need the classloader
+         ClassLoader factoryLoader = tryGetClassLoader(factoryName);
+         if (factoryLoader == null) {
+            continue;
+         }
+         ScriptEngineManager manager = tryCreateScriptEngineManager(
+               factoryName, factoryLoader);
+         if (manager != null) {
+            manager.setBindings(bindings);
+            managers.put(manager, factoryLoader);
+         }
+      }
+      return managers;
+   }
+
+   private static ClassLoader tryGetClassLoader(String className) {
+      try {
+         return Class.forName(className).getClassLoader();
+      } catch (ClassNotFoundException exception) {
+         LOGGER.error("Tried to load class {} but failed due to: {}",
+               className, exception.getMessage());
+         return null;
+      }
+   }
+
+   private static ScriptEngineManager tryCreateScriptEngineManager(
+         String factoryName, ClassLoader factoryLoader) {
+      try {
+         return new ScriptEngineManager(factoryLoader);
+      } catch (Exception exception) {
+         LOGGER.error("Found ScriptEngineFactory candidate {} but failed to create a factory due to: {}",
+               factoryName, exception.getMessage());
+         return null;
+      }
+   }
+
+   /**
+    * Iterates through all bundles to get the available @link
+    * ScriptEngineFactory classes
+    *
+    * @return the names of the available ScriptEngineFactory classes
+    * @throws IOException
+    */
+   private List<String> findFactoryCandidates(BundleContext context) {
+      Bundle[] bundles = context.getBundles();
+      List<String> factoryCandidates = new ArrayList<String>();
+      for (Bundle bundle : bundles) {
+         if (bundle == null) {
+            continue;
+         }
+
+         if (bundle.getSymbolicName().equals("system.bundle")) {
+            continue;
+         }
+         Enumeration<URL> urls = bundle.findEntries("META-INF/services",
+               "javax.script.ScriptEngineFactory", false);
+         if (urls == null) {
+            continue;
+         }
+
+         while (urls.hasMoreElements()) {
+            URL u = (URL) urls.nextElement();
+            try {
+               BufferedReader reader = new BufferedReader(
+                     new InputStreamReader(u.openStream()));
+               String line;
+               while ((line = reader.readLine()) != null) {
+                  line = line.trim();
+                  // ignore comments and empty lines
+                  if (!line.isEmpty() && !line.startsWith("#")) {
+                     factoryCandidates.add(line);
+                  }
+               }
+            } catch (IOException ignored) {
+            }
+         }
+      }
+      return factoryCandidates;
+   }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
----------------------------------------------------------------------
diff --git a/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml b/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
index 30e3dd0..092740e 100644
--- a/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
+++ b/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
@@ -566,7 +566,13 @@ limitations under the License.
 
     <bean id="osFamilyCompleter" class="org.jclouds.karaf.commands.compute.completer.OsFamilyCompleter"/>
 
-  <bean id="shellTableFactory" class="org.jclouds.karaf.commands.table.internal.ManagedShellTableFactory"/>
+  <bean id="osgiScriptEngineManager" class="org.jclouds.karaf.commands.table.internal.OSGiScriptEngineManager">
+      <argument ref="blueprintBundleContext"/>
+  </bean>
+
+  <bean id="shellTableFactory" class="org.jclouds.karaf.commands.table.internal.ManagedShellTableFactory">
+      <property name="scriptEngineManager" ref="osgiScriptEngineManager"/>
+  </bean>
 
   <service ref="shellTableFactory">
       <interfaces>

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/feature/src/main/resources/feature.xml
----------------------------------------------------------------------
diff --git a/feature/src/main/resources/feature.xml b/feature/src/main/resources/feature.xml
index d4cdef8..2a9e191 100644
--- a/feature/src/main/resources/feature.xml
+++ b/feature/src/main/resources/feature.xml
@@ -423,7 +423,6 @@ limitations under the License.
     <feature name="jclouds-commands" description="Karaf Commands for jclouds" version="${project.version}" resolver="(obr)">
         <configfile finalname="/etc/org.apache.jclouds.shell.cfg">mvn:org.apache.jclouds.karaf/jclouds-karaf/${project.version}/cfg/shell</configfile>
         <feature version='${project.version}'>jclouds-services</feature>
-        <bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.scripting-api-1.0/${scripting.api.bundle.version}</bundle>
         <bundle dependency="true">mvn:org.codehaus.groovy/groovy/${groovy.version}</bundle>
         <bundle dependency="true">mvn:org.codehaus.groovy/groovy-jsr223/${groovy.version}</bundle>
         <bundle>mvn:org.apache.jclouds.karaf/core/${project.version}</bundle>

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/31190dab/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f5bf069..2cf463c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -216,7 +216,6 @@ limitations under the License.
     <pax-exam.version>2.6.0</pax-exam.version>
     <pax-url-mvn.version>1.3.5</pax-url-mvn.version>
     <pax-url-aether.version>1.4.0.RC1</pax-url-aether.version>
-    <scripting.api.bundle.version>2.0.0</scripting.api.bundle.version>
     <slf4j.version>1.5.8</slf4j.version>
     <snakeyaml.version>1.11</snakeyaml.version>
 
@@ -381,12 +380,6 @@ limitations under the License.
 
       <dependency>
         <groupId>org.apache.servicemix.specs</groupId>
-        <artifactId>org.apache.servicemix.specs.scripting-api-1.0</artifactId>
-        <version>${scripting.api.bundle.version}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.apache.servicemix.specs</groupId>
         <artifactId>org.apache.servicemix.specs.jsr250-1.0</artifactId>
         <version>${sericemix.specs.jsr250.version}</version>
       </dependency>


[3/5] jclouds-karaf git commit: Added motivation for the bundles module

Posted by an...@apache.org.
Added motivation for the bundles module


Project: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/commit/522e2455
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/tree/522e2455
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/diff/522e2455

Branch: refs/heads/fix-script-engine
Commit: 522e245582acb3595144f4b02208909e3b935564
Parents: ccb5627
Author: Ignasi Barrera <na...@apache.org>
Authored: Thu Sep 8 11:17:26 2016 +0200
Committer: Andrew Phillips <an...@apache.org>
Committed: Wed Sep 14 17:07:51 2016 +0100

----------------------------------------------------------------------
 bundles/README.md                    | 5 +++++
 bundles/jsch-agentproxy-jsch/pom.xml | 4 ++++
 2 files changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/522e2455/bundles/README.md
----------------------------------------------------------------------
diff --git a/bundles/README.md b/bundles/README.md
new file mode 100644
index 0000000..a835cbf
--- /dev/null
+++ b/bundles/README.md
@@ -0,0 +1,5 @@
+Apache jclouds-karaf bundles
+============================
+
+This module provides bundles required to let jclouds run in OSGi environments. These bundles here may not be publicly available elsewhere, or have been repackaged to work with jclouds.
+

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/522e2455/bundles/jsch-agentproxy-jsch/pom.xml
----------------------------------------------------------------------
diff --git a/bundles/jsch-agentproxy-jsch/pom.xml b/bundles/jsch-agentproxy-jsch/pom.xml
index 7a858cb..968f29c 100644
--- a/bundles/jsch-agentproxy-jsch/pom.xml
+++ b/bundles/jsch-agentproxy-jsch/pom.xml
@@ -24,6 +24,10 @@ limitations under the License.
     <version>2.0.0-SNAPSHOT</version>
   </parent>
 
+  <!--
+    This bundle fixes the `org.apache.servicemix.bundles.jsch-agentproxy-jsch` bundle
+    by not exporting the core packages that are already exported by other bundles.
+  -->
   <groupId>org.apache.jclouds.karaf.bundles</groupId>
   <artifactId>jsch-agentproxy-jsch</artifactId>
   <name>jclouds :: Karaf :: JSch Agentproxy for JSch (shaded bundle)</name>


[2/5] jclouds-karaf git commit: JCLOUDS-1005: Add Backblaze B2

Posted by an...@apache.org.
JCLOUDS-1005: Add Backblaze B2


Project: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/commit/ccb56276
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/tree/ccb56276
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-karaf/diff/ccb56276

Branch: refs/heads/fix-script-engine
Commit: ccb5627659bb5895ef49b78db5052d2ff768069d
Parents: 00ff5d2
Author: Andrew Gaul <ga...@apache.org>
Authored: Sun Sep 11 21:45:00 2016 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Sun Sep 11 21:45:35 2016 -0700

----------------------------------------------------------------------
 feature/pom.xml                                                 | 1 +
 feature/src/main/resources/feature.xml                          | 5 +++++
 .../org/jclouds/karaf/itests/MiscFeaturesInstallationTest.java  | 5 +++++
 3 files changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/ccb56276/feature/pom.xml
----------------------------------------------------------------------
diff --git a/feature/pom.xml b/feature/pom.xml
index e4de9ff..a64c5a8 100644
--- a/feature/pom.xml
+++ b/feature/pom.xml
@@ -125,6 +125,7 @@ limitations under the License.
                 <feature>jclouds-aws-sqs</feature>
                 <feature>jclouds-aws-sts</feature>
                 <feature>jclouds-azureblob</feature>
+                <feature>jclouds-b2</feature>
                 <feature>jclouds-cloudsigma2-hnl</feature>
                 <feature>jclouds-cloudsigma2-lvs</feature>
                 <feature>jclouds-cloudsigma2-sjc</feature>

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/ccb56276/feature/src/main/resources/feature.xml
----------------------------------------------------------------------
diff --git a/feature/src/main/resources/feature.xml b/feature/src/main/resources/feature.xml
index fb361a6..d4cdef8 100644
--- a/feature/src/main/resources/feature.xml
+++ b/feature/src/main/resources/feature.xml
@@ -193,6 +193,11 @@ limitations under the License.
         <bundle>mvn:org.apache.jclouds.provider/azureblob/${jclouds.version}</bundle>
     </feature>
 
+    <feature name='jclouds-b2' description='Backblaze B2' version='${project.version}' resolver='(obr)'>
+        <feature version='${project.version}'>jclouds-blobstore</feature>
+        <bundle>mvn:org.apache.jclouds.labs/b2/${jclouds.version}</bundle>
+    </feature>
+
     <feature name='jclouds-dynect' description='DynECT Managed DNS' version='${project.version}' resolver='(obr)'>
         <feature version='${project.version}'>jclouds</feature>
         <bundle>mvn:org.apache.jclouds.provider/dynect/${jclouds.version}</bundle>

http://git-wip-us.apache.org/repos/asf/jclouds-karaf/blob/ccb56276/itests/src/test/java/org/jclouds/karaf/itests/MiscFeaturesInstallationTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/jclouds/karaf/itests/MiscFeaturesInstallationTest.java b/itests/src/test/java/org/jclouds/karaf/itests/MiscFeaturesInstallationTest.java
index b40a56a..fa6f317 100644
--- a/itests/src/test/java/org/jclouds/karaf/itests/MiscFeaturesInstallationTest.java
+++ b/itests/src/test/java/org/jclouds/karaf/itests/MiscFeaturesInstallationTest.java
@@ -80,6 +80,11 @@ public class MiscFeaturesInstallationTest extends JcloudsFeaturesTestSupport {
     }
 
     @Test
+    public void testB2Feature() throws Exception {
+        installAndCheckFeature("jclouds-b2");
+    }
+
+    @Test
     public void testDynectFeature() throws Exception {
         installAndCheckFeature("jclouds-dynect");
     }