Skip to content

Commit

Permalink
Merge pull request #67 from jyksnw/development
Browse files Browse the repository at this point in the history
Create 1.0.2 Release
  • Loading branch information
jyksnw authored Mar 12, 2023
2 parents 73bb95b + c28fde1 commit 8b06f92
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The library provides an `install` function, which takes the following parameters
Here are some example code snippet:

```python
jdk.install('11)
jdk.install('11')
# Platform dependent install of Java JDK 11 into $HOME/.jdk/<VERSION>

jdk.install('11', jre=True)
Expand Down
40 changes: 20 additions & 20 deletions jdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
from collections import namedtuple
from os import path
from os import path as ospath
from subprocess import run # noqa: S404 Security implication noted and mitigated
from typing import Optional
from typing import Union
Expand All @@ -15,9 +15,9 @@
from jdk.extension import deprecated


_USER_DIR = path.expanduser("~")
_JRE_DIR = path.join(_USER_DIR, ".jre")
_JDK_DIR = path.join(_USER_DIR, ".jdk")
_USER_DIR = ospath.expanduser("~")
_JRE_DIR = ospath.join(_USER_DIR, ".jre")
_JDK_DIR = ospath.join(_USER_DIR, ".jdk")

OS = OperatingSystem.detect()
ARCH = Architecture.detect()
Expand All @@ -35,24 +35,24 @@ class JdkError(Exception):


def _path_parse(file_path: str) -> _Path:
dirname = path.dirname(file_path)
base = path.basename(file_path)
name, ext = path.splitext(base)
dirname = ospath.dirname(file_path)
base = ospath.basename(file_path)
name, ext = ospath.splitext(base)
return _Path(dir=dirname, base=base, name=name, ext=ext)


def _unpack_jars(fs_path: str, java_bin_path: str) -> None:
if path.exists(fs_path):
if path.isdir(fs_path):
if ospath.exists(fs_path):
if ospath.isdir(fs_path):
for f in os.listdir(fs_path):
current_path = path.join(fs_path, f)
current_path = ospath.join(fs_path, f)
_unpack_jars(current_path, java_bin_path)
else:
_, file_ext = path.splitext(fs_path)
_, file_ext = ospath.splitext(fs_path)
if file_ext.endswith("pack"):
p = _path_parse(fs_path)
name = path.join(p.dir, p.name)
tool_path = path.join(java_bin_path, _UNPACK200)
name = ospath.join(p.dir, p.name)
tool_path = ospath.join(java_bin_path, _UNPACK200)
run( # noqa: S603 Known arguments being passed into run
[tool_path, _UNPACK200_ARGS, f"{name}.pack", f"{name}.jar"]
)
Expand All @@ -61,20 +61,20 @@ def _unpack_jars(fs_path: str, java_bin_path: str) -> None:
def _decompress_archive(
repo_root: str, file_ending: str, destination_folder: str
) -> str:
if not path.exists(destination_folder):
if not ospath.exists(destination_folder):
os.mkdir(destination_folder)

jdk_file = path.normpath(repo_root)
jdk_file = ospath.normpath(repo_root)

if path.isfile(jdk_file):
if ospath.isfile(jdk_file):
jdk_directory = extractor.extract_files(
jdk_file, file_ending, destination_folder
)
jdk_bin = path.join(jdk_directory, "bin")
jdk_bin = ospath.join(jdk_directory, "bin")
_unpack_jars(jdk_directory, jdk_bin)

return jdk_directory
elif path.isdir(jdk_file):
elif ospath.isdir(jdk_file):
return jdk_file


Expand Down Expand Up @@ -116,11 +116,11 @@ def uninstall(version: str, jre: bool = False):
if jre:
versions = (v for v in os.listdir(_JRE_DIR) if version in v.replace("-", ""))
for v in versions:
shutil.rmtree(path.join(_JRE_DIR, v))
shutil.rmtree(ospath.join(_JRE_DIR, v))
else:
versions = (v for v in os.listdir(_JDK_DIR) if version in v.replace("-", ""))
for v in versions:
shutil.rmtree(path.join(_JDK_DIR, v))
shutil.rmtree(ospath.join(_JDK_DIR, v))


def get_download_url(
Expand Down
16 changes: 8 additions & 8 deletions jdk/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from lzma import LZMAFile
from lzma import open as lzma_open
from os import listdir
from os import path
from os import path as ospath
from os import stat
from tarfile import TarFile
from tarfile import open as tarfile_open
Expand All @@ -24,10 +24,10 @@ class ExtractorError(Exception):


def _is_within_directory(directory: str, target: str):
abs_directory = path.abspath(directory)
abs_target = path.abspath(target)
abs_directory = ospath.abspath(directory)
abs_target = ospath.abspath(target)

prefix = path.commonprefix([abs_directory, abs_target])
prefix = ospath.commonprefix([abs_directory, abs_target])
return prefix == abs_directory


Expand All @@ -42,7 +42,7 @@ def _safe_extract(
tar.extractall(path)
else:
for member in tar.getmembers():
member_path = path.join(path, member.name)
member_path = ospath.join(path, member.name)
if not _is_within_directory(path, member_path):
raise ExtractorError("Attempted Path Traversal in Archive File")
tar.extractall(path, members, numeric_owner=numeric_owner)
Expand All @@ -62,7 +62,7 @@ def get_compressed_file_ext(file: str) -> str:
def extract_files(
file: str, file_ending: str, destination_folder: str
) -> Optional[str]:
if path.isfile(file):
if ospath.isfile(file):
if file_ending == _TAR:
with tarfile_open(file, "r:") as tar:
_safe_extract(tar, path=destination_folder)
Expand All @@ -78,6 +78,6 @@ def extract_files(

jdk_directory = max(
listdir(destination_folder),
key=lambda d: stat(path.join(destination_folder, d)).st_ctime,
key=lambda d: stat(ospath.join(destination_folder, d)).st_ctime,
)
return path.join(destination_folder, jdk_directory)
return ospath.join(destination_folder, jdk_directory)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
description = "install-jdk allows you to easily install latest Java OpenJDK version. Supports OpenJDK builds from Adoptium (previously AdoptOpenJDK), Corretto, and Zulu. Simplify your Java development with the latest OpenJDK builds."
name = "install-jdk"
version = "1.0.1"
version = "1.0.2"
keywords = [
"Java",
"OpenJDK",
Expand Down

0 comments on commit 8b06f92

Please sign in to comment.