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

Add setConfigurations for jarJar #145

Merged
merged 3 commits into from
May 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ComponentSelector;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentSelector;
import org.gradle.api.artifacts.result.*;
import org.gradle.api.artifacts.result.DependencyResult;
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.artifacts.result.ResolvedVariantResult;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.capabilities.Capability;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.SetProperty;
Expand All @@ -23,7 +25,14 @@
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public abstract class JarJarArtifacts {
Expand Down Expand Up @@ -68,6 +77,7 @@ public JarJarArtifacts() {

includedArtifacts.finalizeValueOnRead();
includedRootComponents.finalizeValueOnRead();
getResolvedArtifacts().finalizeValueOnRead();

final DependencyFilter filter = getDependencyFilter();
final DependencyVersionInformationHandler versionHandler = getDependencyVersionInformationHandler();
Expand All @@ -83,6 +93,14 @@ public void configuration(Configuration jarJarConfiguration) {
getIncludedRootComponents().add(jarJarConfiguration.getIncoming().getResolutionResult().getRootComponent());
}

public void setConfigurations(Collection<? extends Configuration> configurations) {
includedRootComponents.empty();
includedArtifacts.empty();
for (Configuration configuration : configurations) {
configuration(configuration);
}
}

private static List<ResolvedJarJarArtifact> getIncludedJars(DependencyFilter filter, DependencyVersionInformationHandler versionHandler, Set<ResolvedComponentResult> rootComponents, Set<ResolvedArtifactResult> artifacts) {
Map<ContainedJarIdentifier, String> versions = new HashMap<>();
Map<ContainedJarIdentifier, String> versionRanges = new HashMap<>();
Expand Down
13 changes: 11 additions & 2 deletions common/src/main/java/net/neoforged/gradle/common/tasks/JarJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gradle.api.file.CopySpec;
import org.gradle.api.file.DuplicatesStrategy;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.bundling.Jar;
Expand All @@ -21,6 +22,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -44,12 +46,14 @@ public JarJar() {
setManifest(new DefaultInheritManifest(getServices().get(FileResolver.class)));
}

@Nested
// Already included in the JarJarArtifacts
@Internal
public DependencyFilter getDependencyFilter() {
return getJarJarArtifacts().getDependencyFilter();
}

@Nested
// Already included in the JarJarArtifacts
@Internal
public DependencyVersionInformationHandler getDependencyVersionInformationHandler() {
return getJarJarArtifacts().getDependencyVersionInformationHandler();
}
Expand Down Expand Up @@ -100,6 +104,11 @@ public void configuration(Configuration jarJarConfiguration) {
dependsOn(jarJarConfiguration);
}

public void setConfigurations(Collection<? extends Configuration> configurations) {
getJarJarArtifacts().setConfigurations(configurations);
configurations.forEach(this::dependsOn);
}

private Path getJarJarMetadataPath() {
return getTemporaryDir().toPath().resolve("metadata.json");
}
Expand Down
Loading