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

Draft: Use dependency attributes instead of version markers for remapped dependencies #953

Draft
wants to merge 4 commits into
base: FG_6.0
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
import groovy.util.NodeList;
import net.minecraftforge.gradle.common.util.BaseRepo;
import net.minecraftforge.gradle.common.util.MinecraftExtension;
import net.minecraftforge.gradle.userdev.dependency.RemappedExternalModuleDependency;
import net.minecraftforge.gradle.userdev.util.DeobfuscatingRepo;
import net.minecraftforge.gradle.userdev.util.DeobfuscatingVersionUtils;
import net.minecraftforge.gradle.userdev.util.DependencyRemapper;
import net.minecraftforge.gradle.userdev.util.MavenPomUtils;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.*;
import org.gradle.api.artifacts.dsl.ExternalModuleDependencyVariantSpec;
import org.gradle.api.artifacts.repositories.ArtifactRepository;
import org.gradle.api.provider.Provider;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.tasks.GenerateModuleMetadata;

Expand All @@ -30,19 +32,29 @@
public class DependencyManagementExtension extends GroovyObjectSupport {
public static final String EXTENSION_NAME = "fg";
private final Project project;
private final DependencyRemapper remapper;
private final DeobfuscatingRepo deobfuscatingRepo;
private final ArtifactRepository repository;

public DependencyManagementExtension(Project project, DependencyRemapper remapper, DeobfuscatingRepo deobfuscatingRepo) {
public DependencyManagementExtension(Project project, DeobfuscatingRepo deobfuscatingRepo) {
this.project = project;
this.remapper = remapper;
this.deobfuscatingRepo = deobfuscatingRepo;
this.repository = new BaseRepo.Builder()
.add(deobfuscatingRepo)
.attach(project, "bundled_deobf_repo");
}

private Dependency createRemappedDependency(Dependency dependency) {
if(dependency instanceof ExternalModuleDependency) {
return new RemappedExternalModuleDependency((ExternalModuleDependency) dependency);
}
if(dependency instanceof FileCollectionDependency) {
project.getLogger().warn("Dependency {} will not be deobfuscated. Use a flatDir repository instead: https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver", dependency);
} else {
project.getLogger().warn("Dependency {} is not being deobfuscated", dependency);
}
return dependency;
}

public DeobfuscatingRepo getDeobfuscatingRepo() {
return deobfuscatingRepo;
}
Expand All @@ -51,16 +63,26 @@ public ArtifactRepository getRepository() {
return repository;
}

@SuppressWarnings("unused")
public Dependency deobf(Object dependency) {
return deobf(dependency, null);
}

public Dependency deobf(Object dependency, Closure<?> configure) {
Dependency baseDependency = project.getDependencies().create(dependency, configure);
project.getConfigurations().getByName(UserDevPlugin.OBF).getDependencies().add(baseDependency);
return createRemappedDependency(baseDependency);
}

return remapper.remap(baseDependency);
public Dependency deobf(Provider<MinimalExternalModuleDependency> provider) {
MinimalExternalModuleDependency baseDependency = provider.get();
project.getConfigurations().getByName(UserDevPlugin.OBF).getDependencies().add(baseDependency);
return createRemappedDependency(baseDependency);
}

public Dependency deobf(Provider<MinimalExternalModuleDependency> provider, Action<? super ExternalModuleDependencyVariantSpec> variantSpec) {
MinimalExternalModuleDependency baseDependency = project.getDependencies().variantOf(provider, variantSpec).get();
project.getConfigurations().getByName(UserDevPlugin.OBF).getDependencies().add(baseDependency);
return createRemappedDependency(baseDependency);
}

@SuppressWarnings({"ConstantConditions", "unchecked"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace;
import net.minecraftforge.gradle.userdev.util.DeobfuscatingRepo;
import net.minecraftforge.gradle.userdev.util.Deobfuscator;
import net.minecraftforge.gradle.userdev.util.DependencyRemapper;
import net.minecraftforge.srgutils.IMappingFile;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -104,8 +103,7 @@ public void apply(@Nonnull Project project) {
// Create extension for dependency remapping
// Can't create at top-level or put in `minecraft` ext due to configuration name conflict
final Deobfuscator deobfuscator = new Deobfuscator(project, Utils.getCache(project, "deobf_dependencies"));
final DependencyRemapper remapper = new DependencyRemapper(project, deobfuscator);
DependencyManagementExtension fgExtension = project.getExtensions().create(DependencyManagementExtension.EXTENSION_NAME, DependencyManagementExtension.class, project, remapper, new DeobfuscatingRepo(project, internalObfConfiguration, deobfuscator));
DependencyManagementExtension fgExtension = project.getExtensions().create(DependencyManagementExtension.EXTENSION_NAME, DependencyManagementExtension.class, project, new DeobfuscatingRepo(project, internalObfConfiguration, deobfuscator));
JarJarProjectExtension jarJarExtension = project.getExtensions().create(JarJarProjectExtension.EXTENSION_NAME, JarJarProjectExtension.class, project);

final TaskContainer tasks = project.getTasks();
Expand Down Expand Up @@ -254,8 +252,6 @@ public void apply(@Nonnull Project project) {
});
});

remapper.attachMappings(extension.getMappings().get());

if (fgExtension.getDeobfuscatingRepo().getResolvedOrigin() == null) {
project.getLogger().error("DeobfRepo attempted to resolve an origin repo early but failed, this may cause issues with some IDEs");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package net.minecraftforge.gradle.userdev.dependency;

import groovy.lang.Closure;
import net.minecraftforge.gradle.userdev.util.MutableAttributeContainer;
import org.gradle.api.Action;
import org.gradle.api.artifacts.*;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeContainer;
import org.gradle.api.capabilities.Capability;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class RemappedExternalModuleDependency implements ExternalModuleDependency {
public static final Attribute<Boolean> ATTRIBUTE = Attribute.of("remapped", Boolean.class);

private final ExternalModuleDependency dependency;
private final MutableAttributeContainer attributes;

public RemappedExternalModuleDependency(ExternalModuleDependency dependency) {
this.dependency = dependency;
attributes = new MutableAttributeContainer();
attributes.attributes(dependency.getAttributes()); // Copy base attributes
attributes.attribute(ATTRIBUTE, true); // Add marker for remapped dependencies
}

@Override
public boolean isChanging() {
return dependency.isChanging();
}

@Override
public @Nonnull ExternalModuleDependency setChanging(boolean changing) {
return dependency.setChanging(changing);
}

@Override
public @Nonnull ExternalModuleDependency copy() {
return new RemappedExternalModuleDependency(dependency);
}

@Override
public boolean isForce() {
return dependency.isForce();
}

@Override
public void version(@Nonnull Action<? super MutableVersionConstraint> configureAction) {
dependency.version(configureAction);
}

@Override
public @Nonnull VersionConstraint getVersionConstraint() {
return dependency.getVersionConstraint();
}

@Override
public @Nonnull ModuleDependency exclude(@Nonnull Map<String, String> excludeProperties) {
return dependency.exclude(excludeProperties);
}

@Override
public @Nonnull Set<ExcludeRule> getExcludeRules() {
return dependency.getExcludeRules();
}

@Override
public @Nonnull Set<DependencyArtifact> getArtifacts() {
return dependency.getArtifacts();
}

@Override
public @Nonnull ModuleDependency addArtifact(@Nonnull DependencyArtifact artifact) {
return dependency.addArtifact(artifact);
}

@Override
public @Nonnull DependencyArtifact artifact(@Nonnull Closure configureClosure) {
return dependency.artifact(configureClosure);
}

@Override
public @Nonnull DependencyArtifact artifact(@Nonnull Action<? super DependencyArtifact> configureAction) {
return dependency.artifact(configureAction);
}

@Override
public boolean isTransitive() {
return dependency.isTransitive();
}

@Override
public @Nonnull ModuleDependency setTransitive(boolean transitive) {
return dependency.setTransitive(transitive);
}

@Override
public @Nullable String getTargetConfiguration() {
return dependency.getTargetConfiguration();
}

@Override
public void setTargetConfiguration(@Nullable String name) {
dependency.setTargetConfiguration(name);
}

@Override
public @Nonnull AttributeContainer getAttributes() {
return attributes;
}

@Override
public @Nonnull ModuleDependency attributes(@Nonnull Action<? super AttributeContainer> configureAction) {
configureAction.execute(attributes);
return this;
}

@Override
public @Nonnull ModuleDependency capabilities(@Nonnull Action<? super ModuleDependencyCapabilitiesHandler> configureAction) {
return dependency.capabilities(configureAction);
}

@Override
public @Nonnull List<Capability> getRequestedCapabilities() {
return dependency.getRequestedCapabilities();
}

@Override
public void endorseStrictVersions() {
dependency.endorseStrictVersions();
}

@Override
public void doNotEndorseStrictVersions() {
dependency.doNotEndorseStrictVersions();
}

@Override
public boolean isEndorsingStrictVersions() {
return dependency.isEndorsingStrictVersions();
}

@Override
public @Nonnull String getGroup() {
return Objects.requireNonNull(dependency.getGroup());
}

@Override
public @Nonnull String getName() {
return dependency.getName();
}

@Override
public @Nullable String getVersion() {
return dependency.getVersion();
}

@Override
public boolean contentEquals(@Nonnull Dependency dependency) {
return dependency.contentEquals(dependency);
}

@Override
public @Nullable String getReason() {
return dependency.getReason();
}

@Override
public void because(@Nullable String reason) {
dependency.because(reason);
}

@Override
public boolean matchesStrictly(@Nonnull ModuleVersionIdentifier identifier) {
return dependency.matchesStrictly(identifier);
}

@Override
public @Nonnull ModuleIdentifier getModule() {
return dependency.getModule();
}
}

This file was deleted.

Loading