Skip to content

Commit f171609

Browse files
authored
*: Support libraries in cli runner (#179)
Signed-off-by: Ce Gao <[email protected]>
1 parent 2a9347b commit f171609

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

build.xml.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<remoteRepository refid="remote.repository" />
9090
<dependency groupId="org.renjin" artifactId="renjin-script-engine" version="${renjin-version}" />
9191
<dependency groupId="org.renjin" artifactId="renjin-cli" version="${renjin-version}" />
92+
<dependency groupId="commons-cli" artifactId="commons-cli" version="1.4" />
9293
</artifact:dependencies>
9394
<copy todir="${mode-lib}">
9495
<fileset refid="dependency.fileset" />
@@ -120,6 +121,7 @@
120121
<manifest>
121122
<attribute name="Main-Class" value="rprocessing.Runner" />
122123
</manifest>
124+
<zipfileset src="${processing.classes.pde}"/>
123125
<zipgroupfileset dir="${processing.classes.core}" includes="*.jar" />
124126
<zipgroupfileset dir="${mode-lib}" includes="**/*.jar" />
125127
</jar>

lib/mode/commons-cli.jar

52.6 KB
Binary file not shown.

src/rprocessing/lancher/StandaloneSketch.java

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import java.io.FileOutputStream;
55
import java.io.PrintStream;
66
import java.net.URISyntaxException;
7+
import java.util.ArrayList;
78
import java.util.Arrays;
89
import java.util.List;
910

11+
import processing.app.Platform;
1012
import processing.core.PApplet;
1113
import rprocessing.RunnableSketch;
1214
import rprocessing.Runner;
@@ -103,44 +105,26 @@ public StandaloneSketch(final String[] args) throws Exception {
103105
this.code = RScriptReader.readText(sketchPath.toPath());
104106

105107
// TODO: Support library in standalone sketch.
106-
this.libraryDirs = null;
107-
// {
108-
// log("Populate library directories.");
109-
// this.libraryDirs = new ArrayList<>();
110-
// final String buildProperties = "build.properties";
111-
// final String propsResource;
112-
// try {
113-
// propsResource =
114-
// URLDecoder.decode(Runner.class.getResource(buildProperties).toString(), "UTF-8");
115-
// log(propsResource);
116-
// } catch (final UnsupportedEncodingException e) {
117-
// throw new RuntimeException("Impossible: " + e);
118-
// }
119-
//
120-
// if (propsResource == null) {
121-
// log("Could not get build.properties from Runner.");
122-
// libraryDirs.add(new File("libraries"));
123-
// return;
124-
// }
125-
//
126-
// final Pattern jarResource = Pattern
127-
// .compile("jar:file:(.+?)/RLangMode\\.jar!/rprocessing/" + Pattern.quote(buildProperties));
128-
// final Pattern fileResource =
129-
// Pattern.compile("file:(.+?)/bin/rprocessing/" + Pattern.quote(buildProperties));
130-
//
131-
// final Matcher jarMatcher = jarResource.matcher(propsResource);
132-
// final Matcher fileMatcher = fileResource.matcher(propsResource);
133-
// if (jarMatcher.matches()) {
134-
// log("We're running from a JAR file.");
135-
// libraryDirs.add(new File(jarMatcher.group(1), "libraries"));
136-
// } else if (fileMatcher.matches()) {
137-
// log("We're running from class files.");
138-
// libraryDirs.add(new File(fileMatcher.group(1), "libraries"));
139-
// } else {
140-
// log("WARNING: I can't find my libraries directory!");
141-
// libraryDirs.add(new File("libraries"));
142-
// }
143-
// }
108+
final List<File> libraryDirs = new ArrayList<>();
109+
libraryDirs.add(getLibraryDir());
110+
log(getLibraryDir());
111+
libraryDirs.add(sketchPath);
112+
this.libraryDirs = libraryDirs;
113+
}
114+
115+
private File getLibraryDir() {
116+
if (Platform.isMacOS()) {
117+
String home = System.getProperty("user.home");
118+
return new File(home + "/Documents/Processing/libraries");
119+
} else if (Platform.isLinux()) {
120+
String home = System.getProperty("user.home");
121+
return new File(home + "/sketchbook/libraries");
122+
} else if (Platform.isWindows()) {
123+
String home = System.getProperty("user.home");
124+
return new File(home + "\\Documents\\Processing\\modes");
125+
}
126+
log("Operating System is not supported now.");
127+
return null;
144128
}
145129

146130
@Override

0 commit comments

Comments
 (0)