diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.kt new file mode 100644 index 000000000..94c8a051e --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.kt @@ -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 { + + 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 + } +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.kt new file mode 100644 index 000000000..6b22883a1 --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.kt @@ -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)) + } +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.kt new file mode 100644 index 000000000..0b5c58e3c --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.kt @@ -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 { + + 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) + } + } +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.kt new file mode 100644 index 000000000..993165cf0 --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.kt @@ -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 + + /** + * Exclude dependencies that match the provided spec. + */ + fun exclude(spec: Spec): DependencyFilter + + /** + * Include dependencies that match the provided spec. + */ + fun include(spec: Spec): DependencyFilter + + /** + * Create a spec that matches the provided project notation on group, name, and version. + */ + fun project(notation: Map): Spec + + /** + * Create a spec that matches the default configuration for the provided project path on group, name, and version. + */ + fun project(notation: String): Spec + + /** + * Create a spec that matches dependencies using the provided notation on group, name, and version. + */ + fun dependency(notation: Any): Spec + + /** + * Create a spec that matches the provided dependency on group, name, and version. + */ + fun dependency(dependency: Dependency): Spec + + /** + * Create a spec that matches the provided closure. + */ + fun dependency(closure: Closure<*>): Spec +} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/legacy/LegacyShadowPlugin.groovy b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/legacy/LegacyShadowPlugin.kt similarity index 51% rename from src/main/groovy/com/github/jengelman/gradle/plugins/shadow/legacy/LegacyShadowPlugin.groovy rename to api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/legacy/LegacyShadowPlugin.kt index e3e69a7ef..834ee364d 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/legacy/LegacyShadowPlugin.groovy +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/legacy/LegacyShadowPlugin.kt @@ -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 { - @Override - void apply(Project target) { - // Do nothing - } +abstract class LegacyShadowPlugin : Plugin { + override fun apply(project: Project): Unit = Unit } diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/CacheableRelocator.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/CacheableRelocator.kt new file mode 100644 index 000000000..cde63e424 --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/CacheableRelocator.kt @@ -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 diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.kt new file mode 100644 index 000000000..8d3b321e5 --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.kt @@ -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() + } +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.kt new file mode 100644 index 000000000..87babb5d6 --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.kt @@ -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() + } +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/Relocator.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/Relocator.kt new file mode 100644 index 000000000..d754ba7a1 --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/Relocator.kt @@ -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 + } +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.kt new file mode 100644 index 000000000..d14ecb18f --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.kt @@ -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 +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.kt new file mode 100644 index 000000000..04caf7315 --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.kt @@ -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?): ShadowSpec + + fun dependencies(action: Action?): ShadowSpec + + @Throws( + InstantiationException::class, + IllegalAccessException::class, + NoSuchMethodException::class, + InvocationTargetException::class, + ) + fun transform(clazz: Class): ShadowSpec + + @Throws( + InstantiationException::class, + IllegalAccessException::class, + NoSuchMethodException::class, + InvocationTargetException::class, + ) + fun transform(clazz: Class, action: Action?): ShadowSpec + + fun transform(transformer: Transformer): ShadowSpec + + fun mergeServiceFiles(): ShadowSpec + + fun mergeServiceFiles(rootPath: String): ShadowSpec + + fun mergeServiceFiles(action: Action?): ShadowSpec + + fun mergeGroovyExtensionModules(): ShadowSpec + + fun append(resourcePath: String): ShadowSpec + + fun relocate(pattern: String, destination: String): ShadowSpec + + fun relocate(pattern: String, destination: String, action: Action?): ShadowSpec + + fun relocate(relocator: Relocator): ShadowSpec + + @Throws( + InstantiationException::class, + IllegalAccessException::class, + NoSuchMethodException::class, + InvocationTargetException::class, + ) + fun relocate(clazz: Class): ShadowSpec + + @Throws( + InstantiationException::class, + IllegalAccessException::class, + NoSuchMethodException::class, + InvocationTargetException::class, + ) + fun relocate(clazz: Class, action: Action?): ShadowSpec + + val stats: ShadowStats +} diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/CacheableTransformer.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/CacheableTransformer.kt new file mode 100644 index 000000000..6bea5011c --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/CacheableTransformer.kt @@ -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 diff --git a/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/Transformer.kt b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/Transformer.kt new file mode 100644 index 000000000..9a2aa5e5c --- /dev/null +++ b/api/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/Transformer.kt @@ -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 +} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy deleted file mode 100644 index ccb64cf5c..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy +++ /dev/null @@ -1,32 +0,0 @@ -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 - -class ShadowBasePlugin implements Plugin { - - public static final String EXTENSION_NAME = 'shadow' - public static final String CONFIGURATION_NAME = 'shadow' - public static final String COMPONENT_NAME = 'shadow' - - @Override - void apply(Project project) { - if (GradleVersion.current() < GradleVersion.version("8.3")) { - throw new GradleException("This version of Shadow supports Gradle 8.3+ only. Please upgrade.") - } - project.extensions.create(EXTENSION_NAME, ShadowExtension, project) - createShadowConfiguration(project) - - project.tasks.register(KnowsTask.NAME, KnowsTask) { knows -> - knows.group = ShadowJavaPlugin.SHADOW_GROUP - knows.description = KnowsTask.DESC - } - } - - private static void createShadowConfiguration(Project project) { - project.configurations.create(CONFIGURATION_NAME) - } -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy deleted file mode 100644 index 53fc8b38d..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow - -import org.gradle.api.Project -import org.gradle.api.component.SoftwareComponentContainer -import org.gradle.api.publish.maven.MavenPublication - -@Deprecated -class ShadowExtension { - private final SoftwareComponentContainer components - - ShadowExtension(Project project) { - components = project.components - } - - /** - * @deprecated configure publication using component.shadow directly. - */ - @Deprecated - void component(MavenPublication publication) { - publication.from(components.findByName("shadow")) - } -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.groovy deleted file mode 100644 index 63db72aab..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.groovy +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow - -import com.github.jengelman.gradle.plugins.shadow.legacy.LegacyShadowPlugin -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.ApplicationPlugin -import org.gradle.api.plugins.JavaPlugin - -class ShadowPlugin implements Plugin { - - @Override - void apply(Project project) { - project.with { - plugins.apply(ShadowBasePlugin) - plugins.withType(JavaPlugin) { - plugins.apply(ShadowJavaPlugin) - } - plugins.withType(ApplicationPlugin) { - plugins.apply(ShadowApplicationPlugin) - } - // 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 and - // 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) - } - } -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy index 3232a9af9..160d34c15 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy @@ -12,8 +12,8 @@ import org.gradle.api.specs.Specs abstract class AbstractDependencyFilter implements DependencyFilter { private final Project project - protected final List> includeSpecs = [] - protected final List> excludeSpecs = [] + protected final List> includeSpecs = [] + protected final List> excludeSpecs = [] AbstractDependencyFilter(Project project) { assert project @@ -35,7 +35,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { } @Override - FileCollection resolve(Collection configurations) { + FileCollection resolve(Collection configurations) { configurations.collect { resolve(it) }.sum() as FileCollection ?: project.files() @@ -48,7 +48,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { * @return */ @Override - DependencyFilter exclude(Spec spec) { + DependencyFilter exclude(Spec spec) { excludeSpecs << spec return this } @@ -60,7 +60,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { * @return */ @Override - DependencyFilter include(Spec spec) { + DependencyFilter include(Spec spec) { includeSpecs << spec return this } @@ -71,7 +71,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { * @return */ @Override - Spec project(Map notation) { + Spec project(Map notation) { dependency(project.dependencies.project(notation)) } @@ -82,7 +82,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { * @return */ @Override - Spec project(String notation) { + Spec project(String notation) { dependency(project.dependencies.project(path: notation, configuration: 'default')) } @@ -92,7 +92,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { * @return */ @Override - Spec dependency(Object notation) { + Spec dependency(Object notation) { dependency(project.dependencies.create(notation)) } @@ -102,7 +102,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { * @return */ @Override - Spec dependency(Dependency dependency) { + Spec dependency(Dependency dependency) { this.dependency({ ResolvedDependency it -> (!dependency.group || it.moduleGroup.matches(dependency.group)) && (!dependency.name || it.moduleName.matches(dependency.name)) && @@ -116,7 +116,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { * @return */ @Override - Spec dependency(Closure spec) { + Spec dependency(Closure spec) { return Specs.convertClosureToSpec(spec) } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy deleted file mode 100644 index e8f6d4644..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.internal - -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 - * @param configuration - * @return - */ - FileCollection resolve(FileCollection configuration) - - /** - * Resolve all FileCollections against the include/exclude ruels in the filter and combine the results - * @param configurations - * @return - */ - FileCollection resolve(Collection configurations) - - /** - * Exclude dependencies that match the provided spec. - * - * @param spec - * @return - */ - DependencyFilter exclude(Spec spec) - - /** - * Include dependencies that match the provided spec. - * - * @param spec - * @return - */ - DependencyFilter include(Spec spec) - - /** - * Create a spec that matches the provided project notation on group, name, and version - * @param notation - * @return - */ - Spec project(Map notation) - - /** - * Create a spec that matches the default configuration for the provided project path on group, name, and version - * - * @param notation - * @return - */ - Spec project(String notation) - - /** - * Create a spec that matches dependencies using the provided notation on group, name, and version - * @param notation - * @return - */ - Spec dependency(Object notation) - - /** - * Create a spec that matches the provided dependency on group, name, and version - * @param dependency - * @return - */ - Spec dependency(Dependency dependency) - - /** - * Create a spec that matches the provided closure - * @param spec - * @return - */ - Spec dependency(Closure spec) -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/CacheableRelocator.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/CacheableRelocator.groovy deleted file mode 100644 index 966e3f524..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/CacheableRelocator.groovy +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.relocation - -import java.lang.annotation.ElementType -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy -import java.lang.annotation.Target - -/** - * Marks that a given instance of {@link Relocator} is 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(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@interface CacheableRelocator { - -} \ No newline at end of file diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.groovy deleted file mode 100644 index 9e0e97e6f..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.relocation - -import com.github.jengelman.gradle.plugins.shadow.ShadowStats -import groovy.transform.Canonical -import groovy.transform.builder.Builder - -@Canonical -@Builder -class RelocateClassContext { - - String className - ShadowStats stats - -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.groovy deleted file mode 100644 index 34be58b4f..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.groovy +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.relocation - -import com.github.jengelman.gradle.plugins.shadow.ShadowStats -import groovy.transform.Canonical -import groovy.transform.builder.Builder - -@Canonical -@Builder -class RelocatePathContext { - - String path - ShadowStats stats -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/Relocator.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/Relocator.groovy deleted file mode 100644 index d9cb1d48f..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/Relocator.groovy +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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 { - String ROLE = Relocator.class.getName() - - boolean canRelocatePath(String path) - - String relocatePath(RelocatePathContext context) - - boolean canRelocateClass(String className) - - String relocateClass(RelocateClassContext context) - - String applyToSourceContent(String sourceContent) -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy index 7f3ad7d37..04992fb4f 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy @@ -9,6 +9,8 @@ import org.gradle.api.java.archives.ManifestException import org.gradle.api.java.archives.ManifestMergeSpec import org.gradle.api.java.archives.internal.DefaultManifest import org.gradle.api.java.archives.internal.DefaultManifestMergeSpec +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable class DefaultInheritManifest implements InheritManifest { @@ -33,11 +35,11 @@ class DefaultInheritManifest implements InheritManifest { } @Override - InheritManifest inheritFrom(Object inheritPaths, Closure closure) { + InheritManifest inheritFrom(@NotNull Object[] inheritPaths, @Nullable Action action) { DefaultManifestMergeSpec mergeSpec = new DefaultManifestMergeSpec() mergeSpec.from(inheritPaths) inheritMergeSpecs.add(mergeSpec) - project.configure(mergeSpec, closure) + action?.execute(mergeSpec) return this } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.groovy deleted file mode 100644 index 1cfed3c4c..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.groovy +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.tasks - -import org.gradle.api.java.archives.Manifest - -interface InheritManifest extends Manifest { - - InheritManifest inheritFrom(Object... inheritPaths) - - InheritManifest inheritFrom(inheritPaths, Closure closure) -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java index dc4cfe9e3..8f9b486fe 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java @@ -201,7 +201,7 @@ public ShadowJar dependencies(Action c) { * @return this */ @Override - public ShadowJar transform(Class clazz) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + public ShadowJar transform(Class clazz) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return transform(clazz, null); } @@ -251,7 +251,7 @@ private void addTransform(T transformer, Action c) { @Override public ShadowJar mergeServiceFiles() { try { - transform(ServiceFileTransformer.class); + transform(ServiceFileTransformer.class, null); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException ignored) { } @@ -294,9 +294,9 @@ public ShadowJar mergeServiceFiles(Action configureClosu * @return this */ @Override - public ShadowJar mergeGroovyExtensionModules() { + public ShadowSpec mergeGroovyExtensionModules() { try { - transform(GroovyExtensionModuleTransformer.class); + transform(GroovyExtensionModuleTransformer.class, null); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException ignored) { } @@ -364,7 +364,7 @@ public ShadowJar relocate(Relocator relocator) { * @return this */ @Override - public ShadowJar relocate(Class relocatorClass) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + public ShadowJar relocate(Class relocatorClass) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return relocate(relocatorClass, null); } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.java b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.java deleted file mode 100644 index cc86e4e5c..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.java +++ /dev/null @@ -1,48 +0,0 @@ -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 org.gradle.api.Action; -import org.gradle.api.file.CopySpec; - -import java.lang.reflect.InvocationTargetException; - -interface ShadowSpec extends CopySpec { - ShadowSpec minimize(); - - ShadowSpec minimize(Action configureClosure); - - ShadowSpec dependencies(Action configure); - - ShadowSpec transform(Class clazz) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException; - - ShadowSpec transform(Class clazz, Action configure) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException; - - ShadowSpec transform(Transformer transformer); - - ShadowSpec mergeServiceFiles(); - - ShadowSpec mergeServiceFiles(String rootPath); - - ShadowSpec mergeServiceFiles(Action configureClosure); - - ShadowSpec mergeGroovyExtensionModules(); - - ShadowSpec append(String resourcePath); - - ShadowSpec relocate(String pattern, String destination); - - ShadowSpec relocate(String pattern, String destination, Action configure); - - ShadowSpec relocate(Relocator relocator); - - ShadowSpec relocate(Class clazz) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException; - - ShadowSpec relocate(Class clazz, Action configure) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException; - - ShadowStats getStats(); -} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/CacheableTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/CacheableTransformer.groovy deleted file mode 100644 index ae3b74e56..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/CacheableTransformer.groovy +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.transformers - -import java.lang.annotation.ElementType -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy -import java.lang.annotation.Target - -/** - * Marks that a given instance of {@link Transformer} is 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(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@interface CacheableTransformer { - -} \ No newline at end of file diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Transformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Transformer.groovy deleted file mode 100644 index 630d41301..000000000 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Transformer.groovy +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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 - */ -trait Transformer implements Named { - - abstract boolean canTransformResource(FileTreeElement element) - - abstract void transform(TransformerContext context) - - abstract boolean hasTransformedResource() - - abstract void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) - - @Internal - String getName() { - return getClass().simpleName - } -}