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

Resolve Configuration directly in DependencyFilter #1045

Merged
merged 3 commits into from
Nov 26, 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
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