Skip to content
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
@@ -0,0 +1,31 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.tasks.KnowsTask
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.util.GradleVersion

abstract class ShadowBasePlugin : Plugin<Project> {

override fun apply(project: Project) {
if (GradleVersion.current() < GradleVersion.version("8.3")) {
throw GradleException("This version of Shadow supports Gradle 8.3+ only. Please upgrade.")
}
project.extensions.create(EXTENSION_NAME, ShadowExtension::class.java, project)
project.configurations.create(CONFIGURATION_NAME)
project.tasks.register(KnowsTask.NAME, KnowsTask::class.java) { knows ->
knows.group = GROUP_NAME
knows.description = KnowsTask.DESC
}
}

companion object {
const val SHADOW: String = "shadow"
const val GROUP_NAME: String = SHADOW
const val EXTENSION_NAME: String = SHADOW
const val CONFIGURATION_NAME: String = SHADOW
const val COMPONENT_NAME: String = SHADOW
const val DISTRIBUTION_NAME: String = SHADOW
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.jengelman.gradle.plugins.shadow

import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPublication

@Deprecated("This is deprecated since 8.3.2")
abstract class ShadowExtension(project: Project) {
private val components = project.components

@Deprecated("configure publication using component.shadow directly.")
fun component(publication: MavenPublication) {
publication.from(components.findByName(ShadowBasePlugin.COMPONENT_NAME))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.legacy.LegacyShadowPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.api.plugins.JavaPlugin

abstract class ShadowPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.run {
plugins.apply(ShadowBasePlugin::class.java)
plugins.withType(JavaPlugin::class.java) {
plugins.apply(ShadowJavaPlugin::class.java)
}
plugins.withType(ApplicationPlugin::class.java) {
plugins.apply(ShadowApplicationPlugin::class.java)
}
// Apply the legacy plugin last
// Because we apply the ShadowJavaPlugin/ShadowApplication plugin in a withType callback for the
// respective JavaPlugin/ApplicationPlugin, it may still apply before the shadowJar task is created etc.
// If the user applies shadow before those plugins. However, this is fine, because this was also
// the behavior with the old plugin when applying in that order.
plugins.apply(LegacyShadowPlugin::class.java)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.github.jengelman.gradle.plugins.shadow.internal

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

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

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

/**
* Exclude dependencies that match the provided spec.
*/
fun exclude(spec: Spec<ResolvedDependency>): DependencyFilter

/**
* Include dependencies that match the provided spec.
*/
fun include(spec: Spec<ResolvedDependency>): DependencyFilter

/**
* Create a spec that matches the provided project notation on group, name, and version.
*/
fun project(notation: Map<String, *>): Spec<ResolvedDependency>

/**
* Create a spec that matches the default configuration for the provided project path on group, name, and version.
*/
fun project(notation: String): Spec<ResolvedDependency>

/**
* Create a spec that matches dependencies using the provided notation on group, name, and version.
*/
fun dependency(notation: Any): Spec<ResolvedDependency>

/**
* Create a spec that matches the provided dependency on group, name, and version.
*/
fun dependency(dependency: Dependency): Spec<ResolvedDependency>

/**
* Create a spec that matches the provided closure.
*/
fun dependency(closure: Closure<*>): Spec<ResolvedDependency>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import org.gradle.api.Plugin
import org.gradle.api.Project

/**
* Empty plugin to still have the com.github.johnrengelman.shadow plugin applied.
* Empty plugin to still have the `com.github.johnrengelman.shadow` plugin applied.
*
* This allows older build logic to keep on working as if that old plugin ID was applied.
*/
class LegacyShadowPlugin implements Plugin<Project> {
@Override
void apply(Project target) {
// Do nothing
}
abstract class LegacyShadowPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.jengelman.gradle.plugins.shadow.relocation

/**
* Marks that a given instance of [Relocator] is compatible with the Gradle build cache.
* In other words, it has its appropriate inputs annotated so that Gradle can consider them when
* determining the cache key.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class CacheableRelocator
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.jengelman.gradle.plugins.shadow.relocation

import com.github.jengelman.gradle.plugins.shadow.ShadowStats

data class RelocateClassContext(
val className: String,
val stats: ShadowStats,
) {
class Builder {
private var className = ""
private var stats = ShadowStats()

fun className(className: String): Builder = apply { this.className = className }
fun stats(stats: ShadowStats): Builder = apply { this.stats = stats }
fun build(): RelocateClassContext = RelocateClassContext(className, stats)
}

companion object {
@JvmStatic
fun builder(): Builder = Builder()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.jengelman.gradle.plugins.shadow.relocation

import com.github.jengelman.gradle.plugins.shadow.ShadowStats

data class RelocatePathContext(
val path: String,
val stats: ShadowStats,
) {
class Builder {
private var path = ""
private var stats = ShadowStats()

fun path(path: String): Builder = apply { this.path = path }
fun stats(stats: ShadowStats): Builder = apply { this.stats = stats }
fun build(): RelocatePathContext = RelocatePathContext(path, stats)
}

companion object {
@JvmStatic
fun builder(): Builder = Builder()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.jengelman.gradle.plugins.shadow.relocation

/**
* Modified from `org.apache.maven.plugins.shade.relocation.Relocator.java`
*
* @author Jason van Zyl
* @author John Engelman
*/
interface Relocator {
fun canRelocatePath(path: String): Boolean

fun relocatePath(context: RelocatePathContext): String

fun canRelocateClass(className: String): Boolean

fun relocateClass(context: RelocateClassContext): String

fun applyToSourceContent(sourceContent: String): String

companion object {
val ROLE: String = Relocator::class.java.name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.jengelman.gradle.plugins.shadow.tasks

import org.gradle.api.Action
import org.gradle.api.java.archives.Manifest

interface InheritManifest : Manifest {
fun inheritFrom(vararg inheritPaths: Any): InheritManifest

fun inheritFrom(vararg inheritPaths: Any, action: Action<*>?): InheritManifest
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.github.jengelman.gradle.plugins.shadow.tasks

import com.github.jengelman.gradle.plugins.shadow.ShadowStats
import com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
import java.lang.reflect.InvocationTargetException
import org.gradle.api.Action
import org.gradle.api.file.CopySpec

interface ShadowSpec : CopySpec {
fun minimize(): ShadowSpec

fun minimize(action: Action<DependencyFilter>?): ShadowSpec

fun dependencies(action: Action<DependencyFilter>?): ShadowSpec

@Throws(
InstantiationException::class,
IllegalAccessException::class,
NoSuchMethodException::class,
InvocationTargetException::class,
)
fun transform(clazz: Class<Transformer>): ShadowSpec

@Throws(
InstantiationException::class,
IllegalAccessException::class,
NoSuchMethodException::class,
InvocationTargetException::class,
)
fun <T : Transformer> transform(clazz: Class<T>, action: Action<T>?): ShadowSpec

fun transform(transformer: Transformer): ShadowSpec

fun mergeServiceFiles(): ShadowSpec

fun mergeServiceFiles(rootPath: String): ShadowSpec

fun mergeServiceFiles(action: Action<ServiceFileTransformer>?): ShadowSpec

fun mergeGroovyExtensionModules(): ShadowSpec

fun append(resourcePath: String): ShadowSpec

fun relocate(pattern: String, destination: String): ShadowSpec

fun relocate(pattern: String, destination: String, action: Action<SimpleRelocator>?): ShadowSpec

fun relocate(relocator: Relocator): ShadowSpec

@Throws(
InstantiationException::class,
IllegalAccessException::class,
NoSuchMethodException::class,
InvocationTargetException::class,
)
fun relocate(clazz: Class<Relocator>): ShadowSpec

@Throws(
InstantiationException::class,
IllegalAccessException::class,
NoSuchMethodException::class,
InvocationTargetException::class,
)
fun <R : Relocator> relocate(clazz: Class<R>, action: Action<R>?): ShadowSpec

val stats: ShadowStats
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.jengelman.gradle.plugins.shadow.transformers

/**
* Marks that a given instance of [Transformer] is compatible with the Gradle build cache.
* In other words, it has its appropriate inputs annotated so that Gradle can consider them when
* determining the cache key.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class CacheableTransformer
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.jengelman.gradle.plugins.shadow.transformers

import org.apache.tools.zip.ZipOutputStream
import org.gradle.api.Named
import org.gradle.api.file.FileTreeElement
import org.gradle.api.tasks.Internal

/**
* Modified from `org.apache.maven.plugins.shade.resource.ResourceTransformer.java`
*
* @author Jason van Zyl
* @author Charlie Knudsen
* @author John Engelman
*/
interface Transformer : Named {
fun canTransformResource(element: FileTreeElement): Boolean

fun transform(context: TransformerContext)

fun hasTransformedResource(): Boolean

fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean)

@Internal
override fun getName(): String = this::class.java.simpleName
}

object NoOpTransformer : Transformer {
override fun canTransformResource(element: FileTreeElement): Boolean = false
override fun transform(context: TransformerContext): Unit = Unit
override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean): Unit = Unit
override fun hasTransformedResource(): Boolean = false
}

This file was deleted.

Loading