Skip to content

Commit 0172415

Browse files
committed
⚙️ Make compilable
1 parent e6affb0 commit 0172415

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import jython.JythonTask
33
plugins {
44
id 'java'
55
id 'java-library'
6+
id 'application'
67
id("com.github.rzabini.gradle-jython") version "1.1.0"
78
}
89

910
group = 'io.github.xypercode'
10-
version = '1.0-SNAPSHOT'
11+
version = '1.0.0'
1112

1213
repositories {
1314
mavenCentral()
@@ -16,6 +17,10 @@ repositories {
1617
}
1718
}
1819

20+
application {
21+
mainClass = "qbubbles.Launcher"
22+
}
23+
1924
afterEvaluate {
2025
tasks.register('testJython', JythonTask) {
2126
script file('src/main/python/main.py')

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'libgdx-pythonic'
1+
rootProject.name = 'qbubbles-pygdx'
22

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package qbubbles;
2+
3+
import org.python.apache.commons.compress.utils.IOUtils;
4+
import org.python.core.PySystemState;
5+
import org.python.util.PythonInterpreter;
6+
7+
import java.io.FileInputStream;
8+
import java.io.IOException;
9+
import java.net.URLConnection;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.StandardOpenOption;
13+
import java.util.jar.JarFile;
14+
import java.util.zip.ZipEntry;
15+
import java.util.zip.ZipFile;
16+
import java.util.zip.ZipInputStream;
17+
18+
public class Launcher {
19+
public static void main(String[] args) throws IOException {
20+
System.setProperty("python.import.site", "false");
21+
22+
PythonInterpreter.initialize(null, null, args);
23+
PySystemState state = new PySystemState();
24+
Path tempDirectory = Files.createTempDirectory("qbubbles_");
25+
URLConnection connection = Launcher.class.getProtectionDomain().getCodeSource().getLocation().openConnection();
26+
try (var stream = new ZipInputStream(connection.getInputStream())) {
27+
ZipEntry entry;
28+
while ((entry = stream.getNextEntry()) != null) {
29+
copyEntry(entry, tempDirectory, stream);
30+
}
31+
}
32+
33+
state.path.add(0, tempDirectory.toString());
34+
state.setClassLoader(ClassLoader.getSystemClassLoader());
35+
try (PythonInterpreter pythonInterpreter = new PythonInterpreter(null, state)) {
36+
pythonInterpreter.execfile(tempDirectory.resolve("main.py").toString());
37+
}
38+
}
39+
40+
private static void copyEntry(ZipEntry entry, Path tempDirectory, ZipInputStream stream) throws IOException {
41+
if (entry.getName().endsWith(".py")) {
42+
String name = entry.getName();
43+
if (name.startsWith("/")) name = name.substring(1);
44+
if (name.equals("main.py") || name.startsWith("qbubbles/")) {
45+
var path = tempDirectory.resolve(name);
46+
if (Files.notExists(path.getParent())) {
47+
Files.createDirectories(path.getParent());
48+
}
49+
byte[] bytes = stream.readAllBytes();
50+
Files.write(path, bytes, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
51+
}
52+
}
53+
}
54+
}

src/main/java/qplaysoftware/bubbles/Launcher.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)