From 988d4bc75f561f364b5d611ccb821cdcdf832472 Mon Sep 17 00:00:00 2001
From: Florian Angerer <florian.angerer@oracle.com>
Date: Thu, 29 Jun 2017 13:53:52 +0200
Subject: [PATCH] java.addClasspathEntry now accepts a string vector

---
 .../r/nodes/builtin/fastr/FastRInterop.java   | 20 +++++++++++--------
 .../truffle/r/runtime/context/RContext.java   | 13 +++++++-----
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java
index 47c62cd5b0..d87fd82091 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java
@@ -84,7 +84,6 @@ import com.oracle.truffle.r.runtime.data.RList;
 import com.oracle.truffle.r.runtime.data.RMissing;
 import com.oracle.truffle.r.runtime.data.RNull;
 import com.oracle.truffle.r.runtime.data.RRaw;
-import com.oracle.truffle.r.runtime.data.RTypedValue;
 import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector;
 import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector;
 import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
@@ -121,7 +120,7 @@ public class FastRInterop {
 
         @SuppressWarnings("unused")
         @Specialization(guards = {"cachedMimeType != null", "cachedMimeType.equals(mimeType)", "cachedSource != null", "cachedSource.equals(source)"})
-        protected Object evalCached(String mimeType, String source, @SuppressWarnings("unused") RMissing path,
+        protected Object evalCached(String mimeType, String source, RMissing path,
                         @Cached("mimeType") String cachedMimeType,
                         @Cached("source") String cachedSource,
                         @Cached("createCall(mimeType, source)") DirectCallNode call) {
@@ -134,9 +133,10 @@ public class FastRInterop {
             return parse(mimeType, source).call();
         }
 
+        @SuppressWarnings("unused")
         @Specialization()
         @TruffleBoundary
-        protected Object eval(@SuppressWarnings("unused") RMissing mimeType, String source, @SuppressWarnings("unused") RMissing path) {
+        protected Object eval(RMissing mimeType, String source, RMissing path) {
             throw RError.error(this, RError.Message.INVALID_ARG, "mimeType");
         }
 
@@ -452,23 +452,27 @@ public class FastRInterop {
         }
     }
 
-    @RBuiltin(name = "java.addClasspathEntry", visibility = OFF, kind = PRIMITIVE, parameterNames = {"entry", "silent"}, behavior = COMPLEX)
+    @RBuiltin(name = "java.addClasspathEntry", visibility = OFF, kind = PRIMITIVE, parameterNames = {"value", "silent"}, behavior = COMPLEX)
     public abstract static class JavaAddClasspathEntry extends RBuiltinNode.Arg2 {
 
         static {
             Casts casts = new Casts(JavaAddClasspathEntry.class);
-            casts.arg("entry").mustBe(stringValue()).asStringVector().mustBe(Predef.singleElement()).findFirst();
+            casts.arg("value").mustBe(stringValue()).asStringVector();
             casts.arg("silent").mapMissing(Predef.constant(RRuntime.LOGICAL_FALSE)).mustBe(logicalValue().or(Predef.nullValue())).asLogicalVector().mustBe(singleElement()).findFirst().mustBe(
                             notLogicalNA()).map(Predef.toBoolean());
         }
 
         @Specialization
         @TruffleBoundary
-        public TruffleObject javaClass(String entry, boolean silent) {
+        public TruffleObject addEntries(RAbstractStringVector value, boolean silent) {
             try {
                 RContext ctx = RContext.getInstance();
-                ctx.addInteropClasspathEntry(entry);
-                return RNull.instance;
+                String[] entriesArr = new String[value.getLength()];
+                for (int i = 0; i < value.getLength(); i++) {
+                    entriesArr[i] = value.getDataAt(i);
+                }
+                ctx.addInteropClasspathEntries(entriesArr);
+                return value;
             } catch (MalformedURLException e) {
                 if (silent) {
                     return RNull.instance;
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java
index 801a51bd97..d12bdff737 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java
@@ -25,12 +25,12 @@ package com.oracle.truffle.r.runtime.context;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.Closeable;
-import java.io.File;
 import java.lang.ref.WeakReference;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.TimeZone;
@@ -821,11 +821,14 @@ public final class RContext implements RTruffleObject {
     }
 
     /**
-     * Adds an entry to the Java interop class loader. This will effectively create a new class
+     * Adds entries to the Java interop class loader. This will effectively create a new class
      * loader with the previous one as parent.
      */
-    public void addInteropClasspathEntry(String entry) throws MalformedURLException {
-        URL url = new File(entry).toURI().toURL();
-        interopClassLoader = URLClassLoader.newInstance(new URL[]{url}, interopClassLoader);
+    public void addInteropClasspathEntries(String... entries) throws MalformedURLException {
+        URL[] urls = new URL[entries.length];
+        for (int i = 0; i < entries.length; i++) {
+            urls[i] = Paths.get(entries[i]).toUri().toURL();
+        }
+        interopClassLoader = URLClassLoader.newInstance(urls, interopClassLoader);
     }
 }
-- 
GitLab