33import com .google .common .collect .Maps ;
44import net .neoforged .gradle .common .extensions .problems .IProblemReporter ;
55import net .neoforged .gradle .common .runtime .tasks .GenerateExtraJar ;
6+ import net .neoforged .gradle .common .util .ConfigurationUtils ;
67import net .neoforged .gradle .dsl .common .extensions .MinecraftArtifactCache ;
78import net .neoforged .gradle .dsl .common .extensions .dependency .replacement .DependencyReplacement ;
89import net .neoforged .gradle .dsl .common .extensions .dependency .replacement .ReplacementResult ;
9- import net .neoforged .gradle .common .util .ConfigurationUtils ;
1010import net .neoforged .gradle .dsl .common .tasks .WithOutput ;
1111import net .neoforged .gradle .dsl .common .util .DistributionType ;
1212import net .neoforged .gradle .dsl .common .util .GameArtifact ;
1818import org .gradle .api .tasks .TaskProvider ;
1919
2020import javax .inject .Inject ;
21- import java .util .*;
21+ import java .util .Collections ;
22+ import java .util .Locale ;
23+ import java .util .Map ;
24+ import java .util .Objects ;
25+ import java .util .Optional ;
2226
23- public abstract class ExtraJarDependencyManager {
27+ public abstract class ExtraJarDependencyManager
28+ {
2429
2530 private final Map <String , ReplacementResult > replacements = Maps .newHashMap ();
2631
27- public static String generateClientCoordinateFor (final String version ) {
32+ public static String generateClientCoordinateFor (final String version )
33+ {
2834 return "net.minecraft:client:" + version + ":client-extra" ;
2935 }
30-
31- public static String generateServerCoordinateFor (final String version ) {
36+
37+ public static String generateServerCoordinateFor (final String version )
38+ {
3239 return "net.minecraft:client:" + version + ":client-extra" ;
3340 }
34-
35- public static String generateCoordinateFor (final DistributionType type , final String version ) {
41+
42+ public static String generateCoordinateFor (final DistributionType type , final String version )
43+ {
3644 return String .format ("net.minecraft:%s:%s:%s-extra" , type .getName ().toLowerCase (Locale .ROOT ), version , type .getName ().toLowerCase (Locale .ROOT ));
3745 }
3846
3947 @ Inject
40- public ExtraJarDependencyManager (final Project project ) {
48+ public ExtraJarDependencyManager (final Project project )
49+ {
4150 final DependencyReplacement dependencyReplacementsExtension = project .getExtensions ().getByType (DependencyReplacement .class );
4251
4352 dependencyReplacementsExtension .getReplacementHandlers ().register ("extraJar" , dependencyReplacementHandler -> dependencyReplacementHandler .getReplacer ().set (context -> {
44- if (isNotAMatchingDependency (context .getDependency ()))
45- return Optional .empty ();
53+ if (isNotAMatchingDependency (context .getDependency ()))
54+ {
55+ return Optional .empty ();
56+ }
4657
47- return Optional .of (generateReplacement (project , context .getDependency ()));
48- }));
58+ return Optional .of (generateReplacement (project , context .getDependency ()));
59+ }));
4960 }
5061
51- private boolean isNotAMatchingDependency (final Dependency dependencyToCheck ) {
52- if (dependencyToCheck instanceof ExternalModuleDependency ) {
62+ private boolean isNotAMatchingDependency (final Dependency dependencyToCheck )
63+ {
64+ if (dependencyToCheck instanceof ExternalModuleDependency )
65+ {
5366 final ExternalModuleDependency externalModuleDependency = (ExternalModuleDependency ) dependencyToCheck ;
54- return externalModuleDependency .getGroup () == null || !externalModuleDependency .getGroup ().equals ("net.minecraft" ) || !isSupportedSide (dependencyToCheck ) || !hasMatchingArtifact (externalModuleDependency );
67+ return externalModuleDependency .getGroup () == null || !externalModuleDependency .getGroup ().equals ("net.minecraft" ) || !isSupportedSide (dependencyToCheck )
68+ || !hasMatchingArtifact (externalModuleDependency );
5569 }
5670
5771 return true ;
5872 }
5973
60- private boolean isSupportedSide (final Dependency dependency ) {
74+ private boolean isSupportedSide (final Dependency dependency )
75+ {
6176 return dependency .getName ().equals ("client" ) || dependency .getName ().equals ("server" );
6277 }
6378
64- private boolean hasMatchingArtifact (ExternalModuleDependency externalModuleDependency ) {
65- if (externalModuleDependency .getVersion () == null ) {
79+ private boolean hasMatchingArtifact (ExternalModuleDependency externalModuleDependency )
80+ {
81+ if (externalModuleDependency .getVersion () == null )
82+ {
6683 return false ;
6784 }
6885
69- if (externalModuleDependency .getArtifacts ().size () != 1 ) {
86+ if (externalModuleDependency .getArtifacts ().size () != 1 )
87+ {
7088 return false ;
7189 }
7290
7391 final DependencyArtifact artifact = externalModuleDependency .getArtifacts ().iterator ().next ();
7492 return Objects .equals (artifact .getClassifier (), "client-extra" ) || Objects .equals (artifact .getClassifier (), "server-extra" );
7593 }
7694
77- private ReplacementResult generateReplacement (final Project project , final Dependency dependency ) {
95+ private ReplacementResult generateReplacement (final Project project , final Dependency dependency )
96+ {
7897 final String minecraftVersion = dependency .getVersion ();
79- if (minecraftVersion == null ) {
98+ if (minecraftVersion == null )
99+ {
80100 final IProblemReporter problemReporter = project .getExtensions ().getByType (IProblemReporter .class );
81101 throw problemReporter .throwing (spec -> {
82- spec .id ("dependencies.extra-jar" , "missingVersion" )
83- .contextualLabel ("Client-Extra Jar: Missing Version" )
84- .details ("The dependency %s does not have a version specified" .formatted (dependency ))
85- .solution ("Specify a version for the dependency" )
86- .section ("common-dep-management-extra-jar" );
102+ spec .id ("dependencies.extra-jar" , "missingVersion" )
103+ .contextualLabel ("Client-Extra Jar: Missing Version" )
104+ .details ("The dependency %s does not have a version specified" .formatted (dependency ))
105+ .solution ("Specify a version for the dependency" )
106+ .section ("common-dep-management-extra-jar" );
87107 });
88108 }
89109
@@ -92,22 +112,27 @@ private ReplacementResult generateReplacement(final Project project, final Depen
92112
93113 Map <GameArtifact , TaskProvider <? extends WithOutput >> tasks = minecraftArtifactCacheExtension .cacheGameVersionTasks (project , minecraftVersion , DistributionType .JOINED );
94114
95- final TaskProvider <GenerateExtraJar > extraJarTaskProvider = project .getTasks ().register ("create" + minecraftVersion + StringUtils .capitalize (dependency .getName ()) + "ExtraJar" , GenerateExtraJar .class , task -> {
96- task .getOriginalJar ().set (tasks .get (GameArtifact .CLIENT_JAR ).flatMap (WithOutput ::getOutput ));
97- task .getServerJar ().set (tasks .get (GameArtifact .EXTRACTED_SERVER_JAR ).flatMap (WithOutput ::getOutput ));
98- task .getMappings ().set (tasks .get (GameArtifact .CLIENT_MAPPINGS ).flatMap (WithOutput ::getOutput ));
99- task .getOutput ().set (project .getLayout ().getBuildDirectory ().dir ("jars/extra/" + dependency .getName ()).map (cacheDir -> cacheDir .dir (Objects .requireNonNull (minecraftVersion )).file ( dependency .getName () + "-extra.jar" )));
100- });
115+ final TaskProvider <GenerateExtraJar > extraJarTaskProvider =
116+ project .getTasks ().register ("create" + minecraftVersion + StringUtils .capitalize (dependency .getName ()) + "ExtraJar" , GenerateExtraJar .class , task -> {
117+ task .getOriginalJar ().set (tasks .get (GameArtifact .CLIENT_JAR ).flatMap (WithOutput ::getOutput ));
118+ task .getServerJar ().set (tasks .get (GameArtifact .EXTRACTED_SERVER_JAR ).flatMap (WithOutput ::getOutput ));
119+ task .getMappings ().set (tasks .get (GameArtifact .CLIENT_MAPPINGS ).flatMap (WithOutput ::getOutput ));
120+ task .getOutput ()
121+ .set (project .getLayout ()
122+ .getBuildDirectory ()
123+ .dir ("jars/extra/" + dependency .getName ())
124+ .map (cacheDir -> cacheDir .dir (Objects .requireNonNull (minecraftVersion )).file (dependency .getName () + "-extra.jar" )));
125+ });
101126
102127 return new ReplacementResult (
103- project ,
104- extraJarTaskProvider ,
105- project .getConfigurations ().detachedConfiguration (),
106- ConfigurationUtils .temporaryUnhandledConfiguration (
107- project .getConfigurations (),
108- "EmptyExtraJarConfigurationFor" + minecraftVersion .replace ("." , "_" )
109- ),
110- Collections .emptySet ()
128+ project ,
129+ extraJarTaskProvider ,
130+ project .getConfigurations ().detachedConfiguration (),
131+ ConfigurationUtils .temporaryUnhandledConfiguration (
132+ project .getConfigurations (),
133+ "EmptyExtraJarConfigurationFor" + minecraftVersion .replace ("." , "_" )
134+ ),
135+ Collections .emptySet ()
111136 );
112137 });
113138 }
0 commit comments