diff --git a/src/main/java/com/wildermods/workspace/tasks/eclipse/GenerateRunConfigurationTask.java b/src/main/java/com/wildermods/workspace/tasks/eclipse/GenerateRunConfigurationTask.java new file mode 100644 index 0000000..1fb703f --- /dev/null +++ b/src/main/java/com/wildermods/workspace/tasks/eclipse/GenerateRunConfigurationTask.java @@ -0,0 +1,63 @@ +package com.wildermods.workspace.tasks.eclipse; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Path; + +import org.gradle.api.DefaultTask; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; + +public class GenerateRunConfigurationTask extends DefaultTask { + + private static final String LAUNCH_CONTENT_TEMPLATE = + """ + + + + + + + + + + + + + + + + + + + + """; + + @OutputFile + public Path getLaunchFile() { + return getProject().getProjectDir().toPath().resolve(".eclipse/configurations/runClient.launch"); + } + + @TaskAction + private void generateLaunchConfig(boolean overwrite) { + Path launchFile = getLaunchFile(); + + String projectName = getProject().getName(); + + // Check if the file exists and if overwrite is allowed + if (launchFile.toFile().exists() && !overwrite) { + System.out.println("Launch configuration file already exists and overwrite is false: " + launchFile); + return; + } + + String launchContent = String.format(LAUNCH_CONTENT_TEMPLATE, projectName); + + try (BufferedWriter writer = new BufferedWriter(new FileWriter(launchFile.toFile()))) { + writer.write(launchContent); + System.out.println("Eclipse run configuration generated at: " + launchFile.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file