You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2012/11/25 20:15:48 UTC
svn commit: r1413392 - in /maven/plugins/trunk/maven-shade-plugin/src:
it/plugin-descriptor-relocation/ it/plugin-descriptor-relocation/repo/
it/plugin-descriptor-relocation/repo/org/
it/plugin-descriptor-relocation/repo/org/apache/ it/plugin-descripto...
Author: rfscholte
Date: Sun Nov 25 19:15:46 2012
New Revision: 1413392
URL: http://svn.apache.org/viewvc?rev=1413392&view=rev
Log:
[MSHADE-135] Add PluginXmlTransformer
Added:
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/pom.xml
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.jar (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.pom
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/maven-metadata.xml
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/Entry.java
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/TestMojo.java
maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/verify.groovy
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/PluginXmlResourceTransformer.java
Added: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/pom.xml?rev=1413392&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/pom.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/pom.xml Sun Nov 25 19:15:46 2012
@@ -0,0 +1,126 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.cdr</groupId>
+ <artifactId>mshade-135</artifactId>
+ <version>1.0</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>MSHADE-135</name>
+ <description>
+ Test that plugin descriptors get adjusted to account for relocation of role/impl classes.
+ </description>
+
+ <repositories>
+ <repository>
+ <id>shade-it</id>
+ <url>file:///${basedir}/repo</url>
+ <releases>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.shade.cdr</groupId>
+ <artifactId>comp</artifactId>
+ <version>0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.2</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.2</version>
+ <configuration>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ <executions>
+ <execution>
+ <id>mojo-descriptor</id>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>shade</id>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.maven.component.api</pattern>
+ <shadedPattern>hidden.api</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.maven.component.impl</pattern>
+ <shadedPattern>hidden.impl</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.maven.test</pattern>
+ <shadedPattern>hidden.impl</shadedPattern>
+ </relocation>
+ </relocations>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer"/>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.jar?rev=1413392&view=auto
==============================================================================
Binary file - no diff available.
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.pom
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.pom?rev=1413392&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.pom (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/0.1/comp-0.1.pom Sun Nov 25 19:15:46 2012
@@ -0,0 +1,51 @@
+<?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.cdr</groupId>
+ <artifactId>comp</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+
+ <distributionManagement>
+ <repository>
+ <id>maven-core-it</id>
+ <url>file:///${basedir}/repo</url>
+ </repository>
+ </distributionManagement>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>.</directory>
+ <includes>
+ <include>pom.xml</include>
+ <include>src/**</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
+</project>
Added: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/maven-metadata.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/maven-metadata.xml?rev=1413392&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/maven-metadata.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/repo/org/apache/maven/its/shade/cdr/comp/maven-metadata.xml Sun Nov 25 19:15:46 2012
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+ <groupId>org.apache.maven.its.shade.cdr</groupId>
+ <artifactId>comp</artifactId>
+ <version>0.1</version>
+ <versioning>
+ <versions>
+ <version>0.1</version>
+ </versions>
+ <lastUpdated>20091230143912</lastUpdated>
+ </versioning>
+</metadata>
Added: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/Entry.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/Entry.java?rev=1413392&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/Entry.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/Entry.java Sun Nov 25 19:15:46 2012
@@ -0,0 +1,25 @@
+package org.apache.maven.test;
+
+/*
+ * 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.
+ */
+
+public class Entry
+{
+
+}
\ No newline at end of file
Added: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/TestMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/TestMojo.java?rev=1413392&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/TestMojo.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/src/main/java/org/apache/maven/test/TestMojo.java Sun Nov 25 19:15:46 2012
@@ -0,0 +1,46 @@
+package org.apache.maven.test;
+
+/*
+ * 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.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+@Mojo( name = "test" )
+public class TestMojo extends AbstractMojo
+{
+ @Component
+ private org.apache.maven.component.api.Component component;
+
+ @Parameter
+ private Entry entry;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+
+ }
+
+}
Added: maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/verify.groovy?rev=1413392&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/verify.groovy (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/plugin-descriptor-relocation/verify.groovy Sun Nov 25 19:15:46 2012
@@ -0,0 +1,24 @@
+/*
+ * 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 shadedJar = new File( basedir, "target/mshade-135-1.0.jar")
+def pluginXml = new URL( "jar:" + shadedJar.toURL() + "!/META-INF/maven/plugin.xml" )
+def plugin = new XmlSlurper().parse( pluginXml.openStream() );
+assert plugin.mojos.mojo[0].implementation == "hidden.impl.TestMojo";
+assert plugin.mojos.mojo[0].parameters.parameter[0].type == "hidden.impl.Entry";
+assert plugin.mojos.mojo[0].requirements.requirement[0].role == "hidden.api.Component";
\ No newline at end of file
Added: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/PluginXmlResourceTransformer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/PluginXmlResourceTransformer.java?rev=1413392&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/PluginXmlResourceTransformer.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/PluginXmlResourceTransformer.java Sun Nov 25 19:15:46 2012
@@ -0,0 +1,231 @@
+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.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.apache.maven.plugins.shade.relocation.Relocator;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.Xpp3DomWriter;
+
+/**
+ * A resource processor that aggregates Maven <code>plugin.xml</code> files.
+ *
+ * @author Robert Scholte
+ * @since 3.0
+ */
+public class PluginXmlResourceTransformer
+ implements ResourceTransformer
+{
+ private List<Xpp3Dom> mojos = new LinkedList<Xpp3Dom>();
+
+ public static final String PLUGIN_XML_PATH = "META-INF/maven/plugin.xml";
+
+ public boolean canTransformResource( String resource )
+ {
+ return PLUGIN_XML_PATH.equals( resource );
+ }
+
+ public void processResource( String resource, InputStream is, List<Relocator> relocators )
+ throws IOException
+ {
+ Xpp3Dom newDom;
+
+ try
+ {
+ BufferedInputStream bis = new BufferedInputStream( is )
+ {
+ public void close()
+ throws IOException
+ {
+ // leave ZIP open
+ }
+ };
+
+ Reader reader = ReaderFactory.newXmlReader( bis );
+
+ newDom = Xpp3DomBuilder.build( reader );
+ }
+ catch ( Exception e )
+ {
+ throw (IOException) new IOException( "Error parsing plugin.xml in " + is ).initCause( e );
+ }
+
+ // Only try to merge in mojos if there are some elements in the plugin
+ if ( newDom.getChild( "mojos" ) == null )
+ {
+ return;
+ }
+
+ for ( Xpp3Dom mojo : newDom.getChild( "mojos" ).getChildren( "mojo" ) )
+ {
+
+ String impl = getValue( mojo, "implementation" );
+ impl = getRelocatedClass( impl, relocators );
+ setValue( mojo, "implementation", impl );
+
+ Xpp3Dom parameters = mojo.getChild( "parameters" );
+ if ( parameters != null )
+ {
+ for ( Xpp3Dom parameter : parameters.getChildren() )
+ {
+ String type = getValue( parameter, "type" );
+ type = getRelocatedClass( type, relocators );
+ setValue( parameter, "type", type );
+ }
+ }
+
+ Xpp3Dom configuration = mojo.getChild( "configuration" );
+ if ( configuration != null )
+ {
+ for ( Xpp3Dom configurationEntry : configuration.getChildren() )
+ {
+ String implementation = getAttribute( configurationEntry, "implementation" );
+ implementation = getRelocatedClass( implementation, relocators );
+ setAttribute( configurationEntry, "implementation", implementation );
+ }
+ }
+
+ Xpp3Dom requirements = mojo.getChild( "requirements" );
+ if ( requirements != null && requirements.getChildCount() > 0 )
+ {
+ for ( Xpp3Dom requirement : requirements.getChildren() )
+ {
+ String requiredRole = getValue( requirement, "role" );
+ requiredRole = getRelocatedClass( requiredRole, relocators );
+ setValue( requirement, "role", requiredRole );
+ }
+ }
+ mojos.add( mojo );
+ }
+ }
+
+ public void modifyOutputStream( JarOutputStream jos )
+ throws IOException
+ {
+ byte[] data = getTransformedResource();
+
+ jos.putNextEntry( new JarEntry( PLUGIN_XML_PATH ) );
+
+ IOUtil.copy( data, jos );
+
+ mojos.clear();
+ }
+
+ public boolean hasTransformedResource()
+ {
+ return !mojos.isEmpty();
+ }
+
+ byte[] getTransformedResource()
+ throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream( 1024 * 4 );
+
+ Writer writer = WriterFactory.newXmlWriter( baos );
+ try
+ {
+ Xpp3Dom dom = new Xpp3Dom( "plugin" );
+
+ Xpp3Dom componentDom = new Xpp3Dom( "mojos" );
+
+ dom.addChild( componentDom );
+
+ for ( Xpp3Dom mojo : mojos )
+ {
+ componentDom.addChild( mojo );
+ }
+
+ Xpp3DomWriter.write( writer, dom );
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+
+ return baos.toByteArray();
+ }
+
+ private String getRelocatedClass( String className, List<Relocator> relocators )
+ {
+ if ( className != null && className.length() > 0 && relocators != null )
+ {
+ for ( Relocator relocator : relocators )
+ {
+ if ( relocator.canRelocateClass( className ) )
+ {
+ return relocator.relocateClass( className );
+ }
+ }
+ }
+
+ return className;
+ }
+
+ private static String getValue( Xpp3Dom dom, String element )
+ {
+ Xpp3Dom child = dom.getChild( element );
+
+ return ( child != null && child.getValue() != null ) ? child.getValue() : "";
+ }
+
+ private static void setValue( Xpp3Dom dom, String element, String value )
+ {
+ Xpp3Dom child = dom.getChild( element );
+
+ if ( child == null || value == null || value.length() <= 0 )
+ {
+ return;
+ }
+
+ child.setValue( value );
+ }
+
+ private static String getAttribute( Xpp3Dom dom, String attribute )
+ {
+ return ( dom.getAttribute( attribute ) != null ) ? dom.getAttribute( attribute ) : "";
+ }
+
+ private static void setAttribute( Xpp3Dom dom, String attribute, String value )
+ {
+ String attr = dom.getAttribute( attribute );
+
+ if ( attr == null || value == null || value.length() <= 0 )
+ {
+ return;
+ }
+
+ dom.setAttribute( attribute, value );
+ }
+
+}