From 4a560c4ad8b580150534c7eb8185aa071840de24 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Tue, 17 Aug 2021 20:47:43 +0100 Subject: [PATCH] Add a task to fixup run configuration JDKs/modules --- go4it | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/go4it b/go4it index 805379698..a714f7c64 100755 --- a/go4it +++ b/go4it @@ -10,26 +10,31 @@ We then build each branch, push changes, and upload all versions. """ import argparse -import subprocess -import shutil -import sys -import re import os import os.path +import pathlib +import regex +import shutil +import subprocess +import sys +import xml.etree.ElementTree as ET from dataclasses import dataclass -from typing import List, Tuple, Optional +from textwrap import dedent +from typing import List, Optional @dataclass class Branch: name: str parent: Optional[str] = None + java: str = "1.8" BRANCHES: List[Branch] = [ Branch('mc-1.15.x'), Branch('mc-1.16.x', parent='mc-1.15.x'), - Branch('mc-1.17.x', parent='mc-1.16.x'), + Branch('mc-1.17.x', parent='mc-1.16.x', java="16"), + # Branch('mc-fabric-1.17.x', parent='mc-1.17.x', java="16"), ] @@ -74,7 +79,19 @@ def setup() -> None: shutil.copy2(src, file) with open("settings.gradle", "w") as h: - h.write("rootProject.name = 'cc-tweaked'\n") + h.write(dedent("""\ + pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } + } + + rootProject.name = 'cc-tweaked' + """)) for branch in BRANCHES: h.write(f"include '{branch.name}'\n") @@ -82,6 +99,47 @@ def setup() -> None: pass +def gen_runs() -> None: + """ + Generate .idea run files + """ + # setup() + # subprocess.check_call(["./gradlew", "--no-daemon", "genRuns"]) + + re = regex.compile(r"(mc-.*)_run(.*)\.xml") + for path in pathlib.Path(".idea/runConfigurations").glob("*.xml"): + group = re.match(path.name) + if not group: + continue + version, name = group[1], group[2] + + for branch in BRANCHES: + if branch.name == version: + break + else: + print("Cannot find Java for branch") + continue + + component = 'testMod' if name == 'TestServer' else 'main' + xml = ET.parse(path) + module = xml.find("./configuration/module") + if module is None: + print("Unknown module for " + path.name) + else: + module.set("name", f"cc-tweaked.{version}.{component}") + + version = xml.find("./configuration/option[@name='ALTERNATIVE_JRE_PATH']") + if version: + version.set("value", branch.java) + else: + root = xml.find("./configuration") + assert root + ET.SubElement(root, 'option', {'name': 'ALTERNATIVE_JRE_PATH', 'value': branch.java}) + ET.SubElement(root, 'option', {'name': 'ALTERNATIVE_JRE_PATH_ENABLED', 'value': 'true'}) + + xml.write(path) + + def check_git() -> None: """ Check all worktrees are in a sensible state prior to merging. @@ -169,6 +227,7 @@ def main() -> None: required=True, ) subparsers.add_parser("setup", help="Setup the git repository and build environment.").set_defaults(func=setup) + subparsers.add_parser("gen-runs", help="Generate IntelliJ IDEA run configurations.").set_defaults(func=gen_runs) subparsers.add_parser("check-git", help="Check the git worktrees are in a state ready for merging.").set_defaults(func=check_git) subparsers.add_parser("build", help="Merge and build all branches.").set_defaults(func=build) subparsers.add_parser("release", help="Publish a release.").set_defaults(func=release)