mirror of
https://github.com/unmojang/meta.git
synced 2025-09-24 03:31:03 -04:00
refactor: move GradleSpecifier into model
This commit is contained in:
parent
00cbf2073b
commit
1bd80e57aa
@ -3,9 +3,8 @@ import os
|
|||||||
|
|
||||||
from meta.common import ensure_component_dir, polymc_path, upstream_path, transform_maven_key
|
from meta.common import ensure_component_dir, polymc_path, upstream_path, transform_maven_key
|
||||||
from meta.common.fabric import JARS_DIR, INSTALLER_INFO_DIR, META_DIR, INTERMEDIARY_COMPONENT, LOADER_COMPONENT
|
from meta.common.fabric import JARS_DIR, INSTALLER_INFO_DIR, META_DIR, INTERMEDIARY_COMPONENT, LOADER_COMPONENT
|
||||||
from meta.model import MetaVersion, Dependency, Library, MetaPackage
|
from meta.model import MetaVersion, Dependency, Library, MetaPackage, GradleSpecifier
|
||||||
from meta.model.fabric import FabricJarInfo, FabricInstallerDataV1, FabricMainClasses
|
from meta.model.fabric import FabricJarInfo, FabricInstallerDataV1, FabricMainClasses
|
||||||
from meta.model.types import GradleSpecifier
|
|
||||||
|
|
||||||
PMC_DIR = polymc_path()
|
PMC_DIR = polymc_path()
|
||||||
UPSTREAM_DIR = upstream_path()
|
UPSTREAM_DIR = upstream_path()
|
||||||
|
@ -389,5 +389,6 @@ def main():
|
|||||||
package.recommended = recommendedVersions
|
package.recommended = recommendedVersions
|
||||||
package.write(os.path.join(PMC_DIR, FORGE_COMPONENT, "package.json"))
|
package.write(os.path.join(PMC_DIR, FORGE_COMPONENT, "package.json"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -4,12 +4,102 @@ from typing import Optional, List, Dict, Any, Iterator
|
|||||||
import pydantic
|
import pydantic
|
||||||
from pydantic import Field, validator
|
from pydantic import Field, validator
|
||||||
|
|
||||||
from .types import GradleSpecifier
|
|
||||||
from ..common import serialize_datetime
|
from ..common import serialize_datetime
|
||||||
|
|
||||||
META_FORMAT_VERSION = 1
|
META_FORMAT_VERSION = 1
|
||||||
|
|
||||||
|
|
||||||
|
class GradleSpecifier:
|
||||||
|
"""
|
||||||
|
A gradle specifier - a maven coordinate. Like one of these:
|
||||||
|
"org.lwjgl.lwjgl:lwjgl:2.9.0"
|
||||||
|
"net.java.jinput:jinput:2.0.5"
|
||||||
|
"net.minecraft:launchwrapper:1.5"
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, group: str, artifact: str, version: str, classifier: Optional[str] = None,
|
||||||
|
extension: Optional[str] = None):
|
||||||
|
if extension is None:
|
||||||
|
extension = "jar"
|
||||||
|
self.group = group
|
||||||
|
self.artifact = artifact
|
||||||
|
self.version = version
|
||||||
|
self.classifier = classifier
|
||||||
|
self.extension = extension
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
ext = ''
|
||||||
|
if self.extension != 'jar':
|
||||||
|
ext = "@%s" % self.extension
|
||||||
|
if self.classifier:
|
||||||
|
return "%s:%s:%s:%s%s" % (self.group, self.artifact, self.version, self.classifier, ext)
|
||||||
|
else:
|
||||||
|
return "%s:%s:%s%s" % (self.group, self.artifact, self.version, ext)
|
||||||
|
|
||||||
|
def filename(self):
|
||||||
|
if self.classifier:
|
||||||
|
return "%s-%s-%s.%s" % (self.artifact, self.version, self.classifier, self.extension)
|
||||||
|
else:
|
||||||
|
return "%s-%s.%s" % (self.artifact, self.version, self.extension)
|
||||||
|
|
||||||
|
def base(self):
|
||||||
|
return "%s/%s/%s/" % (self.group.replace('.', '/'), self.artifact, self.version)
|
||||||
|
|
||||||
|
def path(self):
|
||||||
|
return self.base() + self.filename()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"GradleSpecifier('{self}')"
|
||||||
|
|
||||||
|
def is_lwjgl(self):
|
||||||
|
return self.group in ("org.lwjgl", "org.lwjgl.lwjgl", "net.java.jinput", "net.java.jutils")
|
||||||
|
|
||||||
|
def is_log4j(self):
|
||||||
|
return self.group == "org.apache.logging.log4j"
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return str(self) == str(other)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return str(self) < str(other)
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return str(self) > str(other)
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
return hash(str(self))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __get_validators__(cls):
|
||||||
|
yield cls.validate
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_string(cls, v: str):
|
||||||
|
ext_split = v.split('@')
|
||||||
|
|
||||||
|
components = ext_split[0].split(':')
|
||||||
|
group = components[0]
|
||||||
|
artifact = components[1]
|
||||||
|
version = components[2]
|
||||||
|
|
||||||
|
extension = None
|
||||||
|
if len(ext_split) == 2:
|
||||||
|
extension = ext_split[1]
|
||||||
|
|
||||||
|
classifier = None
|
||||||
|
if len(components) == 4:
|
||||||
|
classifier = components[3]
|
||||||
|
return cls(group, artifact, version, classifier, extension)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def validate(cls, v):
|
||||||
|
if isinstance(v, cls):
|
||||||
|
return v
|
||||||
|
if isinstance(v, str):
|
||||||
|
return cls.from_string(v)
|
||||||
|
raise TypeError("Invalid type")
|
||||||
|
|
||||||
|
|
||||||
class MetaBase(pydantic.BaseModel):
|
class MetaBase(pydantic.BaseModel):
|
||||||
def dict(self, **kwargs) -> Dict[str, Any]:
|
def dict(self, **kwargs) -> Dict[str, Any]:
|
||||||
for k in ["by_alias"]:
|
for k in ["by_alias"]:
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
from typing import Optional
|
|
||||||
|
|
||||||
|
|
||||||
class GradleSpecifier:
|
|
||||||
"""
|
|
||||||
A gradle specifier - a maven coordinate. Like one of these:
|
|
||||||
"org.lwjgl.lwjgl:lwjgl:2.9.0"
|
|
||||||
"net.java.jinput:jinput:2.0.5"
|
|
||||||
"net.minecraft:launchwrapper:1.5"
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, group: str, artifact: str, version: str, classifier: Optional[str] = None,
|
|
||||||
extension: Optional[str] = None):
|
|
||||||
if extension is None:
|
|
||||||
extension = "jar"
|
|
||||||
self.group = group
|
|
||||||
self.artifact = artifact
|
|
||||||
self.version = version
|
|
||||||
self.classifier = classifier
|
|
||||||
self.extension = extension
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
ext = ''
|
|
||||||
if self.extension != 'jar':
|
|
||||||
ext = "@%s" % self.extension
|
|
||||||
if self.classifier:
|
|
||||||
return "%s:%s:%s:%s%s" % (self.group, self.artifact, self.version, self.classifier, ext)
|
|
||||||
else:
|
|
||||||
return "%s:%s:%s%s" % (self.group, self.artifact, self.version, ext)
|
|
||||||
|
|
||||||
def filename(self):
|
|
||||||
if self.classifier:
|
|
||||||
return "%s-%s-%s.%s" % (self.artifact, self.version, self.classifier, self.extension)
|
|
||||||
else:
|
|
||||||
return "%s-%s.%s" % (self.artifact, self.version, self.extension)
|
|
||||||
|
|
||||||
def base(self):
|
|
||||||
return "%s/%s/%s/" % (self.group.replace('.', '/'), self.artifact, self.version)
|
|
||||||
|
|
||||||
def path(self):
|
|
||||||
return self.base() + self.filename()
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return f"GradleSpecifier('{self}')"
|
|
||||||
|
|
||||||
def is_lwjgl(self):
|
|
||||||
return self.group in ("org.lwjgl", "org.lwjgl.lwjgl", "net.java.jinput", "net.java.jutils")
|
|
||||||
|
|
||||||
def is_log4j(self):
|
|
||||||
return self.group == "org.apache.logging.log4j"
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return str(self) == str(other)
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
return str(self) < str(other)
|
|
||||||
|
|
||||||
def __gt__(self, other):
|
|
||||||
return str(self) > str(other)
|
|
||||||
|
|
||||||
def __hash__(self):
|
|
||||||
return hash(str(self))
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def __get_validators__(cls):
|
|
||||||
yield cls.validate
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_string(cls, v: str):
|
|
||||||
ext_split = v.split('@')
|
|
||||||
|
|
||||||
components = ext_split[0].split(':')
|
|
||||||
group = components[0]
|
|
||||||
artifact = components[1]
|
|
||||||
version = components[2]
|
|
||||||
|
|
||||||
extension = None
|
|
||||||
if len(ext_split) == 2:
|
|
||||||
extension = ext_split[1]
|
|
||||||
|
|
||||||
classifier = None
|
|
||||||
if len(components) == 4:
|
|
||||||
classifier = components[3]
|
|
||||||
return cls(group, artifact, version, classifier, extension)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def validate(cls, v):
|
|
||||||
if isinstance(v, cls):
|
|
||||||
return v
|
|
||||||
if isinstance(v, str):
|
|
||||||
return cls.from_string(v)
|
|
||||||
raise TypeError("Invalid type")
|
|
@ -1,15 +1,16 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import zipfile
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import zipfile
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from cachecontrol import CacheControl
|
from cachecontrol import CacheControl
|
||||||
from cachecontrol.caches import FileCache
|
from cachecontrol.caches import FileCache
|
||||||
from meta.model.fabric import FabricJarInfo
|
|
||||||
from meta.common import DATETIME_FORMAT_HTTP, upstream_path, ensure_upstream_dir, transform_maven_key
|
from meta.common import DATETIME_FORMAT_HTTP, upstream_path, ensure_upstream_dir, transform_maven_key
|
||||||
from meta.common.fabric import JARS_DIR, INSTALLER_INFO_DIR, META_DIR
|
from meta.common.fabric import JARS_DIR, INSTALLER_INFO_DIR, META_DIR
|
||||||
|
from meta.model.fabric import FabricJarInfo
|
||||||
|
|
||||||
UPSTREAM_DIR = upstream_path()
|
UPSTREAM_DIR = upstream_path()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user