Skip to content

Commit

Permalink
Resolve Configuration directly in DependencyFilter (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Nov 26, 2024
1 parent d5e3cec commit d373be1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/shadow.api
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public abstract interface class com/github/jengelman/gradle/plugins/shadow/inter
public abstract fun project (Ljava/lang/String;)Lorg/gradle/api/specs/Spec;
public abstract fun project (Ljava/util/Map;)Lorg/gradle/api/specs/Spec;
public abstract fun resolve (Ljava/util/Collection;)Lorg/gradle/api/file/FileCollection;
public abstract fun resolve (Lorg/gradle/api/file/FileCollection;)Lorg/gradle/api/file/FileCollection;
public abstract fun resolve (Lorg/gradle/api/artifacts/Configuration;)Lorg/gradle/api/file/FileCollection;
}

public abstract interface class com/github/jengelman/gradle/plugins/shadow/internal/ZipCompressor : org/gradle/api/internal/file/archive/compression/ArchiveOutputStreamFactory {
Expand Down
1 change: 1 addition & 0 deletions src/docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
**Changed**

- **BREAKING CHANGE:** Rewrite this plugin in Kotlin. ([#1012](https://github.com/GradleUp/shadow/pull/1012))
- **BREAKING CHANGE:** Resolve `Configuration` directly in `DependencyFilter`. ([#1045](https://github.com/GradleUp/shadow/pull/1045))

**Removed**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ internal sealed class AbstractDependencyFilter(
excludedDependencies: MutableSet<ResolvedDependency>,
)

override fun resolve(configuration: FileCollection): FileCollection {
override fun resolve(configuration: Configuration): FileCollection {
val includedDeps = mutableSetOf<ResolvedDependency>()
val excludedDeps = mutableSetOf<ResolvedDependency>()
configuration as Configuration
resolve(configuration.resolvedConfiguration.firstLevelModuleDependencies, includedDeps, excludedDeps)
return project.files(configuration.files) -
project.files(excludedDeps.flatMap { it.moduleArtifacts.map(ResolvedArtifact::getFile) })
}

override fun resolve(configurations: Collection<FileCollection>): FileCollection {
override fun resolve(configurations: Collection<Configuration>): FileCollection {
return configurations.map { resolve(it) }
.reduceOrNull { acc, fileCollection -> acc + fileCollection }
?: project.files()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.github.jengelman.gradle.plugins.shadow.internal

import groovy.lang.Closure
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ResolvedDependency
import org.gradle.api.file.FileCollection
import org.gradle.api.specs.Spec

public interface DependencyFilter {
/**
* Resolve a FileCollection against the include/exclude rules in the filter.
* Resolve a [Configuration] against the include/exclude rules in the filter.
*/
public fun resolve(configuration: FileCollection): FileCollection
public fun resolve(configuration: Configuration): FileCollection

/**
* Resolve all FileCollections against the include/exclude rules in the filter and combine the results.
* Resolve all [Configuration]s against the include/exclude rules in the filter and combine the results.
*/
public fun resolve(configurations: Collection<FileCollection>): FileCollection
public fun resolve(configurations: Collection<Configuration>): FileCollection

/**
* Exclude dependencies that match the provided spec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.util.concurrent.Callable
import java.util.jar.JarFile
import org.apache.tools.zip.ZipOutputStream
import org.gradle.api.Action
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.DocumentationRegistry
Expand Down Expand Up @@ -47,7 +48,7 @@ public abstract class ShadowJar :
ShadowSpec {
private val _transformers = mutableListOf<Transformer>()
private val _relocators = mutableListOf<Relocator>()
private val _configurations = mutableListOf<FileCollection>()
private val _configurations = mutableListOf<Configuration>()
private val _stats = ShadowStats()
private val _includedDependencies = project.files(Callable { _dependencyFilter.resolve(_configurations) })

Expand Down Expand Up @@ -158,7 +159,7 @@ public abstract class ShadowJar :

@get:Classpath
@get:Optional
public var configurations: List<FileCollection>
public var configurations: List<Configuration>
get() = _configurations
set(value) {
_configurations.clear()
Expand Down Expand Up @@ -327,7 +328,8 @@ public abstract class ShadowJar :

private fun configureRelocation() {
val packages = mutableSetOf<String>()
configurations.forEach { configuration ->
// Must cast configurations to List<FileCollection> to fix type mismatch in runtime.
(configurations as List<FileCollection>).forEach { configuration ->
configuration.files.forEach { jarFile ->
JarFile(jarFile).use { jf ->
jf.entries().asSequence().forEach { entry ->
Expand Down

0 comments on commit d373be1

Please sign in to comment.