-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83313e4
commit 47c4fbb
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/main/java/com/wildermods/workspace/tasks/eclipse/GenerateRunConfigurationTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = | ||
""" | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication"> | ||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/%1$s"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="4"/> | ||
</listAttribute> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="net.fabricmc.loader.impl.launch.knot.KnotClient"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="%1$s"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="%1$s"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dmixin.debug=true -Dfabric.development=true"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:%1$s/bin}"/> | ||
</launchConfiguration> | ||
"""; | ||
|
||
@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(); | ||
} | ||
} | ||
} |