Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add java runtime metadata #19

Merged
merged 29 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ac5171e
feat: fetch java metadata
Ryex May 10, 2023
651ff83
feat: generate java componate
Ryex May 11, 2023
030c5e7
update update.sh
Ryex May 11, 2023
1b8d9d4
fix: ensure there is a recomended version
Ryex May 11, 2023
c911fbd
fix: spelling
Ryex May 11, 2023
cbe8419
fix: varcase
Ryex May 11, 2023
acc6a4c
fix: ensure JDK options are included (some platform vendor combos don…
Ryex May 13, 2023
19b046d
don't track azul java verisons older than java 8
Ryex May 14, 2023
95223b8
cleanup: types
Ryex May 14, 2023
cc881a8
write java `package.json`
Ryex Jun 17, 2023
939233e
feat: index java verisons
Ryex Jun 17, 2023
f196e36
Merge branch 'main' of github.com:PrismLauncher/meta into javas
Trial97 Nov 4, 2023
453c15a
Merge branch 'main' of github.com:PrismLauncher/meta into javas
Trial97 Jan 16, 2024
6def1ee
Added new java enum
Trial97 Jan 16, 2024
230b8c8
Merge branch 'main' of https://github.com/PrismLauncher/meta into dev…
Trial97 Jan 23, 2024
abc3209
Changed mojang java names to match meta
Trial97 Jan 25, 2024
c8f354e
Merge branch 'main' of https://github.com/PrismLauncher/meta into javas
Trial97 Mar 4, 2024
97f8750
Split java source
Trial97 Mar 19, 2024
b49bec7
Removed jdk
Trial97 Mar 20, 2024
d996dc2
Force sort after major
Trial97 Mar 21, 2024
2eecce3
Merge branch 'main' of https://github.com/PrismLauncher/meta into javas
Trial97 Apr 27, 2024
60a3f5f
Map alpha and beta to gamma in case of arm os
Trial97 May 9, 2024
adef8d6
Mapped linux-arm variants to mojang provider
Trial97 May 10, 2024
c550fea
add java folders to launcher git
Trial97 May 21, 2024
641cbc6
update tool.poetry.scripts
Trial97 Jun 9, 2024
e233614
remove jdk
Trial97 Jun 13, 2024
b3fee53
Merge branch 'main' of https://github.com/PrismLauncher/meta into javas
Trial97 Jun 13, 2024
7aa1bcf
Merge branch 'main' of https://github.com/PrismLauncher/meta into javas
Trial97 Jun 13, 2024
6706cb5
use only latest for azul
Trial97 Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions meta/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import os.path
import datetime
from urllib.parse import urlparse
from typing import Any, Optional

import requests
from cachecontrol import CacheControl
from cachecontrol.caches import FileCache
from cachecontrol import CacheControl # type: ignore
from cachecontrol.caches import FileCache # type: ignore

LAUNCHER_MAVEN = "https://files.prismlauncher.org/maven/%s"

Expand Down Expand Up @@ -41,7 +42,7 @@ def ensure_upstream_dir(path):
os.makedirs(path)


def ensure_component_dir(component_id):
def ensure_component_dir(component_id: str):
path = os.path.join(launcher_path(), component_id)
if not os.path.exists(path):
os.makedirs(path)
Expand All @@ -51,26 +52,26 @@ def transform_maven_key(maven_key: str):
return maven_key.replace(":", ".")


def replace_old_launchermeta_url(url):
def replace_old_launchermeta_url(url: str):
o = urlparse(url)
if o.netloc == "launchermeta.mojang.com":
return o._replace(netloc="piston-meta.mojang.com").geturl()

return url


def get_all_bases(cls, bases=None):
def get_all_bases(cls: type, bases: Optional[list[type]] = None):
bases = bases or []
bases.append(cls)
for c in cls.__bases__:
get_all_bases(c, bases)
return tuple(bases)


def merge_dict(base: dict, overlay: dict):
def merge_dict(base: dict[Any, Any], overlay: dict[Any, Any]):
for k, v in base.items():
if isinstance(v, dict):
merge_dict(v, overlay.setdefault(k, {}))
merge_dict(v, overlay.setdefault(k, {})) # type: ignore
else:
if k not in overlay:
overlay[k] = v
Expand Down
14 changes: 14 additions & 0 deletions meta/common/java.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from os.path import join

BASE_DIR = "java_runtime"

RELEASE_FILE = join(BASE_DIR, "releases.json")
ADOPTIUM_DIR = join(BASE_DIR, "adoptium")
AZUL_DIR = join(BASE_DIR, "azul")

ADOPTIUM_VERSIONS_DIR = join(ADOPTIUM_DIR, "versions")
AZUL_VERSIONS_DIR = join(AZUL_DIR, "versions")

JAVA_MINECRAFT_COMPONENT = "net.minecraft.java"
JAVA_ADOPTIUM_COMPONENT = "net.adoptium.java"
JAVA_AZUL_COMPONENT = "com.azul.java"
2 changes: 2 additions & 0 deletions meta/common/mojang.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
MINECRAFT_COMPONENT = "net.minecraft"
LWJGL_COMPONENT = "org.lwjgl"
LWJGL3_COMPONENT = "org.lwjgl3"

JAVA_MANIFEST_FILE = join(BASE_DIR, "java_all.json")
38 changes: 21 additions & 17 deletions meta/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Optional, List, Dict, Any, Iterator

import pydantic
from pydantic import Field, validator
from pydantic import Field, validator # type: ignore

from ..common import (
LAUNCHER_MAVEN,
Expand Down Expand Up @@ -87,13 +87,16 @@ def is_lwjgl(self):
def is_log4j(self):
return self.group == "org.apache.logging.log4j"

def __eq__(self, other):
return str(self) == str(other)
def __eq__(self, other: Any):
if isinstance(other, GradleSpecifier):
return str(self) == str(other)
else:
return False

def __lt__(self, other):
def __lt__(self, other: "GradleSpecifier"):
return str(self) < str(other)

def __gt__(self, other):
def __gt__(self, other: "GradleSpecifier"):
return str(self) > str(other)

def __hash__(self):
Expand Down Expand Up @@ -122,7 +125,7 @@ def from_string(cls, v: str):
return cls(group, artifact, version, classifier, extension)

@classmethod
def validate(cls, v):
def validate(cls, v: "str | GradleSpecifier"):
if isinstance(v, cls):
return v
if isinstance(v, str):
Expand All @@ -131,7 +134,7 @@ def validate(cls, v):


class MetaBase(pydantic.BaseModel):
def dict(self, **kwargs) -> Dict[str, Any]:
def dict(self, **kwargs: Any) -> Dict[str, Any]:
for k in ["by_alias"]:
if k in kwargs:
del kwargs[k]
Expand All @@ -147,12 +150,12 @@ def json(self, **kwargs: Any) -> str:
exclude_none=True, sort_keys=True, by_alias=True, indent=4, **kwargs
)

def write(self, file_path):
def write(self, file_path: str):
Path(file_path).parent.mkdir(parents=True, exist_ok=True)
with open(file_path, "w") as f:
f.write(self.json())

def merge(self, other):
def merge(self, other: "MetaBase"):
"""
Merge other object with self.
- Concatenates lists
Expand All @@ -176,14 +179,14 @@ def merge(self, other):
elif isinstance(ours, set):
ours |= theirs
elif isinstance(ours, dict):
result = merge_dict(ours, copy.deepcopy(theirs))
result = merge_dict(ours, copy.deepcopy(theirs)) # type: ignore
setattr(self, key, result)
elif MetaBase in get_all_bases(field.type_):
ours.merge(theirs)
else:
setattr(self, key, theirs)

def __hash__(self):
def __hash__(self): # type: ignore
return hash(self.json())

class Config:
Expand All @@ -194,7 +197,7 @@ class Config:

class Versioned(MetaBase):
@validator("format_version")
def format_version_must_be_supported(cls, v):
def format_version_must_be_supported(cls, v: int):
assert v <= META_FORMAT_VERSION
return v

Expand All @@ -209,7 +212,7 @@ class MojangArtifactBase(MetaBase):

class MojangAssets(MojangArtifactBase):
@validator("url")
def validate_url(cls, v):
def validate_url(cls, v: str):
return replace_old_launchermeta_url(v)

id: str
Expand Down Expand Up @@ -245,7 +248,7 @@ class MojangLibraryDownloads(MetaBase):

class OSRule(MetaBase):
@validator("name")
def name_must_be_os(cls, v):
def name_must_be_os(cls, v: str):
assert v in [
"osx",
"linux",
Expand All @@ -263,7 +266,7 @@ def name_must_be_os(cls, v):

class MojangRule(MetaBase):
@validator("action")
def action_must_be_allow_disallow(cls, v):
def action_must_be_allow_disallow(cls, v: str):
assert v in ["allow", "disallow"]
return v

Expand All @@ -274,10 +277,10 @@ def action_must_be_allow_disallow(cls, v):
class MojangRules(MetaBase):
__root__: List[MojangRule]

def __iter__(self) -> Iterator[MojangRule]:
def __iter__(self) -> Iterator[MojangRule]: # type: ignore
return iter(self.__root__)

def __getitem__(self, item) -> MojangRule:
def __getitem__(self, item: int) -> MojangRule:
return self.__root__[item]


Expand Down Expand Up @@ -316,6 +319,7 @@ class MetaVersion(Versioned):
minecraft_arguments: Optional[str] = Field(alias="minecraftArguments")
release_time: Optional[datetime] = Field(alias="releaseTime")
compatible_java_majors: Optional[List[int]] = Field(alias="compatibleJavaMajors")
compatible_java_name: Optional[str] = Field(alias="compatibleJavaName")
additional_traits: Optional[List[str]] = Field(alias="+traits")
additional_tweakers: Optional[List[str]] = Field(alias="+tweakers")
additional_jvm_args: Optional[List[str]] = Field(alias="+jvmArgs")
Expand Down
32 changes: 32 additions & 0 deletions meta/model/enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import enum


class StrEnum(str, enum.Enum):
"""
StrEnum is a Python ``enum.Enum`` that inherits from ``str``. The default
``auto()`` behavior uses the member name as its value.

Example usage::

class Example(StrEnum):
UPPER_CASE = auto()
lower_case = auto()
MixedCase = auto()

assert Example.UPPER_CASE == "UPPER_CASE"
assert Example.lower_case == "lower_case"
assert Example.MixedCase == "MixedCase"
"""

def __new__(cls, value, *args, **kwargs):
if not isinstance(value, (str, enum.auto)):
raise TypeError(
f"Values of StrEnums must be strings: {value!r} is a {type(value)}"
)
return super().__new__(cls, value, *args, **kwargs)

def __str__(self):
return str(self.value)

def _generate_next_value_(name, *_):
return name
Loading