Updated variables and default package names.

This commit is contained in:
Harrison Deng 2022-12-08 17:18:21 +00:00
parent b2dea8d09b
commit d545ac84ff
4 changed files with 86 additions and 76 deletions

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"cSpell.words": [
"BUILDTOOLS",
"spigotmc"
]
}

118
gen.py
View File

@ -30,11 +30,11 @@ def project_gen() -> int:
print("Generate Project:")
print("Step 1) Generate Maven project.")
groupId = input("groupId (package): xyz.reslate.")
groupId = input("groupId (package): net.reslate.")
while (len(groupId) == 0 or (not groupId.islower() and not groupId.isupper()) or (groupId.isupper())):
print("GroupId cannot be empty and must be all lowercase.")
groupId = input("groupId (package): xyz.reslate.")
groupId = "xyz.reslate." + groupId
groupId = input("groupId (package): net.reslate.")
groupId = "net.reslate." + groupId
artifactId = input("artifactId (name of plugin): ")
while (len(artifactId) == 0 or (not artifactId.islower() and not artifactId.isupper()) or (artifactId.isupper())):
@ -47,51 +47,51 @@ def project_gen() -> int:
return 1
print("Step 2) Modify pom.xml")
spigotver = input("Spigot dependency version (default: \"{0}\"): ".format(DEFAULT_SPIGOT_VER))
if (len(spigotver) == 0): spigotver = DEFAULT_SPIGOT_VER
spigot_ver = input("Spigot dependency version (default: \"{0}\"): ".format(DEFAULT_SPIGOT_VER))
if (len(spigot_ver) == 0): spigot_ver = DEFAULT_SPIGOT_VER
spigotvercheck = input("Using \"{0}\". Is this fine? (Y/n)".format(spigotver))
if (len(spigotvercheck) == 0): spigotvercheck = "y"
while (spigotvercheck.lower() != "y"):
if spigotvercheck.lower() == "n":
spigotver = input("Spigot dependency version (Maven Dep. Ver.): ")
spigotvercheck = input("Entered \"{0}\". Is this fine? (Y/n)".format(spigotver))
spigot_ver_check = input("Using \"{0}\". Is this fine? (Y/n)".format(spigot_ver))
if (len(spigot_ver_check) == 0): spigot_ver_check = "y"
while (spigot_ver_check.lower() != "y"):
if spigot_ver_check.lower() == "n":
spigot_ver = input("Spigot dependency version (Maven Dep. Ver.): ")
spigot_ver_check = input("Entered \"{0}\". Is this fine? (Y/n)".format(spigot_ver))
else:
spigotvercheck = input("Please enter \"y\" to continue, or \"n\" to enter version again: ")
print("Using version: \"{0}\"".format(spigotver))
spigot_ver_check = input("Please enter \"y\" to continue, or \"n\" to enter version again: ")
print("Using version: \"{0}\"".format(spigot_ver))
pompath = "{0}/pom.xml".format(artifactId);
pom_path = "{0}/pom.xml".format(artifactId);
ET.register_namespace("", POM_NAMESPACE)
pomxml = ET.parse(pompath)
pomroot = pomxml.getroot()
pom_xml = ET.parse(pom_path)
pom_root = pom_xml.getroot()
repositorieselem = ET.Element("repositories")
repositoryelem = ET.SubElement(repositorieselem, "repository")
ET.SubElement(repositoryelem, "id").text = "spigot-repo"
ET.SubElement(repositoryelem, "url").text = "https://hub.spigotmc.org/nexus/content/repositories/public/"
repositories_elem = ET.Element("repositories")
repository_elem = ET.SubElement(repositories_elem, "repository")
ET.SubElement(repository_elem, "id").text = "spigot-repo"
ET.SubElement(repository_elem, "url").text = "https://hub.spigotmc.org/nexus/content/repositories/public/"
pomroot.append(repositorieselem)
pom_root.append(repositories_elem)
spigotdep = ET.Element("dependency")
ET.SubElement(spigotdep, "groupId").text = "org.spigotmc"
ET.SubElement(spigotdep, "artifactId").text = "spigot-api"
ET.SubElement(spigotdep, "version").text = spigotver
ET.SubElement(spigotdep, "type").text = "jar"
ET.SubElement(spigotdep, "scope").text = "provided"
spigot_dep = ET.Element("dependency")
ET.SubElement(spigot_dep, "groupId").text = "org.spigotmc"
ET.SubElement(spigot_dep, "artifactId").text = "spigot-api"
ET.SubElement(spigot_dep, "version").text = spigot_ver
ET.SubElement(spigot_dep, "type").text = "jar"
ET.SubElement(spigot_dep, "scope").text = "provided"
dependencies = pomroot.find("{" + POM_NAMESPACE + "}" + "dependencies")
dependencies.append(spigotdep)
dependencies = pom_root.find("{" + POM_NAMESPACE + "}" + "dependencies")
dependencies.append(spigot_dep)
pomxml.write(pompath)
pom_xml.write(pom_path)
print("Step 3) Validate pom.xml")
if os.system("mvn -B validate -f {0}".format(pompath)) != 0:
if os.system("mvn -B validate -f {0}".format(pom_path)) != 0:
print("An error has occurred. Please check output and fix issue before running again.")
return 1
print("pom.xml validated.")
print("Step 4) Resolve dependencies")
if os.system("mvn -B dependency:resolve -f {0}".format(pompath)) != 0:
if os.system("mvn -B dependency:resolve -f {0}".format(pom_path)) != 0:
print("An error has occurred. Please check output and fix issue before running again.")
return 1
print("Project generation complete.")
@ -107,38 +107,38 @@ def gen_dev_server() -> int:
os.mkdir(BUILDTOOLS_DIR)
os.chdir(BUILDTOOLS_DIR)
buildtoolrequest = requests.get(BUILDTOOLS_URL, allow_redirects=True)
buildtoolsfile = open("BuildTools.jar", "wb")
buildtoolsfile.write(buildtoolrequest.content)
buildtoolsfile.close()
build_tool_request = requests.get(BUILDTOOLS_URL, allow_redirects=True)
build_tools_file = open("BuildTools.jar", "wb")
build_tools_file.write(build_tool_request.content)
build_tools_file.close()
print("Step 2) Generate server JAR with BuildTools.jar")
spigotver = input("Spigot version to use (buildtools rev.) (default: \"{0}\"): ".format(DEFAULT_SERVER_VER))
if (len(spigotver) == 0): spigotver = DEFAULT_SERVER_VER
spigotververify = input("Attempt to use \"{0}\"? (Y/n)".format(spigotver))
if (len(spigotververify) == 0): spigotververify = "y"
while spigotververify.lower() != "y":
if (spigotververify.lower() == "n"):
spigotver = input("Spigot version to use: ")
spigotververify = input("Attempt to use \"{0}\"? (Y/n)".format(spigotver))
spigot_ver = input("Spigot version to use (buildtools rev.) (default: \"{0}\"): ".format(DEFAULT_SERVER_VER))
if (len(spigot_ver) == 0): spigot_ver = DEFAULT_SERVER_VER
spigot_ver_verify = input("Attempt to use \"{0}\"? (Y/n)".format(spigot_ver))
if (len(spigot_ver_verify) == 0): spigot_ver_verify = "y"
while spigot_ver_verify.lower() != "y":
if (spigot_ver_verify.lower() == "n"):
spigot_ver = input("Spigot version to use: ")
spigot_ver_verify = input("Attempt to use \"{0}\"? (Y/n)".format(spigot_ver))
else:
spigotververify = input("Attempt to use \"{0}\"? Please enter \"y\" or \"n\": ".format(spigotver))
spigot_ver_verify = input("Attempt to use \"{0}\"? Please enter \"y\" or \"n\": ".format(spigot_ver))
if os.system(BUILDTOOLS_CMD.format(ver = spigotver)) != 0:
if os.system(BUILDTOOLS_CMD.format(ver = spigot_ver)) != 0:
print("Error while running build tools.")
return 1
print("Step 3) Moving JARs and cleaning up.")
print("Moving generated JAR file.")
if spigotver == DEFAULT_SERVER_VER:
direntries = os.listdir()
for entry in direntries:
if spigot_ver == DEFAULT_SERVER_VER:
dir_entries = os.listdir()
for entry in dir_entries:
if (entry.startswith("spigot") and entry.endswith(".jar")):
shutil.move(entry, "../spigot.jar")
else:
shutil.move("spigot-{0}.jar".format(spigotver), "../spigot.jar")
shutil.move("spigot-{0}.jar".format(spigot_ver), "../spigot.jar")
os.chdir("../")
print("Deleting \"{0}\".".format(BUILDTOOLS_DIR))
@ -149,19 +149,19 @@ def gen_dev_server() -> int:
return 0
def reset() -> None:
pomxmldir = find_pomxmldir()
if len(pomxmldir) != 0:
shutil.rmtree(pomxmldir)
pom_xml_dir = find_pom_xml_dir()
if len(pom_xml_dir) != 0:
shutil.rmtree(pom_xml_dir)
print("Deleted Maven project directory.")
if os.path.exists(DEV_SERVER_PATH):
shutil.rmtree(DEV_SERVER_PATH)
print("Deleted development server directory.")
def find_pomxml() -> str:
return find_pomxmldir() + "/pom.xml"
def find_pom_xml() -> str:
return find_pom_xml_dir() + "/pom.xml"
def find_pomxmldir() -> str:
def find_pom_xml_dir() -> str:
directories = os.listdir()
if os.path.exists("./pom.xml"):
return "./"
@ -170,12 +170,12 @@ def find_pomxmldir() -> str:
if os.path.isdir(directory) and "pom.xml" in os.listdir(directory):
return directory
def __printhelp():
def __print_help():
print("usage: {0} <setup | project | server | reset>".format(sys.argv[0]))
if __name__ == "__main__":
if len(sys.argv) != 2:
__printhelp()
__print_help()
exit(1)
else:
if sys.argv[1] == "setup":
@ -188,5 +188,5 @@ if __name__ == "__main__":
elif sys.argv[1] == "reset":
reset()
else:
__printhelp()
__print_help()
exit(1)

