Skip to content

Commit

Permalink
Fix gradle emitDependencies task cache
Browse files Browse the repository at this point in the history
Partially revert what I deleted in 2636070
  • Loading branch information
Yeregorix committed Jan 13, 2025
1 parent 37a4757 commit 21bc1ef
Showing 1 changed file with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

Expand All @@ -49,6 +50,7 @@
import java.nio.file.Files;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -108,6 +110,10 @@ public final void dependencies(final String key, final NamedDomainObjectProvider
@Internal
public abstract SetProperty<ResolvedArtifactResult> getExcludedDependencies();

@Input
@Optional
protected abstract SetProperty<ModuleComponentIdentifier> getExcludedDependencyIdentifiers();

public final void excludeDependencies(final NamedDomainObjectProvider<Configuration> config) {
this.getExcludedDependencies().addAll(config.flatMap(conf -> conf.getIncoming().getArtifacts().getResolvedArtifacts()));
}
Expand All @@ -123,18 +129,21 @@ public final void excludeDependencies(final NamedDomainObjectProvider<Configurat

public OutputDependenciesToJson() {
this.getAllowedClassifiers().add("");
this.getExcludedDependencyIdentifiers().set(this.getExcludedDependencies().map(artifacts -> {
final Set<ModuleComponentIdentifier> ids = new HashSet<>();
for (final ResolvedArtifactResult artifact : artifacts) {
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
if (id instanceof ModuleComponentIdentifier) {
ids.add((ModuleComponentIdentifier) id);
}
}
return ids;
}));
}

@TaskAction
public void generateDependenciesJson() {
final Set<ModuleComponentIdentifier> excludedDeps = new HashSet<>();
if (this.getExcludedDependencies().isPresent()) {
for (final ResolvedArtifactResult result : this.getExcludedDependencies().get()) {
if (result.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier) {
excludedDeps.add((ModuleComponentIdentifier) result.getId().getComponentIdentifier());
}
}
}
final Set<ModuleComponentIdentifier> excludedDeps = this.getExcludedDependencyIdentifiers().getOrElse(Collections.emptySet());

final Map<String, ConfigurationHolder> inputConfigs = this.getDependencies().get();
final Map<String, List<DependencyDescriptor>> dependenciesMap = new TreeMap<>();
Expand Down Expand Up @@ -201,15 +210,29 @@ public static String toHexString(final byte[] bytes) {
}

public static class ConfigurationHolder {
private final Provider<Set<ResolvedArtifactResult>> configuration;
private final Provider<Set<ResolvedArtifactResult>> artifacts;

public ConfigurationHolder(final Configuration configuration) {
this.configuration = configuration.getIncoming().getArtifacts().getResolvedArtifacts();
this.artifacts = configuration.getIncoming().getArtifacts().getResolvedArtifacts();
}

@Input
public Provider<Set<String>> getIds() {
return this.artifacts.map(set -> {
final Set<String> ids = new HashSet<>();
for (final ResolvedArtifactResult artifact : set) {
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
if (id instanceof ModuleComponentIdentifier) {
ids.add(id.getDisplayName());
}
}
return ids;
});
}

@Internal
public Provider<Set<ResolvedArtifactResult>> getArtifacts() {
return this.configuration;
return this.artifacts;
}
}
}

0 comments on commit 21bc1ef

Please sign in to comment.