class PropertiesFileTransformer extends java.lang.Object implements Transformer
Resources transformer that merges Properties files.
The default merge strategy discards duplicate values coming from additional resources. This behavior can be changed by setting a value for the mergeStrategy property, such as 'first' (default), 'latest' or 'append'. If the merge strategy is 'latest' then the last value of a matching property entry will be used. If the merge strategy is 'append' then the property values will be combined, using a merge separator (default value is ','). The merge separator can be changed by setting a value for the mergeSeparator property.
Say there are two properties files A and B with the following entries: AThere are three additional properties that can be set: paths, mappings, and keyTransformer. The first contains a list of strings or regexes that will be used to determine if a path should be transformed or not. The merge strategy and merge separator are taken from the global settings.
The mappings property allows you to define merge strategy and separator per path
. If either paths or mappings is defined then no other path entries will be merged. mappings has precedence over paths if both are defined.If you need to transform keys in properties files, e.g. because they contain class names about to be relocated, you can set the keyTransformer property to a closure that receives the original key and returns the key name to be used.
Example:
import org.codehaus.griffon.gradle.shadow.transformers.* shadowJar { transform(PropertiesFileTransformer) { paths = [ 'META-INF/editors/java.beans.PropertyEditor' ] keyTransformer = { key -> key.replaceAll('^(orig\.package\..*)$', 'new.prefix.$1') } } }
Type | Name and description |
---|---|
java.lang.String |
charset |
groovy.lang.Closure<java.lang.String> |
keyTransformer |
java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.String>> |
mappings |
java.lang.String |
mergeSeparator |
java.lang.String |
mergeStrategy |
java.util.List<java.lang.String> |
paths |
Constructor and description |
---|
PropertiesFileTransformer
() |
Type Params | Return Type | Name and description |
---|---|---|
|
boolean |
canTransformResource(org.gradle.api.file.FileTreeElement element) |
|
boolean |
hasTransformedResource() |
|
void |
modifyOutputStream(org.apache.tools.zip.ZipOutputStream os, boolean preserveFileTimestamps) |
|
void |
transform(TransformerContext context) |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Groovy Documentation