From b1afcacbca3ef2c644f7944fd1856ceb621f7d71 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 1 Apr 2021 16:10:11 -0500 Subject: [PATCH] Removed everything and added scripts to generate workspace. Also updated gitignore. --- .gitignore | 246 ++++++++++-------- .vscode/launch.json | 24 -- .vscode/tasks.json | 78 ------ pom.xml | 52 ---- scripts/gen.py | 177 +++++++++++++ scripts/load_plugin.py | 26 ++ scripts/start_server.py | 11 + src/main/java/ca/recrown/PACKAGENAME/App.java | 9 - src/main/resources/plugin.yml | 8 - test-server/bukkit.yml | 39 --- test-server/end_process.ps1 | 8 - test-server/load_latest_build.ps1 | 4 - test-server/start_normal.ps1 | 1 - test-server/start_process.ps1 | 6 - 14 files changed, 354 insertions(+), 335 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/tasks.json delete mode 100644 pom.xml create mode 100644 scripts/gen.py create mode 100644 scripts/load_plugin.py create mode 100644 scripts/start_server.py delete mode 100644 src/main/java/ca/recrown/PACKAGENAME/App.java delete mode 100644 src/main/resources/plugin.yml delete mode 100644 test-server/bukkit.yml delete mode 100644 test-server/end_process.ps1 delete mode 100644 test-server/load_latest_build.ps1 delete mode 100644 test-server/start_normal.ps1 delete mode 100644 test-server/start_process.ps1 diff --git a/.gitignore b/.gitignore index cf51e90..fdfecb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,132 +1,166 @@ -# Created by https://www.gitignore.io/api/java,maven,eclipse,visualstudiocode -# Edit at https://www.gitignore.io/?templates=java,maven,eclipse,visualstudiocode +# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,python +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,python -### Eclipse ### -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class -# External tool builders -.externalToolBuilders/ +# C extensions +*.so -# Locally stored "Eclipse launch configurations" -*.launch +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST -# PyDev specific (Python IDE for Eclipse) -*.pydevproject +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec -# CDT-specific (C/C++ Development Tooling) -.cproject +# Installer logs +pip-log.txt +pip-delete-this-directory.txt -# CDT- autotools -.autotools +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log -# Java annotation processor (APT) -.factorypath +# Translations +*.mo +*.pot -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Annotation Processing -.apt_generated/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -### Eclipse Patch ### -# Eclipse Core -.project - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Annotation Processing -.apt_generated - -.sts4-cache/ - -### Java ### -# Compiled class file -*.class - -# Log file +# Django stuff: *.log +local_settings.py +db.sqlite3 +db.sqlite3-journal -# BlueJ files -*.ctxt +# Flask stuff: +instance/ +.webassets-cache -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +# Scrapy stuff: +.scrapy -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar +# Sphinx documentation +docs/_build/ +doc/_build/ -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -### Maven ### +# PyBuilder target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -.mvn/wrapper/maven-wrapper.jar -.flattened-pom.xml + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +# .env +.env/ +.venv/ +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# operating system-related files +*.DS_Store #file properties cache/storage on macOS +Thumbs.db #thumbnail cache on Windows + +# profiling data +.prof + ### VisualStudioCode ### .vscode/* -!.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json -!.vscode/extensions.json +*.code-workspace ### VisualStudioCode Patch ### # Ignore all local history of files .history +.ionide -# End of https://www.gitignore.io/api/java,maven,eclipse,visualstudiocode +# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python -#Additional -local_tools - -#Test server stuff -test-server/* -!test-server/*.ps1 -!test-server/bukkit.yml -!test-server/paper-195.jar \ No newline at end of file +**/buildtools/ +**/development_server diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index e3bdd28..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "Debug (Launch) - Current File", - "request": "launch", - "mainClass": "${file}" - }, - { - "type": "java", - "name": "Debug With MC Server", - "request": "attach", - "hostName": "localhost", - "port": 25566, - "sourcePaths": ["src/main/java"], - "preLaunchTask": "start test server", - "postDebugTask": "stop test server" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 87028ad..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "verify", - "type": "shell", - "command": "mvn -B verify", - "group": "build" - }, - { - "label": "test", - "type": "shell", - "command": "mvn -B test", - "group": "test" - }, - { - "label": "package", - "type": "shell", - "command": "mvn package", - "group": "build" - }, - { - "dependsOn": ["package"], - "label": "update test server", - "type": "shell", - "args": ["-ExecutionPolicy", "Bypass", "-File", "./load_latest_build.ps1"], - "options": {"cwd": "${workspaceFolder}/test-server/"}, - "command": "powershell", - "problemMatcher": [], - "presentation": { - "echo": true, - "reveal": "silent", - "focus": false, - "panel": "shared", - "showReuseMessage": false, - "clear": false - } - }, - { - "dependsOn": ["update test server"], - "label": "start test server", - "type": "shell", - "runOptions": {"instanceLimit": 1}, - "args": ["-ExecutionPolicy", "Bypass", "-File", "./start_process.ps1"], - "options": {"cwd": "${workspaceFolder}/test-server/"}, - "command": "powershell", - "problemMatcher": [], - "group": "test", - "presentation": { - "echo": true, - "reveal": "silent", - "focus": false, - "panel": "shared", - "showReuseMessage": false, - "clear": false - } - }, - { - "label": "stop test server", - "type": "shell", - "args": ["-ExecutionPolicy", "Bypass", "-File", "./end_process.ps1"], - "options": {"cwd": "${workspaceFolder}/test-server/"}, - "command": "powershell", - "problemMatcher": [], - "group": "test", - "presentation": { - "echo": true, - "reveal": "silent", - "focus": false, - "panel": "shared", - "showReuseMessage": true, - "clear": false - } - } - ] -} \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 11cb116..0000000 --- a/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - 4.0.0 - ca.recrown.PLUGINNAME - PLUGINNAME - jar - 1.0.0 - PLUGINNAME - http://maven.apache.org - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - - - org.junit.jupiter - junit-jupiter-engine - 5.6.2 - test - - - com.destroystokyo.paper - paper-api - 1.15.2-R0.1-SNAPSHOT - provided - - - - - - maven-compiler-plugin - 3.6.0 - - 11 - 11 - - - - maven-surefire-plugin - 2.22.2 - - - - - UTF-8 - 11 - 11 - 11 - - \ No newline at end of file diff --git a/scripts/gen.py b/scripts/gen.py new file mode 100644 index 0000000..20e540e --- /dev/null +++ b/scripts/gen.py @@ -0,0 +1,177 @@ +import sys +import os +import xml.etree.ElementTree as ET +import requests +import shutil + +DEFAULT_BUKKIT_VER = "LATEST" +POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0" +DEV_SERVER_PATH="development_server/" +MVN_CMD = "mvn -B archetype:generate -DgroupId={groupId} -DartifactId={artifactId} -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4"; + +BUILDTOOLS_URL = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar" +BUILDTOOLS_CMD = "java -jar BuildTools.jar --rev {ver}" +BUILDTOOLS_DIR = "buildtools/" +DEFAULT_SERVER_VER = "latest" +DEFAULT_JVM_DEBUG_PORT = 25577 + +if (os.getcwd().endswith("scripts/")): + os.chdir("../") + +if sys.version_info.major != 3: + print("Script requires Python3 to run. You are currently running {0}.".format(sys.version)) + exit(1) + +def project_gen() -> int: + print("Generate Project:") + print("Step 1) Generate Maven project.") + + groupId = input("groupId (package): xyz.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.") + + artifactId = input("artifactId (name of plugin): ") + while (len(artifactId) == 0 or (not artifactId.islower() and not artifactId.isupper()) or (artifactId.isupper())): + print("artifactId cannot be empty and must be all lowercase.") + artifactId = input("artifactId (name of plugin):") + + print("Executing Maven command: \"{0}\"".format(MVN_CMD.format(groupId = groupId, artifactId = artifactId))) + if (os.system(MVN_CMD.format(groupId = groupId, artifactId = artifactId)) != 0): + print("An error occurred while executing Maven step. Stopping.") + return 1 + + print("Step 2) Modify pom.xml") + bukkitver = input("bukkit dependency version (default: \"{0}\"): ".format(DEFAULT_BUKKIT_VER)) + if (len(bukkitver) == 0): bukkitver = DEFAULT_BUKKIT_VER + + bukkitvercheck = input("Entered \"{0}\". Is this fine? (Y/n)".format(bukkitver)) + if (len(bukkitvercheck) == 0): bukkitvercheck = "y" + while (bukkitvercheck.lower() != "y"): + if bukkitvercheck.lower() == "n": + bukkitver = input("bukkit dependency version (Maven Dep. Ver.): ") + bukkitvercheck = input("Entered \"{0}\". Is this fine? (Y/n)".format(bukkitver)) + else: + bukkitvercheck = input("Please enter \"y\" to continue, or \"n\" to enter version again: ") + print("Using version: \"{0}\"".format(bukkitver)) + + pompath = "{0}/pom.xml".format(artifactId); + ET.register_namespace("", POM_NAMESPACE) + pomxml = ET.parse(pompath) + pomroot = pomxml.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/" + + pomroot.append(repositorieselem) + + bukkitdep = ET.Element("dependency") + ET.SubElement(bukkitdep, "groupId").text = "org.bukkit" + ET.SubElement(bukkitdep, "artifactId").text = "bukkit" + ET.SubElement(bukkitdep, "version").text = bukkitver + ET.SubElement(bukkitdep, "type").text = "jar" + ET.SubElement(bukkitdep, "scope").text = "provided" + + dependencies = pomroot.find("{" + POM_NAMESPACE + "}" + "dependencies") + dependencies.append(bukkitdep) + + pomxml.write(pompath) + + print("Step 3) Validate pom.xml") + if os.system("mvn -B validate -f {0}".format(pompath)) != 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: + print("An error has occurred. Please check output and fix issue before running again.") + return 1 + print("Project generation complete.") + return 0 + +def gen_dev_server() -> int: + print("Generate Development Server:") + if not os.path.exists(DEV_SERVER_PATH): + os.mkdir(DEV_SERVER_PATH) + os.chdir(DEV_SERVER_PATH) + + print("Step 1) Download BuildTools") + 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() + + print("Step 2) Generate server JAR with BuildTools.jar") + + bukkitver = input("Bukkit version to use (default: \"{0}\"): ".format(DEFAULT_SERVER_VER)) + if (len(bukkitver) == 0): bukkitver = DEFAULT_SERVER_VER + bukkitververify = input("Attempt to use \"{0}\"? (Y/n)".format(bukkitver)) + if (len(bukkitververify) == 0): bukkitververify = "y" + while bukkitververify.lower() != "y": + if (bukkitververify.lower() == "n"): + bukkitver = input("Bukkit version to use: ") + bukkitververify = input("Attempt to use \"{0}\"? (Y/n)".format(bukkitver)) + else: + bukkitververify = input("Attempt to use \"{0}\"? Please enter \"y\" or \"n\": ".format(bukkitver)) + + if os.system(BUILDTOOLS_CMD.format(ver = bukkitver)) != 0: + print("Error while running build tools.") + return 1 + + print("Step 3) Moving JARs and cleaning up.") + + print("Moving generated JAR file.") + if bukkitver == DEFAULT_SERVER_VER: + direntries = os.listdir() + for entry in direntries: + if (entry.startswith("spigot") and entry.endswith(".jar")): + shutil.move(entry, "../spigot.jar") + else: + shutil.move("spigot-{1}.jar".format(bukkitver), "../spigot.jar") + + os.chdir("../") + print("Deleting \"{0}\".".format(BUILDTOOLS_DIR)) + shutil.rmtree(BUILDTOOLS_DIR) + + os.chdir("../") + print("Done generating files for development server.") + return 0 + +def reset() -> None: + pomxmldir = find_pomxmldir() + if os.path.exists(pomxmldir): + shutil.rmtree(pomxmldir) + + if os.path.exists(DEV_SERVER_PATH): + shutil.rmtree(DEV_SERVER_PATH) + +def find_pomxml() -> str: + return find_pomxmldir() + "/pom.xml" + +def find_pomxmldir() -> str: + directories = os.listdir() + + for directory in directories: + if os.path.isdir(directory) and "pom.xml" in os.listdir(directory): + return directory + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("usage: {0} ".format(sys.argv[0])) + exit(1) + else: + if sys.argv[1] == "setup": + project_gen() + gen_dev_server() + elif sys.argv[1] == "project": + project_gen() + elif sys.argv[1] == "server": + gen_dev_server() + elif sys.argv[1] == "reset": + reset() \ No newline at end of file diff --git a/scripts/load_plugin.py b/scripts/load_plugin.py new file mode 100644 index 0000000..eef51e9 --- /dev/null +++ b/scripts/load_plugin.py @@ -0,0 +1,26 @@ +import os +import xml.etree.ElementTree as ET +import shutil +import gen + +if (os.getcwd().endswith("scripts/")): + 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" + +plugindir = gen.DEV_SERVER_PATH + "plugins/"; +if not os.path.exists(plugindir): + os.mkdir(plugindir) + +pluginpath = gen.find_pomxmldir() + "/target/{0}".format(pluginfilename) + +if not os.path.exists(pluginpath): + print("Could not find \"{0}\". Is it packaged?".format(pluginpath)) + exit(1) + +shutil.copy(pluginpath, plugindir + pluginfilename) +print("Copied \"{0}\" to \"{1}\".".format(pluginpath, plugindir + pluginfilename)) \ No newline at end of file diff --git a/scripts/start_server.py b/scripts/start_server.py new file mode 100644 index 0000000..c92841a --- /dev/null +++ b/scripts/start_server.py @@ -0,0 +1,11 @@ +import os +import gen + +JVM_DEBUG_PORT = 25577 + + +if (os.getcwd().endswith("scripts/")): + os.chdir("../") + +os.chdir(gen.DEV_SERVER_PATH) +os.system("java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address={port} -jar spigot.jar".format(port = JVM_DEBUG_PORT)) \ No newline at end of file diff --git a/src/main/java/ca/recrown/PACKAGENAME/App.java b/src/main/java/ca/recrown/PACKAGENAME/App.java deleted file mode 100644 index 3d3b95a..0000000 --- a/src/main/java/ca/recrown/PACKAGENAME/App.java +++ /dev/null @@ -1,9 +0,0 @@ -package ca.recrown.PACKAGENAME; - -/** - * Hello world! - * - */ -public class App -{ -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml deleted file mode 100644 index d4b346f..0000000 --- a/src/main/resources/plugin.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: PLUGINNAME -main: ca.recrown.PACKAGENAME.PLUGINNAME -version: 1.0.0 -description: DESCRIPTION. -commands: -depend: [] -load: startup -api-version: 1.15 \ No newline at end of file diff --git a/test-server/bukkit.yml b/test-server/bukkit.yml deleted file mode 100644 index 863be86..0000000 --- a/test-server/bukkit.yml +++ /dev/null @@ -1,39 +0,0 @@ -# This is the main configuration file for Bukkit. -# As you can see, there's actually not that much to configure without any plugins. -# For a reference for any variable inside this file, check out the Bukkit Wiki at -# https://www.spigotmc.org/go/bukkit-yml -# -# If you need help on this file, feel free to join us on irc or leave a message -# on the forums asking for advice. -# -# IRC: #spigot @ irc.spi.gt -# (If this means nothing to you, just go to https://www.spigotmc.org/go/irc ) -# Forums: https://www.spigotmc.org/ -# Bug tracker: https://www.spigotmc.org/go/bugs - - -settings: - allow-end: true - warn-on-overload: true - permissions-file: permissions.yml - update-folder: update - plugin-profiling: false - connection-throttle: 4000 - query-plugins: true - deprecated-verbose: default - shutdown-message: Server closed - minimum-api: none -spawn-limits: - monsters: 70 - animals: 10 - water-animals: 15 - ambient: 15 -chunk-gc: - period-in-ticks: 600 -ticks-per: - animal-spawns: 400 - monster-spawns: 1 - water-spawns: 1 - ambient-spawns: 1 - autosave: 6000 -aliases: now-in-commands.yml \ No newline at end of file diff --git a/test-server/end_process.ps1 b/test-server/end_process.ps1 deleted file mode 100644 index 69739ad..0000000 --- a/test-server/end_process.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -if (Test-Path ./pid.temp) { - $sID = Get-Item -Path ./pid.temp | Get-Content -Tail 1 - if (Get-Process -Id $sID -ErrorAction SilentlyContinue) { - Stop-Process -Id $sID - } - Remove-Item "./pid.temp" -} - diff --git a/test-server/load_latest_build.ps1 b/test-server/load_latest_build.ps1 deleted file mode 100644 index 3af6fe3..0000000 --- a/test-server/load_latest_build.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -write-Output "Deleting previous world if there was one..." -remove-Item -Recurse world -Force -ErrorAction Ignore -write-Output "Attempting to copy plugin jar to plugins folder..." -copy-Item -Path "..\target\PLUGINNAME*.jar" -Destination "plugins\PLUGINNAME.jar" diff --git a/test-server/start_normal.ps1 b/test-server/start_normal.ps1 deleted file mode 100644 index c29b11f..0000000 --- a/test-server/start_normal.ps1 +++ /dev/null @@ -1 +0,0 @@ -Start-Process java -ArgumentList "-Xms512M", "-Xmx1G", "-jar", "paper-195.jar", "nogui" \ No newline at end of file diff --git a/test-server/start_process.ps1 b/test-server/start_process.ps1 deleted file mode 100644 index 85f32d0..0000000 --- a/test-server/start_process.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -write-Output "Attempting to start Paper test server." -$SID = Start-Process java -ArgumentList "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=25566", "-Xms512M", "-Xmx1G", "-jar", "paper-195.jar", "nogui" -PassThru -$SID = $SID.Id -write-Output "Process started. PID is: $SID" - -$SID | Out-File -FilePath "pid.temp" \ No newline at end of file