2323 */
2424package dev .aoqia .leaf .loom .configuration ;
2525
26- import javax .inject .Inject ;
2726import java .io .File ;
2827import java .io .IOException ;
2928import java .io .UncheckedIOException ;
6261import dev .aoqia .leaf .loom .util .gradle .daemon .DaemonUtils ;
6362import dev .aoqia .leaf .loom .util .service .ScopedServiceFactory ;
6463import dev .aoqia .leaf .loom .util .service .ServiceFactory ;
64+ import javax .inject .Inject ;
6565import org .gradle .api .GradleException ;
6666import org .gradle .api .Project ;
6767import org .gradle .api .logging .Logger ;
@@ -102,7 +102,8 @@ public void run() {
102102 });
103103
104104 afterEvaluationWithService ((serviceFactory ) -> {
105- final ConfigContext configContext = new ConfigContextImpl (getProject (), serviceFactory , extension );
105+ final ConfigContext configContext = new ConfigContextImpl (getProject (), serviceFactory ,
106+ extension );
106107
107108 ZomboidSourceSets .get (getProject ()).afterEvaluate (getProject ());
108109 final boolean previousRefreshDeps = extension .refreshDeps ();
@@ -112,7 +113,8 @@ public void run() {
112113 getProject ()
113114 .getLogger ()
114115 .lifecycle (
115- "Found existing cache lock file ({}), rebuilding loom cache. This may have been "
116+ "Found existing cache lock file ({}), rebuilding loom cache. This may " +
117+ "have been "
116118 + "caused by a failed or canceled build." ,
117119 lockResult );
118120 extension .setRefreshDeps (true );
@@ -121,22 +123,25 @@ public void run() {
121123 try {
122124 setupZomboid (configContext );
123125
124- if (!GradleUtils .getBooleanProperty (getProject (), Constants .Properties .ONLY_PROVIDE_JARS )) {
126+ if (!GradleUtils .getBooleanProperty (getProject (),
127+ Constants .Properties .ONLY_PROVIDE_JARS )) {
125128 LoomDependencyManager dependencyManager = new LoomDependencyManager ();
126129 extension .setDependencyManager (dependencyManager );
127130 dependencyManager .handleDependencies (getProject (), serviceFactory );
128131 }
129132 } catch (Exception e ) {
130133 ExceptionUtil .processException (e , DaemonUtils .Context .fromProject (getProject ()));
131134 disownLock ();
132- throw ExceptionUtil .createDescriptiveWrapper (RuntimeException ::new , "Failed to setup Zomboid" , e );
135+ throw ExceptionUtil .createDescriptiveWrapper (RuntimeException ::new ,
136+ "Failed to setup Zomboid" , e );
133137 }
134138
135139 releaseLock ();
136140 extension .setRefreshDeps (previousRefreshDeps );
137141
138142 // If only providing jars, we dont do mixin stuff or decompile tasks.
139- if (GradleUtils .getBooleanProperty (getProject (), Constants .Properties .ONLY_PROVIDE_JARS )) {
143+ if (GradleUtils .getBooleanProperty (getProject (),
144+ Constants .Properties .ONLY_PROVIDE_JARS )) {
140145 return ;
141146 }
142147
@@ -161,27 +166,34 @@ public void run() {
161166 // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
162167 getTasks ()
163168 .withType (AbstractCopyTask .class )
164- .configureEach (abstractCopyTask -> abstractCopyTask .setFilteringCharset (StandardCharsets .UTF_8 .name ()));
169+ .configureEach (abstractCopyTask -> abstractCopyTask .setFilteringCharset (
170+ StandardCharsets .UTF_8 .name ()));
165171 getTasks ()
166172 .withType (JavaCompile .class )
167- .configureEach (javaCompile -> javaCompile .getOptions ().setEncoding (StandardCharsets .UTF_8 .name ()));
173+ .configureEach (
174+ javaCompile -> javaCompile .getOptions ().setEncoding (StandardCharsets .UTF_8 .name ()));
168175
169176 if (getProject ().getPluginManager ().hasPlugin ("org.jetbrains.kotlin.kapt" )) {
170- // If loom is applied after kapt, then kapt will use the AP arguments too early for loom to pass the
177+ // If loom is applied after kapt, then kapt will use the AP arguments too early for
178+ // loom to pass the
171179 // arguments we need for mixin.
172- throw new IllegalArgumentException ("leaf-loom must be applied BEFORE kapt in the plugins { } block." );
180+ throw new IllegalArgumentException (
181+ "leaf-loom must be applied BEFORE kapt in the plugins { } block." );
173182 }
174183 }
175184
176- // This is not thread safe across getProject()s synchronize it here just to be sure, might be possible to move
185+ // This is not thread safe across getProject()s synchronize it here just to be sure, might be
186+ // possible to move
177187 // this further down, but for now this will do.
178188 private synchronized void setupZomboid (ConfigContext configContext ) throws Exception {
179189 final Project project = configContext .project ();
180190 final LoomGradleExtension extension = configContext .extension ();
181191
182- final ZomboidMetadataProvider clientMetadataProvider = ZomboidMetadataProvider .create (false , configContext );
192+ final ZomboidMetadataProvider clientMetadataProvider = ZomboidMetadataProvider .create (false ,
193+ configContext );
183194 extension .setClientMetadataProvider (clientMetadataProvider );
184- final ZomboidMetadataProvider serverMetadataProvider = ZomboidMetadataProvider .create (true , configContext );
195+ final ZomboidMetadataProvider serverMetadataProvider = ZomboidMetadataProvider .create (true ,
196+ configContext );
185197 extension .setServerMetadataProvider (serverMetadataProvider );
186198
187199 var jarConfiguration = extension .getZomboidJarConfiguration ().get ();
@@ -197,10 +209,15 @@ private synchronized void setupZomboid(ConfigContext configContext) throws Excep
197209 return ;
198210 }
199211
212+ // Realise the dependencies without actually resolving them, this forces any lazy
213+ // providers to be created, populating the layered mapping factories.
214+ project .getConfigurations ().getByName (Configurations .MAPPINGS ).getDependencies ().toArray ();
215+
200216 // Created any layered mapping files.
201217 LayeredMappingsFactory .afterEvaluate (configContext );
202218
203- final DependencyInfo mappingsDep = DependencyInfo .create (getProject (), Configurations .MAPPINGS );
219+ final DependencyInfo mappingsDep = DependencyInfo .create (getProject (),
220+ Configurations .MAPPINGS );
204221 final MappingConfiguration mappingConfiguration =
205222 MappingConfiguration .create (getProject (),
206223 configContext .serviceFactory (),
@@ -209,10 +226,12 @@ private synchronized void setupZomboid(ConfigContext configContext) throws Excep
209226 extension .setMappingConfiguration (mappingConfiguration );
210227 mappingConfiguration .applyToProject (getProject (), mappingsDep );
211228
212- NamedZomboidProvider <?> namedZomboidProvider = jarConfiguration .createNamedZomboidProvider (project );
229+ NamedZomboidProvider <?> namedZomboidProvider = jarConfiguration .createNamedZomboidProvider (
230+ project );
213231 registerGameProcessors (configContext );
214232
215- ZomboidJarProcessorManager zomboidJarProcessorManager = ZomboidJarProcessorManager .create (getProject ());
233+ ZomboidJarProcessorManager zomboidJarProcessorManager = ZomboidJarProcessorManager .create (
234+ getProject ());
216235 if (zomboidJarProcessorManager != null ) {
217236 // Wrap the named MC provider for one that will provide the processed jars
218237 namedZomboidProvider = jarConfiguration .createProcessedNamedZomboidProvider (
@@ -234,28 +253,29 @@ private void registerGameProcessors(ConfigContext configContext) {
234253 extension .getEnableTransitiveAccessWideners ().get ();
235254 extension .addZomboidJarProcessor (
236255 AccessWidenerJarProcessor .class ,
237- "leaf- loom:access-widener" ,
256+ "loom:access-widener" ,
238257 enableTransitiveAccessWideners ,
239258 extension .getAccessWidenerPath ());
240259
241260 if (extension .getEnableModProvidedJavadoc ().get ()) {
242- extension .addZomboidJarProcessor (ModJavadocProcessor .class , "leaf- loom:mod-javadoc" );
261+ extension .addZomboidJarProcessor (ModJavadocProcessor .class , "loom:mod-javadoc" );
243262 }
244263
245264 final InterfaceInjectionExtensionAPI interfaceInjection = extension .getInterfaceInjection ();
246265
247266 if (interfaceInjection .isEnabled ()) {
248267 extension .addZomboidJarProcessor (
249268 InterfaceInjectionProcessor .class ,
250- "leaf- loom:interface-inject" ,
269+ "loom:interface-inject" ,
251270 interfaceInjection .getEnableDependencyInterfaceInjection ().get ());
252271 }
253272 }
254273
255274 private void setupMixinAp (MixinExtension mixin ) {
256275 mixin .init ();
257276
258- // Disable some things used by log4j via the mixin AP that prevent it from being garbage collected
277+ // Disable some things used by log4j via the mixin AP that prevent it from being garbage
278+ // collected
259279 System .setProperty ("log4j2.disable.jmx" , "true" );
260280 System .setProperty ("log4j.shutdownHookEnabled" , "false" );
261281 System .setProperty ("log4j.skipJansi" , "true" );
@@ -337,7 +357,8 @@ private LockResult acquireProcessLockWaiting(LockFile lockFile, Duration timeout
337357
338358 // Returns true if our process already owns the lock
339359 @ SuppressWarnings ("BusyWait" )
340- private LockResult acquireProcessLockWaiting_ (LockFile lockFile , Duration timeout ) throws IOException {
360+ private LockResult acquireProcessLockWaiting_ (LockFile lockFile , Duration timeout ) throws
361+ IOException {
341362 final long timeoutMs = timeout .toMillis ();
342363 final Logger logger = Logging .getLogger ("loom_acquireProcessLockWaiting" );
343364 final long currentPid = ProcessHandle .current ().pid ();
@@ -354,7 +375,8 @@ private LockResult acquireProcessLockWaiting_(LockFile lockFile, Duration timeou
354375 disowned = true ;
355376 } else {
356377 lockingProcessId = Long .parseLong (lockValue );
357- logger .lifecycle ("\" {}\" is currently held by pid '{}'." , lockFile , lockingProcessId );
378+ logger .lifecycle ("\" {}\" is currently held by pid '{}'." , lockFile ,
379+ lockingProcessId );
358380 }
359381 } catch (final Exception ignored ) {
360382 // ignored
@@ -367,10 +389,13 @@ private LockResult acquireProcessLockWaiting_(LockFile lockFile, Duration timeou
367389 Optional <ProcessHandle > handle = ProcessHandle .of (lockingProcessId );
368390
369391 if (disowned ) {
370- logger .lifecycle ("Previous process has disowned the lock due to abrupt termination." );
392+ logger .lifecycle (
393+ "Previous process has disowned the lock due to abrupt termination." );
371394 Files .deleteIfExists (lockFile .file );
372395 } else if (handle .isEmpty ()) {
373- logger .lifecycle ("Locking process does not exist, assuming abrupt termination and deleting lock file." );
396+ logger .lifecycle (
397+ "Locking process does not exist, assuming abrupt termination and deleting " +
398+ "lock file." );
374399 Files .deleteIfExists (lockFile .file );
375400 abrupt = true ;
376401 } else {
@@ -400,7 +425,9 @@ private LockResult acquireProcessLockWaiting_(LockFile lockFile, Duration timeou
400425
401426 if (sleptMs >= timeoutMs ) {
402427 throw new GradleException (
403- "Have been waiting on lock file '%s' for %s ms. Giving up as timeout is %s ms."
428+ ("Have been waiting on lock file '%s' for %s ms. Giving up as timeout" +
429+ " " +
430+ "is %s ms." )
404431 .formatted (lockFile , sleptMs , timeoutMs ));
405432 }
406433 }
@@ -445,12 +472,14 @@ private void releaseLock() {
445472 Files .delete (lock );
446473 } catch (IOException e1 ) {
447474 try {
448- // If we failed to delete the lock file, moving it before trying to delete it may help.
475+ // If we failed to delete the lock file, moving it before trying to delete it may
476+ // help.
449477 final Path del = lock .resolveSibling (lock .getFileName () + ".del" );
450478 Files .move (lock , del );
451479 Files .delete (del );
452480 } catch (IOException e2 ) {
453- var exception = new UncheckedIOException ("Failed to release getProject() configuration lock" , e2 );
481+ var exception = new UncheckedIOException (
482+ "Failed to release getProject() configuration lock" , e2 );
454483 exception .addSuppressed (e1 );
455484 throw exception ;
456485 }
0 commit comments