-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
96 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .javainfo import assert_java, get_java_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
from importlib import resources | ||
from tempfile import TemporaryDirectory | ||
|
||
from picomc.logging import logger | ||
from picomc.utils import die | ||
|
||
# | ||
# SysDump.class: | ||
# | ||
# import java.io.IOException; | ||
# | ||
# public class SysDump { | ||
# public static void main(String[] args) throws IOException { | ||
# System.getProperties().storeToXML(System.out, ""); | ||
# } | ||
# } | ||
# | ||
# Compiled with an antique version of java for widest compatibility. | ||
# Ideally we would distribute the source .java file and build it in the | ||
# picomc build process, but that would bring in a dependency for (old) java | ||
# and extra complexity. | ||
# | ||
|
||
|
||
def get_java_info(java): | ||
with TemporaryDirectory() as tmpdir: | ||
with resources.open_binary("picomc.java", "SysDump.class") as incf, open( | ||
os.path.join(tmpdir, "SysDump.class"), "wb" | ||
) as outcf: | ||
shutil.copyfileobj(incf, outcf) | ||
ret = subprocess.run( | ||
[java, "-cp", ".", "SysDump"], cwd=tmpdir, capture_output=True | ||
) | ||
from xml.etree import ElementTree | ||
|
||
xmlstr = ret.stdout.decode("utf8") | ||
props = ElementTree.fromstring(xmlstr) | ||
res = dict() | ||
for entry in props: | ||
if "entry" != entry.tag or "key" not in entry.attrib: | ||
continue | ||
res[entry.attrib["key"]] = entry.text | ||
return res | ||
|
||
|
||
def assert_java(java): | ||
try: | ||
jinfo = get_java_info(java) | ||
badjv = not jinfo["java.version"].startswith("1.8.0") | ||
bitness = jinfo.get("sun.arch.data.model", None) | ||
if bitness and bitness != "64": | ||
logger.warning( | ||
"You are not using 64-bit java. Things will probably not work." | ||
) | ||
|
||
logger.info( | ||
"Using java version: {} ({})".format( | ||
jinfo["java.version"], jinfo["java.vm.name"] | ||
) | ||
) | ||
|
||
if badjv: | ||
logger.warning( | ||
"Minecraft uses java 1.8.0 by default." | ||
" You may experience issues, especially with older versions of Minecraft." | ||
) | ||
|
||
return jinfo | ||
|
||
except FileNotFoundError: | ||
die( | ||
"Could not execute java at: {}. Have you installed it? Is it in yout PATH?".format( | ||
java | ||
) | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters