|
2 | 2 |
|
3 | 3 | import static net.minecraftforge.gradle.common.Constants.*; |
4 | 4 | import static net.minecraftforge.gradle.user.UserConstants.*; |
5 | | -import groovy.lang.Closure; |
6 | 5 |
|
7 | 6 | import java.io.File; |
8 | 7 | import java.io.IOException; |
|
17 | 16 | import javax.xml.transform.dom.DOMSource; |
18 | 17 | import javax.xml.transform.stream.StreamResult; |
19 | 18 |
|
20 | | -import net.minecraftforge.gradle.common.BasePlugin; |
21 | | -import net.minecraftforge.gradle.tasks.ApplyFernFlowerTask; |
22 | | -import net.minecraftforge.gradle.tasks.ApplyS2STask; |
23 | | -import net.minecraftforge.gradle.tasks.CreateStartTask; |
24 | | -import net.minecraftforge.gradle.tasks.DeobfuscateJar; |
25 | | -import net.minecraftforge.gradle.tasks.ExtractS2SRangeTask; |
26 | | -import net.minecraftforge.gradle.tasks.GenEclipseRunTask; |
27 | | -import net.minecraftforge.gradle.tasks.PostDecompileTask; |
28 | | -import net.minecraftforge.gradle.tasks.RemapSources; |
29 | | -import net.minecraftforge.gradle.util.GradleConfigurationException; |
30 | | -import net.minecraftforge.gradle.util.delayed.DelayedFile; |
31 | | -import net.minecraftforge.gradle.util.delayed.TokenReplacer; |
32 | | - |
33 | 19 | import org.gradle.api.Action; |
34 | 20 | import org.gradle.api.DefaultTask; |
35 | 21 | import org.gradle.api.Project; |
|
53 | 39 | import org.gradle.api.plugins.JavaPluginConvention; |
54 | 40 | import org.gradle.api.plugins.MavenPluginConvention; |
55 | 41 | import org.gradle.api.tasks.GroovySourceSet; |
| 42 | +import org.gradle.api.tasks.JavaExec; |
56 | 43 | import org.gradle.api.tasks.ScalaSourceSet; |
57 | 44 | import org.gradle.api.tasks.SourceSet; |
58 | 45 | import org.gradle.api.tasks.bundling.Jar; |
|
73 | 60 | import com.google.common.collect.ImmutableMap; |
74 | 61 | import com.google.common.collect.Maps; |
75 | 62 |
|
| 63 | +import groovy.lang.Closure; |
| 64 | +import net.minecraftforge.gradle.common.BasePlugin; |
| 65 | +import net.minecraftforge.gradle.tasks.ApplyFernFlowerTask; |
| 66 | +import net.minecraftforge.gradle.tasks.ApplyS2STask; |
| 67 | +import net.minecraftforge.gradle.tasks.CreateStartTask; |
| 68 | +import net.minecraftforge.gradle.tasks.DeobfuscateJar; |
| 69 | +import net.minecraftforge.gradle.tasks.ExtractS2SRangeTask; |
| 70 | +import net.minecraftforge.gradle.tasks.GenEclipseRunTask; |
| 71 | +import net.minecraftforge.gradle.tasks.PostDecompileTask; |
| 72 | +import net.minecraftforge.gradle.tasks.RemapSources; |
| 73 | +import net.minecraftforge.gradle.util.GradleConfigurationException; |
| 74 | +import net.minecraftforge.gradle.util.delayed.DelayedFile; |
| 75 | +import net.minecraftforge.gradle.util.delayed.TokenReplacer; |
| 76 | + |
76 | 77 | public abstract class UserBasePlugin<T extends UserBaseExtension> extends BasePlugin<T> |
77 | 78 | { |
78 | 79 | private boolean madeDecompTasks = false; // to gaurd against stupid programmers |
@@ -112,10 +113,12 @@ public final void applyPlugin() |
112 | 113 | project.getConfigurations().maybeCreate(CONFIG_DP_RESOLVED); |
113 | 114 |
|
114 | 115 | configureCompilation(); |
| 116 | + |
115 | 117 | // Quality of life stuff for the users |
116 | 118 | createSourceCopyTasks(); |
117 | 119 | doDevTimeDeobf(); |
118 | 120 | makeObfSource(); |
| 121 | + makeRunTasks(); |
119 | 122 |
|
120 | 123 | // use zinc for scala compilation |
121 | 124 | project.getTasks().withType(ScalaCompile.class, new Action<ScalaCompile>() { |
@@ -198,6 +201,36 @@ public void execute(TaskSourceCopy t) |
198 | 201 | project.getDependencies().add(CONFIG_START, col); |
199 | 202 | } |
200 | 203 | // TODO: do some GradleStart stuff based on the MC version? |
| 204 | + |
| 205 | + // run task stuff |
| 206 | + // Add the mod and stuff to the classpath of the exec tasks. |
| 207 | + final Jar jarTask = (Jar) project.getTasks().getByName("jar"); |
| 208 | + |
| 209 | + if (this.hasClientRun()) |
| 210 | + { |
| 211 | + JavaExec exec = (JavaExec) project.getTasks().getByName("runClient"); |
| 212 | + exec.classpath(project.getConfigurations().getByName("runtime")); |
| 213 | + exec.classpath(project.getConfigurations().getByName(CONFIG_MC)); |
| 214 | + exec.classpath(project.getConfigurations().getByName(CONFIG_MC_DEPS)); |
| 215 | + exec.classpath(project.getConfigurations().getByName(CONFIG_START)); |
| 216 | + exec.classpath(jarTask.getArchivePath()); |
| 217 | + exec.dependsOn(jarTask); |
| 218 | + exec.jvmArgs(getClientJvmArgs(getExtension())); |
| 219 | + exec.args(getClientRunArgs(getExtension())); |
| 220 | + } |
| 221 | + |
| 222 | + if (this.hasServerRun()) |
| 223 | + { |
| 224 | + JavaExec exec = (JavaExec) project.getTasks().getByName("runServer"); |
| 225 | + exec.classpath(project.getConfigurations().getByName("runtime")); |
| 226 | + exec.classpath(project.getConfigurations().getByName(CONFIG_MC)); |
| 227 | + exec.classpath(project.getConfigurations().getByName(CONFIG_MC_DEPS)); |
| 228 | + exec.classpath(project.getConfigurations().getByName(CONFIG_START)); |
| 229 | + exec.classpath(jarTask.getArchivePath()); |
| 230 | + exec.dependsOn(jarTask); |
| 231 | + exec.jvmArgs(getServerJvmArgs(getExtension())); |
| 232 | + exec.jvmArgs(getServerRunArgs(getExtension())); |
| 233 | + } |
201 | 234 | } |
202 | 235 |
|
203 | 236 | protected abstract void applyUserPlugin(); |
@@ -285,7 +318,7 @@ protected void makeDecompTasks(final String globalPattern, final String localPat |
285 | 318 | makeStart.addReplacement("@@ASSETINDEX@@", delayedString(REPLACE_ASSET_INDEX)); |
286 | 319 | makeStart.addReplacement("@@ASSETSDIR@@", delayedFile(REPLACE_CACHE_DIR + "/assets")); |
287 | 320 | makeStart.addReplacement("@@NATIVESDIR@@", delayedFile(DIR_NATIVES)); |
288 | | - makeStart.addReplacement("@@CLIENTTWEAKER@@", delayedString(REPLACE_CLIENT_TWEAKER)); |
| 321 | + makeStart.addReplacement("@@TWEAKERCLIENT@@", delayedString(REPLACE_CLIENT_TWEAKER)); |
289 | 322 | makeStart.addReplacement("@@BOUNCERCLIENT@@", delayedString(REPLACE_CLIENT_MAIN)); |
290 | 323 |
|
291 | 324 | makeStart.dependsOn(TASK_DL_ASSET_INDEX, TASK_DL_ASSETS, TASK_EXTRACT_NATIVES); |
@@ -639,6 +672,40 @@ protected void makeObfSource() |
639 | 672 | sourceJar.dependsOn(main.getCompileJavaTaskName(), main.getProcessResourcesTaskName(), retromap); |
640 | 673 | } |
641 | 674 | } |
| 675 | + |
| 676 | + protected void makeRunTasks() |
| 677 | + { |
| 678 | + if (this.hasClientRun()) |
| 679 | + { |
| 680 | + JavaExec exec = makeTask("runClient", JavaExec.class); |
| 681 | + exec.getOutputs().dir(delayedFile(REPLACE_RUN_DIR)); |
| 682 | + exec.setMain(GRADLE_START_CLIENT); |
| 683 | + exec.workingDir(delayedFile(REPLACE_RUN_DIR)); |
| 684 | + exec.setStandardOutput(System.out); |
| 685 | + exec.setErrorOutput(System.err); |
| 686 | + |
| 687 | + exec.setGroup("ForgeGradle"); |
| 688 | + exec.setDescription("Runs the Minecraft client"); |
| 689 | + |
| 690 | + exec.dependsOn("makeStart"); |
| 691 | + } |
| 692 | + |
| 693 | + if (this.hasClientRun()) |
| 694 | + { |
| 695 | + JavaExec exec = makeTask("runServer", JavaExec.class); |
| 696 | + exec.getOutputs().dir(delayedFile(REPLACE_RUN_DIR)); |
| 697 | + exec.setMain(GRADLE_START_SERVER); |
| 698 | + exec.workingDir(delayedFile(REPLACE_RUN_DIR)); |
| 699 | + exec.setStandardOutput(System.out); |
| 700 | + exec.setStandardInput(System.in); |
| 701 | + exec.setErrorOutput(System.err); |
| 702 | + |
| 703 | + exec.setGroup("ForgeGradle"); |
| 704 | + exec.setDescription("Runs the Minecraft Server"); |
| 705 | + |
| 706 | + exec.dependsOn("makeStart"); |
| 707 | + } |
| 708 | + } |
642 | 709 |
|
643 | 710 | protected final TaskDepDummy getDummyDep(String config, DelayedFile dummy, String taskName) |
644 | 711 | { |
|
0 commit comments