Skip to content

Commit 40c3a70

Browse files
committed
use native pjass on linux
1 parent 3665128 commit 40c3a70

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Pjass.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,26 @@ public static Result runPjass(File outputFile) {
9595
args.add(Utils.getResourceFile("common.j"));
9696
args.add(Utils.getResourceFile("blizzard.j"));
9797
args.add(outputFile.getPath());
98-
if (!System.getProperty("os.name").toLowerCase().contains("windows")) {
99-
WLogger.info("Operation system " + System.getProperty("os.name") + " detected.");
98+
String os = System.getProperty("os.name");
99+
if (os.equals("Linux")) {
100+
File fileName = Utils.getResourceFileF("pjass");
101+
boolean success = fileName.setExecutable(true);
102+
if (!success) {
103+
throw new RuntimeException("Could not make pjass executable.");
104+
}
105+
args.set(0, fileName.getAbsolutePath());
106+
} else if (!os.toLowerCase().contains("windows")) {
107+
WLogger.info("Operation system " + os + " detected.");
100108
WLogger.info("Trying to run with wine ...");
101109
// try to run with wine
102110
args.add(0, "wine");
103111
}
112+
104113
p = Runtime.getRuntime().exec(args.toArray(new String[0]));
105114

106115
StringBuilder output = new StringBuilder();
107116

108-
try(BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
117+
try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
109118
String line;
110119
while ((line = input.readLine()) != null) {
111120
WLogger.info(line);
@@ -114,7 +123,6 @@ public static Result runPjass(File outputFile) {
114123
}
115124

116125

117-
118126
int exitValue = p.waitFor();
119127
if (exitValue != 0) {
120128
return new Result(outputFile, false, "pjass errors: \n" + output.toString());

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/utils/Utils.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import de.peeeq.wurstscript.types.WurstType;
1818
import de.peeeq.wurstscript.types.WurstTypeUnknown;
1919
import org.eclipse.jdt.annotation.Nullable;
20+
import org.jetbrains.annotations.NotNull;
2021

2122
import java.awt.event.MouseAdapter;
2223
import java.awt.event.MouseEvent;
@@ -931,12 +932,19 @@ public static String string(String... lines) {
931932
* Extracts a resource from the jar, stores it in a temp file and returns the abolute path to the tempfile
932933
*/
933934
public static synchronized String getResourceFile(String name) {
935+
return getResourceFileF(name).getAbsolutePath();
936+
}
937+
938+
/**
939+
* Extracts a resource from the jar, stores it in a temp file and returns the abolute path to the tempfile
940+
*/
941+
public static synchronized File getResourceFileF(String name) {
934942
try {
935943
File f = resourceMap.get(name);
936944
if (f != null && f.exists()) {
937-
return f.getAbsolutePath();
945+
return f;
938946
}
939-
String[] parts = name.split("\\.");
947+
String[] parts = splitFilename(name);
940948
f = File.createTempFile(parts[0], parts[1]);
941949
f.deleteOnExit();
942950
try (InputStream is = Pjass.class.getClassLoader().getResourceAsStream(name)) {
@@ -946,13 +954,22 @@ public static synchronized String getResourceFile(String name) {
946954
byte[] bytes = Utils.convertStreamToBytes(is);
947955
Files.write(bytes, f);
948956
resourceMap.put(name, f);
949-
return f.getAbsolutePath();
957+
return f;
950958
}
951959
} catch (IOException e) {
952960
throw new RuntimeException(e);
953961
}
954962
}
955963

964+
@NotNull
965+
private static String[] splitFilename(String name) {
966+
int dotPos = name.lastIndexOf('.');
967+
if (dotPos >= 0) {
968+
return new String[] { name.substring(0, dotPos), name.substring(dotPos + 1) };
969+
}
970+
return new String[] { name, "" };
971+
}
972+
956973
private static Map<String, File> resourceMap = new HashMap<>();
957974

958975
public static String elementNameWithPath(AstElementWithNameId n) {
139 KB
Binary file not shown.

0 commit comments

Comments
 (0)