Skip to content

Commit

Permalink
Changed mojang java names to match meta
Browse files Browse the repository at this point in the history
Signed-off-by: Trial97 <[email protected]>
  • Loading branch information
Trial97 committed Jan 25, 2024
1 parent 230b8c8 commit abc3209
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 84 deletions.
155 changes: 78 additions & 77 deletions generateJava.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def mojang_os_to_java_os(mojang_os: MojangJavaOsName) -> JavaRuntimeOS:

def mojang_runtime_to_java_runtime(
mojang_runtime: MojangJavaRuntime,
mojang_component: MojangJavaComponent,
) -> JavaRuntimeMeta:
major, _, security = mojang_runtime.version.name.partition("u")
if major and security:
version_parts = [int(major), 0, int(security)]
else:
version_parts = [int(part)
for part in mojang_runtime.version.name.split(".")]
version_parts = [int(part) for part in mojang_runtime.version.name.split(".")]

while len(version_parts) < 3:
version_parts.append(0)
Expand All @@ -147,7 +147,7 @@ def mojang_runtime_to_java_runtime(
name=mojang_runtime.version.name,
)
return JavaRuntimeMeta(
name=f"mojang_jre_{mojang_runtime.version.name}",
name=mojang_component,
vendor="mojang",
url=mojang_runtime.manifest.url,
releaseTime=mojang_runtime.version.released,
Expand Down Expand Up @@ -177,7 +177,9 @@ def adoptium_release_binary_to_java_runtime(
version = JavaVersionMeta(
major=rls.version_data.major if rls.version_data.major is not None else 0,
minor=rls.version_data.minor if rls.version_data.minor is not None else 0,
security=rls.version_data.security if rls.version_data.security is not None else 0,
security=rls.version_data.security
if rls.version_data.security is not None
else 0,
build=rls.version_data.build,
)
rls_name = f"{rls.vendor}_temurin_{binary.image_type}{version}"
Expand Down Expand Up @@ -217,9 +219,7 @@ def azul_package_to_java_runtime(pkg: ZuluPackageDetail) -> JavaRuntimeMeta:

checksum = None
if pkg.sha256_hash is not None:
checksum = JavaChecksumMeta(
type=JavaChecksumType.Sha256, hash=pkg.sha256_hash
)
checksum = JavaChecksumMeta(type=JavaChecksumType.Sha256, hash=pkg.sha256_hash)

return JavaRuntimeMeta(
name=rls_name,
Expand Down Expand Up @@ -262,7 +262,9 @@ def pkg_type_priority(pkg_type: JavaPackageType) -> int:
return -1


def ensure_one_recommended(runtimes: list[JavaRuntimeMeta]) -> Optional[JavaRuntimeMeta]:
def ensure_one_recommended(
runtimes: list[JavaRuntimeMeta],
) -> Optional[JavaRuntimeMeta]:
if len(runtimes) < 1:
return None # can't do anything

Expand All @@ -287,7 +289,9 @@ def better_java_runtime(runtime: JavaRuntimeMeta):
assert recommended is not None
if vendor_priority(runtime.vendor) < vendor_priority(recommended.vendor):
return False
if pkg_type_priority(runtime.package_type) < pkg_type_priority(recommended.package_type):
if pkg_type_priority(runtime.package_type) < pkg_type_priority(
recommended.package_type
):
return False
if runtime.version < recommended.version:
return False
Expand All @@ -313,8 +317,7 @@ def ensure_javamap(major: int):

def add_java_runtime(runtime: JavaRuntimeMeta, major: int, java_os: JavaRuntimeOS):
ensure_javamap(major)
print(
f"Regestering runtime: {runtime.name} for Java {major} {java_os}")
print(f"Regestering runtime: {runtime.name} for Java {major} {java_os}")
javas[major][java_os].append(runtime)

print("Processing Mojang Javas")
Expand All @@ -334,68 +337,67 @@ def add_java_runtime(runtime: JavaRuntimeMeta, major: int, java_os: JavaRuntimeO
major = 8
else:
major = int(mojang_runtime.version.name.partition(".")[0])
runtime = mojang_runtime_to_java_runtime(mojang_runtime)
runtime = mojang_runtime_to_java_runtime(mojang_runtime, comp)
add_java_runtime(runtime, major, java_os)

print("Processing Adoptium Releases")
adoptium_available_releases = AdoptiumAvailableReleases.parse_file(
os.path.join(UPSTREAM_DIR, ADOPTIUM_DIR, "available_releases.json")
)
for major in adoptium_available_releases.available_releases:
adoptium_releases = AdoptiumReleases.parse_file(
os.path.join(UPSTREAM_DIR, ADOPTIUM_VERSIONS_DIR,
f"java{major}.json")
adoptium_path = os.path.join(UPSTREAM_DIR, ADOPTIUM_DIR, "available_releases.json")
if os.path.exists(adoptium_path):
adoptium_available_releases = AdoptiumAvailableReleases.parse_file(
adoptium_path
)
for _, rls in adoptium_releases:
for binary in rls.binaries:
if binary.package is None:
continue
binary_arch = translate_arch(str(binary.architecture))
binary_os = translate_os(str(binary.os))
if binary_arch is None or binary_os is None:
print(
f"Ignoring release for {binary.os} {binary.architecture}")
continue

java_os = JavaRuntimeOS(f"{binary_os}-{binary_arch}")
runtime = adoptium_release_binary_to_java_runtime(rls, binary)
add_java_runtime(runtime, major, java_os)
for major in adoptium_available_releases.available_releases:
adoptium_releases = AdoptiumReleases.parse_file(
os.path.join(UPSTREAM_DIR, ADOPTIUM_VERSIONS_DIR, f"java{major}.json")
)
for _, rls in adoptium_releases:
for binary in rls.binaries:
if binary.package is None:
continue
binary_arch = translate_arch(str(binary.architecture))
binary_os = translate_os(str(binary.os))
if binary_arch is None or binary_os is None:
print(f"Ignoring release for {binary.os} {binary.architecture}")
continue

java_os = JavaRuntimeOS(f"{binary_os}-{binary_arch}")
runtime = adoptium_release_binary_to_java_runtime(rls, binary)
add_java_runtime(runtime, major, java_os)

print("Processing Azul Packages")
azul_packages = ZuluPackageList.parse_file(
os.path.join(UPSTREAM_DIR, AZUL_DIR, "packages.json")
)
for _, pkg in azul_packages:
pkg_detail = ZuluPackageDetail.parse_file(
os.path.join(UPSTREAM_DIR, AZUL_VERSIONS_DIR,
f"{pkg.package_uuid}.json")
)
major = pkg_detail.java_version[0]
if major < 8:
continue # we will never need java versions less than 8

pkg_os = translate_os(str(pkg_detail.os))
if pkg_detail.arch == AzulArch.Arm:
pkg_arch = translate_arch(
f"{pkg_detail.arch}{pkg_detail.hw_bitness}")
elif pkg_detail.arch == AzulArch.X86:
pkg_arch = translate_arch(int(pkg_detail.hw_bitness))
else:
pkg_arch = None
if pkg_arch is None or pkg_os is None:
print(
f"Ignoring release for {pkg_detail.os} {pkg_detail.arch}_{pkg_detail.hw_bitness}"
azul_path = os.path.join(UPSTREAM_DIR, AZUL_DIR, "packages.json")
if os.path.exists(azul_path):
azul_packages = ZuluPackageList.parse_file(azul_path)
for _, pkg in azul_packages:
pkg_detail = ZuluPackageDetail.parse_file(
os.path.join(
UPSTREAM_DIR, AZUL_VERSIONS_DIR, f"{pkg.package_uuid}.json"
)
)
continue
major = pkg_detail.java_version[0]
if major < 8:
continue # we will never need java versions less than 8

pkg_os = translate_os(str(pkg_detail.os))
if pkg_detail.arch == AzulArch.Arm:
pkg_arch = translate_arch(f"{pkg_detail.arch}{pkg_detail.hw_bitness}")
elif pkg_detail.arch == AzulArch.X86:
pkg_arch = translate_arch(int(pkg_detail.hw_bitness))
else:
pkg_arch = None
if pkg_arch is None or pkg_os is None:
print(
f"Ignoring release for {pkg_detail.os} {pkg_detail.arch}_{pkg_detail.hw_bitness}"
)
continue

java_os = JavaRuntimeOS(f"{pkg_os}-{pkg_arch}")
runtime = azul_package_to_java_runtime(pkg_detail)
add_java_runtime(runtime, major, java_os)
java_os = JavaRuntimeOS(f"{pkg_os}-{pkg_arch}")
runtime = azul_package_to_java_runtime(pkg_detail)
add_java_runtime(runtime, major, java_os)

for major, runtimes in javas.items():
for java_os, runtime_list in runtimes:
print(f"Total runtimes for Java {major} {java_os}:", len(
runtime_list))
print(f"Total runtimes for Java {major} {java_os}:", len(runtime_list))
rec = ensure_one_recommended(runtime_list)
if rec is not None:
print(f"Recomending {rec.name} for Java {major} {java_os}")
Expand All @@ -405,27 +407,26 @@ def newest_timestamp(a: datetime.datetime | None, b: datetime.datetime):
return b
return a

version_file = os.path.join(
LAUNCHER_DIR, JAVA_COMPONENT, f"java{major}.json")
version_file = os.path.join(LAUNCHER_DIR, JAVA_COMPONENT, f"java{major}.json")
java_version = JavaRuntimeVersion(
name = f"Java {major}",
uid = JAVA_COMPONENT,
version = f"java{major}",
name=f"Java {major}",
uid=JAVA_COMPONENT,
version=f"java{major}",
releaseTime=reduce(
newest_timestamp,
(runtime.release_time
for _, runtime_list in runtimes
for runtime in runtime_list
),
None
newest_timestamp,
(
runtime.release_time
for _, runtime_list in runtimes
for runtime in runtime_list
),
runtimes = runtimes)
None,
),
runtimes=runtimes,
)
java_version.write(version_file)

package = MetaPackage(
uid = JAVA_COMPONENT,
name = "Java Runtimes",
recommended = ["java8", "java17"]
uid=JAVA_COMPONENT, name="Java Runtimes", recommended=["java8", "java17"]
)
package.write(os.path.join(LAUNCHER_DIR, JAVA_COMPONENT, "package.json"))

Expand Down
15 changes: 8 additions & 7 deletions meta/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ def __eq__(self, other: Any):
else:
return False

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

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

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

@classmethod
def validate(cls, v: 'str | GradleSpecifier'):
def validate(cls, v: "str | GradleSpecifier"):
if isinstance(v, cls):
return v
if isinstance(v, str):
Expand Down Expand Up @@ -155,7 +155,7 @@ def write(self, file_path: str):
with open(file_path, "w") as f:
f.write(self.json())

def merge(self, other: 'MetaBase'):
def merge(self, other: "MetaBase"):
"""
Merge other object with self.
- Concatenates lists
Expand All @@ -179,14 +179,14 @@ def merge(self, other: 'MetaBase'):
elif isinstance(ours, set):
ours |= theirs
elif isinstance(ours, dict):
result = merge_dict(ours, copy.deepcopy(theirs)) # type: ignore
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): #type: ignore
def __hash__(self): # type: ignore
return hash(self.json())

class Config:
Expand Down Expand Up @@ -277,7 +277,7 @@ def action_must_be_allow_disallow(cls, v: str):
class MojangRules(MetaBase):
__root__: List[MojangRule]

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

def __getitem__(self, item: int) -> MojangRule:
Expand Down Expand Up @@ -319,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
6 changes: 6 additions & 0 deletions meta/model/mojang.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
SUPPORTED_LAUNCHER_VERSION = 21
SUPPORTED_COMPLIANCE_LEVEL = 1
DEFAULT_JAVA_MAJOR = 8 # By default, we should recommend Java 8 if we don't know better
DEFAULT_JAVA_NAME = (
"jre-legacy" # By default, we should recommend Java 8 if we don't know better
)
COMPATIBLE_JAVA_MAPPINGS = {16: [17]}

"""
Expand Down Expand Up @@ -318,10 +321,12 @@ def to_meta_version(self, name: str, uid: str, version: str) -> MetaVersion:
raise Exception(f"Unsupported compliance level {self.compliance_level}")

major = DEFAULT_JAVA_MAJOR
javaName = DEFAULT_JAVA_NAME
if (
self.javaVersion is not None
): # some versions don't have this. TODO: maybe maintain manual overrides
major = self.javaVersion.major_version
javaName = self.javaVersion.component

compatible_java_majors = [major]
if (
Expand All @@ -343,6 +348,7 @@ def to_meta_version(self, name: str, uid: str, version: str) -> MetaVersion:
release_time=self.release_time,
type=new_type,
compatible_java_majors=compatible_java_majors,
compatible_java_name=javaName,
additional_traits=addn_traits,
main_jar=main_jar,
)

0 comments on commit abc3209

Please sign in to comment.