2016-08-16 22:29:10 +00:00
|
|
|
/*
|
|
|
|
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
|
|
|
*
|
2018-10-27 14:14:05 +00:00
|
|
|
* Copyright (c) 2016, 2017, 2018 FabricMC
|
2016-08-16 22:29:10 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-10-22 18:25:18 +00:00
|
|
|
package net.fabricmc.loom;
|
2016-08-15 10:22:14 +00:00
|
|
|
|
2021-05-13 21:06:34 +00:00
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2020-12-24 20:58:30 +00:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2020-12-27 16:25:30 +00:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
2019-11-02 20:23:27 +00:00
|
|
|
import org.gradle.api.Project;
|
2021-05-22 22:28:42 +00:00
|
|
|
import org.gradle.api.plugins.PluginAware;
|
2019-11-02 20:23:27 +00:00
|
|
|
|
2021-05-26 10:41:52 +00:00
|
|
|
import net.fabricmc.loom.bootstrap.BootstrappedPlugin;
|
2020-12-24 20:58:30 +00:00
|
|
|
import net.fabricmc.loom.configuration.CompileConfiguration;
|
|
|
|
import net.fabricmc.loom.configuration.FabricApiExtension;
|
|
|
|
import net.fabricmc.loom.configuration.MavenPublication;
|
|
|
|
import net.fabricmc.loom.configuration.ide.IdeConfiguration;
|
|
|
|
import net.fabricmc.loom.configuration.providers.mappings.MappingsCache;
|
|
|
|
import net.fabricmc.loom.decompilers.DecompilerConfiguration;
|
|
|
|
import net.fabricmc.loom.task.LoomTasks;
|
2019-11-02 20:23:27 +00:00
|
|
|
|
2021-05-26 10:41:52 +00:00
|
|
|
public class LoomGradlePlugin implements BootstrappedPlugin {
|
2020-12-24 20:58:30 +00:00
|
|
|
public static boolean refreshDeps;
|
2020-12-27 16:25:30 +00:00
|
|
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
2021-05-13 21:06:34 +00:00
|
|
|
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
2019-04-22 11:37:14 +00:00
|
|
|
|
2016-08-17 16:38:54 +00:00
|
|
|
@Override
|
2021-05-22 22:28:42 +00:00
|
|
|
public void apply(PluginAware target) {
|
|
|
|
target.getPlugins().apply(LoomRepositoryPlugin.class);
|
|
|
|
|
|
|
|
if (target instanceof Project project) {
|
|
|
|
apply(project);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 20:58:30 +00:00
|
|
|
public void apply(Project project) {
|
|
|
|
project.getLogger().lifecycle("Fabric Loom: " + LoomGradlePlugin.class.getPackage().getImplementationVersion());
|
2019-05-10 11:32:11 +00:00
|
|
|
|
2020-12-24 20:58:30 +00:00
|
|
|
refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies();
|
2019-04-22 11:37:14 +00:00
|
|
|
|
2020-12-24 20:58:30 +00:00
|
|
|
if (refreshDeps) {
|
|
|
|
MappingsCache.INSTANCE.invalidate();
|
|
|
|
project.getLogger().lifecycle("Refresh dependencies is in use, loom will be significantly slower.");
|
|
|
|
}
|
2020-06-01 18:31:32 +00:00
|
|
|
|
2020-12-24 20:58:30 +00:00
|
|
|
// Apply default plugins
|
|
|
|
project.apply(ImmutableMap.of("plugin", "java"));
|
|
|
|
project.apply(ImmutableMap.of("plugin", "eclipse"));
|
|
|
|
project.apply(ImmutableMap.of("plugin", "idea"));
|
|
|
|
|
|
|
|
// Setup extensions, loom shadows minecraft
|
|
|
|
project.getExtensions().create("minecraft", LoomGradleExtension.class, project);
|
|
|
|
project.getExtensions().add("loom", project.getExtensions().getByName("minecraft"));
|
|
|
|
project.getExtensions().create("fabricApi", FabricApiExtension.class, project);
|
|
|
|
|
|
|
|
CompileConfiguration.setupConfigurations(project);
|
|
|
|
IdeConfiguration.setup(project);
|
|
|
|
CompileConfiguration.configureCompile(project);
|
|
|
|
MavenPublication.configure(project);
|
|
|
|
LoomTasks.registerTasks(project);
|
|
|
|
DecompilerConfiguration.setup(project);
|
2016-08-17 16:38:54 +00:00
|
|
|
}
|
2016-08-15 10:22:14 +00:00
|
|
|
}
|