Merge remote-tracking branch 'upstream/dev/1.0' into dev/0.13.0

# Conflicts:
#	build.gradle
This commit is contained in:
Juuz
2022-08-28 14:21:09 +03:00
13 changed files with 141 additions and 53 deletions

View File

@@ -74,6 +74,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.mapped.NamedMinecraft
import net.fabricmc.loom.configuration.providers.minecraft.mapped.SrgMinecraftProvider;
import net.fabricmc.loom.configuration.sources.ForgeSourcesRemapper;
import net.fabricmc.loom.extension.MixinExtension;
import net.fabricmc.loom.util.Checksum;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ExceptionUtil;
import net.fabricmc.loom.util.OperatingSystem;
@@ -411,8 +412,9 @@ public final class CompileConfiguration {
private static Path getLockFile(Project project) {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final Path cacheDirectory = extension.getFiles().getProjectPersistentCache().toPath();
return cacheDirectory.resolve("configuration.lock");
final Path cacheDirectory = extension.getFiles().getUserCache().toPath();
final String pathHash = Checksum.toHex(project.getProjectDir().getAbsolutePath().getBytes(StandardCharsets.UTF_8)).substring(0, 16);
return cacheDirectory.resolve("." + pathHash + ".lock");
}
private static boolean getAndLock(Project project) {
@@ -434,10 +436,23 @@ public final class CompileConfiguration {
private static void releaseLock(Project project) {
final Path lock = getLockFile(project);
if (!Files.exists(lock)) {
return;
}
try {
Files.deleteIfExists(lock);
} catch (IOException e) {
throw new UncheckedIOException("Failed to release project configuration lock", e);
Files.delete(lock);
} catch (IOException e1) {
try {
// If we failed to delete the lock file, moving it before trying to delete it may help.
final Path del = lock.resolveSibling(lock.getFileName() + ".del");
Files.move(lock, del);
Files.delete(del);
} catch (IOException e2) {
var exception = new UncheckedIOException("Failed to release project configuration lock", e2);
exception.addSuppressed(e1);
throw exception;
}
}
}

View File

@@ -89,7 +89,6 @@ public final class MavenPublication {
}
}
// TODO: Remove this in Loom 0.12
private static void processEntry(Project project, String scope, Configuration config, PublishingExtension mavenPublish, AtomicBoolean reportedDeprecation) {
mavenPublish.publications((publications) -> {
for (Publication publication : publications) {
@@ -101,7 +100,7 @@ public final class MavenPublication {
continue;
} else if (!reportedDeprecation.get() && !LoomGradleExtension.get(project).isForge()) {
DeprecationHelper deprecationHelper = LoomGradleExtension.get(project).getDeprecationHelper();
deprecationHelper.warn("Loom is applying dependency data manually to publications instead of using a software component (from(components[\"java\"])). This is deprecated and will be removed in Loom 0.13.");
deprecationHelper.warn("Loom is applying dependency data manually to publications instead of using a software component (from(components[\"java\"])). This is deprecated.");
reportedDeprecation.set(true);
}

View File

@@ -55,8 +55,6 @@ final class AccessWidenerTransformer {
* Apply the rules from an access-widener to the given jar or zip file.
*/
void apply(File jarFile) {
logger.lifecycle("Processing file: " + jarFile.getName());
try {
ZipUtils.transform(jarFile.toPath(), getTransformers(accessWidener.getTargets()));
} catch (IOException e) {

View File

@@ -136,8 +136,6 @@ public class InterfaceInjectionProcessor implements JarProcessor, GenerateSource
}
}
project.getLogger().lifecycle("Processing file: " + jarFile.getName());
try {
ZipUtils.transform(jarFile.toPath(), getTransformers());
} catch (IOException e) {

View File

@@ -103,7 +103,6 @@ public abstract class DownloadAssetsTask extends AbstractLoomTask {
.download(url)
.sha1(sha1)
.progress(new GradleDownloadProgressListener(object.name(), progressGroup::createProgressLogger))
.maxRetries(3)
.downloadPathAsync(getAssetsPath(object, assetIndex), executor);
}
}

View File

@@ -25,6 +25,7 @@
package net.fabricmc.loom.util.download;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.HttpURLConnection;
import java.net.ProxySelector;
@@ -45,8 +46,8 @@ import java.time.Instant;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.zip.GZIPInputStream;
import com.github.mizosoft.methanol.Methanol;
import com.github.mizosoft.methanol.ProgressTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -85,10 +86,9 @@ public class Download {
throw error("Unable to download %s in offline mode", this.url);
}
return Methanol.newBuilder()
return HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.ALWAYS)
.proxy(ProxySelector.getDefault())
.autoAcceptEncoding(true)
.build();
}
@@ -127,7 +127,7 @@ public class Download {
}
String downloadString() throws DownloadException {
final HttpResponse<String> response = send(getRequest(), HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
final HttpResponse<InputStream> response = send(getRequest(), HttpResponse.BodyHandlers.ofInputStream());
final int statusCode = response.statusCode();
final boolean successful = statusCode >= 200 && statusCode < 300;
@@ -135,7 +135,11 @@ public class Download {
throw error("HTTP request to (%s) returned unsuccessful status (%d)", url, statusCode);
}
return response.body();
try (InputStream inputStream = decodeOutput(response)) {
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw error(e, "Failed to decode download output");
}
}
void downloadPath(Path output) throws DownloadException {
@@ -174,7 +178,7 @@ public class Download {
// Create a .lock file, this allows us to re-download if the download was forcefully aborted part way through.
createLock(output);
HttpResponse<Path> response = send(httpRequest, HttpResponse.BodyHandlers.ofFile(output));
HttpResponse<InputStream> response = send(httpRequest, HttpResponse.BodyHandlers.ofInputStream());
getAndResetLock(output);
final int statusCode = response.statusCode();
@@ -185,13 +189,15 @@ public class Download {
return;
}
if (!success) {
try {
Files.deleteIfExists(output);
} catch (IOException ignored) {
// We tried.
if (success) {
try (InputStream inputStream = decodeOutput(response)) {
Files.write(output, inputStream.readAllBytes());
} catch (IOException e) {
tryCleanup(output);
throw error(e, "Failed to decode and write download output");
}
} else {
tryCleanup(output);
throw error("HTTP request to (%s) returned unsuccessful status (%d)", url, statusCode);
}
@@ -224,6 +230,16 @@ public class Download {
}
}
private InputStream decodeOutput(HttpResponse<InputStream> response) throws IOException {
final String encoding = response.headers().firstValue("Content-Encoding").orElse("");
return switch (encoding) {
case "gzip" -> new GZIPInputStream(response.body());
case "" -> response.body();
default -> throw error("Unsupported encoding: %s", encoding);
};
}
private boolean requiresDownload(Path output) throws DownloadException {
if (getAndResetLock(output)) {
LOGGER.warn("Forcing downloading {} as existing lock file was found. This may happen if the gradle build was forcefully canceled.", output);

View File

@@ -44,7 +44,7 @@ public class DownloadBuilder {
private boolean offline = false;
private Duration maxAge = Duration.ZERO;
private DownloadProgressListener progressListener = DownloadProgressListener.NONE;
private int maxRetries = 1;
private int maxRetries = 3;
private DownloadBuilder(URI url) {
this.url = url;

View File

@@ -28,6 +28,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -92,16 +94,7 @@ public final class SourceSetHelper {
*/
public static Project getSourceSetProject(SourceSet sourceSet) {
final DefaultSourceSetOutput sourceSetOutput = (DefaultSourceSetOutput) sourceSet.getOutput();
final DefaultTaskDependency taskDependency = (DefaultTaskDependency) sourceSetOutput.getClassesContributors();
Project project = null;
for (Object object : taskDependency.getMutableValues()) {
if (object instanceof Task task) {
project = task.getProject();
} else if (object instanceof TaskProvider<?> provider) {
project = provider.get().getProject();
}
}
final Project project = getProjectFromSourceSetOutput(sourceSetOutput);
if (project == null) {
throw new NullPointerException("Unable to determine owning project for SourceSet: " + sourceSet.getName());
@@ -110,6 +103,55 @@ public final class SourceSetHelper {
return project;
}
private static Project getProjectFromSourceSetOutput(SourceSetOutput sourceSetOutput) {
final Class<? extends DefaultSourceSetOutput> clazz = DefaultSourceSetOutput.class;
try {
final Method getClassesContributorsMethod = clazz.getMethod("getClassesContributors");
final Object classesContributors = getClassesContributorsMethod.invoke(sourceSetOutput);
if (classesContributors instanceof List<?> list) {
// Gradle 7.7
return getProjectFromDirectoryContributions(list);
} else if (classesContributors instanceof DefaultTaskDependency taskDependency) {
// Pre Gradle 7.7
return getProjectFromTaskDependency(taskDependency);
} else {
throw new UnsupportedOperationException();
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
// Pre Gradle 7.7
private static Project getProjectFromTaskDependency(DefaultTaskDependency taskDependency) {
for (Object object : taskDependency.getMutableValues()) {
if (object instanceof Task task) {
return task.getProject();
} else if (object instanceof TaskProvider<?> provider) {
return provider.get().getProject();
}
}
return null;
}
// Gradle 7.7: https://github.com/gradle/gradle/commit/2797942dc71f0e0e186b7d0c5ba3e09eceea4507#diff-b19ce8fbc4aa4ebaeea74e39609636d65e385bce6990fd42d68581dd829f29b3L153
private static Project getProjectFromDirectoryContributions(List<? /*DirectoryContribution*/> classesContributions) {
for (Object classesContribution : classesContributions) {
try {
final Method getTask = classesContribution.getClass().getMethod("getTask");
final TaskProvider<?> taskProvider = (TaskProvider<?>) getTask.invoke(classesContribution);
return taskProvider.get().getProject();
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return null;
}
public static List<File> getClasspath(ModSettings modSettings, Project project) {
final List<File> files = new ArrayList<>();