37
37
import java .io .File ;
38
38
import java .net .URI ;
39
39
import java .util .ArrayList ;
40
+ import java .util .Collections ;
40
41
import java .util .List ;
41
42
import java .util .Map ;
42
43
import java .util .function .Consumer ;
@@ -100,24 +101,39 @@ public void apply(Project project) {
100
101
);
101
102
var applyAt = configureAccessTransformer (
102
103
project ,
103
- configurations ,
104
104
createSourceArtifacts ,
105
105
neoDevBuildDir ,
106
106
atFiles );
107
107
108
108
applyAt .configure (task -> task .mustRunAfter (genAtsTask ));
109
109
110
- // 3. Apply patches to the source jar from 2.
110
+ // 3. Apply interface injections after the ATs
111
+ // this jar is only used for the patches in the repo
112
+ var applyInterfaceInjection = project .getTasks ().register ("applyInterfaceInjection" , TransformSources .class , task -> {
113
+ task .getInputJar ().set (applyAt .flatMap (TransformSources ::getOutputJar ));
114
+ task .getInterfaceInjectionData ().from (project .getRootProject ().file ("src/main/resources/META-INF/injected-interfaces.json" ));
115
+ task .getOutputJar ().set (neoDevBuildDir .map (dir -> dir .file ("artifacts/interface-injected-sources.jar" )));
116
+ });
117
+
118
+ tasks .withType (TransformSources .class , task -> {
119
+ task .setGroup (INTERNAL_GROUP );
120
+ task .classpath (configurations .getExecutableTool (Tools .JST ));
121
+
122
+ task .getLibraries ().from (configurations .neoFormClasspath );
123
+ task .getLibrariesFile ().set (neoDevBuildDir .map (dir -> dir .file ("minecraft-libraries-for-" + task .getName () + ".txt" )));
124
+ });
125
+
126
+ // 4. Apply patches to the source jar from 3.
111
127
var patchesFolder = project .getRootProject ().file ("patches" );
112
128
var applyPatches = tasks .register ("applyPatches" , ApplyPatches .class , task -> {
113
129
task .setGroup (INTERNAL_GROUP );
114
- task .getOriginalJar ().set (applyAt .flatMap (ApplyAccessTransformer ::getOutputJar ));
130
+ task .getOriginalJar ().set (applyInterfaceInjection .flatMap (TransformSources ::getOutputJar ));
115
131
task .getPatchesFolder ().set (patchesFolder );
116
132
task .getPatchedJar ().set (neoDevBuildDir .map (dir -> dir .file ("artifacts/patched-sources.jar" )));
117
133
task .getRejectsFolder ().set (project .getRootProject ().file ("rejects" ));
118
134
});
119
135
120
- // 4 . Unpack jar from 3 .
136
+ // 5 . Unpack jar from 4 .
121
137
var mcSourcesPath = project .file ("src/main/java" );
122
138
tasks .register ("setup" , Sync .class , task -> {
123
139
task .setGroup (GROUP );
@@ -185,14 +201,22 @@ public void apply(Project project) {
185
201
* OTHER TASKS
186
202
*/
187
203
188
- // Generate source patches into a patch archive.
204
+ // Generate source patches into a patch archive, based on the jar with injected interfaces .
189
205
var genSourcePatches = tasks .register ("generateSourcePatches" , GenerateSourcePatches .class , task -> {
190
206
task .setGroup (INTERNAL_GROUP );
191
- task .getOriginalJar ().set (applyAt .flatMap (ApplyAccessTransformer ::getOutputJar ));
207
+ task .getOriginalJar ().set (applyInterfaceInjection .flatMap (TransformSources ::getOutputJar ));
192
208
task .getModifiedSources ().set (project .file ("src/main/java" ));
193
209
task .getPatchesJar ().set (neoDevBuildDir .map (dir -> dir .file ("source-patches.zip" )));
194
210
});
195
211
212
+ // Generate source patches that are based on the production environment (without separate interface injection)
213
+ var genProductionPatches = tasks .register ("generateProductionSourcePatches" , GenerateSourcePatches .class , task -> {
214
+ task .setGroup (INTERNAL_GROUP );
215
+ task .getOriginalJar ().set (applyAt .flatMap (TransformSources ::getOutputJar ));
216
+ task .getModifiedSources ().set (project .file ("src/main/java" ));
217
+ task .getPatchesFolder ().set (neoDevBuildDir .map (dir -> dir .dir ("production-source-patches" )));
218
+ });
219
+
196
220
// Update the patch/ folder with the current patches.
197
221
tasks .register ("genPatches" , Sync .class , task -> {
198
222
task .setGroup (GROUP );
@@ -245,9 +269,10 @@ public void apply(Project project) {
245
269
configurations ,
246
270
createCleanArtifacts ,
247
271
neoDevBuildDir ,
248
- patchesFolder
272
+ genProductionPatches . flatMap ( GenerateSourcePatches :: getPatchesFolder )
249
273
);
250
274
275
+ var installerRepositoryUrls = getInstallerRepositoryUrls (project );
251
276
// Launcher profile = the version.json file used by the Minecraft launcher.
252
277
var createLauncherProfile = tasks .register ("createLauncherProfile" , CreateLauncherProfile .class , task -> {
253
278
task .setGroup (INTERNAL_GROUP );
@@ -256,17 +281,7 @@ public void apply(Project project) {
256
281
task .getNeoForgeVersion ().set (neoForgeVersion );
257
282
task .getRawNeoFormVersion ().set (rawNeoFormVersion );
258
283
task .setLibraries (configurations .launcherProfileClasspath );
259
- task .getRepositoryURLs ().set (project .provider (() -> {
260
- List <URI > repos = new ArrayList <>();
261
- for (var repo : project .getRepositories ().withType (MavenArtifactRepository .class )) {
262
- var uri = repo .getUrl ();
263
- if (!uri .toString ().endsWith ("/" )) {
264
- uri = URI .create (uri + "/" );
265
- }
266
- repos .add (uri );
267
- }
268
- return repos ;
269
- }));
284
+ task .getRepositoryURLs ().set (installerRepositoryUrls );
270
285
// ${version_name}.jar will be filled out by the launcher. It corresponds to the raw SRG Minecraft client jar.
271
286
task .getIgnoreList ().addAll ("client-extra" , "${version_name}.jar" );
272
287
task .setModules (configurations .modulePath );
@@ -285,17 +300,7 @@ public void apply(Project project) {
285
300
task .addLibraries (configurations .launcherProfileClasspath );
286
301
// We need the NeoForm zip for the SRG mappings.
287
302
task .addLibraries (configurations .neoFormDataOnly );
288
- task .getRepositoryURLs ().set (project .provider (() -> {
289
- List <URI > repos = new ArrayList <>();
290
- for (var repo : project .getRepositories ().withType (MavenArtifactRepository .class )) {
291
- var uri = repo .getUrl ();
292
- if (!uri .toString ().endsWith ("/" )) {
293
- uri = URI .create (uri + "/" );
294
- }
295
- repos .add (uri );
296
- }
297
- return repos ;
298
- }));
303
+ task .getRepositoryURLs ().set (installerRepositoryUrls );
299
304
task .getUniversalJar ().set (universalJar .flatMap (AbstractArchiveTask ::getArchiveFile ));
300
305
task .getInstallerProfile ().set (neoDevBuildDir .map (dir -> dir .file ("installer-profile.json" )));
301
306
@@ -411,7 +416,7 @@ public void apply(Project project) {
411
416
task .from (binaryPatchOutputs .binaryPatchesForMerged (), spec -> {
412
417
spec .rename (s -> "joined.lzma" );
413
418
});
414
- task .from (project .zipTree ( genSourcePatches .flatMap (GenerateSourcePatches ::getPatchesJar )), spec -> {
419
+ task .from (project .fileTree ( genProductionPatches .flatMap (GenerateSourcePatches ::getPatchesFolder )), spec -> {
415
420
spec .into ("patches/" );
416
421
});
417
422
});
@@ -444,32 +449,51 @@ public void apply(Project project) {
444
449
setupProductionServerTest (project , installerJar );
445
450
}
446
451
447
- private static TaskProvider <ApplyAccessTransformer > configureAccessTransformer (
452
+ /**
453
+ * Get the list of Maven repositories that may contain artifacts for the installer.
454
+ */
455
+ private static Provider <List <URI >> getInstallerRepositoryUrls (Project project ) {
456
+ return project .provider (() -> {
457
+ List <URI > repos = new ArrayList <>();
458
+ var projectRepos = project .getRepositories ();
459
+ if (!projectRepos .isEmpty ()) {
460
+ for (var repo : projectRepos .withType (MavenArtifactRepository .class )) {
461
+ repos .add (repo .getUrl ());
462
+ }
463
+ } else {
464
+ // If no project repos are defined, use the repository list we exposed in settings.gradle via an extension
465
+ // See the end of settings.gradle for details
466
+ Collections .addAll (repos , (URI []) project .getGradle ().getExtensions ().getByName ("repositoryBaseUrls" ));
467
+ }
468
+
469
+ // Ensure all base urls end with a slash
470
+ repos .replaceAll (uri -> uri .toString ().endsWith ("/" ) ? uri : URI .create (uri + "/" ));
471
+
472
+ return repos ;
473
+ });
474
+ }
475
+
476
+ private static TaskProvider <TransformSources > configureAccessTransformer (
448
477
Project project ,
449
- NeoDevConfigurations configurations ,
450
478
TaskProvider <CreateMinecraftArtifacts > createSourceArtifacts ,
451
479
Provider <Directory > neoDevBuildDir ,
452
480
List <File > atFiles ) {
453
481
454
482
// Pass -PvalidateAccessTransformers to validate ATs.
455
483
var validateAts = project .getProviders ().gradleProperty ("validateAccessTransformers" ).map (p -> true ).orElse (false );
456
- return project .getTasks ().register ("applyAccessTransformer" , ApplyAccessTransformer .class , task -> {
457
- task .setGroup (INTERNAL_GROUP );
458
- task .classpath (configurations .getExecutableTool (Tools .JST ));
484
+ return project .getTasks ().register ("applyAccessTransformer" , TransformSources .class , task -> {
459
485
task .getInputJar ().set (createSourceArtifacts .flatMap (CreateMinecraftArtifacts ::getSourcesArtifact ));
460
486
task .getAccessTransformers ().from (atFiles );
461
- task .getValidate ().set (validateAts );
487
+ task .getValidateAccessTransformers ().set (validateAts );
462
488
task .getOutputJar ().set (neoDevBuildDir .map (dir -> dir .file ("artifacts/access-transformed-sources.jar" )));
463
- task .getLibraries ().from (configurations .neoFormClasspath );
464
- task .getLibrariesFile ().set (neoDevBuildDir .map (dir -> dir .file ("minecraft-libraries-for-jst.txt" )));
465
489
});
466
490
}
467
491
468
492
private static BinaryPatchOutputs configureBinaryPatchCreation (Project project ,
469
493
NeoDevConfigurations configurations ,
470
494
TaskProvider <CreateCleanArtifacts > createCleanArtifacts ,
471
495
Provider <Directory > neoDevBuildDir ,
472
- File sourcesPatchesFolder ) {
496
+ Provider < Directory > sourcesPatchesFolder ) {
473
497
var tasks = project .getTasks ();
474
498
475
499
var artConfig = configurations .getExecutableTool (Tools .AUTO_RENAMING_TOOL );
0 commit comments