Skip to content

Commit

Permalink
chore: Push breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aoqia194 committed Dec 10, 2024
1 parent c405194 commit 0a22070
Show file tree
Hide file tree
Showing 57 changed files with 548 additions and 667 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ tasks.withType(GenerateModuleMetadata).configureEach {
tasks.register('writeActionsTestMatrix') {
doLast {
def testMatrix = []
file('src/test/groovy/net/fabricmc/loom/test/integration').eachFile {
file('src/test/groovy/net/aoqia/loom/test/integration').eachFile {
if (it.name.endsWith("Test.groovy")) {
if (it.name.endsWith("ReproducibleBuildTest.groovy")) {
// This test gets a special case to run across all os's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ default String zomboidVersion() {

Logger getLogger();

CopyGameFileBuilder copyGameFile(String url);
CopyGameFileBuilder copyGameFile(String path);

DownloadBuilder download(String url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public interface FileMappingsSpecBuilder {
* names to the rest of the mappings. For example, Yarn mappings should be merged through
* the intermediary names.
*
* <p>The default merge namespace is {@link MappingsNamespace#INTERMEDIARY}.
* <p>The default merge namespace is {@link MappingsNamespace#OFFICIAL}.
*
* @param namespace the new merge namespace
* @return this builder
Expand Down
113 changes: 89 additions & 24 deletions src/main/java/net/aoqia/loom/configuration/LeafApiExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,28 @@

package net.aoqia.loom.configuration;

import javax.inject.Inject;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import net.aoqia.loom.LoomGradleExtension;
import net.aoqia.loom.util.download.DownloadException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.SourceSet;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import net.aoqia.loom.LoomGradleExtension;
import net.aoqia.loom.util.download.DownloadException;

public abstract class LeafApiExtension {
@Inject
public abstract Project getProject();

private static final HashMap<String, Map<String, String>> moduleVersionCache = new HashMap<>();
private static final HashMap<String, Map<String, String>> deprecatedModuleVersionCache = new HashMap<>();

Expand All @@ -74,21 +72,21 @@ public String moduleVersion(String moduleName, String fabricApiVersion) {
return moduleVersion;
}

private String getDependencyNotation(String moduleName, String fabricApiVersion) {
return String.format("net.fabricmc.leaf-api:%s:%s", moduleName, moduleVersion(moduleName, fabricApiVersion));
private String getDependencyNotation(String moduleName, String leafApiVersion) {
return String.format("net.aoqia.leaf-api:%s:%s", moduleName, moduleVersion(moduleName, leafApiVersion));
}

private Map<String, String> getApiModuleVersions(String fabricApiVersion) {
private Map<String, String> getApiModuleVersions(String leafApiVersion) {
try {
return populateModuleVersionMap(getApiMavenPom(fabricApiVersion));
return populateModuleVersionMap(getApiMavenPom(leafApiVersion));
} catch (PomNotFoundException e) {
throw new RuntimeException("Could not find leaf-api version: " + fabricApiVersion);
throw new RuntimeException("Could not find leaf-api version: " + leafApiVersion);
}
}

private Map<String, String> getDeprecatedApiModuleVersions(String fabricApiVersion) {
private Map<String, String> getDeprecatedApiModuleVersions(String leafApiVersion) {
try {
return populateModuleVersionMap(getDeprecatedApiMavenPom(fabricApiVersion));
return populateModuleVersionMap(getDeprecatedApiMavenPom(leafApiVersion));
} catch (PomNotFoundException e) {
// Not all fabric-api versions have deprecated modules, return an empty map to cache this fact.
return Collections.emptyMap();
Expand All @@ -103,7 +101,8 @@ private Map<String, String> populateModuleVersionMap(File pomFile) {

Map<String, String> versionMap = new HashMap<>();

NodeList dependencies = ((Element) pom.getElementsByTagName("dependencies").item(0)).getElementsByTagName("dependency");
NodeList dependencies = ((Element) pom.getElementsByTagName("dependencies").item(0)).getElementsByTagName(
"dependency");

for (int i = 0; i < dependencies.getLength(); i++) {
Element dep = (Element) dependencies.item(i);
Expand Down Expand Up @@ -133,10 +132,13 @@ private File getDeprecatedApiMavenPom(String fabricApiVersion) throws PomNotFoun

private File getPom(String name, String version) throws PomNotFoundException {
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());
final var mavenPom = new File(extension.getFiles().getUserCache(), "leaf-api/%s-%s.pom".formatted(name, version));
final var mavenPom = new File(extension.getFiles().getUserCache(),
"leaf-api/%s-%s.pom".formatted(name, version));

try {
extension.download(String.format("https://maven.fabricmc.net/net/aoqia/leaf-api/%2$s/%1$s/%2$s-%1$s.pom", version, name))
extension.download(String.format("https://maven.aoqia.net/net/aoqia/leaf-api/%2$s/%1$s/%2$s-%1$s.pom",
version,
name))
.defaultCache()
.downloadPath(mavenPom.toPath());
} catch (DownloadException e) {
Expand All @@ -150,10 +152,23 @@ private File getPom(String name, String version) throws PomNotFoundException {
return mavenPom;
}

private static class PomNotFoundException extends Exception {
PomNotFoundException(Throwable cause) {
super(cause);
}
private void dependsOn(SourceSet sourceSet, SourceSet other) {
sourceSet.setCompileClasspath(
sourceSet.getCompileClasspath()
.plus(other.getOutput())
);

sourceSet.setRuntimeClasspath(
sourceSet.getRuntimeClasspath()
.plus(other.getOutput())
);

extendsFrom(getProject(),
sourceSet.getCompileClasspathConfigurationName(),
other.getCompileClasspathConfigurationName());
extendsFrom(getProject(),
sourceSet.getRuntimeClasspathConfigurationName(),
other.getRuntimeClasspathConfigurationName());
}

private static void extendsFrom(Project project, String name, String extendsFrom) {
Expand All @@ -163,4 +178,54 @@ private static void extendsFrom(Project project, String name, String extendsFrom
configuration.extendsFrom(configurations.getByName(extendsFrom));
});
}

@Inject
public abstract Project getProject();

public interface DataGenerationSettings {
/**
* Contains the output directory where generated data files will be stored.
*/
RegularFileProperty getOutputDirectory();

/**
* Contains a boolean indicating whether a run configuration should be created for the data generation process.
*/
Property<Boolean> getCreateRunConfiguration();

/**
* Contains a boolean property indicating whether a new source set should be created for the data generation
* process.
*/
Property<Boolean> getCreateSourceSet();

/**
* Contains a string property representing the mod ID associated with the data generation process.
*
* <p>This must be set when {@link #getCreateRunConfiguration()} is set.
*/
Property<String> getModId();

/**
* Contains a boolean property indicating whether strict validation is enabled.
*/
Property<Boolean> getStrictValidation();

/**
* Contains a boolean property indicating whether the generated resources will be automatically added to the
* main sourceset.
*/
Property<Boolean> getAddToResources();

/**
* Contains a boolean property indicating whether data generation will be compiled and ran with the client.
*/
Property<Boolean> getClient();
}

private static class PomNotFoundException extends Exception {
PomNotFoundException(Throwable cause) {
super(cause);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public AccessWidenerJarProcessor(

/* Uncomment to read all access wideners from local mods.
for (FabricModJson fabricModJson : context.localMods()) {
for (LeafModJson fabricModJson : context.localMods()) {
accessWideners.addAll(ModAccessWidenerEntry.readAll(fabricModJson, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import net.aoqia.loom.util.Constants;
import net.aoqia.loom.util.fmj.LeafModJson;
import net.aoqia.loom.util.fmj.LeafModJsonFactory;
import net.aoqia.loom.util.fmj.FabricModJsonHelpers;
import net.aoqia.loom.util.fmj.LeafModJsonHelpers;
import net.aoqia.loom.util.gradle.GradleUtils;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
Expand All @@ -62,7 +62,7 @@ public static SpecContextImpl create(Project project) {
final Map<String, List<LeafModJson>> fmjCache = new HashMap<>();
return new SpecContextImpl(
getDependentMods(project, fmjCache),
FabricModJsonHelpers.getModsInProject(project),
LeafModJsonHelpers.getModsInProject(project),
getCompileRuntimeMods(project, fmjCache));
}

Expand Down Expand Up @@ -92,7 +92,7 @@ private static List<LeafModJson> getDependentMods(Project project, Map<String, L
// Add all the dependent projects
for (Project dependentProject : getDependentProjects(project).toList()) {
mods.addAll(fmjCache.computeIfAbsent(dependentProject.getPath(), $ -> {
return FabricModJsonHelpers.getModsInProject(dependentProject);
return LeafModJsonHelpers.getModsInProject(dependentProject);
}));
}
}
Expand All @@ -118,7 +118,7 @@ private static List<LeafModJson> getCompileRuntimeMods(
for (Project dependentProject :
getCompileRuntimeProjectDependencies(project).toList()) {
mods.addAll(fmjCache.computeIfAbsent(dependentProject.getPath(), $ -> {
return FabricModJsonHelpers.getModsInProject(dependentProject);
return LeafModJsonHelpers.getModsInProject(dependentProject);
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public FileMappingsSpecBuilderImpl mergeNamespace(String namespace) {

if (MappingsNamespace.of(namespace) == null) {
throw new IllegalArgumentException("Namespace '" + namespace
+ "' is unsupported! It must be either 'official', 'intermediary' or 'named'.");
+ "' is unsupported! It must be either 'official' or 'named'.");
}

mergeNamespace = namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

package net.aoqia.loom.configuration.sandbox;

import static net.aoqia.loom.util.fmj.FabricModJsonUtils.ParseException;
import static net.aoqia.loom.util.fmj.FabricModJsonUtils.getJsonObject;
import static net.aoqia.loom.util.fmj.FabricModJsonUtils.readInt;
import static net.aoqia.loom.util.fmj.FabricModJsonUtils.readString;
import static net.aoqia.loom.util.fmj.LeafModJsonUtils.ParseException;
import static net.aoqia.loom.util.fmj.LeafModJsonUtils.getJsonObject;
import static net.aoqia.loom.util.fmj.LeafModJsonUtils.readInt;
import static net.aoqia.loom.util.fmj.LeafModJsonUtils.readString;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/aoqia/loom/task/RemapJarTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import net.aoqia.loom.util.SidedClassVisitor;
import net.aoqia.loom.util.ZipUtils;
import net.aoqia.loom.util.fmj.LeafModJsonFactory;
import net.aoqia.loom.util.fmj.FabricModJsonUtils;
import net.aoqia.loom.util.fmj.LeafModJsonUtils;
import net.aoqia.loom.util.service.ScopedServiceFactory;
import net.aoqia.loom.util.service.ServiceFactory;
import net.fabricmc.tinyremapper.OutputConsumerPath;
Expand Down Expand Up @@ -85,7 +85,7 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
* <p>The schemaVersion entry will be placed first in the json file
*/
@Input
public abstract Property<Boolean> getOptimizeFabricModJson();
public abstract Property<Boolean> getOptimizeLeafModJson();

@Input
@ApiStatus.Internal
Expand All @@ -103,7 +103,7 @@ public RemapJarTask() {
final ConfigurationContainer configurations = getProject().getConfigurations();
getClasspath().from(configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME));
getAddNestedDependencies().convention(true).finalizeValueOnRead();
getOptimizeFabricModJson().convention(false).finalizeValueOnRead();
getOptimizeLeafModJson().convention(false).finalizeValueOnRead();

TaskProvider<NestableJarGenerationTask> processIncludeJars =
getProject().getTasks().named(Constants.Task.PROCESS_INCLUDE_JARS, NestableJarGenerationTask.class);
Expand Down Expand Up @@ -147,7 +147,7 @@ public void run() {
.put(Constants.Manifest.MIXIN_REMAP_TYPE, refmapRemapType.manifestValue());
}

params.getOptimizeFmj().set(getOptimizeFabricModJson().get());
params.getOptimizeFmj().set(getOptimizeLeafModJson().get());
});
}

Expand Down Expand Up @@ -321,7 +321,7 @@ private void optimizeFMJ() throws IOException {
JsonObject.class,
outputFile,
LeafModJsonFactory.LEAF_MOD_JSON,
FabricModJsonUtils::optimizeFmj);
LeafModJsonUtils::optimizeFmj);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/net/aoqia/loom/util/MirrorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

package net.aoqia.loom.util;


import org.gradle.api.plugins.ExtensionAware;
import org.jetbrains.annotations.Nullable;

public class MirrorUtil {
public static String getGameInstallPath(ExtensionAware aware) {
Expand All @@ -35,16 +37,16 @@ public static String getGameInstallPath(ExtensionAware aware) {
return Constants.GAME_INSTALL_PATH;
}

public static String getServerInstallPath(ExtensionAware aware) {
if (aware.getExtensions().getExtraProperties().has("loom_server_install_path")) {
public static String getServerInstallPath(@Nullable ExtensionAware aware) {
if (aware != null && aware.getExtensions().getExtraProperties().has("loom_server_install_path")) {
return String.valueOf(aware.getExtensions().getExtraProperties().get("loom_server_install_path"));
}

return Constants.SERVER_INSTALL_PATH;
}

public static String getClientVersionManifests(ExtensionAware aware) {
if (aware.getExtensions().getExtraProperties().has("loom_version_manifests")) {
public static String getClientVersionManifests(@Nullable ExtensionAware aware) {
if (aware != null && aware.getExtensions().getExtraProperties().has("loom_version_manifests")) {
return String.valueOf(aware.getExtensions().getExtraProperties().get("loom_version_manifests"));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoqia/loom/util/fmj/LeafModJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import static net.aoqia.loom.util.fmj.FabricModJsonUtils.readString;
import static net.aoqia.loom.util.fmj.LeafModJsonUtils.readString;

public abstract sealed class LeafModJson
permits LeafModJsonV0, LeafModJsonV1, LeafModJsonV2, LeafModJson.Mockable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package net.aoqia.loom.util.fmj;

import static net.aoqia.loom.util.fmj.FabricModJsonUtils.readInt;
import static net.aoqia.loom.util.fmj.LeafModJsonUtils.readInt;

import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aoqia/loom/util/fmj/LeafModJsonV0.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public List<String> getMixinConfigurations() {
if (arrayElement instanceof JsonPrimitive jsonPrimitive && jsonPrimitive.isString()) {
mixins.add(jsonPrimitive.getAsString());
} else {
throw new FabricModJsonUtils.ParseException(
throw new LeafModJsonUtils.ParseException(
"Expected entries in mixin %s to be an array of strings", key);
}
}
} else if (jsonElement instanceof JsonPrimitive jsonPrimitive && jsonPrimitive.isString()) {
mixins.add(jsonPrimitive.getAsString());
} else {
throw new FabricModJsonUtils.ParseException(
throw new LeafModJsonUtils.ParseException(
"Expected mixin %s to be a string or an array of strings", key);
}
}
Expand Down
Loading

0 comments on commit 0a22070

Please sign in to comment.