Author: rfscholte Date: Wed Jan 18 14:24:55 2017 New Revision: 1779329 URL: http://svn.apache.org/viewvc?rev=1779329&view=rev Log: [MSHADE-232] Introduce ResourceBundleAppendingTransformer
Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/invoker.properties maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/pom.xml maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/pom.xml maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/pom.xml maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/verify.groovy maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformer.java maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformerTest.java Modified: maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/resource-transformers.apt.vm Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/invoker.properties?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/invoker.properties (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/invoker.properties Wed Jan 18 14:24:55 2017 @@ -0,0 +1,18 @@ +# 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. + +invoker.goals=clean package Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/pom.xml?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/pom.xml (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/pom.xml Wed Jan 18 14:24:55 2017 @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.its.shade.pp</groupId> + <artifactId>mshade-232</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>one</artifactId> + +</project> Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties Wed Jan 18 14:24:55 2017 @@ -0,0 +1,18 @@ +# 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. + +one = one Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/one/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties Wed Jan 18 14:24:55 2017 @@ -0,0 +1,18 @@ +# 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. + +one = een Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/pom.xml?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/pom.xml (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/pom.xml Wed Jan 18 14:24:55 2017 @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.its.shade.pp</groupId> + <artifactId>mshade-232</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.maven.its.shade.pp</groupId> + <artifactId>one</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </dependencyManagement> + + <modules> + <module>one</module> + <module>two</module> + </modules> + +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/pom.xml?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/pom.xml (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/pom.xml Wed Jan 18 14:24:55 2017 @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.its.shade.pp</groupId> + <artifactId>mshade-232</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>two</artifactId> + + <dependencies> + <dependency> + <groupId>org.apache.maven.its.shade.pp</groupId> + <artifactId>one</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>attach-shade</id> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <shadedArtifactAttached>false</shadedArtifactAttached> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ResourceBundleAppendingTransformer"> + <basename>org/apache/maven/plugins/shade/its/Message</basename> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message.properties Wed Jan 18 14:24:55 2017 @@ -0,0 +1,18 @@ +# 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. + +two = two Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/two/src/main/resources/org/apache/maven/plugins/shade/its/Message_nl.properties Wed Jan 18 14:24:55 2017 @@ -0,0 +1,18 @@ +# 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. + +two = twee Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/verify.groovy URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/verify.groovy?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/verify.groovy (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-232_ResourceBundleAppendingTransformer/verify.groovy Wed Jan 18 14:24:55 2017 @@ -0,0 +1,31 @@ +/* + * 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. + */ + +def jarFile = new java.util.jar.JarFile(new File(basedir, "two/target/two-1.0-SNAPSHOT.jar")) +def jarEntry = jarFile.getJarEntry("org/apache/maven/plugins/shade/its/Message.properties") +def props = new Properties(); +props.load(jarFile.getInputStream(jarEntry)); +assert props.one == 'one' +assert props.two == 'two' + +jarEntry = jarFile.getJarEntry("org/apache/maven/plugins/shade/its/Message_nl.properties") +props = new Properties(); +props.load(jarFile.getInputStream(jarEntry)); +assert props.one == 'een' +assert props.two == 'twee' Added: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformer.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformer.java?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformer.java (added) +++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformer.java Wed Jan 18 14:24:55 2017 @@ -0,0 +1,97 @@ +package org.apache.maven.plugins.shade.resource; + +/* + * 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. + */ + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.regex.Pattern; + +import org.apache.maven.plugins.shade.relocation.Relocator; +import org.codehaus.plexus.util.IOUtil; + +/** + * An appending transformer for resource bundles + * + * @author Robert Scholte + * @since 3.0.0 + */ +public class ResourceBundleAppendingTransformer implements ResourceTransformer +{ + private Map<String, ByteArrayOutputStream> dataMap = new HashMap<String, ByteArrayOutputStream>(); + + private Pattern resourceBundlePattern; + + /** + * the base name of the resource bundle, a fully qualified class name + */ + public void setBasename( String basename ) + { + resourceBundlePattern = Pattern.compile( basename + "(_[a-zA-Z]+){0,3}\\.properties" ); + } + + public boolean canTransformResource( String r ) + { + if ( resourceBundlePattern != null && resourceBundlePattern.matcher( r ).matches() ) + { + return true; + } + + return false; + } + + public void processResource( String resource, InputStream is, List<Relocator> relocators ) + throws IOException + { + ByteArrayOutputStream data = dataMap.get( resource ); + if ( data == null ) + { + data = new ByteArrayOutputStream(); + dataMap.put( resource, data ); + } + + IOUtil.copy( is, data ); + data.write( '\n' ); + } + + public boolean hasTransformedResource() + { + return !dataMap.isEmpty(); + } + + public void modifyOutputStream( JarOutputStream jos ) + throws IOException + { + for ( Map.Entry<String, ByteArrayOutputStream> dataEntry : dataMap.entrySet() ) + { + jos.putNextEntry( new JarEntry( dataEntry.getKey() ) ); + + IOUtil.copy( new ByteArrayInputStream( dataEntry.getValue().toByteArray() ), jos ); + dataEntry.getValue().reset(); + } + } + +} Modified: maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/resource-transformers.apt.vm URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/resource-transformers.apt.vm?rev=1779329&r1=1779328&r2=1779329&view=diff ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/resource-transformers.apt.vm (original) +++ maven/plugins/trunk/maven-shade-plugin/src/site/apt/examples/resource-transformers.apt.vm Wed Jan 18 14:24:55 2017 @@ -41,18 +41,20 @@ Resource Transformers *-----------------------------------------+------------------------------------------+ | {{DontIncludeResourceTransformer}} | Prevents inclusion of matching resources | *-----------------------------------------+------------------------------------------+ +| {{GroovyResourceTransformer}} | Merges Apache Groovy extends modules | +*-----------------------------------------+------------------------------------------+ | {{IncludeResourceTransformer}} | Adds files from the project | *-----------------------------------------+------------------------------------------+ | {{ManifestResourceTransformer}} | Sets entries in the <<<MANIFEST>>> | *-----------------------------------------+------------------------------------------+ | {{PluginXmlResourceTransformer}} | Aggregates Mavens <<<plugin.xml>>> | *-----------------------------------------+------------------------------------------+ +| {{ResourceBundleAppendingTransformer}} | Merges ResourceBundles | +*-----------------------------------------+------------------------------------------+ | {{ServicesResourceTransformer}} | Relocated class names in <<<META-INF/services>>> resources and merges them. | *-----------------------------------------+------------------------------------------+ | {{XmlAppendingTransformer}} | Adds XML content to an XML resource | *-----------------------------------------+------------------------------------------+ -| {{GroovyResourceTransformer}} | Merge Apache Groovy extends modules | -*-----------------------------------------+------------------------------------------+ Transformers in <<<org.apache.maven.plugins.shade.resource>>> * Merging Plexus Component Descriptors with the {ComponentsXmlResourceTransformer} @@ -72,7 +74,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -110,7 +111,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -147,7 +147,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -165,7 +164,7 @@ Transformers in <<<org.apache.maven.plug </project> +----- -* Merging Content of Specific Files with {AppendingTransformer} and XmlAppendingTransformer +* Merging Content of Specific Files with {AppendingTransformer}, XmlAppendingTransformer and ResourceBundleAppendingTransformer Some jars contain additional resources (such as properties files) that have the same file name. To avoid overwriting, you can opt to merge them by appending their content into one file. One good example for this is when aggregating both the spring-context @@ -183,7 +182,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -219,7 +217,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -247,6 +244,39 @@ Transformers in <<<org.apache.maven.plug transformation, e.g. when using the Crimson XML parser as used in some JRE 1.4. If the transformed resource uses external entities, DTD resolution can either be turned back on or a plugin dependency on <<<xerces:xercesImpl:2.9.1>>> is added to the POM. + + For ResourceBundles properties files, you can use the <<<{ResourceBundleAppendingTransformer}>>> instead, which will respect all available Locales as well: + ++----- +<project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ResourceBundleAppendingTransformer"> + <!-- the base name of the resource bundle, a fully qualified class name --> + <basename>path/to/Messages</basename> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project> ++----- * Excluding Resources with the {DontIncludeResourceTransformer} @@ -266,7 +296,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -318,7 +347,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -365,7 +393,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -416,7 +443,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -455,7 +481,6 @@ Transformers in <<<org.apache.maven.plug <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> @@ -494,7 +519,6 @@ For example, to simply merge the extensi <version>${project.version}</version> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> Added: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformerTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformerTest.java?rev=1779329&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformerTest.java (added) +++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ResourceBundleAppendingTransformerTest.java Wed Jan 18 14:24:55 2017 @@ -0,0 +1,55 @@ +package org.apache.maven.plugins.shade.resource; + +/* + * 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. + */ + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +public class ResourceBundleAppendingTransformerTest +{ + private ResourceBundleAppendingTransformer transformer; + + @Before + public void setUp() + { + transformer = new ResourceBundleAppendingTransformer(); + } + + @Test + public void testCanTransformResource() + { + transformer.setBasename( "a/b/c/ButtonLabel" ); + + assertTrue( transformer.canTransformResource( "a/b/c/ButtonLabel.properties" ) ); + assertTrue( transformer.canTransformResource( "a/b/c/ButtonLabel_en.properties" ) ); + assertTrue( transformer.canTransformResource( "a/b/c/ButtonLabel_en_US.properties" ) ); + assertTrue( transformer.canTransformResource( "a/b/c/ButtonLabel_fr.properties" ) ); + assertTrue( transformer.canTransformResource( "a/b/c/ButtonLabel_fr_CA.properties" ) ); + assertTrue( transformer.canTransformResource( "a/b/c/ButtonLabel_fr_CA_UNIX.properties" ) ); + + assertFalse( transformer.canTransformResource( "a/b/c/ButtonLabel.class" ) ); + assertFalse( transformer.canTransformResource( "c/ButtonLabel.properties" ) ); + assertFalse( transformer.canTransformResource( "ButtonLabel.properties" ) ); + } + +}