From ac3ff1d921a98c3bf5ed44a474e68f4491f2d8e9 Mon Sep 17 00:00:00 2001 From: Peng1104 Date: Fri, 30 Jun 2023 22:05:53 -0300 Subject: [PATCH] Updated Gradle dependencies --- build.gradle | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../GradeBasePlugin/GradleBasePlugin.java | 124 ++++++++++-------- .../deploy/DeploymentFile.java | 119 +++++++++-------- .../extensions/Downloader.java | 46 ++++--- .../extensions/MetaExtension.java | 5 +- .../resource/ResourceManager.java | 47 ++++--- .../tasks/GenerateMetaFilesTask.java | 47 ++++--- 8 files changed, 207 insertions(+), 189 deletions(-) diff --git a/build.gradle b/build.gradle index e701e29..0cf3380 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { def groupId = 'me.TechsCode' def artifactId = 'GradleBasePlugin' -def versionNum = '2.0.7' +def versionNum = '2.1.0' group = groupId version = versionNum @@ -24,8 +24,8 @@ dependencies { compileOnly localGroovy() compileOnly gradleApi() - implementation 'commons-io:commons-io:2.11.0' - implementation "com.googlecode.json-simple:json-simple:1.1.1" + implementation 'commons-io:commons-io:2.13.0' + implementation "com.google.code.gson:gson:2.10.1" implementation 'com.jcraft:jsch:0.1.55' implementation 'com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.1.2' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..98debb8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/me/TechsCode/GradeBasePlugin/GradleBasePlugin.java b/src/main/java/me/TechsCode/GradeBasePlugin/GradleBasePlugin.java index 0fec3fb..5f294b9 100644 --- a/src/main/java/me/TechsCode/GradeBasePlugin/GradleBasePlugin.java +++ b/src/main/java/me/TechsCode/GradeBasePlugin/GradleBasePlugin.java @@ -1,142 +1,150 @@ package me.TechsCode.GradeBasePlugin; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.Task; + import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar; + import me.TechsCode.GradeBasePlugin.deploy.DeploymentFile; import me.TechsCode.GradeBasePlugin.extensions.MetaExtension; import me.TechsCode.GradeBasePlugin.resource.ResourceManager; import me.TechsCode.GradeBasePlugin.resource.ResourceResponse; import me.TechsCode.GradeBasePlugin.tasks.GenerateMetaFilesTask; -import org.gradle.api.Plugin; -import org.gradle.api.Project; -import org.gradle.api.Task; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; public class GradleBasePlugin implements Plugin { - - private static final String[] repositories = new String[]{ + + private static final String[] repositories = new String[] { "https://hub.spigotmc.org/nexus/content/repositories/snapshots/", - "https://oss.sonatype.org/content/repositories/snapshots", - "https://jitpack.io", - "https://repo.codemc.io/repository/maven-public/" - }; - - private static final String[] dependencies = new String[]{ + "https://oss.sonatype.org/content/repositories/snapshots", "https://jitpack.io", + "https://repo.codemc.io/repository/maven-public/" }; + + private static final String[] dependencies = new String[] { "compileOnly#org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT", - "compileOnly#net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT" - }; - - private static final String[] relocations = new String[]{ + "compileOnly#net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT" }; + + private static final String[] relocations = new String[] { "me.TechsCode.base#me.TechsCode.PROJECT_NAME.base", "me.TechsCode.tpl#me.TechsCode.PROJECT_NAME.tpl", - "me.TechsCode.dependencies#me.TechsCode.PROJECT_NAME.dependencies" - }; - + "me.TechsCode.dependencies#me.TechsCode.PROJECT_NAME.dependencies" }; + private MetaExtension meta; private String username; private String password; - + @Override public void apply(Project project) { DeploymentFile deploymentFile = new DeploymentFile(project); - + this.meta = project.getExtensions().create("meta", MetaExtension.class); - + this.username = System.getenv("TECHSCODE_USERNAME"); this.password = System.getenv("TECHSCODE_PASSWORD"); - + try { ResourceManager.createGitIgnore(project); ResourceManager.createWorkflow(project); - } catch (IOException ignored) { } - + } + catch (IOException ignored) {} + // Registering GradleBasePlugin tasks project.getTasks().create("generateMetaFiles", GenerateMetaFilesTask.class); - + // Setting up Shadow Plugin project.getPlugins().apply("com.github.johnrengelman.shadow"); getShadowJar(project).getArchiveFileName().set(project.getName() + ".jar"); getShadowJar(project).setProperty("destinationDir", project.file(deploymentFile.getLocalOutputPath())); getShadowJar(project).dependsOn("generateMetaFiles"); -// -// project.getTasks().getByName("build").dependsOn("shadowJar"); + + // project.getTasks().getByName("build").dependsOn("shadowJar"); project.getTasks().getByName("build").doLast((task) -> uploadToRemotes(task, deploymentFile)); - + // Add onProjectEvaluation hook project.afterEvaluate(this::onProjectEvaluation); } - + private void onProjectEvaluation(Project project) { - if (meta.validate()) + if (meta.validate()) { return; - + } log(Color.BLUE_BOLD_BRIGHT + "Configuring Gradle Project - Build Settings..."); log(); log("Project Info"); log("Plugin: " + project.getName() + " on Version: " + meta.version); log(); - - if(this.username == null || this.password == null) { + + if (this.username == null || this.password == null) { log(Color.RED + "Missing TECHSCODE_USERNAME and/or TECHSCODE_PASSWORD environment variables!"); log(Color.RED_BRIGHT + "Make sure that you have set the TECHSCODE_USERNAME and TECHSCODE_PASSWORD environment variables that has access to the maven-private repository!"); return; } - if (!meta.baseVersion.equalsIgnoreCase("none")) { ResourceResponse response = ResourceManager.loadBasePlugin(project, meta, username, password, meta.baseVersion); - - if(response == ResourceResponse.SUCCESS) { + + if (response == ResourceResponse.SUCCESS) { log("Successfully retrieved BasePlugin.jar from the techscode repo..."); project.getDependencies().add("implementation", project.files("libs/BasePlugin.jar")); - } else if (response == ResourceResponse.FAIL_USERNAME) { + } + else if (response == ResourceResponse.FAIL_USERNAME) { log(Color.RED + "Could not retrieve BasePlugin.jar from the techscode repo..."); log(Color.RED_BRIGHT + "Make sure that you have set the TECHSCODE_USERNAME environment variable that has access to the maven-private repository!"); - } else if (response == ResourceResponse.FAIL_PASSWORD) { + } + else if (response == ResourceResponse.FAIL_PASSWORD) { log(Color.RED + "Could not retrieve BasePlugin.jar from the techscode repo..."); log(Color.RED_BRIGHT + "Make sure that you have set the TECHSCODE_PASSWORD environment variable that has access to the maven-private repository!"); - } else if (response == ResourceResponse.FAIL) { + } + else if (response == ResourceResponse.FAIL) { log(Color.RED + "Could not retrieve BasePlugin.jar from the techscode repo..."); log(Color.RED_BRIGHT + "There was an error downloading the BasePlugin.jar from the techscode repo..."); - } else if (response == ResourceResponse.NOT_FETCH) { + } + else if (response == ResourceResponse.NOT_FETCH) { log(Color.YELLOW + "Not fetching the build, if this is a mistake, please set fetch to true!"); project.getDependencies().add("implementation", project.files("libs/BasePlugin.jar")); } } - + // Setting properties project.setProperty("version", meta.version); project.setProperty("sourceCompatibility", "1.8"); project.setProperty("targetCompatibility", "1.8"); - + // Setting up repositories project.getRepositories().mavenLocal(); project.getRepositories().mavenCentral(); - Arrays.stream(repositories).forEach(url -> project.getRepositories().maven((maven) -> maven.setUrl(url))); - + Arrays.stream(repositories) + .forEach(url -> project.getRepositories().maven((maven) -> maven.setUrl(url))); + // Setting up dependencies - Arrays.stream(dependencies).map(entry -> entry.split("#")).forEach(confAndUrl -> project.getDependencies().add(confAndUrl[0], confAndUrl[1])); - + Arrays.stream(dependencies).map(entry -> entry.split("#")) + .forEach(confAndUrl -> project.getDependencies().add(confAndUrl[0], confAndUrl[1])); + // Setting up relocations - Arrays.stream(relocations).map(entry -> entry.split("#")).forEach(fromTo -> getShadowJar(project).relocate(fromTo[0], fromTo[1].replace("PROJECT_NAME", project.getName()))); + Arrays.stream(relocations).map(entry -> entry.split("#")) + .forEach(fromTo -> getShadowJar(project).relocate(fromTo[0], + fromTo[1].replace("PROJECT_NAME", project.getName()))); } - + /* After the build prcoess is completed, the file will be uploaded to all remotes */ private void uploadToRemotes(Task buildTask, DeploymentFile deploymentFile) { - File file = new File(deploymentFile.getLocalOutputPath() + "/" + buildTask.getProject().getName() + ".jar"); - - deploymentFile.getRemotes().stream().filter(DeploymentFile.Remote::isEnabled).forEach(all -> all.uploadFile(file)); + File file = new File(deploymentFile.getLocalOutputPath() + '/' + + buildTask.getProject().getName() + ".jar"); + + deploymentFile.getRemotes().stream().filter(DeploymentFile.Remote::isEnabled) + .forEach(all -> all.uploadFile(file)); } - + private ShadowJar getShadowJar(Project project) { return (ShadowJar) project.getTasks().getByName("shadowJar"); } - + public static void log(String message) { System.out.println(Color.RESET + message + Color.RESET); } - + public static void log() { System.out.println(); } diff --git a/src/main/java/me/TechsCode/GradeBasePlugin/deploy/DeploymentFile.java b/src/main/java/me/TechsCode/GradeBasePlugin/deploy/DeploymentFile.java index c9e3090..52b028c 100644 --- a/src/main/java/me/TechsCode/GradeBasePlugin/deploy/DeploymentFile.java +++ b/src/main/java/me/TechsCode/GradeBasePlugin/deploy/DeploymentFile.java @@ -1,114 +1,117 @@ package me.TechsCode.GradeBasePlugin.deploy; -import com.jcraft.jsch.*; -import me.TechsCode.GradeBasePlugin.Color; -import me.TechsCode.GradeBasePlugin.GradleBasePlugin; -import me.TechsCode.GradeBasePlugin.resource.ResourceManager; -import org.apache.commons.io.FileUtils; -import org.gradle.api.Project; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; - -import java.io.*; -import java.nio.charset.StandardCharsets; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; +import java.util.Properties; -public class DeploymentFile { +import org.gradle.api.Project; - private static JSONObject root; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.jcraft.jsch.ChannelSftp; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; +import com.jcraft.jsch.SftpException; + +import me.TechsCode.GradeBasePlugin.Color; +import me.TechsCode.GradeBasePlugin.GradleBasePlugin; +import me.TechsCode.GradeBasePlugin.resource.ResourceManager; +public class DeploymentFile { + + private static JsonObject root; + public DeploymentFile(Project project) { File global = new File(System.getProperty("user.home") + "/deployment.json"); File local = new File(project.getProjectDir().getAbsolutePath() + "/deployment.json"); - + File file = local; - - if (global.exists() && !local.exists()) + + if (global.exists() && !local.exists()) { file = global; - + } if (!file.exists()) { try { InputStream src = ResourceManager.class.getResourceAsStream("/deployment.json"); Files.copy(src, Paths.get(file.toURI()), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } } - try { - String json = FileUtils.readFileToString(file, StandardCharsets.UTF_8); - - JSONParser jsonParser = new JSONParser(); - root = (JSONObject) jsonParser.parse(json); - } catch (IOException | ParseException e) { + root = new Gson().fromJson(new FileReader(file), JsonObject.class); + } + catch (IOException e) { e.printStackTrace(); } } - - + public String getLocalOutputPath() { - JSONObject local = (JSONObject) root.get("local"); - - return (String) local.get("path"); + return root.getAsJsonObject("local").get("outputPath").getAsString(); } - + public List getRemotes() { List remotes = new ArrayList<>(); - - for (Object object : (JSONArray) root.get("remotes")) { - JSONObject remote = (JSONObject) object; - - remotes.add(new Remote(remote)); + + for (JsonElement element : root.getAsJsonArray("remotes")) { + remotes.add(new Remote(element.getAsJsonObject())); } - return remotes; } - + public static class Remote { - + private final boolean enabled; private final String hostname, username, password, path; - private final long port; - - public Remote(JSONObject jsonObject) { - this.enabled = (boolean) jsonObject.get("enabled"); - this.hostname = (String) jsonObject.get("hostname"); - this.port = jsonObject.containsKey("port") ? (long) jsonObject.get("port") : 22; - this.username = (String) jsonObject.get("username"); - this.password = (String) jsonObject.get("password"); - this.path = (String) jsonObject.get("path"); + private final int port; + + public Remote(JsonObject jsonObject) { + this.enabled = jsonObject.get("enabled").getAsBoolean(); + this.hostname = jsonObject.get("hostname").getAsString(); + this.port = jsonObject.has("port") ? jsonObject.get("port").getAsInt() : 22; + this.username = jsonObject.get("username").getAsString(); + this.password = jsonObject.get("password").getAsString(); + this.path = jsonObject.get("path").getAsString(); } - + public void uploadFile(File file) { try { - java.util.Properties config = new java.util.Properties(); + Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); - + JSch jsch = new JSch(); - Session session = jsch.getSession(username, hostname, Math.round(port)); + Session session = jsch.getSession(username, hostname, port); session.setPassword(password); session.setConfig(config); session.connect(); - + ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp"); sftp.connect(); sftp.cd(path); sftp.put(new FileInputStream(file), file.getName(), ChannelSftp.OVERWRITE); sftp.exit(); - + session.disconnect(); - } catch (JSchException | SftpException | FileNotFoundException e) { - GradleBasePlugin.log(Color.RED_BOLD_BRIGHT + "Couldn't upload file to remote '" + hostname + "':"); + } + catch (JSchException | SftpException | FileNotFoundException e) { + GradleBasePlugin.log(Color.RED_BOLD_BRIGHT + "Couldn't upload file to remote '" + + hostname + "':"); e.printStackTrace(); } } - + public boolean isEnabled() { return enabled; } diff --git a/src/main/java/me/TechsCode/GradeBasePlugin/extensions/Downloader.java b/src/main/java/me/TechsCode/GradeBasePlugin/extensions/Downloader.java index d72cbdf..24da876 100644 --- a/src/main/java/me/TechsCode/GradeBasePlugin/extensions/Downloader.java +++ b/src/main/java/me/TechsCode/GradeBasePlugin/extensions/Downloader.java @@ -2,12 +2,10 @@ import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.util.Base64; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; @@ -17,48 +15,48 @@ import org.apache.hc.core5.http.io.HttpClientResponseHandler; public class Downloader { - + private String basicAuth = null; - + public void authorize(String username, String password) { - String userCredentials = username + ":" + password; - this.basicAuth = "Basic " + Base64.getEncoder().encodeToString(userCredentials.getBytes()); + this.basicAuth = "Basic " + + Base64.getEncoder().encodeToString((username + ':' + password).getBytes()); } - + public File download(URL url, File dstFile) { - CloseableHttpClient httpclient = HttpClients.custom() - .build(); + CloseableHttpClient httpclient = HttpClients.custom().build(); + try { HttpGet get = new HttpGet(url.toURI()); - + if (basicAuth != null) { get.setHeader("Authorization", basicAuth); } - httpclient.execute(get, new FileDownloadResponseHandler(dstFile)); - return httpclient.execute(get, new FileDownloadResponseHandler(dstFile)); - } catch (Exception e) { + } + catch (Exception e) { throw new IllegalStateException(e); - } finally { - IOUtils.closeQuietly(httpclient); + } + finally { + try { + httpclient.close(); + } + catch (IOException e) {} } } - + static class FileDownloadResponseHandler implements HttpClientResponseHandler { - + private final File target; - + public FileDownloadResponseHandler(File target) { this.target = target; } - + @Override public File handleResponse(ClassicHttpResponse response) throws HttpException, IOException { - InputStream source = response.getEntity().getContent(); - FileUtils.copyInputStreamToFile(source, this.target); - return this.target; + FileUtils.copyInputStreamToFile(response.getEntity().getContent(), target); + return target; } - } - } diff --git a/src/main/java/me/TechsCode/GradeBasePlugin/extensions/MetaExtension.java b/src/main/java/me/TechsCode/GradeBasePlugin/extensions/MetaExtension.java index 618cf90..5f09704 100644 --- a/src/main/java/me/TechsCode/GradeBasePlugin/extensions/MetaExtension.java +++ b/src/main/java/me/TechsCode/GradeBasePlugin/extensions/MetaExtension.java @@ -1,10 +1,10 @@ package me.TechsCode.GradeBasePlugin.extensions; +import java.util.ArrayList; + import me.TechsCode.GradeBasePlugin.Color; import me.TechsCode.GradeBasePlugin.GradleBasePlugin; -import java.util.ArrayList; - public class MetaExtension { public String version; @@ -20,7 +20,6 @@ public boolean validate() { GradleBasePlugin.log(Color.RED + "Please check the GitHub page of GradleBasePlugin for more information"); return true; } - return false; } } diff --git a/src/main/java/me/TechsCode/GradeBasePlugin/resource/ResourceManager.java b/src/main/java/me/TechsCode/GradeBasePlugin/resource/ResourceManager.java index f7a7026..c621e73 100644 --- a/src/main/java/me/TechsCode/GradeBasePlugin/resource/ResourceManager.java +++ b/src/main/java/me/TechsCode/GradeBasePlugin/resource/ResourceManager.java @@ -1,10 +1,5 @@ package me.TechsCode.GradeBasePlugin.resource; -import me.TechsCode.GradeBasePlugin.extensions.Downloader; -import me.TechsCode.GradeBasePlugin.extensions.MetaExtension; - -import org.gradle.api.Project; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -13,44 +8,54 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; -public class ResourceManager { +import org.gradle.api.Project; +import me.TechsCode.GradeBasePlugin.extensions.Downloader; +import me.TechsCode.GradeBasePlugin.extensions.MetaExtension; + +public class ResourceManager { + public static ResourceResponse loadBasePlugin(Project project, MetaExtension meta, String username, String password, String version) { - if (!meta.fetch) + if (!meta.fetch) { return ResourceResponse.NOT_FETCH; - if (username == null) + } + if (username == null) { return ResourceResponse.FAIL_USERNAME; - if (password == null) + } + if (password == null) { return ResourceResponse.FAIL_PASSWORD; - + } File libraryFolder = new File(project.getProjectDir().getAbsolutePath() + "/libs"); libraryFolder.mkdirs(); - + File libraryFile = new File(libraryFolder.getAbsolutePath() + "/BasePlugin.jar"); libraryFile.delete(); - - String RETRIEVE_RELEASES = "https://repo.techscode.com/repository/maven-private/me/TechsCode/BasePlugin/"+version+"/BasePlugin-"+version+"-all.jar?enable-custom-header=true"; - - try{ + + String RETRIEVE_RELEASES = "https://repo.techscode.com/repository/maven-private/me/TechsCode/BasePlugin/" + + version + "/BasePlugin-" + version + "-all.jar?enable-custom-header=true"; + + try { Downloader downloader = new Downloader(); downloader.authorize(username, password); downloader.download(new URL(RETRIEVE_RELEASES), libraryFile); return ResourceResponse.SUCCESS; - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); return ResourceResponse.FAIL; } } - + public static void createGitIgnore(Project project) throws IOException { - InputStream src = ResourceManager.class.getResourceAsStream("/gitignore.file"); - Files.copy(src, Paths.get(new File(project.getProjectDir().getAbsolutePath() + "/.gitignore").toURI()), StandardCopyOption.REPLACE_EXISTING); + Files.copy(ResourceManager.class.getResourceAsStream("/gitignore.file"), + Paths.get(new File(project.getProjectDir().getAbsolutePath() + "/.gitignore").toURI()), + StandardCopyOption.REPLACE_EXISTING); } - + public static void createWorkflow(Project project) throws IOException { File destination = new File(project.getProjectDir().getAbsolutePath() + "/.github/workflows/build.yml"); destination.mkdirs(); - + InputStream src = ResourceManager.class.getResourceAsStream("/workflows/build.yml"); Files.copy(src, Paths.get(destination.toURI()), StandardCopyOption.REPLACE_EXISTING); } diff --git a/src/main/java/me/TechsCode/GradeBasePlugin/tasks/GenerateMetaFilesTask.java b/src/main/java/me/TechsCode/GradeBasePlugin/tasks/GenerateMetaFilesTask.java index ec406d1..ae180aa 100644 --- a/src/main/java/me/TechsCode/GradeBasePlugin/tasks/GenerateMetaFilesTask.java +++ b/src/main/java/me/TechsCode/GradeBasePlugin/tasks/GenerateMetaFilesTask.java @@ -1,24 +1,24 @@ package me.TechsCode.GradeBasePlugin.tasks; -import me.TechsCode.GradeBasePlugin.Color; -import me.TechsCode.GradeBasePlugin.GradleBasePlugin; -import me.TechsCode.GradeBasePlugin.extensions.MetaExtension; -import org.gradle.api.DefaultTask; -import org.gradle.api.tasks.TaskAction; - import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; +import org.gradle.api.DefaultTask; +import org.gradle.api.tasks.TaskAction; + +import me.TechsCode.GradeBasePlugin.Color; +import me.TechsCode.GradeBasePlugin.GradleBasePlugin; +import me.TechsCode.GradeBasePlugin.extensions.MetaExtension; + public class GenerateMetaFilesTask extends DefaultTask { @TaskAction public void generateMetaFiles() { GradleBasePlugin.log(Color.BLUE_BRIGHT + "Generating Plugin.yml & Bungee.yml......"); - File build = getProject().getBuildDir(); - File resourcesFolder = new File(build.getAbsolutePath() + "/resources/main"); + File resourcesFolder = new File(getProject().getBuildDir().getAbsolutePath() + "/resources/main"); resourcesFolder.mkdirs(); try { @@ -33,10 +33,11 @@ public void generateMetaFiles() { } private void createPluginYml(File resourcesFolder, String projectName, String projectVersion, int buildNumber, String loadAfter, String loadBefore, String load, ArrayList libraries) throws IOException { - File file = new File(resourcesFolder.getAbsolutePath() + "/plugin.yml"); + File file = new File(resourcesFolder, "plugin.yml"); file.createNewFile(); PrintWriter writer = new PrintWriter(file, "UTF-8"); + writer.println("name: " + projectName); writer.println("version: " + projectVersion); writer.println("author: Tech"); @@ -45,40 +46,44 @@ private void createPluginYml(File resourcesFolder, String projectName, String pr writer.println("main: me.TechsCode." + getProject().getName() + ".base.loader.SpigotLoader"); writer.println("api-version: 1.13"); - if (loadAfter != null) writer.println("softdepend: " + loadAfter); - if (loadBefore != null) writer.println("loadbefore: " + loadBefore); - if (load != null) writer.println("load: " + load); - - if(libraries != null) { + if (loadAfter != null) { + writer.println("softdepend: " + loadAfter); + } + if (loadBefore != null) { + writer.println("loadbefore: " + loadBefore); + } + if (load != null) { + writer.println("load: " + load); + } + if (libraries != null) { writer.println("libraries:"); libraries.stream().map(library -> "- " + library).forEach(writer::println); } - writer.close(); } private void createBungeeYml(File resourcesFolder, String projectName, String projectVersion, int buildNumber, ArrayList libraries) throws IOException { - File file = new File(resourcesFolder.getAbsolutePath() + "/bungee.yml"); + File file = new File(resourcesFolder, "bungee.yml"); file.createNewFile(); - + PrintWriter writer = new PrintWriter(file, "UTF-8"); + writer.println("name: " + projectName); writer.println("version: " + projectVersion); writer.println("build: " + buildNumber); writer.println("main: me.TechsCode." + getProject().getName() + ".base.loader.BungeeLoader"); writer.println("author: Tech"); - - if(libraries != null) { + + if (libraries != null) { writer.println("libraries:"); libraries.stream().map(library -> "- " + library).forEach(writer::println); } - writer.close(); } private int getBuildNumber() { String buildNumber = System.getenv("BUILD_NUMBER"); - + return buildNumber != null ? Integer.parseInt(buildNumber) : 0; } }