aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net
diff options
context:
space:
mode:
authorLogicFan <38597904+LogicFan@users.noreply.github.com>2021-05-22 18:28:42 -0400
committerGitHub <noreply@github.com>2021-05-22 23:28:42 +0100
commite955ebb8c56378b166adbd440f237999a346099e (patch)
tree7effc5bfb093afdfceafb3410ae5de2f19417436 /src/main/java/net
parentde665ab4989bceb4ff323ebc0851ef781a0ef5de (diff)
downloadarchitectury-loom-e955ebb8c56378b166adbd440f237999a346099e.tar.gz
architectury-loom-e955ebb8c56378b166adbd440f237999a346099e.tar.bz2
architectury-loom-e955ebb8c56378b166adbd440f237999a346099e.zip
add support for new dependencyResolutionManagement (#400)
* move repo declartions - Move repository declartions in MavenConfiguration.java to LoomRepositoryPlugin.java * move repo declartions - Move repository declartions in MinecraftMappedProvider.java to LoomRepositoryPlugin.java * move repo declartions - Move repository declarations in MinecraftProcessedProvider.java to LoomRepositoryPlugin.java * do not add repositories if dependencyResolutionManagement is used * Simplify the change on LoomGradlePlugin - this is the suggestion from liach * change name to follow fabric naming convension - change getProjectUUID to getProjectUuid - change PROJECT_MAPPED_CLASSIFIER to projectMappedClassifier * remove MavenConfiguration.java - the file currently do nothing. * clean-up for all `instanceof` clause * add DependencyResolutionManagementTest * code cleanup * Update src/test/resources/projects/dependencyResolutionManagement/projmap/src/main/resources/modid.accesswidener * change project uuid to project full name Co-authored-by: modmuss50 <modmuss50@gmail.com>
Diffstat (limited to 'src/main/java/net')
-rw-r--r--src/main/java/net/fabricmc/loom/LoomGradlePlugin.java11
-rw-r--r--src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java200
-rw-r--r--src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java2
-rw-r--r--src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java5
-rw-r--r--src/main/java/net/fabricmc/loom/configuration/MavenConfiguration.java57
-rw-r--r--src/main/java/net/fabricmc/loom/configuration/processors/MinecraftProcessedProvider.java12
-rw-r--r--src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java2
7 files changed, 220 insertions, 69 deletions
diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
index 0a84bdfd..938def6b 100644
--- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
+++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
@@ -31,6 +31,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
+import org.gradle.api.plugins.PluginAware;
import net.fabricmc.loom.configuration.CompileConfiguration;
import net.fabricmc.loom.configuration.FabricApiExtension;
@@ -40,12 +41,20 @@ import net.fabricmc.loom.configuration.providers.mappings.MappingsCache;
import net.fabricmc.loom.decompilers.DecompilerConfiguration;
import net.fabricmc.loom.task.LoomTasks;
-public class LoomGradlePlugin implements Plugin<Project> {
+public class LoomGradlePlugin implements Plugin<PluginAware> {
public static boolean refreshDeps;
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@Override
+ public void apply(PluginAware target) {
+ target.getPlugins().apply(LoomRepositoryPlugin.class);
+
+ if (target instanceof Project project) {
+ apply(project);
+ }
+ }
+
public void apply(Project project) {
project.getLogger().lifecycle("Fabric Loom: " + LoomGradlePlugin.class.getPackage().getImplementationVersion());
diff --git a/src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java b/src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java
new file mode 100644
index 00000000..5d77c0da
--- /dev/null
+++ b/src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java
@@ -0,0 +1,200 @@
+/*
+ * 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;
+
+import java.io.File;
+
+import org.gradle.api.Plugin;
+import org.gradle.api.Project;
+import org.gradle.api.artifacts.dsl.RepositoryHandler;
+import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
+import org.gradle.api.initialization.Settings;
+import org.gradle.api.invocation.Gradle;
+import org.gradle.api.plugins.PluginAware;
+
+public class LoomRepositoryPlugin implements Plugin<PluginAware> {
+ @Override
+ public void apply(PluginAware target) {
+ RepositoryHandler repositories = null;
+
+ if (target instanceof Settings settings) {
+ repositories = settings.getDependencyResolutionManagement().getRepositories();
+
+ // leave a marker so projects don't try to override these
+ settings.getGradle().getPluginManager().apply(LoomRepositoryPlugin.class);
+ } else if (target instanceof Project project) {
+ if (project.getGradle().getPlugins().hasPlugin(LoomRepositoryPlugin.class)) {
+ return;
+ }
+
+ repositories = project.getRepositories();
+ } else if (target instanceof Gradle) {
+ return;
+ } else {
+ throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
+ }
+
+ Cache cache = new Cache(target);
+
+ // MavenConfiguration.java
+ repositories.flatDir(repo -> {
+ repo.setName("UserLocalCacheFiles");
+ repo.dir(cache.getRootBuildCache());
+ });
+ repositories.maven(repo -> {
+ repo.setName("UserLocalRemappedMods");
+ repo.setUrl(cache.getRemappedModCache());
+ });
+ repositories.maven(repo -> {
+ repo.setName("Fabric");
+ repo.setUrl("https://maven.fabricmc.net/");
+ });
+ repositories.maven(repo -> {
+ repo.setName("Mojang");
+ repo.setUrl("https://libraries.minecraft.net/");
+ });
+ repositories.mavenCentral();
+
+ // MinecraftMappedProvider.java
+ repositories.ivy(repo -> {
+ repo.setUrl(cache.getUserCache());
+ repo.patternLayout(layout -> {
+ layout.artifact("[revision]/[artifact]-[revision](.[ext])");
+ });
+ repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
+ });
+
+ // MinecraftProcessedProvider.java
+ repositories.ivy(repo -> {
+ repo.setUrl(cache.getRootPersistentCache());
+ repo.patternLayout(layout -> {
+ layout.artifact("[revision]/[artifact]-[revision](.[ext])");
+ });
+ repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
+ });
+ }
+}
+
+final class Cache {
+ private PluginAware target;
+
+ Cache(PluginAware target) {
+ if (target instanceof Project || target instanceof Settings) {
+ this.target = target;
+ } else {
+ throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
+ }
+ }
+
+ File getUserCache() {
+ File gradleUserHomeDir = null;
+
+ if (target instanceof Settings settings) {
+ gradleUserHomeDir = settings.getGradle().getGradleUserHomeDir();
+ } else if (target instanceof Project project) {
+ gradleUserHomeDir = project.getGradle().getGradleUserHomeDir();
+ } else {
+ throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
+ }
+
+ File userCache = new File(gradleUserHomeDir, "caches" + File.separator + "fabric-loom");
+
+ if (!userCache.exists()) {
+ userCache.mkdirs();
+ }
+
+ return userCache;
+ }
+
+ public File getRootPersistentCache() {
+ File rootDir = null;
+
+ if (target instanceof Settings settings) {
+ rootDir = settings.getRootDir();
+ } else if (target instanceof Project project) {
+ rootDir = project.getRootDir();
+ } else {
+ throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
+ }
+
+ File persistentCache = new File(rootDir, ".gradle" + File.separator + "loom-cache");
+
+ if (!persistentCache.exists()) {
+ persistentCache.mkdirs();
+ }
+
+ return persistentCache;
+ }
+
+ public File getRootBuildCache() {
+ File rootDir = null;
+
+ if (target instanceof Settings settings) {
+ rootDir = settings.getRootDir();
+ } else if (target instanceof Project project) {
+ rootDir = project.getRootDir();
+ } else {
+ throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
+ }
+
+ File buildCache = new File(rootDir, "build" + File.separator + "loom-cache");
+
+ if (!buildCache.exists()) {
+ buildCache.mkdirs();
+ }
+
+ return buildCache;
+ }
+
+ public File getRemappedModCache() {
+ File remappedModCache = new File(getRootPersistentCache(), "remapped_mods");
+
+ if (!remappedModCache.exists()) {
+ remappedModCache.mkdir();
+ }
+
+ return remappedModCache;
+ }
+
+ public File getNestedModCache() {
+ File nestedModCache = new File(getRootPersistentCache(), "nested_mods");
+
+ if (!nestedModCache.exists()) {
+ nestedModCache.mkdir();
+ }
+
+ return nestedModCache;
+ }
+
+ public File getNativesJarStore() {
+ File natives = new File(getUserCache(), "natives/jars");
+
+ if (!natives.exists()) {
+ natives.mkdirs();
+ }
+
+ return natives;
+ }
+}
diff --git a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java
index 343353a1..8e75df82 100644
--- a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java
+++ b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java
@@ -107,8 +107,6 @@ public final class CompileConfiguration {
p.afterEvaluate(project -> {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
- MavenConfiguration.setup(project);
-
LoomDependencyManager dependencyManager = new LoomDependencyManager();
extension.setDependencyManager(dependencyManager);
diff --git a/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java b/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java
index 397908c5..55c544cf 100644
--- a/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java
+++ b/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java
@@ -45,6 +45,7 @@ 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;
+import net.fabricmc.loom.LoomRepositoryPlugin;
public class LoomDependencyManager {
private static class ProviderList {
@@ -193,7 +194,9 @@ public class LoomDependencyManager {
project.getLogger().debug("Loom adding " + name + " from installer JSON");
- if (jsonElement.getAsJsonObject().has("url")) {
+ // If user choose to use dependencyResolutionManagement, then they should declare
+ // these repositories manually in the settings file.
+ if (jsonElement.getAsJsonObject().has("url") && !project.getGradle().getPlugins().hasPlugin(LoomRepositoryPlugin.class)) {
String url = jsonElement.getAsJsonObject().get("url").getAsString();
long count = project.getRepositories().stream().filter(artifactRepository -> artifactRepository instanceof MavenArtifactRepository)
.map(artifactRepository -> (MavenArtifactRepository) artifactRepository)
diff --git a/src/main/java/net/fabricmc/loom/configuration/MavenConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/MavenConfiguration.java
deleted file mode 100644
index 2fb2ae7c..00000000
--- a/src/main/java/net/fabricmc/loom/configuration/MavenConfiguration.java
+++ /dev/null
@@ -1,57 +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.configuration;
-
-import org.gradle.api.Project;
-
-import net.fabricmc.loom.LoomGradleExtension;
-
-public class MavenConfiguration {
- public static void setup(Project project) {
- LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
-
- project.getRepositories().flatDir(repo -> {
- repo.setName("UserLocalCacheFiles");
- repo.dir(extension.getRootProjectBuildCache());
- });
-
- project.getRepositories().maven(repo -> {
- repo.setName("UserLocalRemappedMods");
- repo.setUrl(extension.getRemappedModCache());
- });
-
- project.getRepositories().maven(repo -> {
- repo.setName("Fabric");
- repo.setUrl("https://maven.fabricmc.net/");
- });
-
- project.getRepositories().maven(repo -> {
- repo.setName("Mojang");
- repo.setUrl("https://libraries.minecraft.net/");
- });
-
- project.getRepositories().mavenCentral();
- }
-}
diff --git a/src/main/java/net/fabricmc/loom/configuration/processors/MinecraftProcessedProvider.java b/src/main/java/net/fabricmc/loom/configuration/processors/MinecraftProcessedProvider.java
index adf85fd2..0a24a75f 100644
--- a/src/main/java/net/fabricmc/loom/configuration/processors/MinecraftProcessedProvider.java
+++ b/src/main/java/net/fabricmc/loom/configuration/processors/MinecraftProcessedProvider.java
@@ -37,7 +37,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvid
import net.fabricmc.loom.util.Constants;
public class MinecraftProcessedProvider extends MinecraftMappedProvider {
- public static final String PROJECT_MAPPED_CLASSIFIER = "projectmapped";
+ public final String projectMappedClassifier;
private File projectMappedJar;
@@ -46,6 +46,8 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
public MinecraftProcessedProvider(Project project, JarProcessorManager jarProcessorManager) {
super(project);
this.jarProcessorManager = jarProcessorManager;
+ this.projectMappedClassifier = "project-" + project.getPath().replace(':', '@')
+ + "-mapped";
}
@Override
@@ -63,14 +65,12 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
jarProcessorManager.process(projectMappedJar);
}
- getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER)));
-
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
- getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER)));
+ getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(projectMappedClassifier)));
}
private void invalidateJars() {
- File dir = getJarDirectory(getExtension().getUserCache(), PROJECT_MAPPED_CLASSIFIER);
+ File dir = getJarDirectory(getExtension().getUserCache(), projectMappedClassifier);
if (dir.exists()) {
getProject().getLogger().warn("Invalidating project jars");
@@ -87,7 +87,7 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
public void initFiles(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) {
super.initFiles(minecraftProvider, mappingsProvider);
- projectMappedJar = new File(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER), "minecraft-" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER) + ".jar");
+ projectMappedJar = new File(getJarDirectory(getExtension().getRootProjectPersistentCache(), projectMappedClassifier), "minecraft-" + getJarVersionString(projectMappedClassifier) + ".jar");
}
@Override
diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java
index 0032a177..a2718090 100644
--- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java
+++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java
@@ -144,8 +144,6 @@ public class MinecraftMappedProvider extends DependencyProvider {
}
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
- getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getUserCache(), "mapped")));
-
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString("mapped")));
}