General code cleanup (#313)

* First general cleanup pass

* Review feedback

* Fix build

* Fix tests
dev/0.11
modmuss50 2020-12-24 20:58:30 +00:00 committed by GitHub
parent b0860c36d6
commit 03444f26b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 559 additions and 498 deletions

View File

@ -1,4 +1,4 @@
[*.{gradle,java}] [*.{gradle,java}]
indent_style = tab indent_style = tab
ij_continuation_indent_size = 8 ij_continuation_indent_size = 8
ij_java_imports_layout = $*,|,java.**,|,*,|,net.fabricmc.** ij_java_imports_layout = $*,|,java.**,|,javax.**,|,*,|,net.fabricmc.**

View File

@ -73,6 +73,9 @@ dependencies {
testImplementation('org.spockframework:spock-core:1.3-groovy-2.4') { testImplementation('org.spockframework:spock-core:1.3-groovy-2.4') {
exclude module: 'groovy-all' exclude module: 'groovy-all'
} }
compileOnly 'org.jetbrains:annotations:20.1.0'
} }
jar { jar {

View File

@ -38,8 +38,6 @@ import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nullable;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.cadixdev.lorenz.MappingSet; import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.mercury.Mercury; import org.cadixdev.mercury.Mercury;
@ -48,15 +46,16 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.BasePluginConvention; import org.gradle.api.plugins.BasePluginConvention;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.processors.JarProcessor; import net.fabricmc.loom.configuration.LoomDependencyManager;
import net.fabricmc.loom.processors.JarProcessorManager; import net.fabricmc.loom.configuration.processors.JarProcessor;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.configuration.processors.JarProcessorManager;
import net.fabricmc.loom.providers.MinecraftMappedProvider; import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.providers.MinecraftProvider; import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.LoomDependencyManager; import net.fabricmc.loom.configuration.providers.mappings.MojangMappingsDependency;
import net.fabricmc.loom.util.mappings.MojangMappingsDependency; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
public class LoomGradleExtension { public class LoomGradleExtension {
public String runDir = "run"; public String runDir = "run";
@ -116,7 +115,7 @@ public class LoomGradleExtension {
public LoomGradleExtension(Project project) { public LoomGradleExtension(Project project) {
this.project = project; this.project = project;
this.autoGenIDERuns = AbstractPlugin.isRootProject(project); this.autoGenIDERuns = isRootProject();
this.unmappedMods = project.files(); this.unmappedMods = project.files();
} }
@ -281,7 +280,7 @@ public class LoomGradleExtension {
Project p = this.project; Project p = this.project;
T result; T result;
while (!AbstractPlugin.isRootProject(p)) { while (!isRootProject()) {
if ((result = projectTFunction.apply(p)) != null) { if ((result = projectTFunction.apply(p)) != null) {
return result; return result;
} }
@ -425,4 +424,8 @@ public class LoomGradleExtension {
public Set<File> getAllMixinMappings() { public Set<File> getAllMixinMappings() {
return Collections.unmodifiableSet(mixinMappings); return Collections.unmodifiableSet(mixinMappings);
} }
public List<LoomDecompiler> getDecompilers() {
return decompilers;
}
} }

View File

@ -24,118 +24,47 @@
package net.fabricmc.loom; package net.fabricmc.loom;
import java.io.File; import com.google.common.collect.ImmutableMap;
import java.util.Locale; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.tasks.TaskContainer;
import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.configuration.CompileConfiguration;
import net.fabricmc.loom.decompilers.cfr.FabricCFRDecompiler; import net.fabricmc.loom.configuration.FabricApiExtension;
import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler; import net.fabricmc.loom.configuration.MavenPublication;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.configuration.ide.IdeConfiguration;
import net.fabricmc.loom.task.CleanEclipseRunsTask; import net.fabricmc.loom.configuration.providers.mappings.MappingsCache;
import net.fabricmc.loom.task.CleanLoomBinaries; import net.fabricmc.loom.decompilers.DecompilerConfiguration;
import net.fabricmc.loom.task.CleanLoomMappings; import net.fabricmc.loom.task.LoomTasks;
import net.fabricmc.loom.task.DownloadAssetsTask;
import net.fabricmc.loom.task.GenEclipseRunsTask;
import net.fabricmc.loom.task.GenIdeaProjectTask;
import net.fabricmc.loom.task.GenVsCodeProjectTask;
import net.fabricmc.loom.task.GenerateSourcesTask;
import net.fabricmc.loom.task.MigrateMappingsTask;
import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJarTask;
import net.fabricmc.loom.task.RunClientTask;
import net.fabricmc.loom.task.RunServerTask;
public class LoomGradlePlugin extends AbstractPlugin { public class LoomGradlePlugin implements Plugin<Project> {
public static File getMappedByproduct(Project project, String suffix) { public static boolean refreshDeps;
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
MappingsProvider mappingsProvider = extension.getMappingsProvider();
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
String path = mappedJar.getAbsolutePath();
if (!path.toLowerCase(Locale.ROOT).endsWith(".jar")) {
throw new RuntimeException("Invalid mapped JAR path: " + path);
}
return new File(path.substring(0, path.length() - 4) + suffix);
}
@Override @Override
public void apply(Project target) { public void apply(Project project) {
super.apply(target); project.getLogger().lifecycle("Fabric Loom: " + LoomGradlePlugin.class.getPackage().getImplementationVersion());
TaskContainer tasks = target.getTasks(); refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies();
tasks.register("cleanLoomBinaries", CleanLoomBinaries.class, t -> t.setDescription("Removes binary jars created by Loom.")); if (refreshDeps) {
tasks.register("cleanLoomMappings", CleanLoomMappings.class, t -> t.setDescription("Removes mappings downloaded by Loom.")); MappingsCache.INSTANCE.invalidate();
project.getLogger().lifecycle("Refresh dependencies is in use, loom will be significantly slower.");
}
tasks.register("cleanLoom").configure(task -> { // Apply default plugins
task.setGroup("fabric"); project.apply(ImmutableMap.of("plugin", "java"));
task.setDescription("Runs all Loom cleanup tasks."); project.apply(ImmutableMap.of("plugin", "eclipse"));
task.dependsOn(tasks.getByName("cleanLoomBinaries")); project.apply(ImmutableMap.of("plugin", "idea"));
task.dependsOn(tasks.getByName("cleanLoomMappings"));
});
tasks.register("migrateMappings", MigrateMappingsTask.class, t -> { // Setup extensions, loom shadows minecraft
t.setDescription("Migrates mappings to a new version."); project.getExtensions().create("minecraft", LoomGradleExtension.class, project);
t.getOutputs().upToDateWhen((o) -> false); project.getExtensions().add("loom", project.getExtensions().getByName("minecraft"));
}); project.getExtensions().create("fabricApi", FabricApiExtension.class, project);
tasks.register("remapJar", RemapJarTask.class, t -> { CompileConfiguration.setupConfigurations(project);
t.setDescription("Remaps the built project jar to intermediary mappings."); IdeConfiguration.setup(project);
t.setGroup("fabric"); CompileConfiguration.configureCompile(project);
}); MavenPublication.configure(project);
LoomTasks.registerTasks(project);
tasks.register("downloadAssets", DownloadAssetsTask.class, t -> t.setDescription("Downloads required assets for Fabric.")); DecompilerConfiguration.setup(project);
tasks.register("genIdeaWorkspace", GenIdeaProjectTask.class, t -> {
t.setDescription("Generates an IntelliJ IDEA workspace from this project.");
t.dependsOn("idea", "downloadAssets");
t.setGroup("ide");
});
tasks.register("genEclipseRuns", GenEclipseRunsTask.class, t -> {
t.setDescription("Generates Eclipse run configurations for this project.");
t.dependsOn("downloadAssets");
t.setGroup("ide");
});
tasks.register("cleanEclipseRuns", CleanEclipseRunsTask.class, t -> {
t.setDescription("Removes Eclipse run configurations for this project.");
t.setGroup("ide");
});
tasks.register("vscode", GenVsCodeProjectTask.class, t -> {
t.setDescription("Generates VSCode launch configurations.");
t.dependsOn("downloadAssets");
t.setGroup("ide");
});
tasks.register("remapSourcesJar", RemapSourcesJarTask.class, t -> t.setDescription("Remaps the project sources jar to intermediary names."));
tasks.register("runClient", RunClientTask.class, t -> {
t.setDescription("Starts a development version of the Minecraft client.");
t.dependsOn("downloadAssets");
t.setGroup("fabric");
});
tasks.register("runServer", RunServerTask.class, t -> {
t.setDescription("Starts a development version of the Minecraft server.");
t.setGroup("fabric");
});
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
extension.addDecompiler(new FabricFernFlowerDecompiler(project));
extension.addDecompiler(new FabricCFRDecompiler(project));
project.afterEvaluate((p) -> {
for (LoomDecompiler decompiler : extension.decompilers) {
String taskName = (decompiler instanceof FabricFernFlowerDecompiler) ? "genSources" : "genSourcesWith" + decompiler.name();
// decompiler will be passed to the constructor of GenerateSourcesTask
tasks.register(taskName, GenerateSourcesTask.class, decompiler);
}
});
} }
} }

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.build;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.build;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.build;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -45,8 +45,12 @@ import org.gradle.jvm.JvmLibrary;
import org.gradle.language.base.artifact.SourcesArtifact; import org.gradle.language.base.artifact.SourcesArtifact;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.processors.dependency.ModDependencyInfo; import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
import net.fabricmc.loom.processors.dependency.RemapData; import net.fabricmc.loom.configuration.mods.ModProcessor;
import net.fabricmc.loom.configuration.processors.dependency.ModDependencyInfo;
import net.fabricmc.loom.configuration.processors.dependency.RemapData;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.SourceRemapper;
public class ModCompileRemapper { public class ModCompileRemapper {
public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, SourceRemapper sourceRemapper) { public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, SourceRemapper sourceRemapper) {

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.build;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -41,24 +41,25 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.gradle.api.artifacts.ResolvedConfiguration; import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ProjectDependency; import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.DependencySet; import org.gradle.api.artifacts.ResolvedConfiguration;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.zeroturnaround.zip.FileSource; import org.zeroturnaround.zip.FileSource;
import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.transform.StringZipEntryTransformer; import org.zeroturnaround.zip.transform.StringZipEntryTransformer;
import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.task.RemapJarTask; import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.util.Constants;
public class NestedJars { public class NestedJars {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.mixin; package net.fabricmc.loom.build.mixin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.mixin; package net.fabricmc.loom.build.mixin;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.mixin; package net.fabricmc.loom.build.mixin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.mixin; package net.fabricmc.loom.build.mixin;
import java.io.File; import java.io.File;

View File

@ -22,93 +22,50 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom; package net.fabricmc.loom.configuration;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import com.google.common.collect.ImmutableMap;
import groovy.util.Node;
import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task; import org.gradle.api.Task;
import org.gradle.api.UnknownTaskException; import org.gradle.api.UnknownTaskException;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ExcludeRule;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.publish.Publication;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.bundling.AbstractArchiveTask; import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.api.tasks.javadoc.Javadoc; import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.plugins.ide.idea.model.IdeaModel;
import net.fabricmc.loom.providers.LaunchProvider; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsCache; import net.fabricmc.loom.build.JarRemapper;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.build.NestedJars;
import net.fabricmc.loom.providers.MinecraftProvider; import net.fabricmc.loom.build.mixin.JavaApInvoker;
import net.fabricmc.loom.build.mixin.KaptApInvoker;
import net.fabricmc.loom.build.mixin.ScalaApInvoker;
import net.fabricmc.loom.configuration.ide.SetupIntelijRunConfigs;
import net.fabricmc.loom.configuration.providers.LaunchProvider;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.task.AbstractLoomTask; import net.fabricmc.loom.task.AbstractLoomTask;
import net.fabricmc.loom.task.RemapAllSourcesTask;
import net.fabricmc.loom.task.RemapJarTask; import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJarTask; import net.fabricmc.loom.task.RemapSourcesJarTask;
import net.fabricmc.loom.task.RemapAllSourcesTask;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.FabricApiExtension;
import net.fabricmc.loom.util.GroovyXmlUtil;
import net.fabricmc.loom.util.LoomDependencyManager;
import net.fabricmc.loom.util.NestedJars;
import net.fabricmc.loom.util.RemappedConfigurationEntry;
import net.fabricmc.loom.util.SetupIntelijRunConfigs;
import net.fabricmc.loom.util.mixin.JavaApInvoker;
import net.fabricmc.loom.util.mixin.KaptApInvoker;
import net.fabricmc.loom.util.mixin.ScalaApInvoker;
import net.fabricmc.loom.util.SourceRemapper; import net.fabricmc.loom.util.SourceRemapper;
import net.fabricmc.loom.util.JarRemapper;
public class AbstractPlugin implements Plugin<Project> { /**
protected Project project; * Add Minecraft dependencies to compile time.
*/
public static boolean isRootProject(Project project) { public final class CompileConfiguration {
return project.getRootProject() == project; private CompileConfiguration() {
} }
private void extendsFrom(String a, String b) { public static void setupConfigurations(Project project) {
project.getConfigurations().getByName(a).extendsFrom(project.getConfigurations().getByName(b));
}
@Override
public void apply(Project target) {
this.project = target;
project.getLogger().lifecycle("Fabric Loom: " + AbstractPlugin.class.getPackage().getImplementationVersion());
boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies();
DownloadUtil.refreshDeps = refreshDeps;
if (refreshDeps) {
MappingsCache.INSTANCE.invalidate();
project.getLogger().lifecycle("Refresh dependencies is in use, loom will be significantly slower.");
}
// Apply default plugins
project.apply(ImmutableMap.of("plugin", "java"));
project.apply(ImmutableMap.of("plugin", "eclipse"));
project.apply(ImmutableMap.of("plugin", "idea"));
project.getExtensions().create("minecraft", LoomGradleExtension.class, project);
project.getExtensions().add("loom", project.getExtensions().getByName("minecraft"));
project.getExtensions().create("fabricApi", FabricApiExtension.class, project);
// Force add Mojang repository // Force add Mojang repository
addMavenRepo(target, "Mojang", "https://libraries.minecraft.net/"); addMavenRepo(project, "Mojang", "https://libraries.minecraft.net/");
Configuration modCompileClasspathConfig = project.getConfigurations().maybeCreate(Constants.Configurations.MOD_COMPILE_CLASSPATH); Configuration modCompileClasspathConfig = project.getConfigurations().maybeCreate(Constants.Configurations.MOD_COMPILE_CLASSPATH);
modCompileClasspathConfig.setTransitive(true); modCompileClasspathConfig.setTransitive(true);
@ -136,31 +93,23 @@ public class AbstractPlugin implements Plugin<Project> {
Configuration compileModsMappedConfig = project.getConfigurations().maybeCreate(entry.getRemappedConfiguration()); Configuration compileModsMappedConfig = project.getConfigurations().maybeCreate(entry.getRemappedConfiguration());
compileModsMappedConfig.setTransitive(false); // Don't get transitive deps of already remapped mods compileModsMappedConfig.setTransitive(false); // Don't get transitive deps of already remapped mods
extendsFrom(entry.getTargetConfiguration(project.getConfigurations()), entry.getRemappedConfiguration()); extendsFrom(entry.getTargetConfiguration(project.getConfigurations()), entry.getRemappedConfiguration(), project);
if (entry.isOnModCompileClasspath()) { if (entry.isOnModCompileClasspath()) {
extendsFrom(Constants.Configurations.MOD_COMPILE_CLASSPATH, entry.getSourceConfiguration()); extendsFrom(Constants.Configurations.MOD_COMPILE_CLASSPATH, entry.getSourceConfiguration(), project);
extendsFrom(Constants.Configurations.MOD_COMPILE_CLASSPATH_MAPPED, entry.getRemappedConfiguration()); extendsFrom(Constants.Configurations.MOD_COMPILE_CLASSPATH_MAPPED, entry.getRemappedConfiguration(), project);
} }
} }
extendsFrom("compileClasspath", Constants.Configurations.MINECRAFT_NAMED); extendsFrom(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME, Constants.Configurations.MINECRAFT_NAMED, project);
extendsFrom("runtimeClasspath", Constants.Configurations.MINECRAFT_NAMED); extendsFrom(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME, Constants.Configurations.MINECRAFT_NAMED, project);
extendsFrom("testCompileClasspath", Constants.Configurations.MINECRAFT_NAMED); extendsFrom(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, Constants.Configurations.MINECRAFT_NAMED, project);
extendsFrom("testRuntimeClasspath", Constants.Configurations.MINECRAFT_NAMED); extendsFrom(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME, Constants.Configurations.MINECRAFT_NAMED, project);
extendsFrom(Constants.Configurations.LOADER_DEPENDENCIES, Constants.Configurations.MINECRAFT_DEPENDENCIES); extendsFrom(Constants.Configurations.LOADER_DEPENDENCIES, Constants.Configurations.MINECRAFT_DEPENDENCIES, project);
extendsFrom(Constants.Configurations.MINECRAFT_NAMED, Constants.Configurations.LOADER_DEPENDENCIES); extendsFrom(Constants.Configurations.MINECRAFT_NAMED, Constants.Configurations.LOADER_DEPENDENCIES, project);
extendsFrom("compile", Constants.Configurations.MAPPINGS_FINAL); extendsFrom(JavaPlugin.COMPILE_CONFIGURATION_NAME, Constants.Configurations.MAPPINGS_FINAL, project);
configureIDEs();
configureCompile();
configureMaven();
}
public Project getProject() {
return project;
} }
/** /**
@ -171,30 +120,14 @@ public class AbstractPlugin implements Plugin<Project> {
* @param url The URL of the repository * @param url The URL of the repository
* @return An object containing the name and the URL of the repository that can be modified later * @return An object containing the name and the URL of the repository that can be modified later
*/ */
public MavenArtifactRepository addMavenRepo(Project target, final String name, final String url) { public static MavenArtifactRepository addMavenRepo(Project target, final String name, final String url) {
return target.getRepositories().maven(repo -> { return target.getRepositories().maven(repo -> {
repo.setName(name); repo.setName(name);
repo.setUrl(url); repo.setUrl(url);
}); });
} }
/** public static void configureCompile(Project project) {
* Add Minecraft dependencies to IDE dependencies.
*/
protected void configureIDEs() {
// IDEA
IdeaModel ideaModel = (IdeaModel) project.getExtensions().getByName("idea");
ideaModel.getModule().getExcludeDirs().addAll(project.files(".gradle", "build", ".idea", "out").getFiles());
ideaModel.getModule().setDownloadJavadoc(true);
ideaModel.getModule().setDownloadSources(true);
ideaModel.getModule().setInheritOutputDirs(true);
}
/**
* Add Minecraft dependencies to compile time.
*/
protected void configureCompile() {
JavaPluginConvention javaModule = (JavaPluginConvention) project.getConvention().getPlugins().get("java"); JavaPluginConvention javaModule = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
@ -231,9 +164,9 @@ public class AbstractPlugin implements Plugin<Project> {
LoomDependencyManager dependencyManager = new LoomDependencyManager(); LoomDependencyManager dependencyManager = new LoomDependencyManager();
extension.setDependencyManager(dependencyManager); extension.setDependencyManager(dependencyManager);
dependencyManager.addProvider(new MinecraftProvider(getProject())); dependencyManager.addProvider(new MinecraftProvider(project));
dependencyManager.addProvider(new MappingsProvider(getProject())); dependencyManager.addProvider(new MappingsProvider(project));
dependencyManager.addProvider(new LaunchProvider(getProject())); dependencyManager.addProvider(new LaunchProvider(project));
dependencyManager.handleDependencies(project1); dependencyManager.handleDependencies(project1);
@ -365,66 +298,7 @@ public class AbstractPlugin implements Plugin<Project> {
} }
} }
protected void configureMaven() { private static void extendsFrom(String a, String b, Project project) {
project.afterEvaluate((p) -> { project.getConfigurations().getByName(a).extendsFrom(project.getConfigurations().getByName(b));
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
if (!entry.hasMavenScope()) {
continue;
}
Configuration compileModsConfig = p.getConfigurations().getByName(entry.getSourceConfiguration());
// add modsCompile to maven-publish
PublishingExtension mavenPublish = p.getExtensions().findByType(PublishingExtension.class);
if (mavenPublish != null) {
mavenPublish.publications((publications) -> {
for (Publication publication : publications) {
if (publication instanceof MavenPublication) {
((MavenPublication) publication).pom((pom) -> pom.withXml((xml) -> {
Node dependencies = GroovyXmlUtil.getOrCreateNode(xml.asNode(), "dependencies");
Set<String> foundArtifacts = new HashSet<>();
GroovyXmlUtil.childrenNodesStream(dependencies).filter((n) -> "dependency".equals(n.name())).forEach((n) -> {
Optional<Node> groupId = GroovyXmlUtil.getNode(n, "groupId");
Optional<Node> artifactId = GroovyXmlUtil.getNode(n, "artifactId");
if (groupId.isPresent() && artifactId.isPresent()) {
foundArtifacts.add(groupId.get().text() + ":" + artifactId.get().text());
}
});
for (Dependency dependency : compileModsConfig.getAllDependencies()) {
if (foundArtifacts.contains(dependency.getGroup() + ":" + dependency.getName())) {
continue;
}
Node depNode = dependencies.appendNode("dependency");
depNode.appendNode("groupId", dependency.getGroup());
depNode.appendNode("artifactId", dependency.getName());
depNode.appendNode("version", dependency.getVersion());
depNode.appendNode("scope", entry.getMavenScope());
if (dependency instanceof ModuleDependency) {
final Set<ExcludeRule> exclusions = ((ModuleDependency) dependency).getExcludeRules();
if (!exclusions.isEmpty()) {
Node exclusionsNode = depNode.appendNode("exclusions");
for (ExcludeRule rule : exclusions) {
Node exclusionNode = exclusionsNode.appendNode("exclusion");
exclusionNode.appendNode("groupId", rule.getGroup() == null ? "*" : rule.getGroup());
exclusionNode.appendNode("artifactId", rule.getModule() == null ? "*" : rule.getModule());
}
}
}
}
}));
}
}
});
}
}
});
} }
} }

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -40,6 +40,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.DownloadUtil;
public class FabricApiExtension { public class FabricApiExtension {
private final Project project; private final Project project;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -39,8 +39,12 @@ import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.build.ModCompileRemapper;
import net.fabricmc.loom.util.DependencyProvider.DependencyInfo; import net.fabricmc.loom.configuration.DependencyProvider.DependencyInfo;
import net.fabricmc.loom.configuration.mods.ModProcessor;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.SourceRemapper;
public class LoomDependencyManager { public class LoomDependencyManager {
private static class ProviderList { private static class ProviderList {

View File

@ -0,0 +1,119 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.configuration;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import groovy.util.Node;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ExcludeRule;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.publish.Publication;
import org.gradle.api.publish.PublishingExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.GroovyXmlUtil;
public final class MavenPublication {
private MavenPublication() {
}
public static void configure(Project project) {
project.afterEvaluate((p) -> {
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
if (!entry.hasMavenScope()) {
continue;
}
Configuration compileModsConfig = p.getConfigurations().getByName(entry.getSourceConfiguration());
// add modsCompile to maven-publish
PublishingExtension mavenPublish = p.getExtensions().findByType(PublishingExtension.class);
if (mavenPublish != null) {
processEntry(entry, compileModsConfig, mavenPublish);
}
}
});
}
private static void processEntry(RemappedConfigurationEntry entry, Configuration compileModsConfig, PublishingExtension mavenPublish) {
mavenPublish.publications((publications) -> {
for (Publication publication : publications) {
if (!(publication instanceof org.gradle.api.publish.maven.MavenPublication)) {
continue;
}
((org.gradle.api.publish.maven.MavenPublication) publication).pom((pom) -> pom.withXml((xml) -> {
Node dependencies = GroovyXmlUtil.getOrCreateNode(xml.asNode(), "dependencies");
Set<String> foundArtifacts = new HashSet<>();
GroovyXmlUtil.childrenNodesStream(dependencies).filter((n) -> "dependency".equals(n.name())).forEach((n) -> {
Optional<Node> groupId = GroovyXmlUtil.getNode(n, "groupId");
Optional<Node> artifactId = GroovyXmlUtil.getNode(n, "artifactId");
if (groupId.isPresent() && artifactId.isPresent()) {
foundArtifacts.add(groupId.get().text() + ":" + artifactId.get().text());
}
});
for (Dependency dependency : compileModsConfig.getAllDependencies()) {
if (foundArtifacts.contains(dependency.getGroup() + ":" + dependency.getName())) {
continue;
}
Node depNode = dependencies.appendNode("dependency");
depNode.appendNode("groupId", dependency.getGroup());
depNode.appendNode("artifactId", dependency.getName());
depNode.appendNode("version", dependency.getVersion());
depNode.appendNode("scope", entry.getMavenScope());
if (!(dependency instanceof ModuleDependency)) {
continue;
}
final Set<ExcludeRule> exclusions = ((ModuleDependency) dependency).getExcludeRules();
if (exclusions.isEmpty()) {
continue;
}
Node exclusionsNode = depNode.appendNode("exclusions");
for (ExcludeRule rule : exclusions) {
Node exclusionNode = exclusionsNode.appendNode("exclusion");
exclusionNode.appendNode("groupId", rule.getGroup() == null ? "*" : rule.getGroup());
exclusionNode.appendNode("artifactId", rule.getModule() == null ? "*" : rule.getModule());
}
}
}));
}
});
}
}

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration;
import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.ConfigurationContainer;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.accesswidener; package net.fabricmc.loom.configuration.accesswidener;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -48,14 +48,14 @@ import org.zeroturnaround.zip.transform.ZipEntryTransformer;
import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
import net.fabricmc.accesswidener.AccessWidener; import net.fabricmc.accesswidener.AccessWidener;
import net.fabricmc.accesswidener.AccessWidenerRemapper;
import net.fabricmc.accesswidener.AccessWidenerReader; import net.fabricmc.accesswidener.AccessWidenerReader;
import net.fabricmc.accesswidener.AccessWidenerRemapper;
import net.fabricmc.accesswidener.AccessWidenerVisitor; import net.fabricmc.accesswidener.AccessWidenerVisitor;
import net.fabricmc.accesswidener.AccessWidenerWriter; import net.fabricmc.accesswidener.AccessWidenerWriter;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.processors.JarProcessor; import net.fabricmc.loom.configuration.processors.JarProcessor;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.util.Checksum;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper;
public class AccessWidenerJarProcessor implements JarProcessor { public class AccessWidenerJarProcessor implements JarProcessor {

View File

@ -0,0 +1,42 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.configuration.ide;
import org.gradle.api.Project;
import org.gradle.plugins.ide.idea.model.IdeaModel;
public final class IdeConfiguration {
private IdeConfiguration() {
}
public static void setup(Project project) {
IdeaModel ideaModel = (IdeaModel) project.getExtensions().getByName("idea");
ideaModel.getModule().getExcludeDirs().addAll(project.files(".gradle", "build", ".idea", "out").getFiles());
ideaModel.getModule().setDownloadJavadoc(true);
ideaModel.getModule().setDownloadSources(true);
ideaModel.getModule().setInheritOutputDirs(true);
}
}

View File

@ -22,9 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration.ide;
import static net.fabricmc.loom.AbstractPlugin.isRootProject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -41,13 +39,15 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.gradle.api.Project;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.gradle.api.Project;
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.OperatingSystem;
public class RunConfig { public class RunConfig {
public String configName; public String configName;
@ -105,7 +105,7 @@ public class RunConfig {
} }
private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String mode) { private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String mode) {
runConfig.configName += isRootProject(project) ? "" : " (" + project.getPath() + ")"; runConfig.configName += extension.isRootProject() ? "" : " (" + project.getPath() + ")";
runConfig.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName(); runConfig.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName();
runConfig.ideaModuleName = getIdeaModuleName(project); runConfig.ideaModuleName = getIdeaModuleName(project);
runConfig.runDir = "file://$PROJECT_DIR$/" + extension.runDir; runConfig.runDir = "file://$PROJECT_DIR$/" + extension.runDir;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration.ide;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -32,8 +32,8 @@ import org.apache.commons.io.FileUtils;
import org.gradle.api.Project; import org.gradle.api.Project;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftAssetsProvider; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftNativesProvider;
import net.fabricmc.loom.providers.MinecraftNativesProvider; import net.fabricmc.loom.configuration.providers.minecraft.assets.MinecraftAssetsProvider;
public class SetupIntelijRunConfigs { public class SetupIntelijRunConfigs {
public static void setup(Project project) { public static void setup(Project project) {

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration.mods;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -56,12 +56,15 @@ import net.fabricmc.accesswidener.AccessWidenerReader;
import net.fabricmc.accesswidener.AccessWidenerRemapper; import net.fabricmc.accesswidener.AccessWidenerRemapper;
import net.fabricmc.accesswidener.AccessWidenerWriter; import net.fabricmc.accesswidener.AccessWidenerWriter;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
import net.fabricmc.loom.providers.MinecraftMappedProvider; import net.fabricmc.loom.configuration.processors.dependency.ModDependencyInfo;
import net.fabricmc.loom.processors.dependency.ModDependencyInfo; import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
import net.fabricmc.tinyremapper.InputTag; import net.fabricmc.tinyremapper.InputTag;
import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
public class ModProcessor { public class ModProcessor {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
@ -202,7 +205,7 @@ public class ModProcessor {
} }
} }
static JsonObject readInstallerJson(File file, Project project) { public static JsonObject readInstallerJson(File file, Project project) {
try { try {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
String launchMethod = extension.getLoaderLaunchMethod(); String launchMethod = extension.getLoaderLaunchMethod();

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.processors; package net.fabricmc.loom.configuration.processors;
import java.io.File; import java.io.File;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.processors; package net.fabricmc.loom.configuration.processors;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.processors; package net.fabricmc.loom.configuration.processors;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -31,9 +31,9 @@ import java.util.function.Consumer;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.gradle.api.Project; import org.gradle.api.Project;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider; import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftProvider; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
public class MinecraftProcessedProvider extends MinecraftMappedProvider { public class MinecraftProcessedProvider extends MinecraftMappedProvider {

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.processors.dependency; package net.fabricmc.loom.configuration.processors.dependency;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -37,7 +37,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import net.fabricmc.loom.util.ModProcessor; import net.fabricmc.loom.configuration.mods.ModProcessor;
public class ModDependencyInfo { public class ModDependencyInfo {
private final String group; private final String group;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.processors.dependency; package net.fabricmc.loom.configuration.processors.dependency;
import java.io.File; import java.io.File;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -42,9 +42,9 @@ import org.apache.commons.io.FileUtils;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import net.fabricmc.loom.configuration.DependencyProvider;
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DependencyProvider;
import net.fabricmc.loom.util.RemappedConfigurationEntry;
public class LaunchProvider extends DependencyProvider { public class LaunchProvider extends DependencyProvider {
public Dependency annotationDependency; public Dependency annotationDependency;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@ -40,11 +40,12 @@ import org.gradle.api.GradleException;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logger;
import net.fabricmc.loom.configuration.DependencyProvider;
import net.fabricmc.loom.configuration.providers.minecraft.ManifestVersion;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftLibraryProvider;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionInfo;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DependencyProvider;
import net.fabricmc.loom.util.DownloadUtil; import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.ManifestVersion;
import net.fabricmc.loom.util.MinecraftVersionInfo;
import net.fabricmc.loom.util.StaticPathWatcher; import net.fabricmc.loom.util.StaticPathWatcher;
import net.fabricmc.stitch.merge.JarMerger; import net.fabricmc.stitch.merge.JarMerger;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers.mappings;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers.mappings;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -46,13 +46,15 @@ import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.processors.JarProcessorManager; import net.fabricmc.loom.configuration.DependencyProvider;
import net.fabricmc.loom.processors.MinecraftProcessedProvider; import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.configuration.processors.JarProcessorManager;
import net.fabricmc.loom.configuration.processors.MinecraftProcessedProvider;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DeletingFileVisitor; import net.fabricmc.loom.util.DeletingFileVisitor;
import net.fabricmc.loom.util.DependencyProvider;
import net.fabricmc.loom.util.DownloadUtil; import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.mapping.reader.v2.TinyV2Factory; import net.fabricmc.mapping.reader.v2.TinyV2Factory;
import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.stitch.Command; import net.fabricmc.stitch.Command;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.mappings; package net.fabricmc.loom.configuration.providers.mappings;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -54,8 +54,8 @@ import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionInfo;
import net.fabricmc.loom.util.DownloadUtil; import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.MinecraftVersionInfo;
import net.fabricmc.lorenztiny.TinyMappingsReader; import net.fabricmc.lorenztiny.TinyMappingsReader;
import net.fabricmc.mapping.tree.TinyMappingFactory; import net.fabricmc.mapping.tree.TinyMappingFactory;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration.providers.minecraft;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -22,15 +22,15 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers.minecraft;
import java.io.File; import java.io.File;
import org.gradle.api.Project; import org.gradle.api.Project;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.MinecraftVersionInfo;
public class MinecraftLibraryProvider { public class MinecraftLibraryProvider {
public File MINECRAFT_LIBS; public File MINECRAFT_LIBS;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers.minecraft;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -34,11 +34,13 @@ import java.util.function.Consumer;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.gradle.api.Project; import org.gradle.api.Project;
import net.fabricmc.loom.configuration.DependencyProvider;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.TinyRemapperMappingsHelper; import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DependencyProvider;
public class MinecraftMappedProvider extends DependencyProvider { public class MinecraftMappedProvider extends DependencyProvider {
private static final Map<String, String> JSR_TO_JETBRAINS = new ImmutableMap.Builder<String, String>() private static final Map<String, String> JSR_TO_JETBRAINS = new ImmutableMap.Builder<String, String>()

View File

@ -22,19 +22,19 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers.minecraft;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import org.gradle.api.GradleException; import org.gradle.api.GradleException;
import org.zeroturnaround.zip.ZipUtil;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.util.DownloadUtil; import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.MinecraftVersionInfo;
public class MinecraftNativesProvider { public class MinecraftNativesProvider {
public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException { public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.configuration.providers.minecraft;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -31,6 +31,9 @@ import java.util.Map;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.OperatingSystem;
public class MinecraftVersionInfo { public class MinecraftVersionInfo {
public List<Library> libraries; public List<Library> libraries;
public Map<String, Downloads> downloads; public Map<String, Downloads> downloads;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.assets; package net.fabricmc.loom.configuration.providers.minecraft.assets;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.assets; package net.fabricmc.loom.configuration.providers.minecraft.assets;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class AssetObject { public class AssetObject {

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.providers; package net.fabricmc.loom.configuration.providers.minecraft.assets;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@ -40,13 +40,12 @@ import org.gradle.api.GradleException;
import org.gradle.api.Project; import org.gradle.api.Project;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionInfo;
import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.util.Checksum;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DownloadUtil; import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.MinecraftVersionInfo; import net.fabricmc.loom.util.gradle.ProgressLogger;
import net.fabricmc.loom.util.assets.AssetIndex;
import net.fabricmc.loom.util.assets.AssetObject;
import net.fabricmc.loom.util.progress.ProgressLogger;
public class MinecraftAssetsProvider { public class MinecraftAssetsProvider {
public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException { public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {

View File

@ -0,0 +1,42 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.decompilers;
import org.gradle.api.Project;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.decompilers.cfr.FabricCFRDecompiler;
import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler;
public final class DecompilerConfiguration {
private DecompilerConfiguration() {
}
public static void setup(Project project) {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
extension.addDecompiler(new FabricFernFlowerDecompiler(project));
extension.addDecompiler(new FabricCFRDecompiler(project));
}
}

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.decompilers;
import static java.text.MessageFormat.format; import static java.text.MessageFormat.format;
@ -46,7 +46,8 @@ import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import net.fabricmc.loom.util.progress.ProgressLogger; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.gradle.ProgressLogger;
/** /**
* TODO, Move to stitch. * TODO, Move to stitch.

View File

@ -35,7 +35,7 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.JavaExec;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
public abstract class AbstractRunTask extends JavaExec { public abstract class AbstractRunTask extends JavaExec {
private final Function<Project, RunConfig> configProvider; private final Function<Project, RunConfig> configProvider;

View File

@ -1,49 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.task;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.LoomGradleExtension;
public class CleanLoomBinaries extends AbstractLoomTask {
@TaskAction
public void run() {
LoomGradleExtension extension = getExtension();
extension.getMinecraftProvider().getMergedJar().delete();
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
extension.getMinecraftMappedProvider().getMappedJar().delete();
try {
FileUtils.deleteDirectory(extension.getNativesDirectory());
FileUtils.deleteDirectory(extension.getNativesJarStore());
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,49 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.task;
import java.io.IOException;
import java.nio.file.Files;
import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.DeletingFileVisitor;
public class CleanLoomMappings extends AbstractLoomTask {
@TaskAction
public void run() {
try {
LoomGradleExtension extension = getExtension();
extension.getMappingsProvider().clean();
extension.getMinecraftMappedProvider().getIntermediaryJar().delete();
extension.getMinecraftMappedProvider().getMappedJar().delete();
Files.walkFileTree(extension.getRootProjectBuildCache().toPath(), new DeletingFileVisitor());
getExtension().getMappingsProvider().cleanFiles();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -30,8 +30,8 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftAssetsProvider; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftNativesProvider;
import net.fabricmc.loom.providers.MinecraftNativesProvider; import net.fabricmc.loom.configuration.providers.minecraft.assets.MinecraftAssetsProvider;
public class DownloadAssetsTask extends AbstractLoomTask { public class DownloadAssetsTask extends AbstractLoomTask {
@TaskAction @TaskAction

View File

@ -32,7 +32,7 @@ import org.apache.commons.io.FileUtils;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
import org.gradle.plugins.ide.eclipse.model.EclipseModel; import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import net.fabricmc.loom.util.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
public class GenEclipseRunsTask extends AbstractLoomTask { public class GenEclipseRunsTask extends AbstractLoomTask {
@TaskAction @TaskAction

View File

@ -37,28 +37,28 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.AbstractPlugin;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
public class GenIdeaProjectTask extends AbstractLoomTask { public class GenIdeaProjectTask extends AbstractLoomTask {
@TaskAction @TaskAction
public void genIdeaRuns() throws IOException, ParserConfigurationException, SAXException, TransformerException { public void genIdeaRuns() throws IOException, ParserConfigurationException, SAXException, TransformerException {
Project project = this.getProject(); Project project = this.getProject();
LoomGradleExtension extension = getExtension();
// Only generate the idea runs on the root project // Only generate the idea runs on the root project
if (!AbstractPlugin.isRootProject(project)) { if (!extension.isRootProject()) {
return; return;
} }
LoomGradleExtension extension = getExtension();
project.getLogger().lifecycle(":Building idea workspace"); project.getLogger().lifecycle(":Building idea workspace");
File file = project.file(project.getName() + ".iws"); File file = project.file(project.getName() + ".iws");

View File

@ -37,7 +37,7 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
// Recommended vscode plugins: // Recommended vscode plugins:
// https://marketplace.visualstudio.com/items?itemName=redhat.java // https://marketplace.visualstudio.com/items?itemName=redhat.java

View File

@ -30,18 +30,20 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.Collection; import java.util.Collection;
import java.util.Locale;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.api.decompilers.DecompilationMetadata; import net.fabricmc.loom.api.decompilers.DecompilationMetadata;
import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.util.LineNumberRemapper; import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.progress.ProgressLogger; import net.fabricmc.loom.decompilers.LineNumberRemapper;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.gradle.ProgressLogger;
import net.fabricmc.stitch.util.StitchUtil; import net.fabricmc.stitch.util.StitchUtil;
public class GenerateSourcesTask extends AbstractLoomTask { public class GenerateSourcesTask extends AbstractLoomTask {
@ -64,18 +66,18 @@ public class GenerateSourcesTask extends AbstractLoomTask {
DecompilationMetadata metadata = new DecompilationMetadata(threads, javaDocs, libraries); DecompilationMetadata metadata = new DecompilationMetadata(threads, javaDocs, libraries);
Path compiledJar = getExtension().getMappingsProvider().mappedProvider.getMappedJar().toPath(); Path compiledJar = getExtension().getMappingsProvider().mappedProvider.getMappedJar().toPath();
Path sourcesDestination = LoomGradlePlugin.getMappedByproduct(getProject(), "-sources.jar").toPath(); Path sourcesDestination = getMappedJarFileWithSuffix("-sources.jar").toPath();
Path linemap = LoomGradlePlugin.getMappedByproduct(getProject(), "-sources.lmap").toPath(); Path linemap = getMappedJarFileWithSuffix("-sources.lmap").toPath();
decompiler.decompile(compiledJar, sourcesDestination, linemap, metadata); decompiler.decompile(compiledJar, sourcesDestination, linemap, metadata);
if (Files.exists(linemap)) { if (Files.exists(linemap)) {
Path linemappedJarDestination = LoomGradlePlugin.getMappedByproduct(getProject(), "-linemapped.jar").toPath(); Path linemappedJarDestination = getMappedJarFileWithSuffix("-linemapped.jar").toPath();
remapLineNumbers(compiledJar, linemap, linemappedJarDestination); remapLineNumbers(compiledJar, linemap, linemappedJarDestination);
// In order for IDEs to recognize the new line mappings, we need to overwrite the existing compiled jar // In order for IDEs to recognize the new line mappings, we need to overwrite the existing compiled jar
// with the linemapped one. In the name of not destroying the existing jar, we will copy it to somewhere else. // with the linemapped one. In the name of not destroying the existing jar, we will copy it to somewhere else.
Path unlinemappedJar = LoomGradlePlugin.getMappedByproduct(getProject(), "-unlinemapped.jar").toPath(); Path unlinemappedJar = getMappedJarFileWithSuffix("-unlinemapped.jar").toPath();
// The second time genSources is ran, we want to keep the existing unlinemapped jar. // The second time genSources is ran, we want to keep the existing unlinemapped jar.
if (!Files.exists(unlinemappedJar)) { if (!Files.exists(unlinemappedJar)) {
@ -92,7 +94,7 @@ public class GenerateSourcesTask extends AbstractLoomTask {
LineNumberRemapper remapper = new LineNumberRemapper(); LineNumberRemapper remapper = new LineNumberRemapper();
remapper.readMappings(linemap.toFile()); remapper.readMappings(linemap.toFile());
ProgressLogger progressLogger = net.fabricmc.loom.util.progress.ProgressLogger.getProgressFactory(getProject(), getClass().getName()); ProgressLogger progressLogger = ProgressLogger.getProgressFactory(getProject(), getClass().getName());
progressLogger.start("Adjusting line numbers", "linemap"); progressLogger.start("Adjusting line numbers", "linemap");
try (StitchUtil.FileSystemDelegate inFs = StitchUtil.getJarFileSystem(oldCompiledJar.toFile(), true); try (StitchUtil.FileSystemDelegate inFs = StitchUtil.getJarFileSystem(oldCompiledJar.toFile(), true);
@ -102,4 +104,17 @@ public class GenerateSourcesTask extends AbstractLoomTask {
progressLogger.completed(); progressLogger.completed();
} }
private File getMappedJarFileWithSuffix(String suffix) {
LoomGradleExtension extension = getProject().getExtensions().getByType(LoomGradleExtension.class);
MappingsProvider mappingsProvider = extension.getMappingsProvider();
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
String path = mappedJar.getAbsolutePath();
if (!path.toLowerCase(Locale.ROOT).endsWith(".jar")) {
throw new RuntimeException("Invalid mapped JAR path: " + path);
}
return new File(path.substring(0, path.length() - 4) + suffix);
}
} }

View File

@ -0,0 +1,108 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.task;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskContainer;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler;
public final class LoomTasks {
private LoomTasks() {
}
public static void registerTasks(Project project) {
TaskContainer tasks = project.getTasks();
tasks.register("migrateMappings", MigrateMappingsTask.class, t -> {
t.setDescription("Migrates mappings to a new version.");
t.getOutputs().upToDateWhen((o) -> false);
});
tasks.register("remapJar", RemapJarTask.class, t -> {
t.setDescription("Remaps the built project jar to intermediary mappings.");
t.setGroup("fabric");
});
tasks.register("downloadAssets", DownloadAssetsTask.class, t -> t.setDescription("Downloads required assets for Fabric."));
tasks.register("remapSourcesJar", RemapSourcesJarTask.class, t -> t.setDescription("Remaps the project sources jar to intermediary names."));
registerIDETasks(tasks);
registerRunTasks(tasks);
registerDecompileTasks(tasks, project);
}
private static void registerIDETasks(TaskContainer tasks) {
tasks.register("genIdeaWorkspace", GenIdeaProjectTask.class, t -> {
t.setDescription("Generates an IntelliJ IDEA workspace from this project.");
t.dependsOn("idea", "downloadAssets");
t.setGroup("ide");
});
tasks.register("genEclipseRuns", GenEclipseRunsTask.class, t -> {
t.setDescription("Generates Eclipse run configurations for this project.");
t.dependsOn("downloadAssets");
t.setGroup("ide");
});
tasks.register("cleanEclipseRuns", CleanEclipseRunsTask.class, t -> {
t.setDescription("Removes Eclipse run configurations for this project.");
t.setGroup("ide");
});
tasks.register("vscode", GenVsCodeProjectTask.class, t -> {
t.setDescription("Generates VSCode launch configurations.");
t.dependsOn("downloadAssets");
t.setGroup("ide");
});
}
private static void registerRunTasks(TaskContainer tasks) {
tasks.register("runClient", RunClientTask.class, t -> {
t.setDescription("Starts a development version of the Minecraft client.");
t.dependsOn("downloadAssets");
t.setGroup("fabric");
});
tasks.register("runServer", RunServerTask.class, t -> {
t.setDescription("Starts a development version of the Minecraft server.");
t.setGroup("fabric");
});
}
private static void registerDecompileTasks(TaskContainer tasks, Project project) {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
project.afterEvaluate((p) -> {
for (LoomDecompiler decompiler : extension.getDecompilers()) {
String taskName = (decompiler instanceof FabricFernFlowerDecompiler) ? "genSources" : "genSourcesWith" + decompiler.name();
// decompiler will be passed to the constructor of GenerateSourcesTask
tasks.register(taskName, GenerateSourcesTask.class, decompiler);
}
});
}
}

View File

@ -49,10 +49,10 @@ import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option; import org.gradle.api.tasks.options.Option;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider; import net.fabricmc.loom.configuration.providers.mappings.MojangMappingsDependency;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
import net.fabricmc.loom.util.SourceRemapper; import net.fabricmc.loom.util.SourceRemapper;
import net.fabricmc.loom.util.mappings.MojangMappingsDependency;
import net.fabricmc.lorenztiny.TinyMappingsJoiner; import net.fabricmc.lorenztiny.TinyMappingsJoiner;
import net.fabricmc.mapping.tree.TinyMappingFactory; import net.fabricmc.mapping.tree.TinyMappingFactory;
import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.mapping.tree.TinyTree;

View File

@ -45,14 +45,14 @@ import org.gradle.jvm.tasks.Jar;
import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.build.JarRemapper;
import net.fabricmc.loom.util.GradleSupport; import net.fabricmc.loom.build.MixinRefmapHelper;
import net.fabricmc.loom.util.MixinRefmapHelper; import net.fabricmc.loom.build.NestedJars;
import net.fabricmc.loom.util.NestedJars; import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.TinyRemapperMappingsHelper; import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
import net.fabricmc.loom.util.ZipReprocessorUtil; import net.fabricmc.loom.util.ZipReprocessorUtil;
import net.fabricmc.loom.util.accesswidener.AccessWidenerJarProcessor; import net.fabricmc.loom.util.gradle.GradleSupport;
import net.fabricmc.loom.util.JarRemapper;
import net.fabricmc.stitch.util.Pair; import net.fabricmc.stitch.util.Pair;
import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper;

View File

@ -24,7 +24,7 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import net.fabricmc.loom.util.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
public class RunClientTask extends AbstractRunTask { public class RunClientTask extends AbstractRunTask {
public RunClientTask() { public RunClientTask() {

View File

@ -24,7 +24,7 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import net.fabricmc.loom.util.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
public class RunServerTask extends AbstractRunTask { public class RunServerTask extends AbstractRunTask {
public RunServerTask() { public RunServerTask() {

View File

@ -29,6 +29,8 @@ import java.util.List;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
public class Constants { public class Constants {
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/"; public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
public static final String RESOURCES_BASE = "http://resources.download.minecraft.net/"; public static final String RESOURCES_BASE = "http://resources.download.minecraft.net/";

View File

@ -35,9 +35,9 @@ import org.apache.commons.io.FileUtils;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logger;
public class DownloadUtil { import net.fabricmc.loom.LoomGradlePlugin;
public static boolean refreshDeps = false;
public class DownloadUtil {
/** /**
* Download from the given {@link URL} to the given {@link File} so long as there are differences between them. * Download from the given {@link URL} to the given {@link File} so long as there are differences between them.
* *
@ -62,7 +62,7 @@ public class DownloadUtil {
public static void downloadIfChanged(URL from, File to, Logger logger, boolean quiet) throws IOException { public static void downloadIfChanged(URL from, File to, Logger logger, boolean quiet) throws IOException {
HttpURLConnection connection = (HttpURLConnection) from.openConnection(); HttpURLConnection connection = (HttpURLConnection) from.openConnection();
if (refreshDeps) { if (LoomGradlePlugin.refreshDeps) {
getETagFile(to).delete(); getETagFile(to).delete();
to.delete(); to.delete();
} }

View File

@ -41,9 +41,10 @@ import org.gradle.api.artifacts.Dependency;
import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
import net.fabricmc.loom.providers.LaunchProvider; import net.fabricmc.loom.configuration.providers.LaunchProvider;
import net.fabricmc.loom.util.progress.ProgressLogger; import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.gradle.ProgressLogger;
import net.fabricmc.lorenztiny.TinyMappingsReader; import net.fabricmc.lorenztiny.TinyMappingsReader;
import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.stitch.util.StitchUtil; import net.fabricmc.stitch.util.StitchUtil;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util; package net.fabricmc.loom.util.gradle;
import java.lang.reflect.Method; import java.lang.reflect.Method;

View File

@ -22,7 +22,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package net.fabricmc.loom.util.progress; package net.fabricmc.loom.util.gradle;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;