Add debug logging to publication modification, remove log spam in asset downloading.

This commit is contained in:
shedaniel
2021-02-21 21:58:11 +08:00
parent ce4a1cb2a3
commit 2e2554d9cf
3 changed files with 32 additions and 8 deletions

View File

@@ -34,6 +34,7 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ExcludeRule;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.logging.Logger;
import org.gradle.api.publish.Publication;
import org.gradle.api.publish.PublishingExtension;
@@ -46,6 +47,14 @@ public final class MavenPublication {
public static void configure(Project project) {
project.afterEvaluate((p) -> {
// add modsCompile to maven-publish
PublishingExtension mavenPublish = p.getExtensions().findByType(PublishingExtension.class);
if (mavenPublish == null) {
p.getLogger().info("No maven publications for project [" + p.getName() + "], skipping configuration.");
return;
}
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
if (!entry.hasMavenScope()) {
continue;
@@ -53,23 +62,20 @@ public final class MavenPublication {
Configuration compileModsConfig = p.getConfigurations().getByName(entry.getSourceConfiguration());
// add modsCompile to maven-publish
PublishingExtension mavenPublish = p.getExtensions().findByType(PublishingExtension.class);
if (mavenPublish != null) {
processEntry(entry, compileModsConfig, mavenPublish);
}
p.getLogger().info("Processing maven publication for project [" + p.getName() + "] of " + entry.getSourceConfiguration());
processEntry(p.getLogger(), entry, compileModsConfig, mavenPublish);
}
});
}
private static void processEntry(RemappedConfigurationEntry entry, Configuration compileModsConfig, PublishingExtension mavenPublish) {
private static void processEntry(Logger logger, RemappedConfigurationEntry entry, Configuration compileModsConfig, PublishingExtension mavenPublish) {
mavenPublish.publications((publications) -> {
for (Publication publication : publications) {
if (!(publication instanceof org.gradle.api.publish.maven.MavenPublication)) {
continue;
}
logger.info("Processing maven publication [" + publication.getName() + "]");
((org.gradle.api.publish.maven.MavenPublication) publication).pom((pom) -> pom.withXml((xml) -> {
Node dependencies = GroovyXmlUtil.getOrCreateNode(xml.asNode(), "dependencies");
Set<String> foundArtifacts = new HashSet<>();
@@ -85,9 +91,12 @@ public final class MavenPublication {
for (Dependency dependency : compileModsConfig.getAllDependencies()) {
if (foundArtifacts.contains(dependency.getGroup() + ":" + dependency.getName())) {
logger.info("Found inserted artifact " + dependency.getGroup() + ":" + dependency.getName());
continue;
}
logger.info("Inserting artifact " + dependency.getGroup() + ":" + dependency.getName());
Node depNode = dependencies.appendNode("dependency");
depNode.appendNode("groupId", dependency.getGroup());
depNode.appendNode("artifactId", dependency.getName());

View File

@@ -107,7 +107,7 @@ public class MinecraftAssetsProvider {
} else {
throw new GradleException("Asset " + entry.getKey() + " not found at " + file.getAbsolutePath());
}
} else {
} else if (HashedDownloadUtil.requiresDownload(file, sha1, project.getLogger())) {
toDownload++;
if (progressBar[0] == null) {

View File

@@ -40,6 +40,21 @@ import org.gradle.api.logging.Logger;
import net.fabricmc.loom.LoomGradlePlugin;
public class HashedDownloadUtil {
public static boolean requiresDownload(File to, String expectedHash, Logger logger) {
if (LoomGradlePlugin.refreshDeps) {
return true;
}
if (to.exists()) {
String sha1 = getSha1(to, logger);
// The hash in the sha1 file matches
return !expectedHash.equals(sha1);
}
return true;
}
public static void downloadIfInvalid(URL from, File to, String expectedHash, Logger logger, boolean quiet) throws IOException {
if (LoomGradlePlugin.refreshDeps) {
delete(to);