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

Migrate transformers to using lazy properties #1036

Merged
merged 29 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7fb8947
Inject ObjectFactory for Transformer
Goooler Nov 26, 2024
682b6b3
Migrate AppendingTransformer
Goooler Nov 26, 2024
7ef5e05
Add ObjectFactory.property extension
Goooler Nov 26, 2024
d3bd1c4
Migrate ApacheNoticeResourceTransformer
Goooler Nov 26, 2024
5d5030f
Migrate DontIncludeResourceTransformer
Goooler Nov 26, 2024
602349d
Migrate IncludeResourceTransformer
Goooler Nov 26, 2024
dd50ad1
Migrate ManifestAppenderTransformer
Goooler Nov 26, 2024
96dde01
Migrate ManifestResourceTransformer
Goooler Nov 26, 2024
a226c52
Migrate XmlAppendingTransformer
Goooler Nov 26, 2024
fce25d5
Migrate PropertiesFileTransformer
Goooler Nov 26, 2024
8476f1c
Replace === with ==
Goooler Nov 26, 2024
2e904bc
Mark all public properties open
Goooler Nov 26, 2024
c075ac0
Migrate MergeStrategy to enum
Goooler Nov 26, 2024
858f7e6
Migrate charset properties to Charsets
Goooler Nov 26, 2024
1c54a37
Reformat
Goooler Nov 26, 2024
74a33b9
Ensure charset must be serializable
Goooler Nov 26, 2024
04493c3
Note this change
Goooler Nov 26, 2024
04dd456
Mark objectFactory properties final
Goooler Nov 27, 2024
6969759
Tweak objectFactory
Goooler Nov 27, 2024
c5165b6
Tweak kdoc for PropertiesFileTransformer
Goooler Nov 27, 2024
9a27b67
Inline getters
Goooler Nov 27, 2024
74b8aea
Replace values with entries
Goooler Nov 27, 2024
ef99074
IncludeResourceTransformer.file is not optional
Goooler Nov 27, 2024
77a772c
Rename encoding to charsetName
Goooler Nov 27, 2024
32da3ee
Migrate PropertiesFileTransformer.mappings to using Properties
Goooler Nov 27, 2024
00398e4
Tweak comment
Goooler Nov 27, 2024
26b70ab
Revert "Migrate PropertiesFileTransformer.mappings to using Properties"
Goooler Nov 27, 2024
599d7eb
Revert annoying changes to reduce diffs
Goooler Nov 27, 2024
84b806a
Tweak style
Goooler Nov 27, 2024
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
116 changes: 59 additions & 57 deletions api/shadow.api
Original file line number Diff line number Diff line change
Expand Up @@ -363,46 +363,38 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicen
public fun <init> ()V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public fun getName ()Ljava/lang/String;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public final fun getAddHeader ()Z
public final fun getCopyright ()Ljava/lang/String;
public final fun getEncoding ()Ljava/lang/String;
public final fun getInceptionYear ()Ljava/lang/String;
public final fun getOrganizationName ()Ljava/lang/String;
public final fun getOrganizationURL ()Ljava/lang/String;
public final fun getPreamble1 ()Ljava/lang/String;
public final fun getPreamble2 ()Ljava/lang/String;
public final fun getPreamble3 ()Ljava/lang/String;
public final fun getProjectName ()Ljava/lang/String;
public fun getAddHeader ()Lorg/gradle/api/provider/Property;
public fun getCopyright ()Lorg/gradle/api/provider/Property;
public fun getEncoding ()Lorg/gradle/api/provider/Property;
public fun getInceptionYear ()Lorg/gradle/api/provider/Property;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun getOrganizationName ()Lorg/gradle/api/provider/Property;
public fun getOrganizationURL ()Lorg/gradle/api/provider/Property;
public fun getPreamble1 ()Lorg/gradle/api/provider/Property;
public fun getPreamble2 ()Lorg/gradle/api/provider/Property;
public fun getPreamble3 ()Lorg/gradle/api/provider/Property;
public fun getProjectName ()Lorg/gradle/api/provider/Property;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setAddHeader (Z)V
public final fun setCopyright (Ljava/lang/String;)V
public final fun setEncoding (Ljava/lang/String;)V
public final fun setInceptionYear (Ljava/lang/String;)V
public final fun setOrganizationName (Ljava/lang/String;)V
public final fun setOrganizationURL (Ljava/lang/String;)V
public final fun setPreamble1 (Ljava/lang/String;)V
public final fun setPreamble2 (Ljava/lang/String;)V
public final fun setPreamble3 (Ljava/lang/String;)V
public final fun setProjectName (Ljava/lang/String;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public final fun getResource ()Ljava/lang/String;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun getResource ()Lorg/gradle/api/provider/Property;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setResource (Ljava/lang/String;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

Expand All @@ -423,13 +415,13 @@ public final class com/github/jengelman/gradle/plugins/shadow/transformers/Compo
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/DontIncludeResourceTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public fun getName ()Ljava/lang/String;
public final fun getResource ()Ljava/lang/String;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun getResource ()Lorg/gradle/api/provider/Property;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setResource (Ljava/lang/String;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

Expand All @@ -442,15 +434,14 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExten
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public final fun getFile ()Ljava/io/File;
public fun getFile ()Lorg/gradle/api/file/RegularFileProperty;
public fun getName ()Ljava/lang/String;
public final fun getResource ()Ljava/lang/String;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun getResource ()Lorg/gradle/api/provider/Property;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setFile (Ljava/io/File;)V
public final fun setResource (Ljava/lang/String;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

Expand All @@ -463,25 +454,25 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2Plugi
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun append (Ljava/lang/String;Ljava/lang/Comparable;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformer;
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public fun getAttributes ()Ljava/util/List;
public fun getAttributes ()Lorg/gradle/api/provider/ListProperty;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/ManifestResourceTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun attributes (Ljava/util/Map;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/ManifestResourceTransformer;
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public final fun getMainClass ()Ljava/lang/String;
public final fun getManifestEntries ()Ljava/util/Map;
public fun getMainClass ()Lorg/gradle/api/provider/Property;
public fun getManifestEntries ()Lorg/gradle/api/provider/MapProperty;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setMainClass (Ljava/lang/String;)V
public final fun setManifestEntries (Ljava/util/Map;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

Expand All @@ -494,25 +485,35 @@ public final class com/github/jengelman/gradle/plugins/shadow/transformers/NoOpT
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public final fun getCharset ()Ljava/lang/String;
public final fun getKeyTransformer ()Ljava/util/function/Function;
public final fun getMappings ()Ljava/util/Map;
public final fun getMergeSeparator ()Ljava/lang/String;
public final fun getMergeStrategy ()Ljava/lang/String;
public final fun getPaths ()Ljava/util/List;
public fun getEncoding ()Lorg/gradle/api/provider/Property;
public fun getKeyTransformer ()Lorg/gradle/api/provider/Property;
public fun getMappings ()Lorg/gradle/api/provider/MapProperty;
public fun getMergeSeparator ()Lorg/gradle/api/provider/Property;
public fun getMergeStrategy ()Lorg/gradle/api/provider/Property;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun getPaths ()Lorg/gradle/api/provider/ListProperty;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setCharset (Ljava/lang/String;)V
public final fun setKeyTransformer (Ljava/util/function/Function;)V
public final fun setMappings (Ljava/util/Map;)V
public final fun setMergeSeparator (Ljava/lang/String;)V
public final fun setMergeStrategy (Ljava/lang/String;)V
public final fun setPaths (Ljava/util/List;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

public final class com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy : java/lang/Enum {
public static final field Append Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy;
public static final field Companion Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy$Companion;
public static final field First Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy;
public static final field Latest Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy;
public static final fun from (Ljava/lang/String;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy;
public static fun values ()[Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy;
}

public final class com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy$Companion {
public final fun from (Ljava/lang/String;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer$MergeStrategy;
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer, org/gradle/api/tasks/util/PatternFilterable {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/tasks/util/PatternSet;)V
Expand Down Expand Up @@ -545,13 +546,15 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFile
public abstract interface class com/github/jengelman/gradle/plugins/shadow/transformers/Transformer : org/gradle/api/Named {
public abstract fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public fun getName ()Ljava/lang/String;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public abstract fun hasTransformedResource ()Z
public abstract fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public abstract fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

public final class com/github/jengelman/gradle/plugins/shadow/transformers/Transformer$DefaultImpls {
public static fun getName (Lcom/github/jengelman/gradle/plugins/shadow/transformers/Transformer;)Ljava/lang/String;
public static fun getObjectFactory (Lcom/github/jengelman/gradle/plugins/shadow/transformers/Transformer;)Lorg/gradle/api/model/ObjectFactory;
}

public final class com/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext {
Expand Down Expand Up @@ -594,14 +597,13 @@ public final class com/github/jengelman/gradle/plugins/shadow/transformers/Trans
public class com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public static final field Companion Lcom/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer$Companion;
public static final field XSI_NS Ljava/lang/String;
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public final fun getIgnoreDtd ()Z
public final fun getResource ()Ljava/lang/String;
public fun getIgnoreDtd ()Lorg/gradle/api/provider/Property;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun getResource ()Lorg/gradle/api/provider/Property;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setIgnoreDtd (Z)V
public final fun setResource (Ljava/lang/String;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.github.jengelman.gradle.plugins.shadow.internal
import java.io.InputStream
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.provider.Property

/**
* Return `runtimeClasspath` or `runtime` configuration.
Expand All @@ -13,6 +15,12 @@ internal inline val Project.runtimeConfiguration: Configuration get() {
?: configurations.getByName("runtime")
}

internal inline fun <reified T : Any> ObjectFactory.property(defaultValue: T? = null): Property<T> {
return property(T::class.java).apply {
if (defaultValue != null) convention(defaultValue)
}
}

@Suppress("NOTHING_TO_INLINE")
internal inline fun <T> unsafeLazy(noinline initializer: () -> T): Lazy<T> =
lazy(LazyThreadSafetyMode.NONE, initializer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.gradle.api.internal.DocumentationRegistry
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.internal.file.copy.DefaultCopySpec
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
Expand Down Expand Up @@ -153,7 +154,15 @@ public abstract class ShadowJar :
}

override fun <T : Transformer> transform(clazz: Class<T>, action: Action<T>?): ShadowJar = apply {
val transformer = clazz.getDeclaredConstructor().newInstance()
// If the constructor takes a single ObjectFactory, inject it in.
val constructor = clazz.constructors.find {
it.parameterTypes.singleOrNull() == ObjectFactory::class.java
}
val transformer = if (constructor != null) {
objectFactory.newInstance(clazz)
} else {
clazz.getDeclaredConstructor().newInstance()
}
addTransform(transformer, action)
}

Expand Down Expand Up @@ -190,7 +199,7 @@ public abstract class ShadowJar :
override fun append(resourcePath: String): ShadowJar {
return runCatching {
transform(AppendingTransformer::class.java) {
it.resource = resourcePath
it.resource.set(resourcePath)
}
}.getOrDefault(this)
}
Expand Down
Loading