Updated variables and default package names.
This commit is contained in:
parent
b2dea8d09b
commit
d545ac84ff
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"BUILDTOOLS",
|
||||||
|
"spigotmc"
|
||||||
|
]
|
||||||
|
}
|
118
gen.py
118
gen.py
@ -30,11 +30,11 @@ def project_gen() -> int:
|
|||||||
print("Generate Project:")
|
print("Generate Project:")
|
||||||
print("Step 1) Generate Maven 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())):
|
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.")
|
print("GroupId cannot be empty and must be all lowercase.")
|
||||||
groupId = input("groupId (package): xyz.reslate.")
|
groupId = input("groupId (package): net.reslate.")
|
||||||
groupId = "xyz.reslate." + groupId
|
groupId = "net.reslate." + groupId
|
||||||
|
|
||||||
artifactId = input("artifactId (name of plugin): ")
|
artifactId = input("artifactId (name of plugin): ")
|
||||||
while (len(artifactId) == 0 or (not artifactId.islower() and not artifactId.isupper()) or (artifactId.isupper())):
|
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
|
return 1
|
||||||
|
|
||||||
print("Step 2) Modify pom.xml")
|
print("Step 2) Modify pom.xml")
|
||||||
spigotver = input("Spigot dependency version (default: \"{0}\"): ".format(DEFAULT_SPIGOT_VER))
|
spigot_ver = input("Spigot dependency version (default: \"{0}\"): ".format(DEFAULT_SPIGOT_VER))
|
||||||
if (len(spigotver) == 0): spigotver = DEFAULT_SPIGOT_VER
|
if (len(spigot_ver) == 0): spigot_ver = DEFAULT_SPIGOT_VER
|
||||||
|
|
||||||
spigotvercheck = input("Using \"{0}\". Is this fine? (Y/n)".format(spigotver))
|
spigot_ver_check = input("Using \"{0}\". Is this fine? (Y/n)".format(spigot_ver))
|
||||||
if (len(spigotvercheck) == 0): spigotvercheck = "y"
|
if (len(spigot_ver_check) == 0): spigot_ver_check = "y"
|
||||||
while (spigotvercheck.lower() != "y"):
|
while (spigot_ver_check.lower() != "y"):
|
||||||
if spigotvercheck.lower() == "n":
|
if spigot_ver_check.lower() == "n":
|
||||||
spigotver = input("Spigot dependency version (Maven Dep. Ver.): ")
|
spigot_ver = input("Spigot dependency version (Maven Dep. Ver.): ")
|
||||||
spigotvercheck = input("Entered \"{0}\". Is this fine? (Y/n)".format(spigotver))
|
spigot_ver_check = input("Entered \"{0}\". Is this fine? (Y/n)".format(spigot_ver))
|
||||||
else:
|
else:
|
||||||
spigotvercheck = input("Please enter \"y\" to continue, or \"n\" to enter version again: ")
|
spigot_ver_check = input("Please enter \"y\" to continue, or \"n\" to enter version again: ")
|
||||||
print("Using version: \"{0}\"".format(spigotver))
|
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)
|
ET.register_namespace("", POM_NAMESPACE)
|
||||||
pomxml = ET.parse(pompath)
|
pom_xml = ET.parse(pom_path)
|
||||||
pomroot = pomxml.getroot()
|
pom_root = pom_xml.getroot()
|
||||||
|
|
||||||
repositorieselem = ET.Element("repositories")
|
repositories_elem = ET.Element("repositories")
|
||||||
repositoryelem = ET.SubElement(repositorieselem, "repository")
|
repository_elem = ET.SubElement(repositories_elem, "repository")
|
||||||
ET.SubElement(repositoryelem, "id").text = "spigot-repo"
|
ET.SubElement(repository_elem, "id").text = "spigot-repo"
|
||||||
ET.SubElement(repositoryelem, "url").text = "https://hub.spigotmc.org/nexus/content/repositories/public/"
|
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")
|
spigot_dep = ET.Element("dependency")
|
||||||
ET.SubElement(spigotdep, "groupId").text = "org.spigotmc"
|
ET.SubElement(spigot_dep, "groupId").text = "org.spigotmc"
|
||||||
ET.SubElement(spigotdep, "artifactId").text = "spigot-api"
|
ET.SubElement(spigot_dep, "artifactId").text = "spigot-api"
|
||||||
ET.SubElement(spigotdep, "version").text = spigotver
|
ET.SubElement(spigot_dep, "version").text = spigot_ver
|
||||||
ET.SubElement(spigotdep, "type").text = "jar"
|
ET.SubElement(spigot_dep, "type").text = "jar"
|
||||||
ET.SubElement(spigotdep, "scope").text = "provided"
|
ET.SubElement(spigot_dep, "scope").text = "provided"
|
||||||
|
|
||||||
dependencies = pomroot.find("{" + POM_NAMESPACE + "}" + "dependencies")
|
dependencies = pom_root.find("{" + POM_NAMESPACE + "}" + "dependencies")
|
||||||
dependencies.append(spigotdep)
|
dependencies.append(spigot_dep)
|
||||||
|
|
||||||
pomxml.write(pompath)
|
pom_xml.write(pom_path)
|
||||||
|
|
||||||
print("Step 3) Validate pom.xml")
|
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.")
|
print("An error has occurred. Please check output and fix issue before running again.")
|
||||||
return 1
|
return 1
|
||||||
print("pom.xml validated.")
|
print("pom.xml validated.")
|
||||||
|
|
||||||
print("Step 4) Resolve dependencies")
|
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.")
|
print("An error has occurred. Please check output and fix issue before running again.")
|
||||||
return 1
|
return 1
|
||||||
print("Project generation complete.")
|
print("Project generation complete.")
|
||||||
@ -107,38 +107,38 @@ def gen_dev_server() -> int:
|
|||||||
os.mkdir(BUILDTOOLS_DIR)
|
os.mkdir(BUILDTOOLS_DIR)
|
||||||
os.chdir(BUILDTOOLS_DIR)
|
os.chdir(BUILDTOOLS_DIR)
|
||||||
|
|
||||||
buildtoolrequest = requests.get(BUILDTOOLS_URL, allow_redirects=True)
|
build_tool_request = requests.get(BUILDTOOLS_URL, allow_redirects=True)
|
||||||
buildtoolsfile = open("BuildTools.jar", "wb")
|
build_tools_file = open("BuildTools.jar", "wb")
|
||||||
buildtoolsfile.write(buildtoolrequest.content)
|
build_tools_file.write(build_tool_request.content)
|
||||||
buildtoolsfile.close()
|
build_tools_file.close()
|
||||||
|
|
||||||
print("Step 2) Generate server JAR with BuildTools.jar")
|
print("Step 2) Generate server JAR with BuildTools.jar")
|
||||||
|
|
||||||
spigotver = input("Spigot version to use (buildtools rev.) (default: \"{0}\"): ".format(DEFAULT_SERVER_VER))
|
spigot_ver = input("Spigot version to use (buildtools rev.) (default: \"{0}\"): ".format(DEFAULT_SERVER_VER))
|
||||||
if (len(spigotver) == 0): spigotver = DEFAULT_SERVER_VER
|
if (len(spigot_ver) == 0): spigot_ver = DEFAULT_SERVER_VER
|
||||||
spigotververify = input("Attempt to use \"{0}\"? (Y/n)".format(spigotver))
|
spigot_ver_verify = input("Attempt to use \"{0}\"? (Y/n)".format(spigot_ver))
|
||||||
if (len(spigotververify) == 0): spigotververify = "y"
|
if (len(spigot_ver_verify) == 0): spigot_ver_verify = "y"
|
||||||
while spigotververify.lower() != "y":
|
while spigot_ver_verify.lower() != "y":
|
||||||
if (spigotververify.lower() == "n"):
|
if (spigot_ver_verify.lower() == "n"):
|
||||||
spigotver = input("Spigot version to use: ")
|
spigot_ver = input("Spigot version to use: ")
|
||||||
spigotververify = input("Attempt to use \"{0}\"? (Y/n)".format(spigotver))
|
spigot_ver_verify = input("Attempt to use \"{0}\"? (Y/n)".format(spigot_ver))
|
||||||
else:
|
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.")
|
print("Error while running build tools.")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
print("Step 3) Moving JARs and cleaning up.")
|
print("Step 3) Moving JARs and cleaning up.")
|
||||||
|
|
||||||
print("Moving generated JAR file.")
|
print("Moving generated JAR file.")
|
||||||
if spigotver == DEFAULT_SERVER_VER:
|
if spigot_ver == DEFAULT_SERVER_VER:
|
||||||
direntries = os.listdir()
|
dir_entries = os.listdir()
|
||||||
for entry in direntries:
|
for entry in dir_entries:
|
||||||
if (entry.startswith("spigot") and entry.endswith(".jar")):
|
if (entry.startswith("spigot") and entry.endswith(".jar")):
|
||||||
shutil.move(entry, "../spigot.jar")
|
shutil.move(entry, "../spigot.jar")
|
||||||
else:
|
else:
|
||||||
shutil.move("spigot-{0}.jar".format(spigotver), "../spigot.jar")
|
shutil.move("spigot-{0}.jar".format(spigot_ver), "../spigot.jar")
|
||||||
|
|
||||||
os.chdir("../")
|
os.chdir("../")
|
||||||
print("Deleting \"{0}\".".format(BUILDTOOLS_DIR))
|
print("Deleting \"{0}\".".format(BUILDTOOLS_DIR))
|
||||||
@ -149,19 +149,19 @@ def gen_dev_server() -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def reset() -> None:
|
def reset() -> None:
|
||||||
pomxmldir = find_pomxmldir()
|
pom_xml_dir = find_pom_xml_dir()
|
||||||
if len(pomxmldir) != 0:
|
if len(pom_xml_dir) != 0:
|
||||||
shutil.rmtree(pomxmldir)
|
shutil.rmtree(pom_xml_dir)
|
||||||
print("Deleted Maven project directory.")
|
print("Deleted Maven project directory.")
|
||||||
|
|
||||||
if os.path.exists(DEV_SERVER_PATH):
|
if os.path.exists(DEV_SERVER_PATH):
|
||||||
shutil.rmtree(DEV_SERVER_PATH)
|
shutil.rmtree(DEV_SERVER_PATH)
|
||||||
print("Deleted development server directory.")
|
print("Deleted development server directory.")
|
||||||
|
|
||||||
def find_pomxml() -> str:
|
def find_pom_xml() -> str:
|
||||||
return find_pomxmldir() + "/pom.xml"
|
return find_pom_xml_dir() + "/pom.xml"
|
||||||
|
|
||||||
def find_pomxmldir() -> str:
|
def find_pom_xml_dir() -> str:
|
||||||
directories = os.listdir()
|
directories = os.listdir()
|
||||||
if os.path.exists("./pom.xml"):
|
if os.path.exists("./pom.xml"):
|
||||||
return "./"
|
return "./"
|
||||||
@ -170,12 +170,12 @@ def find_pomxmldir() -> str:
|
|||||||
if os.path.isdir(directory) and "pom.xml" in os.listdir(directory):
|
if os.path.isdir(directory) and "pom.xml" in os.listdir(directory):
|
||||||
return directory
|
return directory
|
||||||
|
|
||||||
def __printhelp():
|
def __print_help():
|
||||||
print("usage: {0} <setup | project | server | reset>".format(sys.argv[0]))
|
print("usage: {0} <setup | project | server | reset>".format(sys.argv[0]))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
__printhelp()
|
__print_help()
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
if sys.argv[1] == "setup":
|
if sys.argv[1] == "setup":
|
||||||
@ -188,5 +188,5 @@ if __name__ == "__main__":
|
|||||||
elif sys.argv[1] == "reset":
|
elif sys.argv[1] == "reset":
|
||||||
reset()
|
reset()
|
||||||
else:
|
else:
|
||||||
__printhelp()
|
__print_help()
|
||||||
exit(1)
|
exit(1)
|
@ -6,21 +6,21 @@ import gen
|
|||||||
if (os.getcwd().endswith("SpigotPluginBaseTools/")):
|
if (os.getcwd().endswith("SpigotPluginBaseTools/")):
|
||||||
os.chdir("../")
|
os.chdir("../")
|
||||||
|
|
||||||
pomxml = ET.parse(gen.find_pomxml())
|
pom_xml = ET.parse(gen.find_pom_xml())
|
||||||
pomroot = pomxml.getroot()
|
pom_root = pom_xml.getroot()
|
||||||
projname = pomroot.find("{" + gen.POM_NAMESPACE + "}" + "name").text
|
proj_name = pom_root.find("{" + gen.POM_NAMESPACE + "}" + "name").text
|
||||||
pluginver = pomroot.find("{" + gen.POM_NAMESPACE + "}" + "version").text
|
plugin_ver = pom_root.find("{" + gen.POM_NAMESPACE + "}" + "version").text
|
||||||
pluginfilename = projname + "-" + pluginver + ".jar"
|
plugin_filename = proj_name + "-" + plugin_ver + ".jar"
|
||||||
|
|
||||||
plugindir = gen.DEV_SERVER_PATH + "plugins/"
|
plugin_dir = gen.DEV_SERVER_PATH + "plugins/"
|
||||||
if not os.path.exists(plugindir):
|
if not os.path.exists(plugin_dir):
|
||||||
os.mkdir(plugindir)
|
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):
|
if not os.path.exists(plugin_path):
|
||||||
print("Could not find \"{0}\". Is it packaged?".format(pluginpath))
|
print("Could not find \"{0}\". Is it packaged?".format(plugin_path))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
shutil.copy(pluginpath, plugindir + pluginfilename)
|
shutil.copy(plugin_path, plugin_dir + plugin_filename)
|
||||||
print("Copied \"{0}\" to \"{1}\".".format(pluginpath, plugindir + pluginfilename))
|
print("Copied \"{0}\" to \"{1}\".".format(plugin_path, plugin_dir + plugin_filename))
|
@ -1,13 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
import gen
|
import gen
|
||||||
|
|
||||||
MIN_RAM="1024M"
|
MIN_RAM = "1024M"
|
||||||
MAX_RAM="2048M"
|
MAX_RAM = "2048M"
|
||||||
JVM_DEBUG_PORT = 25577
|
JVM_DEBUG_PORT = 25577
|
||||||
|
|
||||||
|
|
||||||
if (os.getcwd().endswith("SpigotPluginBaseTools/")):
|
if os.getcwd().endswith("SpigotPluginBaseTools/"):
|
||||||
os.chdir("../")
|
os.chdir("../")
|
||||||
|
|
||||||
os.chdir(gen.DEV_SERVER_PATH)
|
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
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user