View File

@ -6,21 +6,21 @@ import gen
if (os.getcwd().endswith("SpigotPluginBaseTools/")):
os.chdir("../")
pomxml = ET.parse(gen.find_pomxml())
pomroot = pomxml.getroot()
projname = pomroot.find("{" + gen.POM_NAMESPACE + "}" + "name").text
pluginver = pomroot.find("{" + gen.POM_NAMESPACE + "}" + "version").text
pluginfilename = projname + "-" + pluginver + ".jar"
pom_xml = ET.parse(gen.find_pom_xml())
pom_root = pom_xml.getroot()
proj_name = pom_root.find("{" + gen.POM_NAMESPACE + "}" + "name").text
plugin_ver = pom_root.find("{" + gen.POM_NAMESPACE + "}" + "version").text
plugin_filename = proj_name + "-" + plugin_ver + ".jar"
plugindir = gen.DEV_SERVER_PATH + "plugins/"
if not os.path.exists(plugindir):
os.mkdir(plugindir)
plugin_dir = gen.DEV_SERVER_PATH + "plugins/"
if not os.path.exists(plugin_dir):
os.mkdir(plugin_dir)
pluginpath = gen.find_pomxmldir() + "/target/{0}".format(pluginfilename)
plugin_path = gen.find_pom_xml_dir() + "/target/{0}".format(plugin_filename)
if not os.path.exists(pluginpath):
print("Could not find \"{0}\". Is it packaged?".format(pluginpath))
if not os.path.exists(plugin_path):
print("Could not find \"{0}\". Is it packaged?".format(plugin_path))
exit(1)
shutil.copy(pluginpath, plugindir + pluginfilename)
print("Copied \"{0}\" to \"{1}\".".format(pluginpath, plugindir + pluginfilename))
shutil.copy(plugin_path, plugin_dir + plugin_filename)
print("Copied \"{0}\" to \"{1}\".".format(plugin_path, plugin_dir + plugin_filename))

View File

@ -6,8 +6,12 @@ MAX_RAM="2048M"
JVM_DEBUG_PORT = 25577
if (os.getcwd().endswith("SpigotPluginBaseTools/")):
if os.getcwd().endswith("SpigotPluginBaseTools/"):
os.chdir("../")
os.chdir(gen.DEV_SERVER_PATH)
os.system("java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address={port} -Xms{minram} -Xmx{maxram} -jar spigot.jar".format(port = JVM_DEBUG_PORT, minram = MIN_RAM, maxram = MAX_RAM))
os.system(
"java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address={port} -Xms{min_ram} -Xmx{max_ram} -jar spigot.jar".format(
port=JVM_DEBUG_PORT, min_ram=MIN_RAM, max_ram=MAX_RAM
)
)