Remap less (#77)
* Avoid remapping jars every time Loom starts * Attempt to find installer JSON if it isn't found Remapping Fabric-Loader used to find it every time, now we might skip that we have to go looking for it * Log a little more when skipping things Makes it more clear cut when it is avoiding doing things compared to failing after trying
This commit is contained in:
		
							parent
							
								
									86ae0146d9
								
							
						
					
					
						commit
						03fb478166
					
				
					 3 changed files with 46 additions and 11 deletions
				
			
		|  | @ -50,15 +50,19 @@ public class ModRemapperProvider extends DependencyProvider { | ||||||
| 		//Output name should match whatever it's under as a dependency so Gradle finds it | 		//Output name should match whatever it's under as a dependency so Gradle finds it | ||||||
| 		String outputNamePrefix = rds.substring(rds.indexOf(':') + 1).replace(':', '-') + verSuffix; //group:name:version -> name-version.mapped.yarn.5 | 		String outputNamePrefix = rds.substring(rds.indexOf(':') + 1).replace(':', '-') + verSuffix; //group:name:version -> name-version.mapped.yarn.5 | ||||||
| 		File modStore = extension.getRemappedModCache(); | 		File modStore = extension.getRemappedModCache(); | ||||||
|  | 
 | ||||||
| 		File output = new File(modStore, outputNamePrefix + ".jar"); | 		File output = new File(modStore, outputNamePrefix + ".jar"); | ||||||
| 		if(output.exists()){ | 		if (!output.exists() || input.lastModified() <= 0 || input.lastModified() > output.lastModified()) { | ||||||
| 			output.delete(); | 			//If the output doesn't exist, or appears to be outdated compared to the input we'll remap it | ||||||
| 		} | 			ModProcessor.handleMod(input, output, project); | ||||||
| 
 | 
 | ||||||
| 		ModProcessor.handleMod(input, output, project); | 			if (!output.exists()){ | ||||||
|  | 				throw new RuntimeException("Failed to remap mod"); | ||||||
|  | 			} | ||||||
| 
 | 
 | ||||||
| 		if(!output.exists()){ | 			output.setLastModified(input.lastModified()); | ||||||
| 			throw new RuntimeException("Failed to remap mod"); | 		} else { | ||||||
|  | 			project.getLogger().info(output.getName() + " is up to date with " + input.getName()); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		project.getDependencies().add(Constants.COMPILE_MODS_MAPPED, project.getDependencies().module( | 		project.getDependencies().add(Constants.COMPILE_MODS_MAPPED, project.getDependencies().module( | ||||||
|  | @ -71,11 +75,23 @@ public class ModRemapperProvider extends DependencyProvider { | ||||||
| 			if (sourcesFile.isPresent()) { | 			if (sourcesFile.isPresent()) { | ||||||
| 				project.getLogger().lifecycle(":providing " + rds + " sources"); | 				project.getLogger().lifecycle(":providing " + rds + " sources"); | ||||||
| 
 | 
 | ||||||
| 				try { | 				File sources = sourcesFile.get(); | ||||||
| 					SourceRemapper.remapSources(project, sourcesFile.get(), new File(modStore, outputNamePrefix + "-sources.jar"), true); | 				File remappedSources = new File(modStore, outputNamePrefix + "-sources.jar"); | ||||||
| 				} catch (Exception e) { | 
 | ||||||
| 					e.printStackTrace(); | 				if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified()) { | ||||||
|  | 					try { | ||||||
|  | 						SourceRemapper.remapSources(project, sources, remappedSources, true); | ||||||
|  | 
 | ||||||
|  | 						//Set the remapped sources creation date to match the sources if we're likely succeeded in making it | ||||||
|  | 						remappedSources.setLastModified(sources.lastModified()); | ||||||
|  | 					} catch (Exception e) { | ||||||
|  | 						e.printStackTrace(); | ||||||
|  | 					} | ||||||
|  | 				} else { | ||||||
|  | 					project.getLogger().info(remappedSources.getName() + " is up to date with " + sources.getName()); | ||||||
| 				} | 				} | ||||||
|  | 			} else { | ||||||
|  | 				project.getLogger().info(":skipping " + rds + " sources, not found"); | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -30,9 +30,11 @@ import net.fabricmc.loom.util.DependencyProvider.DependencyInfo; | ||||||
| 
 | 
 | ||||||
| import org.gradle.api.Project; | import org.gradle.api.Project; | ||||||
| import org.gradle.api.artifacts.Configuration; | import org.gradle.api.artifacts.Configuration; | ||||||
|  | import org.gradle.api.artifacts.Dependency; | ||||||
| import org.gradle.api.artifacts.ExternalModuleDependency; | import org.gradle.api.artifacts.ExternalModuleDependency; | ||||||
| import org.gradle.api.artifacts.repositories.MavenArtifactRepository; | import org.gradle.api.artifacts.repositories.MavenArtifactRepository; | ||||||
| 
 | 
 | ||||||
|  | import java.io.File; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.LinkedHashSet; | import java.util.LinkedHashSet; | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  | @ -87,6 +89,23 @@ public class LoomDependencyManager { | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		if (extension.getInstallerJson() == null) { | ||||||
|  | 			//If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking | ||||||
|  | 			project.getLogger().info("Didn't find installer JSON, searching through compileMods"); | ||||||
|  | 			Configuration configuration = project.getConfigurations().getByName(Constants.COMPILE_MODS); | ||||||
|  | 
 | ||||||
|  | 			for (Dependency dependency : configuration.getDependencies()) { | ||||||
|  | 				DependencyInfo info = DependencyInfo.create(project, dependency, configuration); | ||||||
|  | 				File input = info.resolveFile().orElseThrow(() -> new RuntimeException("Could not find dependency " + info)); | ||||||
|  | 
 | ||||||
|  | 				ModProcessor.readInstallerJson(input, project); | ||||||
|  | 				if (extension.getInstallerJson() != null) { | ||||||
|  | 					project.getLogger().info("Found installer JSON in " + info); | ||||||
|  | 					break; //Found it, probably don't need to look any further | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		if (extension.getInstallerJson() != null) { | 		if (extension.getInstallerJson() != null) { | ||||||
| 			handleInstallerJson(extension.getInstallerJson(), project); | 			handleInstallerJson(extension.getInstallerJson(), project); | ||||||
| 		} else { | 		} else { | ||||||
|  |  | ||||||
|  | @ -190,7 +190,7 @@ public class ModProcessor { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private static void readInstallerJson(File file, Project project){ | 	static void readInstallerJson(File file, Project project){ | ||||||
| 		try { | 		try { | ||||||
| 			JarFile jarFile = new JarFile(file); | 			JarFile jarFile = new JarFile(file); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue