Skip to content

Commit

Permalink
Merge pull request FabricMC#737
Browse files Browse the repository at this point in the history
New Jar Processor API
Shared Service improvements
FMJ 2.0 support
Move Minecraft jars to maven structure
Improve intelij source attachment
  • Loading branch information
modmuss50 authored Oct 26, 2022
2 parents fccb667 + e7bee0d commit 196ee87
Show file tree
Hide file tree
Showing 92 changed files with 2,912 additions and 1,092 deletions.
15 changes: 5 additions & 10 deletions src/main/java/net/fabricmc/loom/LoomGradleExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
import net.fabricmc.loom.configuration.InstallerData;
import net.fabricmc.loom.configuration.LoomDependencyManager;
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile;
import net.fabricmc.loom.configuration.processors.JarProcessorManager;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
import net.fabricmc.loom.configuration.providers.minecraft.mapped.IntermediaryMinecraftProvider;
import net.fabricmc.loom.configuration.providers.minecraft.mapped.NamedMinecraftProvider;
Expand Down Expand Up @@ -69,17 +68,13 @@ static LoomGradleExtension get(Project project) {

LoomDependencyManager getDependencyManager();

void setJarProcessorManager(JarProcessorManager jarProcessorManager);

JarProcessorManager getJarProcessorManager();

MinecraftProvider getMinecraftProvider();

void setMinecraftProvider(MinecraftProvider minecraftProvider);

MappingsProviderImpl getMappingsProvider();
MappingConfiguration getMappingConfiguration();

void setMappingsProvider(MappingsProviderImpl mappingsProvider);
void setMappingConfiguration(MappingConfiguration mappingConfiguration);

NamedMinecraftProvider<?> getNamedMinecraftProvider();

Expand All @@ -91,8 +86,8 @@ static LoomGradleExtension get(Project project) {

default List<Path> getMinecraftJars(MappingsNamespace mappingsNamespace) {
return switch (mappingsNamespace) {
case NAMED -> getNamedMinecraftProvider().getMinecraftJars();
case INTERMEDIARY -> getIntermediaryMinecraftProvider().getMinecraftJars();
case NAMED -> getNamedMinecraftProvider().getMinecraftJarPaths();
case INTERMEDIARY -> getIntermediaryMinecraftProvider().getMinecraftJarPaths();
case OFFICIAL -> getMinecraftProvider().getMinecraftJars();
};
}
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.gradle.api.artifacts.ArtifactRepositoryContainer;
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.artifacts.repositories.ArtifactRepository;
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.initialization.Settings;
import org.gradle.api.invocation.Gradle;
Expand Down Expand Up @@ -62,10 +61,8 @@ public void apply(@NotNull PluginAware target) {
}

private void declareRepositories(RepositoryHandler repositories, LoomFiles files, ExtensionAware target) {
repositories.maven(repo -> {
repo.setName("UserLocalRemappedMods");
repo.setUrl(files.getRemappedModCache());
});
declareLocalRepositories(repositories, files);

repositories.maven(repo -> {
repo.setName("Fabric");
repo.setUrl(MirrorUtil.getFabricRepository(target));
Expand Down Expand Up @@ -93,17 +90,22 @@ private void declareRepositories(RepositoryHandler repositories, LoomFiles files
}

repositories.mavenCentral();
}

repositories.ivy(repo -> {
repo.setUrl(files.getUserCache());
repo.patternLayout(layout -> layout.artifact("[revision]/[artifact](-[classifier])(.[ext])"));
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
private void declareLocalRepositories(RepositoryHandler repositories, LoomFiles files) {
repositories.maven(repo -> {
repo.setName("LoomLocalRemappedMods");
repo.setUrl(files.getRemappedModCache());
});

repositories.ivy(repo -> {
repo.setUrl(files.getRootProjectPersistentCache());
repo.patternLayout(layout -> layout.artifact("[revision]/[artifact](-[classifier])(.[ext])"));
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
repositories.maven(repo -> {
repo.setName("LoomGlobalMinecraft");
repo.setUrl(files.getGlobalMinecraftRepo());
});

repositories.maven(repo -> {
repo.setName("LoomLocalMinecraft");
repo.setUrl(files.getLocalMinecraftRepo());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public interface InterfaceInjectionExtensionAPI {
*/
Property<Boolean> getEnableDependencyInterfaceInjection();

Property<Boolean> getIsEnabled();

/**
* Contains a list of {@link SourceSet} that may contain a fabric.mod.json file with interfaces to inject.
* By default, this list contains only the main {@link SourceSet}.
*
* @return the list property containing the {@link SourceSet}
* @deprecated now uses the source sets defined in {@link LoomGradleExtensionAPI#getMods()}
*/
@Deprecated(forRemoval = true)
ListProperty<SourceSet> getInterfaceInjectionSourceSets();

default boolean isEnabled() {
return getEnableDependencyInterfaceInjection().get() || !getInterfaceInjectionSourceSets().get().isEmpty();
return getIsEnabled().get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import net.fabricmc.loom.api.decompilers.DecompilerOptions;
import net.fabricmc.loom.api.mappings.intermediate.IntermediateMappingsProvider;
import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
import net.fabricmc.loom.api.processor.MinecraftJarProcessor;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.processors.JarProcessor;
import net.fabricmc.loom.configuration.providers.mappings.NoOpIntermediateMappingsProvider;
Expand All @@ -62,12 +63,18 @@ public interface LoomGradleExtensionAPI {

void decompilers(Action<NamedDomainObjectContainer<DecompilerOptions>> action);

@Deprecated()
ListProperty<JarProcessor> getGameJarProcessors();

@Deprecated()
default void addJarProcessor(JarProcessor processor) {
getGameJarProcessors().add(processor);
}

ListProperty<MinecraftJarProcessor<?>> getMinecraftJarProcessors();

void addMinecraftJarProcessor(Class<? extends MinecraftJarProcessor<?>> clazz, Object... parameters);

ConfigurableFileCollection getLog4jConfigs();

Dependency officialMojangMappings();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016-2021 FabricMC
* Copyright (c) 2022 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
Expand All @@ -22,13 +22,7 @@
* SOFTWARE.
*/

package net.fabricmc.loom.configuration.providers.mappings;
package net.fabricmc.loom.api.processor;

import java.io.File;
import java.nio.file.Path;

public interface MappingsProvider {
Path mappingsWorkingDir();

File intermediaryTinyFile();
public interface MappingProcessorContext {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016-2022 FabricMC
* Copyright (c) 2022 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
Expand All @@ -22,34 +22,32 @@
* SOFTWARE.
*/

package net.fabricmc.loom.util;
package net.fabricmc.loom.api.processor;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;

import com.google.gson.JsonObject;
import org.gradle.api.Named;
import org.jetbrains.annotations.Nullable;

public final class ModUtils {
private ModUtils() {
}
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public interface MinecraftJarProcessor<S extends MinecraftJarProcessor.Spec> extends Named {
@Nullable
S buildSpec(SpecContext context);

public static boolean isMod(File file) {
return isMod(file.toPath());
void processJar(Path jar, S spec, ProcessorContext context) throws IOException;

@Nullable
default MappingsProcessor<S> processMappings() {
return null;
}

public static boolean isMod(Path input) {
return ZipUtils.contains(input, "fabric.mod.json");
interface Spec {
// Must make sure hashCode is correctly implemented.
}

@Nullable
public static JsonObject getFabricModJson(Path path) {
try {
return ZipUtils.unpackGsonNullable(path, "fabric.mod.json", JsonObject.class);
} catch (IOException e) {
throw new UncheckedIOException("Failed to extract fabric.mod.json from " + path, e);
}
interface MappingsProcessor<S> {
boolean transform(MemoryMappingTree mappings, S spec, MappingProcessorContext context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2022 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.api.processor;

import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
import net.fabricmc.tinyremapper.TinyRemapper;

public interface ProcessorContext {
MinecraftJarConfiguration getJarConfiguration();

boolean isMerged();

boolean includesClient();

boolean includesServer();

TinyRemapper createRemapper(MappingsNamespace from, MappingsNamespace to);
}
43 changes: 43 additions & 0 deletions src/main/java/net/fabricmc/loom/api/processor/SpecContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2022 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.api.processor;

import java.util.List;
import java.util.stream.Stream;

import net.fabricmc.loom.util.fmj.FabricModJson;

public interface SpecContext {
List<FabricModJson> modDependencies();

List<FabricModJson> localMods();

// Returns mods that are both on the compile and runtime classpath
List<FabricModJson> modDependenciesCompileRuntime();

default List<FabricModJson> allMods() {
return Stream.concat(modDependencies().stream(), localMods().stream()).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import net.fabricmc.loom.configuration.ide.idea.IdeaUtils;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
import net.fabricmc.loom.extension.MixinExtension;
import net.fabricmc.loom.task.service.MixinMappingsService;
import net.fabricmc.loom.task.PrepareJarRemapTask;
import net.fabricmc.loom.util.Constants;

/**
Expand Down Expand Up @@ -93,8 +93,8 @@ private void passMixinArguments(T task, SourceSet sourceSet) {
LoomGradleExtension loom = LoomGradleExtension.get(project);
String refmapName = Objects.requireNonNull(MixinExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
Map<String, String> args = new HashMap<>() {{
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingsProvider().tinyMappings.toFile().getCanonicalPath());
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, MixinMappingsService.getMixinMappingFile(project, sourceSet).getCanonicalPath());
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingConfiguration().tinyMappings.toFile().getCanonicalPath());
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, getMixinMappingsForSourceSet(project, sourceSet).getCanonicalPath());
put(Constants.MixinArguments.OUT_REFMAP_FILE, getRefmapDestination(task, refmapName));
put(Constants.MixinArguments.DEFAULT_OBFUSCATION_ENV, "named:" + loom.getMixin().getRefmapTargetNamespace().get());
put(Constants.MixinArguments.QUIET, "true");
Expand All @@ -111,6 +111,9 @@ private void passMixinArguments(T task, SourceSet sourceSet) {
args.put("MSG_" + key, value);
});

// Ensure that all of the mixin mappings have been generated before we create the mixin mappings.
runBeforePrepare(project, task);

project.getLogger().debug("Outputting refmap to dir: " + getRefmapDestinationDir(task) + " for compile task: " + task);
args.forEach((k, v) -> passArgument(task, k, v));
} catch (IOException e) {
Expand Down Expand Up @@ -143,11 +146,22 @@ public void configureMixin() {
}
}

private void runBeforePrepare(Project project, Task compileTask) {
project.getGradle().allprojects(otherProject -> {
otherProject.getTasks().withType(PrepareJarRemapTask.class, prepareRemapTask -> prepareRemapTask.mustRunAfter(compileTask));
});
}

private static void checkPattern(String input, Pattern pattern) {
final Matcher matcher = pattern.matcher(input);

if (!matcher.find()) {
throw new IllegalArgumentException("Mixin argument (%s) does not match pattern (%s)".formatted(input, pattern.toString()));
}
}

public static File getMixinMappingsForSourceSet(Project project, SourceSet sourceSet) {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
return new File(extension.getFiles().getProjectBuildCache(), "mixin-map-" + extension.getMappingConfiguration().mappingsIdentifier() + "." + sourceSet.getName() + ".tiny");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.task.RemapTaskConfiguration;
import net.fabricmc.loom.util.ModUtils;
import net.fabricmc.loom.util.ZipUtils;
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;

public final class IncludedJarFactory {
private final Project project;
Expand Down Expand Up @@ -143,7 +143,7 @@ private ConfigurableFileCollection getProjectDeps(Configuration configuration, S
}

private File getNestableJar(final File input, final Metadata metadata) {
if (ModUtils.isMod(input)) {
if (FabricModJsonFactory.isModJar(input)) {
// Input is a mod, nothing needs to be done.
return input;
}
Expand Down
Loading

0 comments on commit 196ee87

Please sign in to comment.