Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]: Fix ATs not applying. #211

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ subprojects.forEach { Project subProject ->
//General project metadata. Everything has the same version and group.
subProject.version = subProject.rootProject.version
subProject.group = 'net.neoforged.gradle'
subProject.base.archivesName = "ng-${subProject.name.toLowerCase()}"
subProject.base.archivesName = "ng-${subProject.name.toLowerCase(Locale.ROOT)}"

//Setup the java toolchain
subProject.java.toolchain.languageVersion = JavaLanguageVersion.of(project.java_version)
Expand Down Expand Up @@ -166,12 +166,14 @@ subprojects.forEach { subProject ->
evalSubProject.dependencies.functionalTestImplementation project(':test-utils')

//Configure the plugin metadata, so we can publish it.
evalSubProject.gradlePlugin.website = "https://github.com/NeoForged/NeoGradle"
evalSubProject.gradlePlugin.vcsUrl = "https://github.com/NeoForged/NeoGradle.git"
evalSubProject.gradlePlugin.plugins { NamedDomainObjectContainer<PluginDeclaration> plugins ->
plugins.register(evalSubProject.name.toLowerCase()) {
plugins.register(evalSubProject.name.toLowerCase(Locale.ROOT)) {

//Determine the class name and package of the plugin.
def pluginFile = evalSubProject.fileTree('src/main/java')
.filter { it.name.toLowerCase() == "${evalSubProject.getName()}plugin.java".toLowerCase() }
.filter { it.name.toLowerCase(Locale.ROOT) == "${evalSubProject.getName()}plugin.java".toLowerCase(Locale.ROOT) }
.first()

//We need to handle the case of a fresh new project, no files exist yet, so the pluginFile object will be null.
Expand All @@ -180,7 +182,7 @@ subprojects.forEach { subProject ->
pluginClassName = evalSubProject.file('src/main/java/').toPath().relativize(pluginFile.toPath()).toString().replace('/', '.').replace('\\', '.').replace(".java", "")
}

def pluginId = 'net.neoforged.gradle.' + evalSubProject.name.toLowerCase()
def pluginId = 'net.neoforged.gradle.' + evalSubProject.name.toLowerCase(Locale.ROOT)
try {
var propertyValue = evalSubProject.property('pluginId')
if (propertyValue != null) {
Expand All @@ -192,6 +194,10 @@ subprojects.forEach { subProject ->
id = pluginId
//And the implementation class.
implementationClass = pluginClassName

displayName = "NeoForged Gradle ${evalSubProject.name.capitalize()} Plugin"
description = "A plugin for NeoForged Gradle, providing ${evalSubProject.name.capitalize()} functionality. Allowing you to setup Minecraft Modding workspaces with ease."
tags = ['minecraft', 'modding', 'gradle', 'neoforged', 'neoforge', evalSubProject.name.toLowerCase(Locale.ROOT)]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void apply(Project project) {
if (devLogin.getEnabled().get()) {
runs.configureEach(run -> {
final RunDevLogin runsDevLogin = run.getExtensions().create("devLogin", RunDevLogin.class);
runsDevLogin.getIsEnabled().convention(devLogin.getConventionForRun());
runsDevLogin.getIsEnabled().convention(devLogin.getConventionForRun().zip(run.getIsClient(), (conventionForRun, isClient) -> conventionForRun && isClient));
});
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import org.gradle.api.tasks.TaskProvider;

import javax.inject.Inject;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.*;

public abstract class ExtraJarDependencyManager {

Expand All @@ -34,7 +31,7 @@ public static String generateServerCoordinateFor(final String version) {
}

public static String generateCoordinateFor(final DistributionType type, final String version) {
return String.format("net.minecraft:%s:%s:%s-extra", type.getName().toLowerCase(), version, type.getName().toLowerCase());
return String.format("net.minecraft:%s:%s:%s-extra", type.getName().toLowerCase(Locale.ROOT), version, type.getName().toLowerCase(Locale.ROOT));
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,18 @@ public NamedDomainObjectContainer<DependencyReplacementHandler> getReplacementHa

@NotNull
@Override
public Dependency optionallyConvertBackToOriginal(Dependency dependency, Configuration configuration) {
public Dependency optionallyConvertBackToOriginal(@NotNull final Dependency dependency, Configuration configuration) {
final Dependency originalDependency = originalDependencyLookup.get(dependency, configuration);
return originalDependency == null ? dependency : originalDependency;
if (originalDependency == null && !configuration.getExtendsFrom().isEmpty()) {
//Check if we have a parent configuration that might have the original dependency.
for (Configuration parentConfiguration : configuration.getExtendsFrom()) {
return optionallyConvertBackToOriginal(dependency, parentConfiguration);
}
} else if (originalDependency != null) {
return originalDependency;
}

return dependency;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected Map<String, String> buildRunInterpolationData(RunImpl run) {

interpolationData.put("runtime_name", specification.getVersionedName());
interpolationData.put("mc_version", specification.getMinecraftVersion());
interpolationData.put("assets_root", getAssets().get().getOutputDirectory().get().getAsFile().getAbsolutePath());
interpolationData.put("assets_root", DownloadAssets.getAssetsDirectory(specification.getProject(), specification.getProject().provider(this::getVersionJson)).get().getAsFile().getAbsolutePath());
interpolationData.put("asset_index", getAssets().get().getAssetIndexFile().get().getAsFile().getName().substring(0, getAssets().get().getAssetIndexFile().get().getAsFile().getName().lastIndexOf('.')));
interpolationData.put("natives", getNatives().get().getOutputDirectory().get().getAsFile().getAbsolutePath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ public Set<D> findIn(final Configuration configuration) {
protected final TaskProvider<DownloadAssets> createDownloadAssetsTasks(final CommonRuntimeSpecification specification, final Map<String, String> symbolicDataSources, final File runtimeDirectory, final VersionJson versionJson) {
return specification.getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(specification, "downloadAssets"), DownloadAssets.class, task -> {
task.getVersionJson().set(versionJson);

configureCommonRuntimeTaskParameters(task, symbolicDataSources, "downloadAssets", specification, runtimeDirectory);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private String getMapped(String srg, @Nullable Set<String> blacklist) {

String ret = getNames().getOrDefault(srg, srg);
if (cap)
ret = ret.substring(0, 1).toUpperCase(Locale.ENGLISH) + ret.substring(1);
ret = ret.substring(0, 1).toUpperCase(Locale.ROOT) + ret.substring(1);
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.gradle.api.provider.Provider;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;

Expand Down Expand Up @@ -63,7 +64,7 @@ public String getName() {
@NotNull
@Override
public String getIdentifier() {
return getName() + StringUtils.capitalize(getDistribution().getName().toLowerCase()) + version;
return getName() + StringUtils.capitalize(getDistribution().getName().toLowerCase(Locale.ROOT)) + version;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,10 @@ public String getGroup() {
return String.format("NeoGradle/Runtime/%s", name);
}


protected Provider<File> getFileInOutputDirectory(final String fileName) {
return getOutputDirectory().map(directory -> directory.file(fileName).getAsFile());
}

protected Provider<File> getFileInOutputDirectory(final Provider<String> fileName) {
return getOutputDirectory().flatMap(directory -> fileName.map(f -> directory.file(f).getAsFile()));
}

protected Provider<RegularFile> getRegularFileInOutputDirectory(final Provider<String> fileName) {
return getOutputDirectory().flatMap(directory -> fileName.map(directory::file));
}

@Internal
public abstract MapProperty<String, FileTree> getRuntimeData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,57 @@
import net.neoforged.gradle.common.CommonProjectPlugin;
import net.neoforged.gradle.common.caching.CentralCacheService;
import net.neoforged.gradle.common.util.FileCacheUtils;
import net.neoforged.gradle.dsl.common.tasks.WithWorkspace;
import net.neoforged.gradle.util.TransformerUtils;
import net.neoforged.gradle.common.runtime.tasks.action.DownloadFileAction;
import net.neoforged.gradle.common.util.SerializationUtils;
import net.neoforged.gradle.common.util.VersionJson;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.services.ServiceReference;
import org.gradle.api.tasks.*;
import org.gradle.workers.WorkQueue;
import org.gradle.workers.WorkerExecutor;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;
import java.io.File;
import java.util.Map;

@SuppressWarnings({"UnstableApiUsage", "ResultOfMethodCallIgnored"})
@SuppressWarnings({"UnstableApiUsage"})
@CacheableTask
public abstract class DownloadAssets extends DefaultRuntime {
public abstract class DownloadAssets extends DefaultTask implements WithWorkspace {

private final Provider<Directory> assetsCache;

public DownloadAssets() {
getAssetsDirectory().convention(FileCacheUtils.getAssetsCacheDirectory(getProject()).flatMap(assetsDir -> assetsDir.dir(getVersionJson().map(VersionJson::getId))).map(TransformerUtils.ensureExists()));
getOutputDirectory().convention(getAssetsDirectory());
this.assetsCache = getAssetsDirectory(getProject(), getVersionJson());
getAssetIndex().convention("asset-index");
getAssetIndexFileName().convention(getAssetIndex().map(index -> index + ".json"));
getAssetIndexFile().convention(getRegularFileInOutputDirectory(getAssetIndexFileName().map(name -> "indexes/" + name)));
getAssetIndexFile().convention(getRegularFileInAssetsDirectory(getAssetIndexFileName().map(name -> "indexes/" + name)));
getVersionJson().convention(getVersionJsonFile().map(TransformerUtils.guard(file -> VersionJson.get(file.getAsFile()))));
getAssetRepository().convention("https://resources.download.minecraft.net/");
getIsOffline().convention(getProject().getGradle().getStartParameter().isOffline());
}


public static @NotNull Provider<Directory> getAssetsDirectory(final Project project, final Provider<VersionJson> versionJsonProvider) {
return FileCacheUtils.getAssetsCacheDirectory(project).flatMap(assetsDir -> assetsDir.dir(versionJsonProvider.map(VersionJson::getId))).map(TransformerUtils.ensureExists());
}

protected Provider<File> getFileInAssetsDirectory(final String fileName) {
return assetsCache.map(directory -> directory.file(fileName).getAsFile());
}

protected Provider<RegularFile> getRegularFileInAssetsDirectory(final Provider<String> fileName) {
return assetsCache.flatMap(directory -> fileName.map(directory::file));
}

@ServiceReference(CommonProjectPlugin.ASSETS_SERVICE)
public abstract Property<CentralCacheService> getAssetsCache();

Expand Down Expand Up @@ -67,7 +86,7 @@ private void downloadAssets() {
final WorkQueue executor = getWorkerExecutor().noIsolation();

assetIndex.getObjects().values().stream().distinct().forEach((asset) -> {
final Provider<File> assetFile = getFileInOutputDirectory(String.format("objects%s%s", File.separator, asset.getPath()));
final Provider<File> assetFile = getFileInAssetsDirectory(String.format("objects%s%s", File.separator, asset.getPath()));
final Provider<String> assetUrl = getAssetRepository()
.map(repo -> repo.endsWith("/") ? repo : repo + "/")
.map(TransformerUtils.guard(repository -> repository + asset.getPath()));
Expand Down Expand Up @@ -110,10 +129,6 @@ private void downloadAssets() {
@Input
public abstract Property<Boolean> getIsOffline();

@InputDirectory
@PathSensitive(PathSensitivity.NONE)
public abstract DirectoryProperty getAssetsDirectory();

private static class AssetIndex {
private Map<String, Asset> objects = Maps.newHashMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ public void execute() {
}
}

private static final class Monitor implements CopyProgressListener {
private final GradleInternalUtils.ProgressLoggerWrapper progress;

private Monitor(GradleInternalUtils.ProgressLoggerWrapper progress) {
this.progress = progress;
}
private record Monitor(GradleInternalUtils.ProgressLoggerWrapper progress) implements CopyProgressListener {

@Override
public void start(CopyProgressEvent evt) {
Expand Down Expand Up @@ -148,9 +143,13 @@ public int getReadTimeout() {

public interface Params extends WorkParameters {
Property<String> getUrl();

Property<String> getSha1();

Property<Boolean> getShouldValidateHash();

RegularFileProperty getOutputFile();

Property<Boolean> getIsOffline();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

public final class FileCacheUtils {

Expand Down Expand Up @@ -52,9 +53,9 @@ public static TaskProvider<MinecraftVersionManifestFileCacheProvider> createVers
public static TaskProvider<MinecraftArtifactFileCacheProvider> createArtifactFileCacheProvidingTask(final Project project, final String minecraftVersion, final DistributionType distributionType, final MinecraftArtifactType type, final TaskProvider<MinecraftVersionManifestFileCacheProvider> versionManifestProvider, final Collection<TaskProvider<? extends WithOutput>> otherProviders) {
final String taskName = NamingConstants.Task.CACHE_VERSION_PREFIX +
StringUtils.capitalize(
type.name().toLowerCase()
type.name().toLowerCase(Locale.ROOT)
) + StringUtils.capitalize(
distributionType.getName().toLowerCase()
distributionType.getName().toLowerCase(Locale.ROOT)
) + minecraftVersion;

if (project.getTasks().getNames().contains(taskName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.neoforged.gradle.dsl.common.util.Artifact;
import org.gradle.api.Buildable;
import org.gradle.api.Project;
import org.gradle.api.ProjectConfigurationException;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
Expand Down Expand Up @@ -212,6 +213,12 @@ public void add(@NotNull Object dependency) {
}

private void processTask(Task task) {
//Tasks that are outside our project are not relevant, they can cause issues in parallel projects anyway
//And their runtimes should not configure our runs anyway!
if (task.getProject() != this.project) {
return;
}

final Optional<? extends Definition<?>> rawJarRuntime = this.runtimes.stream().filter(runtime -> runtime.getRawJarTask().get().equals(task)).findFirst();
final Optional<? extends Definition<?>> sourceJarRuntime = this.runtimes.stream().filter(runtime -> runtime.getSourceJarTask().get().equals(task)).findFirst();
if (rawJarRuntime.isPresent()) {
Expand All @@ -226,7 +233,7 @@ private void processTask(Task task) {
}

private void processConfiguration(Configuration configuration) {
DependencySet dependencies = configuration.getDependencies();
DependencySet dependencies = configuration.getAllDependencies();

//Grab the original dependencies if we have a replacement extension
final DependencyReplacement replacement = project.getExtensions().findByType(DependencyReplacement.class);
Expand All @@ -244,14 +251,6 @@ private void processConfiguration(Configuration configuration) {
return false;
}
}).forEach(this::add);

configuration.getExtendsFrom().forEach(this::add);

if (configuration.isCanBeResolved()) {
for (Task task : configuration.getBuildDependencies().getDependencies(null)) {
add(task);
}
}
}

private void processSourceDirectorySet(SourceDirectorySet sourceDirectorySet) {
Expand All @@ -268,6 +267,13 @@ private void processSourceDirectorySet(SourceDirectorySet sourceDirectorySet) {
}

private void processSourceSet(SourceSet sourceSet) {
//We only care about source sets in our project
//We don't want to configure runtimes for other projects
//This can cause issues with parallel projects
if (SourceSetUtils.getProject(sourceSet) != this.project) {
return;
}

Property<CommonRuntimeDefinition<?>> runtimeDefinition = (Property<CommonRuntimeDefinition<?>>) sourceSet.getExtensions().findByName("runtimeDefinition");
if (runtimeDefinition != null && runtimeDefinition.isPresent()) {
this.add(runtimeDefinition.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public String getName() {
}

public static OS getCurrent() {
String prop = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
String prop = System.getProperty("os.name").toLowerCase(Locale.ROOT);
for (OS os : OS.values()) {
for (String key : os.keys) {
if (prop.contains(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;

public class Hashing {
private static final HashFunction MD5 = MessageDigestHashFunction.of("MD5");
Expand Down Expand Up @@ -355,9 +356,24 @@ public HashCode hashStream(InputStream stream) throws IOException {
}

public HashCode hashFile(File file) throws IOException {
HashingOutputStream hashingOutputStream = this.primitiveStreamHasher();
Files.copy(file, hashingOutputStream);
return hashingOutputStream.hash();
if (file.exists()) {
if (file.isDirectory()) {
final Hasher hasher = this.newHasher();

for (File listFile : Objects.requireNonNull(file.listFiles())) {
final HashCode innerHash = this.hashFile(listFile);
hasher.putHash(innerHash);
}

return hasher.hash();
} else {
HashingOutputStream hashingOutputStream = this.primitiveStreamHasher();
Files.copy(file, hashingOutputStream);
return hashingOutputStream.hash();
}
} else {
return HashCode.fromString("");
}
}

private HashingOutputStream primitiveStreamHasher() {
Expand Down
Loading
Loading