diff --git a/pom.xml b/pom.xml index bab024eb..435722d3 100644 --- a/pom.xml +++ b/pom.xml @@ -23,19 +23,29 @@ under the License. maven-plugins org.apache.maven.plugins - 8 + 11 maven-shade-plugin - 1.0.1 + 1.1 maven-plugin - maven-shade-plugin + Maven Shade Plugin jira http://jira.codehaus.org/browse/MSHADE + + scm:svn:http://svn.apache.org/repos/asf/maven/plugins/tags/maven-shade-plugin-1.1 + scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-shade-plugin-1.1 + http://svn.apache.org/viewvc/maven/plugins/tags/maven-shade-plugin-1.1 + + + + 2.0.6 + + @@ -58,7 +68,7 @@ under the License. org.codehaus.plexus plexus-utils - 1.4.1 + 1.5.1 @@ -82,11 +92,16 @@ under the License. jdom 1.0 + + org.apache.maven.shared + maven-dependency-tree + 1.1 + junit junit - 3.8.1 + 3.8.2 test @@ -107,10 +122,4 @@ under the License. - - - scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-shade-plugin-1.0.1 - scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-shade-plugin-1.0.1 - https://svn.apache.org/repos/asf/maven/plugins/tags/maven-shade-plugin-1.0.1 - diff --git a/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java b/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java index 7255647d..bec8cca3 100644 --- a/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java +++ b/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java @@ -1,320 +1,320 @@ -package org.apache.maven.plugins.shade; - -/* - * 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.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.ArrayList; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.jar.JarOutputStream; -import java.util.zip.ZipException; - -import org.apache.maven.plugins.shade.relocation.Relocator; -import org.apache.maven.plugins.shade.resource.ResourceTransformer; -import org.apache.maven.plugins.shade.filter.Filter; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.util.IOUtil; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.commons.Remapper; -import org.objectweb.asm.commons.RemappingClassAdapter; - -/** - * @author Jason van Zyl - * @plexus.component - */ -public class DefaultShader - extends AbstractLogEnabled - implements Shader -{ - public void shade( Set jars, File uberJar, List filters, List relocators, List resourceTransformers ) - throws IOException - { - Set resources = new HashSet(); - - RelocatorRemapper remapper = new RelocatorRemapper( relocators ); - - JarOutputStream jos = new JarOutputStream( new FileOutputStream( uberJar ) ); - - for ( Iterator i = jars.iterator(); i.hasNext(); ) - { - File jar = (File) i.next(); - - List jarFilters = getFilters( jar, filters ); - - JarFile jarFile = new JarFile( jar ); - - for ( Enumeration j = jarFile.entries(); j.hasMoreElements(); ) - { - JarEntry entry = (JarEntry) j.nextElement(); - - String name = entry.getName(); - if ( "META-INF/INDEX.LIST".equals( name ) ) - { - //we cannot allow the jar indexes to be copied over or the - //jar is useless. Ideally, we could create a new one - //later - continue; - } - - String mappedName = remapper.map( name ); - - InputStream is = jarFile.getInputStream( entry ); - if ( !entry.isDirectory() && !isFiltered( jarFilters, name ) ) - { - int idx = mappedName.lastIndexOf('/'); - if ( idx != -1 ) - { - //make sure dirs are created - String dir = mappedName.substring(0, idx); - if ( !resources.contains( dir ) ) - { - addDirectory( resources, jos, dir ); - } - } - - if ( name.endsWith( ".class" ) ) - { - addRemappedClass( remapper, jos, jar, name, is ); - } - else - { - if ( !resourceTransformed( resourceTransformers, mappedName, is ) ) - { - // Avoid duplicates that aren't accounted for by the resource transformers - if ( resources.contains( mappedName ) ) - { - continue; - } - - addResource( resources, jos, mappedName, is ); - } - } - } - - IOUtil.close( is ); - } - - jarFile.close(); - } - - for ( Iterator i = resourceTransformers.iterator(); i.hasNext(); ) - { - ResourceTransformer transformer = (ResourceTransformer) i.next(); - - if ( transformer.hasTransformedResource() ) - { - transformer.modifyOutputStream( jos ); - } - } - - IOUtil.close( jos ); - } - - private List getFilters(File jar, List filters) - { - List list = new ArrayList(); - - for ( int i = 0; i < filters.size(); i++ ) - { - Filter filter = (Filter) filters.get( i ); - - if ( filter.canFilter( jar ) ) - { - list.add( filter ); - } - - } - - return list; - } - - private void addDirectory( Set resources, JarOutputStream jos, String name ) - throws IOException - { - if ( name.lastIndexOf( '/' ) > 0 ) - { - String parent = name.substring( 0, name.lastIndexOf( '/' ) ); - if ( !resources.contains( parent ) ) - { - addDirectory( resources, jos, parent ); - } - } - - //directory entries must end in "/" - JarEntry entry = new JarEntry( name + "/" ); - jos.putNextEntry( entry ); - - resources.add( name ); - } - - private void addRemappedClass( RelocatorRemapper remapper, JarOutputStream jos, File jar, String name, InputStream is ) - throws IOException - { - if ( !remapper.hasRelocators() ) - { - jos.putNextEntry( new JarEntry( name ) ); - - IOUtil.copy( is, jos ); - return; - } - - ClassReader cr = new ClassReader( is ); - - ClassWriter cw = new ClassWriter( cr, 0 ); - - ClassVisitor cv = new RemappingClassAdapter( cw, remapper ); - - cr.accept( cv, ClassReader.EXPAND_FRAMES ); - - byte[] renamedClass = cw.toByteArray(); - - // Need to take the .class off for remapping evaluation - String mappedName = remapper.map( name.substring( 0, name.indexOf( '.' ) ) ); - - try - { - // Now we put it back on so the class file is written out with the right extension. - jos.putNextEntry( new JarEntry( mappedName + ".class" ) ); - - IOUtil.copy( renamedClass, jos ); - } - catch ( ZipException e ) - { - getLogger().warn( "We have a duplicate " + mappedName + " in " + jar ); - } - } - - private boolean isFiltered( List filters, String name ) - { - for ( int i = 0; i < filters.size(); i++ ) - { - Filter filter = (Filter) filters.get( i ); - - if ( filter.isFiltered( name ) ) - { - return true; - } - } - - return false; - } - - private boolean resourceTransformed( List resourceTransformers, String name, InputStream is ) - throws IOException - { - boolean resourceTransformed = false; - - for ( Iterator k = resourceTransformers.iterator(); k.hasNext(); ) - { - ResourceTransformer transformer = (ResourceTransformer) k.next(); - - if ( transformer.canTransformResource( name ) ) - { - transformer.processResource( is ); - - resourceTransformed = true; - - break; - } - } - return resourceTransformed; - } - - private void addResource( Set resources, JarOutputStream jos, String name, InputStream is ) - throws IOException - { - jos.putNextEntry( new JarEntry( name ) ); - - IOUtil.copy( is, jos ); - - resources.add( name ); - } - - class RelocatorRemapper - extends Remapper - { - List relocators; - - public RelocatorRemapper( List relocators ) - { - this.relocators = relocators; - } - - public boolean hasRelocators() - { - return !relocators.isEmpty(); - } - - public Object mapValue( Object object ) - { - if ( object instanceof String ) - { - String name = (String) object; - String value = name; - for ( Iterator i = relocators.iterator(); i.hasNext(); ) - { - Relocator r = (Relocator) i.next(); - - if ( r.canRelocatePath( name ) ) - { - value = r.relocatePath( name ); - break; - } - - if ( r.canRelocateClass( name ) ) - { - value = r.relocateClass( name ); - break; - } - } - - return value; - } - return object; - } - - public String map( String name ) - { - String value = name; - for ( Iterator i = relocators.iterator(); i.hasNext(); ) - { - Relocator r = (Relocator) i.next(); - - if ( r.canRelocatePath( name ) ) - { - value = r.relocatePath( name ); - break; - } - } - - return value; - } - } -} +package org.apache.maven.plugins.shade; + +/* + * 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.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.ArrayList; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; +import java.util.zip.ZipException; + +import org.apache.maven.plugins.shade.relocation.Relocator; +import org.apache.maven.plugins.shade.resource.ResourceTransformer; +import org.apache.maven.plugins.shade.filter.Filter; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.IOUtil; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.commons.Remapper; +import org.objectweb.asm.commons.RemappingClassAdapter; + +/** + * @author Jason van Zyl + * @plexus.component + */ +public class DefaultShader + extends AbstractLogEnabled + implements Shader +{ + public void shade( Set jars, File uberJar, List filters, List relocators, List resourceTransformers ) + throws IOException + { + Set resources = new HashSet(); + + RelocatorRemapper remapper = new RelocatorRemapper( relocators ); + + JarOutputStream jos = new JarOutputStream( new FileOutputStream( uberJar ) ); + + for ( Iterator i = jars.iterator(); i.hasNext(); ) + { + File jar = (File) i.next(); + + List jarFilters = getFilters( jar, filters ); + + JarFile jarFile = new JarFile( jar ); + + for ( Enumeration j = jarFile.entries(); j.hasMoreElements(); ) + { + JarEntry entry = (JarEntry) j.nextElement(); + + String name = entry.getName(); + if ( "META-INF/INDEX.LIST".equals( name ) ) + { + //we cannot allow the jar indexes to be copied over or the + //jar is useless. Ideally, we could create a new one + //later + continue; + } + + String mappedName = remapper.map( name ); + + InputStream is = jarFile.getInputStream( entry ); + if ( !entry.isDirectory() && !isFiltered( jarFilters, name ) ) + { + int idx = mappedName.lastIndexOf('/'); + if ( idx != -1 ) + { + //make sure dirs are created + String dir = mappedName.substring(0, idx); + if ( !resources.contains( dir ) ) + { + addDirectory( resources, jos, dir ); + } + } + + if ( name.endsWith( ".class" ) ) + { + addRemappedClass( remapper, jos, jar, name, is ); + } + else + { + if ( !resourceTransformed( resourceTransformers, mappedName, is ) ) + { + // Avoid duplicates that aren't accounted for by the resource transformers + if ( resources.contains( mappedName ) ) + { + continue; + } + + addResource( resources, jos, mappedName, is ); + } + } + } + + IOUtil.close( is ); + } + + jarFile.close(); + } + + for ( Iterator i = resourceTransformers.iterator(); i.hasNext(); ) + { + ResourceTransformer transformer = (ResourceTransformer) i.next(); + + if ( transformer.hasTransformedResource() ) + { + transformer.modifyOutputStream( jos ); + } + } + + IOUtil.close( jos ); + } + + private List getFilters(File jar, List filters) + { + List list = new ArrayList(); + + for ( int i = 0; i < filters.size(); i++ ) + { + Filter filter = (Filter) filters.get( i ); + + if ( filter.canFilter( jar ) ) + { + list.add( filter ); + } + + } + + return list; + } + + private void addDirectory( Set resources, JarOutputStream jos, String name ) + throws IOException + { + if ( name.lastIndexOf( '/' ) > 0 ) + { + String parent = name.substring( 0, name.lastIndexOf( '/' ) ); + if ( !resources.contains( parent ) ) + { + addDirectory( resources, jos, parent ); + } + } + + //directory entries must end in "/" + JarEntry entry = new JarEntry( name + "/" ); + jos.putNextEntry( entry ); + + resources.add( name ); + } + + private void addRemappedClass( RelocatorRemapper remapper, JarOutputStream jos, File jar, String name, InputStream is ) + throws IOException + { + if ( !remapper.hasRelocators() ) + { + jos.putNextEntry( new JarEntry( name ) ); + + IOUtil.copy( is, jos ); + return; + } + + ClassReader cr = new ClassReader( is ); + + ClassWriter cw = new ClassWriter( cr, 0 ); + + ClassVisitor cv = new RemappingClassAdapter( cw, remapper ); + + cr.accept( cv, ClassReader.EXPAND_FRAMES ); + + byte[] renamedClass = cw.toByteArray(); + + // Need to take the .class off for remapping evaluation + String mappedName = remapper.map( name.substring( 0, name.indexOf( '.' ) ) ); + + try + { + // Now we put it back on so the class file is written out with the right extension. + jos.putNextEntry( new JarEntry( mappedName + ".class" ) ); + + IOUtil.copy( renamedClass, jos ); + } + catch ( ZipException e ) + { + getLogger().warn( "We have a duplicate " + mappedName + " in " + jar ); + } + } + + private boolean isFiltered( List filters, String name ) + { + for ( int i = 0; i < filters.size(); i++ ) + { + Filter filter = (Filter) filters.get( i ); + + if ( filter.isFiltered( name ) ) + { + return true; + } + } + + return false; + } + + private boolean resourceTransformed( List resourceTransformers, String name, InputStream is ) + throws IOException + { + boolean resourceTransformed = false; + + for ( Iterator k = resourceTransformers.iterator(); k.hasNext(); ) + { + ResourceTransformer transformer = (ResourceTransformer) k.next(); + + if ( transformer.canTransformResource( name ) ) + { + transformer.processResource( is ); + + resourceTransformed = true; + + break; + } + } + return resourceTransformed; + } + + private void addResource( Set resources, JarOutputStream jos, String name, InputStream is ) + throws IOException + { + jos.putNextEntry( new JarEntry( name ) ); + + IOUtil.copy( is, jos ); + + resources.add( name ); + } + + class RelocatorRemapper + extends Remapper + { + List relocators; + + public RelocatorRemapper( List relocators ) + { + this.relocators = relocators; + } + + public boolean hasRelocators() + { + return !relocators.isEmpty(); + } + + public Object mapValue( Object object ) + { + if ( object instanceof String ) + { + String name = (String) object; + String value = name; + for ( Iterator i = relocators.iterator(); i.hasNext(); ) + { + Relocator r = (Relocator) i.next(); + + if ( r.canRelocatePath( name ) ) + { + value = r.relocatePath( name ); + break; + } + + if ( r.canRelocateClass( name ) ) + { + value = r.relocateClass( name ); + break; + } + } + + return value; + } + return object; + } + + public String map( String name ) + { + String value = name; + for ( Iterator i = relocators.iterator(); i.hasNext(); ) + { + Relocator r = (Relocator) i.next(); + + if ( r.canRelocatePath( name ) ) + { + value = r.relocatePath( name ); + break; + } + } + + return value; + } + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/ShadeConfiguration.java b/src/main/java/org/apache/maven/plugins/shade/ShadeConfiguration.java index b3075832..16b64141 100644 --- a/src/main/java/org/apache/maven/plugins/shade/ShadeConfiguration.java +++ b/src/main/java/org/apache/maven/plugins/shade/ShadeConfiguration.java @@ -1,25 +1,25 @@ -package org.apache.maven.plugins.shade; - -/* - * 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. - */ - -/** @author Jason van Zyl */ -public interface ShadeConfiguration -{ -} +package org.apache.maven.plugins.shade; + +/* + * 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. + */ + +/** @author Jason van Zyl */ +public interface ShadeConfiguration +{ +} diff --git a/src/main/java/org/apache/maven/plugins/shade/Shader.java b/src/main/java/org/apache/maven/plugins/shade/Shader.java index 864d1ac8..f475a569 100644 --- a/src/main/java/org/apache/maven/plugins/shade/Shader.java +++ b/src/main/java/org/apache/maven/plugins/shade/Shader.java @@ -1,38 +1,38 @@ -package org.apache.maven.plugins.shade; - -/* - * 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.File; -import java.io.IOException; -import java.util.List; -import java.util.Set; - -/** @author Jason van Zyl */ -public interface Shader -{ - String ROLE = Shader.class.getName(); - - public void shade(Set jars, - File uberJar, - List filters, - List relocators, - List resourceTransformers) - throws IOException; -} +package org.apache.maven.plugins.shade; + +/* + * 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.File; +import java.io.IOException; +import java.util.List; +import java.util.Set; + +/** @author Jason van Zyl */ +public interface Shader +{ + String ROLE = Shader.class.getName(); + + public void shade(Set jars, + File uberJar, + List filters, + List relocators, + List resourceTransformers) + throws IOException; +} diff --git a/src/main/java/org/apache/maven/plugins/shade/ShadingResult.java b/src/main/java/org/apache/maven/plugins/shade/ShadingResult.java index a005066a..4c678e12 100644 --- a/src/main/java/org/apache/maven/plugins/shade/ShadingResult.java +++ b/src/main/java/org/apache/maven/plugins/shade/ShadingResult.java @@ -1,25 +1,25 @@ -package org.apache.maven.plugins.shade; - -/* - * 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. - */ - -/** @author Jason van Zyl */ -public class ShadingResult -{ -} +package org.apache.maven.plugins.shade; + +/* + * 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. + */ + +/** @author Jason van Zyl */ +public class ShadingResult +{ +} diff --git a/src/main/java/org/apache/maven/plugins/shade/mojo/PackageRelocation.java b/src/main/java/org/apache/maven/plugins/shade/mojo/PackageRelocation.java index 23026062..42c619a3 100644 --- a/src/main/java/org/apache/maven/plugins/shade/mojo/PackageRelocation.java +++ b/src/main/java/org/apache/maven/plugins/shade/mojo/PackageRelocation.java @@ -1,50 +1,50 @@ -package org.apache.maven.plugins.shade.mojo; - -/* - * 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; - -/** - * @author Jason van Zyl - * @author Mauro Talevi - */ -public class PackageRelocation -{ - private String pattern; - - private String shadedPattern; - - private List excludes; - - public String getPattern() - { - return pattern; - } - - public String getShadedPattern() - { - return shadedPattern; - } - - public List getExcludes() - { - return excludes; - } -} +package org.apache.maven.plugins.shade.mojo; + +/* + * 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; + +/** + * @author Jason van Zyl + * @author Mauro Talevi + */ +public class PackageRelocation +{ + private String pattern; + + private String shadedPattern; + + private List excludes; + + public String getPattern() + { + return pattern; + } + + public String getShadedPattern() + { + return shadedPattern; + } + + public List getExcludes() + { + return excludes; + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java index 66942f53..843c8c43 100644 --- a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java +++ b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java @@ -1,687 +1,849 @@ -package org.apache.maven.plugins.shade.mojo; - -/* - * 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.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.Map; -import java.util.HashMap; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.shade.Shader; -import org.apache.maven.plugins.shade.filter.SimpleFilter; -import org.apache.maven.plugins.shade.pom.PomWriter; -import org.apache.maven.plugins.shade.relocation.SimpleRelocator; -import org.apache.maven.plugins.shade.resource.ResourceTransformer; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectHelper; -import org.codehaus.plexus.util.IOUtil; - -/** - * Mojo that performs shading delegating to the Shader component. - * - * @author Jason van Zyl - * @author Mauro Talevi - * @author David Blevins - * @goal shade - * @phase package - * @requiresDependencyResolution runtime - */ -public class ShadeMojo - extends AbstractMojo -{ - /** - * @parameter expression="${project}" - * @readonly - */ - private MavenProject project; - - /** @component */ - private MavenProjectHelper projectHelper; - - /** @component */ - private Shader shader; - - /** - * Remote repositories which will be searched for source attachments. - * - * @parameter expression="${project.remoteArtifactRepositories}" - * @required - * @readonly - */ - protected List remoteArtifactRepositories; - - /** - * Local maven repository. - * - * @parameter expression="${localRepository}" - * @required - * @readonly - */ - protected ArtifactRepository localRepository; - - /** - * Artifact factory, needed to download source jars for inclusion in classpath. - * - * @component role="org.apache.maven.artifact.factory.ArtifactFactory" - * @required - * @readonly - */ - protected ArtifactFactory artifactFactory; - - /** - * Artifact resolver, needed to download source jars for inclusion in classpath. - * - * @component role="org.apache.maven.artifact.resolver.ArtifactResolver" - * @required - * @readonly - */ - protected ArtifactResolver artifactResolver; - - /** - * Artifacts to include/exclude from the final artifact. - * - * @parameter - */ - private ArtifactSet artifactSet; - - /** - * Packages to be relocated. - * - * @parameter - */ - private PackageRelocation[] relocations; - - /** - * Resource transformers to be used. - * - * @parameter - */ - private ResourceTransformer[] transformers; - - /** - * Archive Filters to be used. Allows you to specify an artifact in the form of - * groupId:artifactId and a set of include/exclude file patterns for filtering which - * contents of the archive are added to the shaded jar. From a logical perspective, - * includes are processed before excludes, thus it's possible to use an include to - * collect a set of files from the archive then use excludes to further reduce the set. - * By default, all files are included and no files are excluded. - * - * @parameter - */ - private ArchiveFilter[] filters; - - /** @parameter expression="${project.build.directory}" */ - private File outputDirectory; - - /** - * The name of the shaded artifactId - * - * @parameter expression="${finalName}" - */ - private String finalName; - - /** - * The name of the shaded artifactId. So you may want to use a different artifactId and keep - * the standard version. If the original artifactId was "foo" then the final artifact would - * be something like foo-1.0.jar. So if you change the artifactId you might have something - * like foo-special-1.0.jar. - * - * @parameter expression="${shadedArtifactId}" default-value="${project.artifactId}" - */ - private String shadedArtifactId; - - /** - * If specified, this will include only artifacts which have groupIds which - * start with this. - * - * @parameter expression="${shadedGroupFilter}" - */ - private String shadedGroupFilter; - - /** - * Defines whether the shaded artifact should be attached as classifier to - * the original artifact. If false, the shaded jar will be the main artifact - * of the project - * - * @parameter expression="${shadedArtifactAttached}" default-value="false" - */ - private boolean shadedArtifactAttached; - - /** - * @parameter expression="${createDependencyReducedPom}" default-value="true" - */ - private boolean createDependencyReducedPom; - - /** - * When true, dependencies are kept in the pom but with scope 'provided'; when false, - * the dependency is removed. - * - * @parameter expression="${keepDependenciesWithProvidedScope}" default-value="false" - */ - private boolean keepDependenciesWithProvidedScope; - - /** - * When true, transitive deps of removed dependencies are promoted to direct dependencies. - * This should allow the drop in replacement of the removed deps with the new shaded - * jar and everything should still work. - * - * @parameter expression="${promoteTransitiveDependencies}" default-value="false" - */ - private boolean promoteTransitiveDependencies; - - - /** - * The name of the classifier used in case the shaded artifact is attached. - * - * @parameter expression="${shadedClassifierName}" default-value="shaded" - */ - private String shadedClassifierName; - - /** - * When true, it will attempt to create a sources jar as well - * - * @parameter expression="${createSourcesJar}" default-value="false" - */ - private boolean createSourcesJar; - - - /** @throws MojoExecutionException */ - public void execute() - throws MojoExecutionException - { - Set artifacts = new LinkedHashSet(); - Set artifactIds = new LinkedHashSet(); - Set sourceArtifacts = new LinkedHashSet(); - - artifacts.add( project.getArtifact().getFile() ); - - if ( createSourcesJar ) - { - File file = shadedSourcesArtifactFile(); - if ( file.exists() ) - { - sourceArtifacts.add( file ); - } - } - - for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) - { - Artifact artifact = (Artifact) it.next(); - - if ( excludeArtifact( artifact ) ) - { - getLog().info( "Excluding " + artifact.getId() + " from the shaded jar." ); - - continue; - } - - getLog().info( "Including " + artifact.getId() + " in the shaded jar." ); - - artifacts.add( artifact.getFile() ); - - artifactIds.add( getId( artifact ) ); - - if ( createSourcesJar ) - { - File file = resolveArtifactSources( artifact ); - if ( file != null ) - { - sourceArtifacts.add( file ); - } - } - } - - - File outputJar = shadedArtifactFileWithClassifier(); - File sourcesJar = shadedSourceArtifactFileWithClassifier(); - - // Now add our extra resources - try - { - List filters = getFilters(); - - List relocators = getRelocators(); - - List resourceTransformers = getResourceTrasformers(); - - shader.shade( artifacts, outputJar, filters, relocators, resourceTransformers ); - - if (createSourcesJar) - { - shader.shade( sourceArtifacts, sourcesJar, filters, relocators, resourceTransformers ); - } - - if ( shadedArtifactAttached ) - { - getLog().info( "Attaching shaded artifact." ); - projectHelper.attachArtifact( getProject(), "jar", shadedClassifierName, outputJar ); - if ( createSourcesJar ) - { - projectHelper.attachArtifact( getProject(), "jar", - shadedClassifierName + "-sources", sourcesJar ); - } - } - - else - { - getLog().info( "Replacing original artifact with shaded artifact." ); - File file = shadedArtifactFile(); - replaceFile( file, outputJar ); - - if ( createSourcesJar ) - { - file = shadedSourcesArtifactFile(); - - replaceFile( file, sourcesJar ); - - projectHelper.attachArtifact( project, "jar", - "sources", file ); - } - - if ( createDependencyReducedPom ) - { - createDependencyReducedPom( artifactIds ); - } - } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error creating shaded jar.", e ); - } - } - - private void replaceFile(File oldFile, File newFile) throws MojoExecutionException - { - getLog().info("Replacing " + oldFile + " with " + newFile); - - File origFile = new File( outputDirectory, "original-" + oldFile.getName() ); - if ( oldFile.exists() && !oldFile.renameTo( origFile ) ) - { - //try a gc to see if an unclosed stream needs garbage collecting - System.gc(); - System.gc(); - - if ( !oldFile.renameTo( origFile ) ) - { - // Still didn't work. We'll do a copy - try - { - FileOutputStream fout = new FileOutputStream( origFile ); - FileInputStream fin = new FileInputStream( oldFile ); - try - { - IOUtil.copy(fin, fout); - } - finally - { - IOUtil.close( fin ); - IOUtil.close( fout ); - } - } - catch (IOException ex) - { - //kind of ignorable here. We're just trying to save the original - getLog().warn(ex); - } - } - } - if ( !newFile.renameTo( oldFile ) ) - { - //try a gc to see if an unclosed stream needs garbage collecting - System.gc(); - System.gc(); - if ( !newFile.renameTo( oldFile ) ) - { - // Still didn't work. We'll do a copy - try - { - FileOutputStream fout = new FileOutputStream( oldFile ); - FileInputStream fin = new FileInputStream( newFile ); - try - { - IOUtil.copy(fin, fout); - } - finally - { - IOUtil.close( fin ); - IOUtil.close( fout ); - } - } - catch (IOException ex) - { - throw new MojoExecutionException( "Could not replace original artifact with shaded artifact!", ex); - } - } - } - } - - private File resolveArtifactSources(Artifact artifact) { - - Artifact resolvedArtifact = - artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getVersion(), - "java-source", - "sources"); - - try - { - artifactResolver.resolve( resolvedArtifact, remoteArtifactRepositories, localRepository ); - } - catch ( ArtifactNotFoundException e ) - { - // ignore, the jar has not been found - } - catch ( ArtifactResolutionException e ) - { - getLog().warn( "Could not get sources for " + artifact ); - } - - if ( resolvedArtifact.isResolved() ) - { - return resolvedArtifact.getFile(); - } - return null; - } - - private boolean excludeArtifact( Artifact artifact ) - { - String id = getId( artifact ); - - // This is the case where we have only stated artifacts to include and no exclusions - // have been listed. We just want what we have asked to include. - if ( artifactSet != null && ( artifactSet.getExcludes() == null && artifactSet.getIncludes() != null ) && !includedArtifacts().contains( id ) ) - { - return true; - } - - if ( excludedArtifacts().contains( id ) ) - { - return true; - } - - if ( shadedGroupFilter != null && !artifact.getGroupId().startsWith( shadedGroupFilter ) ) - { - return true; - } - - return false; - } - - private Set excludedArtifacts() - { - if ( artifactSet != null && artifactSet.getExcludes() != null ) - { - return artifactSet.getExcludes(); - } - - return Collections.EMPTY_SET; - } - - private Set includedArtifacts() - { - if ( artifactSet != null && artifactSet.getIncludes() != null ) - { - return artifactSet.getIncludes(); - } - - return Collections.EMPTY_SET; - } - - private List getRelocators() - { - List relocators = new ArrayList(); - - if ( relocations == null ) - { - return relocators; - } - - for ( int i = 0; i < relocations.length; i++ ) - { - PackageRelocation r = relocations[i]; - - relocators.add( new SimpleRelocator( r.getPattern(), r.getShadedPattern(), r.getExcludes() ) ); - - } - return relocators; - } - - private List getResourceTrasformers() - { - if ( transformers == null ) - { - return Collections.EMPTY_LIST; - } - - return Arrays.asList( transformers ); - } - - private List getFilters() - { - List filters = new ArrayList(); - - if ( this.filters == null ) - { - return filters; - } - - Map artifacts = new HashMap(); - - artifacts.put( getId( project.getArtifact() ), project.getArtifact().getFile() ); - - for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) - { - Artifact artifact = (Artifact) it.next(); - - artifacts.put( getId( artifact ), artifact.getFile() ); - } - - for ( int i = 0; i < this.filters.length; i++ ) - { - ArchiveFilter f = this.filters[i]; - - File jar = (File) artifacts.get( f.getArtifact() ); - - if ( jar == null ) - { - getLog().info( "No artifact matching filter " + f.getArtifact() ); - - continue; - } - - filters.add( new SimpleFilter( jar, f.getIncludes(), f.getExcludes() ) ); - - } - - return filters; - } - - private File shadedArtifactFileWithClassifier() - { - Artifact artifact = project.getArtifact(); - final String shadedName = - shadedArtifactId + "-" + artifact.getVersion() + "-" + shadedClassifierName + "." + artifact.getArtifactHandler().getExtension(); - return new File( outputDirectory, shadedName ); - } - private File shadedSourceArtifactFileWithClassifier() - { - Artifact artifact = project.getArtifact(); - final String shadedName = - shadedArtifactId + "-" + artifact.getVersion() + "-" + shadedClassifierName + "-sources." + artifact.getArtifactHandler().getExtension(); - return new File( outputDirectory, shadedName ); - } - - private File shadedArtifactFile() - { - Artifact artifact = project.getArtifact(); - - String shadedName; - - if ( finalName != null ) - { - shadedName = finalName + "." + artifact.getArtifactHandler().getExtension(); - } - else - { - shadedName = shadedArtifactId + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension(); - } - - return new File( outputDirectory, shadedName ); - } - private File shadedSourcesArtifactFile() - { - Artifact artifact = project.getArtifact(); - - String shadedName; - - if ( finalName != null ) - { - shadedName = finalName + "-sources." + artifact.getArtifactHandler().getExtension(); - } - else - { - shadedName = shadedArtifactId + "-" + artifact.getVersion() + "-sources." + artifact.getArtifactHandler().getExtension(); - } - - return new File( outputDirectory, shadedName ); - } - - protected MavenProject getProject() - { - if ( project.getExecutionProject() != null ) - { - return project.getExecutionProject(); - } - else - { - return project; - } - } - - // We need to find the direct dependencies that have been included in the uber JAR so that we can modify the - // POM accordingly. - private void createDependencyReducedPom( Set artifactsToRemove ) - throws IOException - { - Model model = getProject().getOriginalModel(); - - List dependencies = new ArrayList(); - - boolean modified = false; - - List origDeps = getProject().getDependencies(); - if ( promoteTransitiveDependencies ) - { - origDeps = new ArrayList(); - for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) - { - Artifact artifact = (Artifact) it.next(); - - //promote - Dependency dep = new Dependency(); - dep.setArtifactId( artifact.getArtifactId() ); - if (artifact.hasClassifier()) - { - dep.setClassifier( artifact.getClassifier() ); - } - dep.setGroupId( artifact.getGroupId() ); - dep.setOptional( artifact.isOptional() ); - dep.setScope( artifact.getScope() ); - dep.setType( artifact.getType() ); - dep.setVersion( artifact.getVersion() ); - - // How to do these? - //dep.setSystemPath( .... ); - //dep.setExclusions( exclusions ); - origDeps.add( dep ); - } - } - - for ( Iterator i = origDeps.iterator(); i.hasNext(); ) - { - Dependency d = (Dependency) i.next(); - - dependencies.add( d ); - - String id = d.getGroupId() + ":" + d.getArtifactId(); - - if ( artifactsToRemove.contains( id ) ) - { - modified = true; - - if ( keepDependenciesWithProvidedScope ) - { - d.setScope( "provided" ); - } - else - { - dependencies.remove( d ); - } - } - } - - // Check to see if we have a reduction and if so rewrite the POM. - if ( modified ) - { - model.setDependencies( dependencies ); - - File f = new File( outputDirectory, "dependency-reduced-pom.xml" ); - if (f.exists()) - { - f.delete(); - } - - Writer w = new FileWriter( f ); - - PomWriter.write( w, model, true ); - - w.close(); - - project.setFile( f ); - } - } - - private String getId( Artifact artifact ) - { - return artifact.getGroupId() + ":" + artifact.getArtifactId(); - } -} +package org.apache.maven.plugins.shade.mojo; + +/* + * 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.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.Map; +import java.util.HashMap; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Exclusion; +import org.apache.maven.model.Model; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.shade.Shader; +import org.apache.maven.plugins.shade.filter.SimpleFilter; +import org.apache.maven.plugins.shade.pom.PomWriter; +import org.apache.maven.plugins.shade.relocation.SimpleRelocator; +import org.apache.maven.plugins.shade.resource.ResourceTransformer; +import org.apache.maven.profiles.ProfileManager; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.apache.maven.shared.dependency.tree.DependencyNode; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.apache.maven.shared.dependency.tree.DependencyTreeResolutionListener; +import org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter; +import org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter; +import org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor; +import org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor; +import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; +import org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor; +import org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor; +import org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.TreeTokens; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.WriterFactory; + +/** + * Mojo that performs shading delegating to the Shader component. + * + * @author Jason van Zyl + * @author Mauro Talevi + * @author David Blevins + * @author Hiram Chirino + * @goal shade + * @phase package + * @requiresDependencyResolution runtime + */ +public class ShadeMojo + extends AbstractMojo +{ + /** + * @parameter expression="${project}" + * @readonly + * @required + */ + private MavenProject project; + + /** + * @component + * @required + * @readonly + */ + private MavenProjectHelper projectHelper; + + /** + * @component + * @required + * @readonly + */ + private Shader shader; + + /** + * The dependency tree builder to use. + * + * @component + * @required + * @readonly + */ + private DependencyTreeBuilder dependencyTreeBuilder; + + /** + * ProjectBuilder, needed to create projects from the artifacts. + * + * @component role="org.apache.maven.project.MavenProjectBuilder" + * @required + * @readonly + */ + private MavenProjectBuilder mavenProjectBuilder; + + /** + * The artifact metadata source to use. + * + * @component + * @required + * @readonly + */ + private ArtifactMetadataSource artifactMetadataSource; + + /** + * The artifact collector to use. + * + * @component + * @required + * @readonly + */ + private ArtifactCollector artifactCollector; + + /** + * Remote repositories which will be searched for source attachments. + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @required + * @readonly + */ + protected List remoteArtifactRepositories; + + /** + * Local maven repository. + * + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + protected ArtifactRepository localRepository; + + /** + * Artifact factory, needed to download source jars for inclusion in classpath. + * + * @component role="org.apache.maven.artifact.factory.ArtifactFactory" + * @required + * @readonly + */ + protected ArtifactFactory artifactFactory; + + /** + * Artifact resolver, needed to download source jars for inclusion in classpath. + * + * @component role="org.apache.maven.artifact.resolver.ArtifactResolver" + * @required + * @readonly + */ + protected ArtifactResolver artifactResolver; + + /** + * Artifacts to include/exclude from the final artifact. + * + * @parameter + */ + private ArtifactSet artifactSet; + + /** + * Packages to be relocated. + * + * @parameter + */ + private PackageRelocation[] relocations; + + /** + * Resource transformers to be used. + * + * @parameter + */ + private ResourceTransformer[] transformers; + + /** + * Archive Filters to be used. Allows you to specify an artifact in the form of + * groupId:artifactId and a set of include/exclude file patterns for filtering which + * contents of the archive are added to the shaded jar. From a logical perspective, + * includes are processed before excludes, thus it's possible to use an include to + * collect a set of files from the archive then use excludes to further reduce the set. + * By default, all files are included and no files are excluded. + * + * @parameter + */ + private ArchiveFilter[] filters; + + /** + * The destination directory for the shaded artifact. + * + * @parameter default-value="${project.build.directory}" + */ + private File outputDirectory; + + /** + * The name of the shaded artifactId + * + * @parameter expression="${finalName}" + */ + private String finalName; + + /** + * The name of the shaded artifactId. So you may want to use a different artifactId and keep + * the standard version. If the original artifactId was "foo" then the final artifact would + * be something like foo-1.0.jar. So if you change the artifactId you might have something + * like foo-special-1.0.jar. + * + * @parameter expression="${shadedArtifactId}" default-value="${project.artifactId}" + */ + private String shadedArtifactId; + + /** + * If specified, this will include only artifacts which have groupIds which + * start with this. + * + * @parameter expression="${shadedGroupFilter}" + */ + private String shadedGroupFilter; + + /** + * Defines whether the shaded artifact should be attached as classifier to + * the original artifact. If false, the shaded jar will be the main artifact + * of the project + * + * @parameter expression="${shadedArtifactAttached}" default-value="false" + */ + private boolean shadedArtifactAttached; + + /** + * Flag whether to generate a simplified POM for the shaded artifact. If set to true, dependencies that + * have been included into the uber JAR will be removed from the <dependencies> section of the + * generated POM. The reduced POM will be named dependency-reduced-pom.xml and is stored into the same + * directory as the shaded artifact. + * + * @parameter expression="${createDependencyReducedPom}" default-value="true" + */ + private boolean createDependencyReducedPom; + + /** + * When true, dependencies are kept in the pom but with scope 'provided'; when false, + * the dependency is removed. + * + * @parameter expression="${keepDependenciesWithProvidedScope}" default-value="false" + */ + private boolean keepDependenciesWithProvidedScope; + + /** + * When true, transitive deps of removed dependencies are promoted to direct dependencies. + * This should allow the drop in replacement of the removed deps with the new shaded + * jar and everything should still work. + * + * @parameter expression="${promoteTransitiveDependencies}" default-value="false" + */ + private boolean promoteTransitiveDependencies; + + /** + * The name of the classifier used in case the shaded artifact is attached. + * + * @parameter expression="${shadedClassifierName}" default-value="shaded" + */ + private String shadedClassifierName; + + /** + * When true, it will attempt to create a sources jar as well + * + * @parameter expression="${createSourcesJar}" default-value="false" + */ + private boolean createSourcesJar; + + + /** @throws MojoExecutionException */ + public void execute() + throws MojoExecutionException + { + Set artifacts = new LinkedHashSet(); + Set artifactIds = new LinkedHashSet(); + Set sourceArtifacts = new LinkedHashSet(); + + if ( project.getArtifact().getFile() == null ) + { + getLog().error( "The project main artifact does not exist. This could have the following" ); + getLog().error( "reasons:" ); + getLog().error( "- You have invoked the goal directly from the command line. This is not" ); + getLog().error( " supported. Please add the goal to the default lifecycle via an" ); + getLog().error( " element in your POM and use \"mvn package\" to have it run." ); + getLog().error( "- You have bound the goal to a lifecycle phase before \"package\". Please" ); + getLog().error( " remove this binding from your POM such that the goal will be run in" ); + getLog().error( " the proper phase." ); + throw new MojoExecutionException( "Failed to create shaded artifact.", + new IllegalStateException( "Project main artifact does not exist." ) ); + } + artifacts.add( project.getArtifact().getFile() ); + + if ( createSourcesJar ) + { + File file = shadedSourcesArtifactFile(); + if ( file.exists() ) + { + sourceArtifacts.add( file ); + } + } + + for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) + { + Artifact artifact = (Artifact) it.next(); + + if ( excludeArtifact( artifact ) ) + { + getLog().info( "Excluding " + artifact.getId() + " from the shaded jar." ); + + continue; + } + + getLog().info( "Including " + artifact.getId() + " in the shaded jar." ); + + artifacts.add( artifact.getFile() ); + + artifactIds.add( getId( artifact ) ); + + if ( createSourcesJar ) + { + File file = resolveArtifactSources( artifact ); + if ( file != null ) + { + sourceArtifacts.add( file ); + } + } + } + + + File outputJar = shadedArtifactFileWithClassifier(); + File sourcesJar = shadedSourceArtifactFileWithClassifier(); + + // Now add our extra resources + try + { + List filters = getFilters(); + + List relocators = getRelocators(); + + List resourceTransformers = getResourceTrasformers(); + + shader.shade( artifacts, outputJar, filters, relocators, resourceTransformers ); + + if (createSourcesJar) + { + shader.shade( sourceArtifacts, sourcesJar, filters, relocators, resourceTransformers ); + } + + if ( shadedArtifactAttached ) + { + getLog().info( "Attaching shaded artifact." ); + projectHelper.attachArtifact( getProject(), "jar", shadedClassifierName, outputJar ); + if ( createSourcesJar ) + { + projectHelper.attachArtifact( getProject(), "jar", + shadedClassifierName + "-sources", sourcesJar ); + } + } + + else + { + getLog().info( "Replacing original artifact with shaded artifact." ); + File file = shadedArtifactFile(); + replaceFile( file, outputJar ); + + if ( createSourcesJar ) + { + file = shadedSourcesArtifactFile(); + + replaceFile( file, sourcesJar ); + + projectHelper.attachArtifact( project, "jar", + "sources", file ); + } + + if ( createDependencyReducedPom ) + { + createDependencyReducedPom( artifactIds ); + } + } + } + catch ( Exception e ) + { + throw new MojoExecutionException( "Error creating shaded jar.", e ); + } + } + + private void replaceFile(File oldFile, File newFile) throws MojoExecutionException + { + getLog().info("Replacing " + oldFile + " with " + newFile); + + File origFile = new File( outputDirectory, "original-" + oldFile.getName() ); + if ( oldFile.exists() && !oldFile.renameTo( origFile ) ) + { + //try a gc to see if an unclosed stream needs garbage collecting + System.gc(); + System.gc(); + + if ( !oldFile.renameTo( origFile ) ) + { + // Still didn't work. We'll do a copy + try + { + FileOutputStream fout = new FileOutputStream( origFile ); + FileInputStream fin = new FileInputStream( oldFile ); + try + { + IOUtil.copy(fin, fout); + } + finally + { + IOUtil.close( fin ); + IOUtil.close( fout ); + } + } + catch (IOException ex) + { + //kind of ignorable here. We're just trying to save the original + getLog().warn(ex); + } + } + } + if ( !newFile.renameTo( oldFile ) ) + { + //try a gc to see if an unclosed stream needs garbage collecting + System.gc(); + System.gc(); + if ( !newFile.renameTo( oldFile ) ) + { + // Still didn't work. We'll do a copy + try + { + FileOutputStream fout = new FileOutputStream( oldFile ); + FileInputStream fin = new FileInputStream( newFile ); + try + { + IOUtil.copy(fin, fout); + } + finally + { + IOUtil.close( fin ); + IOUtil.close( fout ); + } + } + catch (IOException ex) + { + throw new MojoExecutionException( "Could not replace original artifact with shaded artifact!", ex); + } + } + } + } + + private File resolveArtifactSources(Artifact artifact) { + + Artifact resolvedArtifact = + artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion(), + "java-source", + "sources"); + + try + { + artifactResolver.resolve( resolvedArtifact, remoteArtifactRepositories, localRepository ); + } + catch ( ArtifactNotFoundException e ) + { + // ignore, the jar has not been found + } + catch ( ArtifactResolutionException e ) + { + getLog().warn( "Could not get sources for " + artifact ); + } + + if ( resolvedArtifact.isResolved() ) + { + return resolvedArtifact.getFile(); + } + return null; + } + + private boolean excludeArtifact( Artifact artifact ) + { + String id = getId( artifact ); + + // This is the case where we have only stated artifacts to include and no exclusions + // have been listed. We just want what we have asked to include. + if ( artifactSet != null && ( artifactSet.getExcludes() == null && artifactSet.getIncludes() != null ) && !includedArtifacts().contains( id ) ) + { + return true; + } + + if ( excludedArtifacts().contains( id ) ) + { + return true; + } + + if ( shadedGroupFilter != null && !artifact.getGroupId().startsWith( shadedGroupFilter ) ) + { + return true; + } + + return false; + } + + private Set excludedArtifacts() + { + if ( artifactSet != null && artifactSet.getExcludes() != null ) + { + return artifactSet.getExcludes(); + } + + return Collections.EMPTY_SET; + } + + private Set includedArtifacts() + { + if ( artifactSet != null && artifactSet.getIncludes() != null ) + { + return artifactSet.getIncludes(); + } + + return Collections.EMPTY_SET; + } + + private List getRelocators() + { + List relocators = new ArrayList(); + + if ( relocations == null ) + { + return relocators; + } + + for ( int i = 0; i < relocations.length; i++ ) + { + PackageRelocation r = relocations[i]; + + relocators.add( new SimpleRelocator( r.getPattern(), r.getShadedPattern(), r.getExcludes() ) ); + + } + return relocators; + } + + private List getResourceTrasformers() + { + if ( transformers == null ) + { + return Collections.EMPTY_LIST; + } + + return Arrays.asList( transformers ); + } + + private List getFilters() + { + List filters = new ArrayList(); + + if ( this.filters == null ) + { + return filters; + } + + Map artifacts = new HashMap(); + + artifacts.put( getId( project.getArtifact() ), project.getArtifact().getFile() ); + + for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) + { + Artifact artifact = (Artifact) it.next(); + + artifacts.put( getId( artifact ), artifact.getFile() ); + } + + for ( int i = 0; i < this.filters.length; i++ ) + { + ArchiveFilter f = this.filters[i]; + + File jar = (File) artifacts.get( f.getArtifact() ); + + if ( jar == null ) + { + getLog().info( "No artifact matching filter " + f.getArtifact() ); + + continue; + } + + filters.add( new SimpleFilter( jar, f.getIncludes(), f.getExcludes() ) ); + + } + + return filters; + } + + private File shadedArtifactFileWithClassifier() + { + Artifact artifact = project.getArtifact(); + final String shadedName = + shadedArtifactId + "-" + artifact.getVersion() + "-" + shadedClassifierName + "." + artifact.getArtifactHandler().getExtension(); + return new File( outputDirectory, shadedName ); + } + private File shadedSourceArtifactFileWithClassifier() + { + Artifact artifact = project.getArtifact(); + final String shadedName = + shadedArtifactId + "-" + artifact.getVersion() + "-" + shadedClassifierName + "-sources." + artifact.getArtifactHandler().getExtension(); + return new File( outputDirectory, shadedName ); + } + + private File shadedArtifactFile() + { + Artifact artifact = project.getArtifact(); + + String shadedName; + + if ( finalName != null ) + { + shadedName = finalName + "." + artifact.getArtifactHandler().getExtension(); + } + else + { + shadedName = shadedArtifactId + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension(); + } + + return new File( outputDirectory, shadedName ); + } + private File shadedSourcesArtifactFile() + { + Artifact artifact = project.getArtifact(); + + String shadedName; + + if ( finalName != null ) + { + shadedName = finalName + "-sources." + artifact.getArtifactHandler().getExtension(); + } + else + { + shadedName = shadedArtifactId + "-" + artifact.getVersion() + "-sources." + artifact.getArtifactHandler().getExtension(); + } + + return new File( outputDirectory, shadedName ); + } + + protected MavenProject getProject() + { + if ( project.getExecutionProject() != null ) + { + return project.getExecutionProject(); + } + else + { + return project; + } + } + + // We need to find the direct dependencies that have been included in the uber JAR so that we can modify the + // POM accordingly. + private void createDependencyReducedPom( Set artifactsToRemove ) + throws IOException, DependencyTreeBuilderException, ProjectBuildingException + { + Model model = getProject().getOriginalModel(); + List dependencies = new ArrayList(); + + boolean modified = false; + + List origDeps = getProject().getDependencies(); + if ( promoteTransitiveDependencies ) + { + origDeps = new ArrayList(); + for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) + { + Artifact artifact = (Artifact) it.next(); + + //promote + Dependency dep = new Dependency(); + dep.setArtifactId( artifact.getArtifactId() ); + if (artifact.hasClassifier()) + { + dep.setClassifier( artifact.getClassifier() ); + } + dep.setGroupId( artifact.getGroupId() ); + dep.setOptional( artifact.isOptional() ); + dep.setScope( artifact.getScope() ); + dep.setType( artifact.getType() ); + dep.setVersion( artifact.getVersion() ); + + //we'll figure out the exclusions in a bit. + + origDeps.add( dep ); + } + } + + for ( Iterator i = origDeps.iterator(); i.hasNext(); ) + { + Dependency d = (Dependency) i.next(); + + dependencies.add( d ); + + String id = d.getGroupId() + ":" + d.getArtifactId(); + + if ( artifactsToRemove.contains( id ) ) + { + modified = true; + + if ( keepDependenciesWithProvidedScope ) + { + d.setScope( "provided" ); + } + else + { + dependencies.remove( d ); + } + } + } + + // Check to see if we have a reduction and if so rewrite the POM. + if (modified) + { + while (modified) + { + + model.setDependencies( dependencies ); + + File f = new File( outputDirectory, "dependency-reduced-pom.xml" ); + if ( f.exists() ) + { + f.delete(); + } + + Writer w = WriterFactory.newXmlWriter( f ); + + PomWriter.write( w, model, true ); + + w.close(); + + MavenProject p2 = mavenProjectBuilder.build( f, localRepository, null ); + modified = updateExcludesInDeps( p2, dependencies ); + + } + + //copy the dependecy-reduced-pom.xml to the basedir where + //we'll set the file for the project to it. We cannot set + //it to the real version in "target" as then ${basedir} gets + //messed up. We'll delete this file on exit to make + //sure it gets cleaned up. + File f = new File( project.getBasedir(), "dependency-reduced-pom.xml" ); + File f2 = new File( outputDirectory, "dependency-reduced-pom.xml" ); + if (f.exists() ) + { + f.delete(); + } + FileUtils.copyFile( f2, f ); + FileUtils.forceDeleteOnExit( f ); + project.setFile( f ); + } + } + + private String getId( Artifact artifact ) + { + if ( artifact.getClassifier() == null || "jar".equals( artifact.getClassifier() ) ) + { + return artifact.getGroupId() + ":" + artifact.getArtifactId(); + } + else + { + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getClassifier(); + } + } + + + public boolean updateExcludesInDeps( MavenProject project, List dependencies ) + throws DependencyTreeBuilderException + { + DependencyNode node = dependencyTreeBuilder.buildDependencyTree( + project, + localRepository, + artifactFactory, + artifactMetadataSource, + null, + artifactCollector ); + boolean modified = false; + Iterator it = node.getChildren().listIterator(); + while ( it.hasNext() ) + { + DependencyNode n2 = (DependencyNode) it.next(); + Iterator it2 = n2.getChildren().listIterator(); + while ( it2.hasNext() ) + { + DependencyNode n3 = (DependencyNode) it2.next(); + //anything two levels deep that is not marked "included" + //is stuff that was excluded by the original poms, make sure it + //remains excluded + if ( n3.getState() == DependencyNode.INCLUDED) + { + for ( int x = 0; x < dependencies.size(); x++ ) + { + Dependency dep = (Dependency) dependencies.get( x ); + if ( dep.getArtifactId().equals( n2.getArtifact().getArtifactId() ) + && dep.getGroupId().equals( n2.getArtifact().getGroupId() ) ) + { + Exclusion exclusion = new Exclusion(); + exclusion.setArtifactId( n3.getArtifact().getArtifactId() ); + exclusion.setGroupId( n3.getArtifact().getGroupId() ); + dep.addExclusion( exclusion ); + modified = true; + break; + } + } + } + } + } + return modified; + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java b/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java index fb2dc491..aededbf3 100644 --- a/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java +++ b/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java @@ -1,2021 +1,2021 @@ -package org.apache.maven.plugins.shade.pom; - -//package org.apache.maven.model.io.jdom; - -/* - * 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. - */ - - //---------------------------------/ - //- Imported classes and packages -/ -//---------------------------------/ - -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Map; - -import org.apache.maven.model.ActivationFile; -import org.apache.maven.model.ActivationOS; -import org.apache.maven.model.ActivationProperty; -import org.apache.maven.model.Build; -import org.apache.maven.model.BuildBase; -import org.apache.maven.model.CiManagement; -import org.apache.maven.model.ConfigurationContainer; -import org.apache.maven.model.Contributor; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.DeploymentRepository; -import org.apache.maven.model.Developer; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.Exclusion; -import org.apache.maven.model.Extension; -import org.apache.maven.model.FileSet; -import org.apache.maven.model.IssueManagement; -import org.apache.maven.model.License; -import org.apache.maven.model.MailingList; -import org.apache.maven.model.Model; -import org.apache.maven.model.ModelBase; -import org.apache.maven.model.Notifier; -import org.apache.maven.model.Organization; -import org.apache.maven.model.Parent; -import org.apache.maven.model.PatternSet; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginConfiguration; -import org.apache.maven.model.PluginContainer; -import org.apache.maven.model.PluginExecution; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.model.Prerequisites; -import org.apache.maven.model.Profile; -import org.apache.maven.model.Relocation; -import org.apache.maven.model.ReportPlugin; -import org.apache.maven.model.ReportSet; -import org.apache.maven.model.Reporting; -import org.apache.maven.model.Repository; -import org.apache.maven.model.RepositoryBase; -import org.apache.maven.model.RepositoryPolicy; -import org.apache.maven.model.Resource; -import org.apache.maven.model.Scm; -import org.apache.maven.model.Site; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.jdom.Content; -import org.jdom.DefaultJDOMFactory; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.Text; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; - -/** - * Class MavenJDOMWriter. - * - * @version $Revision: 3974 $ $Date: 2007-04-23 19:55:40 -0400 (Mon, 23 Apr 2007) $ - */ -public class MavenJDOMWriter { - - - //--------------------------/ - //- Class/Member Variables -/ - //--------------------------/ - - /** - * Field factory - */ - private DefaultJDOMFactory factory; - - /** - * Field lineSeparator - */ - private String lineSeparator; - - - //----------------/ - //- Constructors -/ - //----------------/ - - public MavenJDOMWriter() { - factory = new DefaultJDOMFactory(); - lineSeparator = "\n"; - } //-- org.apache.maven.model.io.jdom.MavenJDOMWriter() - - - //-----------/ - //- Methods -/ - //-----------/ - - /** - * Method findAndReplaceProperties - * - * @param counter - * @param props - * @param name - * @param parent - */ - protected Element findAndReplaceProperties(Counter counter, Element parent, String name, Map props) - { - boolean shouldExist = props != null && ! props.isEmpty(); - Element element = updateElement(counter, parent, name, shouldExist); - if (shouldExist) { - Iterator it = props.keySet().iterator(); - Counter innerCounter = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - String key = (String) it.next(); - findAndReplaceSimpleElement(innerCounter, element, key, (String)props.get(key), null); - } - ArrayList lst = new ArrayList(props.keySet()); - it = element.getChildren().iterator(); - while (it.hasNext()) { - Element elem = (Element) it.next(); - String key = elem.getName(); - if (!lst.contains(key)) { - it.remove(); - } - } - } - return element; - } //-- Element findAndReplaceProperties(Counter, Element, String, Map) - - /** - * Method findAndReplaceSimpleElement - * - * @param counter - * @param defaultValue - * @param text - * @param name - * @param parent - */ - protected Element findAndReplaceSimpleElement(Counter counter, Element parent, String name, String text, String defaultValue) - { - if (defaultValue != null && text != null && defaultValue.equals(text)) { - Element element = parent.getChild(name, parent.getNamespace()); - // if exist and is default value or if doesn't exist.. just keep the way it is.. - if ((element != null && defaultValue.equals(element.getText())) || element == null) { - return element; - } - } - boolean shouldExist = text != null && text.trim().length() > 0; - Element element = updateElement(counter, parent, name, shouldExist); - if (shouldExist) { - element.setText(text); - } - return element; - } //-- Element findAndReplaceSimpleElement(Counter, Element, String, String, String) - - /** - * Method findAndReplaceSimpleLists - * - * @param counter - * @param childName - * @param parentName - * @param list - * @param parent - */ - protected Element findAndReplaceSimpleLists(Counter counter, Element parent, java.util.Collection list, String parentName, String childName) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentName, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childName, element.getNamespace()).iterator(); - if (! elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - String value = (String) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childName, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - el.setText(value); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - return element; - } //-- Element findAndReplaceSimpleLists(Counter, Element, java.util.Collection, String, String) - - /** - * Method findAndReplaceXpp3DOM - * - * @param counter - * @param dom - * @param name - * @param parent - */ - protected Element findAndReplaceXpp3DOM(Counter counter, Element parent, String name, Xpp3Dom dom) - { - boolean shouldExist = dom != null && (dom.getChildCount() > 0 || dom.getValue() != null); - Element element = updateElement(counter, parent, name, shouldExist); - if (shouldExist) { - replaceXpp3DOM(element, dom, new Counter(counter.getDepth() + 1)); - } - return element; - } //-- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom) - - /** - * Method insertAtPreferredLocation - * - * @param parent - * @param counter - * @param child - */ - protected void insertAtPreferredLocation(Element parent, Element child, Counter counter) - { - int contentIndex = 0; - int elementCounter = 0; - Iterator it = parent.getContent().iterator(); - Text lastText = null; - int offset = 0; - while (it.hasNext() && elementCounter <= counter.getCurrentIndex()) { - Object next = it.next(); - offset = offset + 1; - if (next instanceof Element) { - elementCounter = elementCounter + 1; - contentIndex = contentIndex + offset; - offset = 0; - } - if (next instanceof Text && it.hasNext()) { - lastText = (Text)next; - } - } - if (lastText != null && lastText.getTextTrim().length() == 0) { - lastText = (Text)lastText.clone(); - } else { - String starter = lineSeparator; - for (int i = 0; i < counter.getDepth(); i++) { - starter = starter + " "; //TODO make settable? - } - lastText = factory.text(starter); - } - if (parent.getContentSize() == 0) { - Text finalText = (Text)lastText.clone(); - finalText.setText(finalText.getText().substring(0, finalText.getText().length() - " ".length())); - parent.addContent(contentIndex, finalText); - } - parent.addContent(contentIndex, child); - parent.addContent(contentIndex, lastText); - } //-- void insertAtPreferredLocation(Element, Element, Counter) - - /** - * Method iterateContributor - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateContributor(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Contributor value = (Contributor) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateContributor(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateContributor(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateDependency - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateDependency(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Dependency value = (Dependency) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateDependency(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateDependency(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateDeveloper - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateDeveloper(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Developer value = (Developer) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateDeveloper(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateDeveloper(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateExclusion - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateExclusion(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Exclusion value = (Exclusion) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateExclusion(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateExclusion(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateExtension - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateExtension(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Extension value = (Extension) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateExtension(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateExtension(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateLicense - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateLicense(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - License value = (License) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateLicense(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateLicense(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateMailingList - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateMailingList(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - MailingList value = (MailingList) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateMailingList(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateMailingList(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateNotifier - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateNotifier(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Notifier value = (Notifier) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateNotifier(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateNotifier(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iteratePlugin - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iteratePlugin(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Plugin value = (Plugin) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updatePlugin(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iteratePluginExecution - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iteratePluginExecution(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - PluginExecution value = (PluginExecution) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updatePluginExecution(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateProfile - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateProfile(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Profile value = (Profile) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateProfile(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateProfile(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateReportPlugin - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateReportPlugin(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - ReportPlugin value = (ReportPlugin) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateReportPlugin(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateReportPlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateReportSet - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateReportSet(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - ReportSet value = (ReportSet) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateReportSet(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateReportSet(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateRepository - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateRepository(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Repository value = (Repository) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateRepository(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateRepository(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method iterateResource - * - * @param counter - * @param childTag - * @param parentTag - * @param list - * @param parent - */ - protected void iterateResource(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) - { - boolean shouldExist = list != null && list.size() > 0; - Element element = updateElement(counter, parent, parentTag, shouldExist); - if (shouldExist) { - Iterator it = list.iterator(); - Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); - if (!elIt.hasNext()) elIt = null; - Counter innerCount = new Counter(counter.getDepth() + 1); - while (it.hasNext()) { - Resource value = (Resource) it.next(); - Element el; - if (elIt != null && elIt.hasNext()) { - el = (Element) elIt.next(); - if (! elIt.hasNext()) elIt = null; - } else { - el = factory.element(childTag, element.getNamespace()); - insertAtPreferredLocation(element, el, innerCount); - } - updateResource(value, childTag, innerCount, el); - innerCount.increaseCount(); - } - if (elIt != null) { - while (elIt.hasNext()) { - elIt.next(); - elIt.remove(); - } - } - } - } //-- void iterateResource(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) - - /** - * Method replaceXpp3DOM - * - * @param parent - * @param counter - * @param parentDom - */ - protected void replaceXpp3DOM(Element parent, Xpp3Dom parentDom, Counter counter) - { - if (parentDom.getChildCount() > 0) { - Xpp3Dom[] childs = parentDom.getChildren(); - Collection domChilds = new ArrayList(); - for (int i = 0; i < childs.length; i++) { - domChilds.add(childs[i]); - } - // int domIndex = 0; - ListIterator it = parent.getChildren().listIterator(); - while (it.hasNext()) { - Element elem = (Element) it.next(); - Iterator it2 = domChilds.iterator(); - Xpp3Dom corrDom = null; - while (it2.hasNext()) { - Xpp3Dom dm = (Xpp3Dom)it2.next(); - if (dm.getName().equals(elem.getName())) { - corrDom = dm; - break; - } - } - if (corrDom != null) { - domChilds.remove(corrDom); - replaceXpp3DOM(elem, corrDom, new Counter(counter.getDepth() + 1)); - counter.increaseCount(); - } else { - parent.removeContent(elem); - } - } - Iterator it2 = domChilds.iterator(); - while (it2.hasNext()) { - Xpp3Dom dm = (Xpp3Dom) it2.next(); - Element elem = factory.element(dm.getName(), parent.getNamespace()); - insertAtPreferredLocation(parent, elem, counter); - counter.increaseCount(); - replaceXpp3DOM(elem, dm, new Counter(counter.getDepth() + 1)); - } - } else if (parentDom.getValue() != null) { - parent.setText(parentDom.getValue()); - } - } //-- void replaceXpp3DOM(Element, Xpp3Dom, Counter) - - /** - * Method updateActivation - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - /* - protected void updateActivation(Activation value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "activeByDefault", value.isActiveByDefault() == false ? null : String.valueOf( value.isActiveByDefault() ), "false"); - findAndReplaceSimpleElement(innerCount, root, "jdk", value.getJdk(), null); - updateActivationOS( value.getOs(), "os", innerCount, root); - updateActivationProperty( value.getProperty(), "property", innerCount, root); - updateActivationFile( value.getFile(), "file", innerCount, root); - updateActivationCustom( value.getCustom(), "custom", innerCount, root); - } - } //-- void updateActivation(Activation, String, Counter, Element) - */ - - /** - * Method updateActivationCustom - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - /* - protected void updateActivationCustom(ActivationCustom value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); - findAndReplaceSimpleElement(innerCount, root, "type", value.getType(), null); - } - } //-- void updateActivationCustom(ActivationCustom, String, Counter, Element) - */ - - /** - * Method updateActivationFile - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateActivationFile(ActivationFile value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "missing", value.getMissing(), null); - findAndReplaceSimpleElement(innerCount, root, "exists", value.getExists(), null); - } - } //-- void updateActivationFile(ActivationFile, String, Counter, Element) - - /** - * Method updateActivationOS - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateActivationOS(ActivationOS value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "family", value.getFamily(), null); - findAndReplaceSimpleElement(innerCount, root, "arch", value.getArch(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - } - } //-- void updateActivationOS(ActivationOS, String, Counter, Element) - - /** - * Method updateActivationProperty - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateActivationProperty(ActivationProperty value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "value", value.getValue(), null); - } - } //-- void updateActivationProperty(ActivationProperty, String, Counter, Element) - - /** - * Method updateBuild - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateBuild(Build value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "sourceDirectory", value.getSourceDirectory(), null); - findAndReplaceSimpleElement(innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(), null); - findAndReplaceSimpleElement(innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(), null); - findAndReplaceSimpleElement(innerCount, root, "outputDirectory", value.getOutputDirectory(), null); - findAndReplaceSimpleElement(innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(), null); - iterateExtension(innerCount, root, value.getExtensions(),"extensions","extension"); - findAndReplaceSimpleElement(innerCount, root, "defaultGoal", value.getDefaultGoal(), null); - iterateResource(innerCount, root, value.getResources(),"resources","resource"); - iterateResource(innerCount, root, value.getTestResources(),"testResources","testResource"); - findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); - findAndReplaceSimpleElement(innerCount, root, "finalName", value.getFinalName(), null); - findAndReplaceSimpleLists(innerCount, root, value.getFilters(), "filters", "filter"); - updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root); - iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); - } - } //-- void updateBuild(Build, String, Counter, Element) - - /** - * Method updateBuildBase - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateBuildBase(BuildBase value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "defaultGoal", value.getDefaultGoal(), null); - iterateResource(innerCount, root, value.getResources(),"resources","resource"); - iterateResource(innerCount, root, value.getTestResources(),"testResources","testResource"); - findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); - findAndReplaceSimpleElement(innerCount, root, "finalName", value.getFinalName(), null); - findAndReplaceSimpleLists(innerCount, root, value.getFilters(), "filters", "filter"); - updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root); - iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); - } - } //-- void updateBuildBase(BuildBase, String, Counter, Element) - - /** - * Method updateCiManagement - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateCiManagement(CiManagement value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "system", value.getSystem(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - iterateNotifier(innerCount, root, value.getNotifiers(),"notifiers","notifier"); - } - } //-- void updateCiManagement(CiManagement, String, Counter, Element) - - /** - * Method updateConfigurationContainer - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateConfigurationContainer(ConfigurationContainer value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); - findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); - } - } //-- void updateConfigurationContainer(ConfigurationContainer, String, Counter, Element) - - /** - * Method updateContributor - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateContributor(Contributor value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "email", value.getEmail(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - findAndReplaceSimpleElement(innerCount, root, "organization", value.getOrganization(), null); - findAndReplaceSimpleElement(innerCount, root, "organizationUrl", value.getOrganizationUrl(), null); - findAndReplaceSimpleLists(innerCount, root, value.getRoles(), "roles", "role"); - findAndReplaceSimpleElement(innerCount, root, "timezone", value.getTimezone(), null); - findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); - } //-- void updateContributor(Contributor, String, Counter, Element) - - /** - * Method updateDependency - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateDependency(Dependency value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - findAndReplaceSimpleElement(innerCount, root, "type", value.getType(), "jar"); - findAndReplaceSimpleElement(innerCount, root, "classifier", value.getClassifier(), null); - findAndReplaceSimpleElement(innerCount, root, "scope", value.getScope(), null); - findAndReplaceSimpleElement(innerCount, root, "systemPath", value.getSystemPath(), null); - iterateExclusion(innerCount, root, value.getExclusions(),"exclusions","exclusion"); - findAndReplaceSimpleElement(innerCount, root, "optional", value.isOptional() == false ? null : String.valueOf( value.isOptional() ), "false"); - } //-- void updateDependency(Dependency, String, Counter, Element) - - /** - * Method updateDependencyManagement - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateDependencyManagement(DependencyManagement value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); - } - } //-- void updateDependencyManagement(DependencyManagement, String, Counter, Element) - - /** - * Method updateDeploymentRepository - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateDeploymentRepository(DeploymentRepository value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "uniqueVersion", value.isUniqueVersion() == true ? null : String.valueOf( value.isUniqueVersion() ), "true"); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - findAndReplaceSimpleElement(innerCount, root, "layout", value.getLayout(), "default"); - } - } //-- void updateDeploymentRepository(DeploymentRepository, String, Counter, Element) - - /** - * Method updateDeveloper - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateDeveloper(Developer value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "email", value.getEmail(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - findAndReplaceSimpleElement(innerCount, root, "organization", value.getOrganization(), null); - findAndReplaceSimpleElement(innerCount, root, "organizationUrl", value.getOrganizationUrl(), null); - findAndReplaceSimpleLists(innerCount, root, value.getRoles(), "roles", "role"); - findAndReplaceSimpleElement(innerCount, root, "timezone", value.getTimezone(), null); - findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); - } //-- void updateDeveloper(Developer, String, Counter, Element) - - /** - * Method updateDistributionManagement - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateDistributionManagement(DistributionManagement value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - updateDeploymentRepository( value.getRepository(), "repository", innerCount, root); - updateDeploymentRepository( value.getSnapshotRepository(), "snapshotRepository", innerCount, root); - updateSite( value.getSite(), "site", innerCount, root); - findAndReplaceSimpleElement(innerCount, root, "downloadUrl", value.getDownloadUrl(), null); - updateRelocation( value.getRelocation(), "relocation", innerCount, root); - findAndReplaceSimpleElement(innerCount, root, "status", value.getStatus(), null); - } - } //-- void updateDistributionManagement(DistributionManagement, String, Counter, Element) - - /** - * Method updateElement - * - * @param counter - * @param shouldExist - * @param name - * @param parent - */ - protected Element updateElement(Counter counter, Element parent, String name, boolean shouldExist) - { - Element element = parent.getChild(name, parent.getNamespace()); - if (element != null && shouldExist) { - counter.increaseCount(); - } - if (element == null && shouldExist) { - element = factory.element(name, parent.getNamespace()); - insertAtPreferredLocation(parent, element, counter); - counter.increaseCount(); - } - if (!shouldExist && element != null) { - int index = parent.indexOf(element); - if (index > 0) { - Content previous = parent.getContent(index - 1); - if (previous instanceof Text) { - Text txt = (Text)previous; - if (txt.getTextTrim().length() == 0) { - parent.removeContent(txt); - } - } - } - parent.removeContent(element); - } - return element; - } //-- Element updateElement(Counter, Element, String, boolean) - - /** - * Method updateExclusion - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateExclusion(Exclusion value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); - } //-- void updateExclusion(Exclusion, String, Counter, Element) - - /** - * Method updateExtension - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateExtension(Extension value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - } //-- void updateExtension(Extension, String, Counter, Element) - - /** - * Method updateFileSet - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateFileSet(FileSet value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); - findAndReplaceSimpleLists(innerCount, root, value.getIncludes(), "includes", "include"); - findAndReplaceSimpleLists(innerCount, root, value.getExcludes(), "excludes", "exclude"); - } - } //-- void updateFileSet(FileSet, String, Counter, Element) - - /** - * Method updateIssueManagement - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateIssueManagement(IssueManagement value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "system", value.getSystem(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - } - } //-- void updateIssueManagement(IssueManagement, String, Counter, Element) - - /** - * Method updateLicense - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateLicense(License value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - findAndReplaceSimpleElement(innerCount, root, "distribution", value.getDistribution(), null); - findAndReplaceSimpleElement(innerCount, root, "comments", value.getComments(), null); - } //-- void updateLicense(License, String, Counter, Element) - - /** - * Method updateMailingList - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateMailingList(MailingList value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "subscribe", value.getSubscribe(), null); - findAndReplaceSimpleElement(innerCount, root, "unsubscribe", value.getUnsubscribe(), null); - findAndReplaceSimpleElement(innerCount, root, "post", value.getPost(), null); - findAndReplaceSimpleElement(innerCount, root, "archive", value.getArchive(), null); - findAndReplaceSimpleLists(innerCount, root, value.getOtherArchives(), "otherArchives", "otherArchive"); - } //-- void updateMailingList(MailingList, String, Counter, Element) - - /** - * Method updateModel - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateModel(Model value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - updateParent( value.getParent(), "parent", innerCount, root); - findAndReplaceSimpleElement(innerCount, root, "modelVersion", value.getModelVersion(), null); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "packaging", value.getPackaging(), "jar"); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - findAndReplaceSimpleElement(innerCount, root, "description", value.getDescription(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - updatePrerequisites( value.getPrerequisites(), "prerequisites", innerCount, root); - updateIssueManagement( value.getIssueManagement(), "issueManagement", innerCount, root); - updateCiManagement( value.getCiManagement(), "ciManagement", innerCount, root); - findAndReplaceSimpleElement(innerCount, root, "inceptionYear", value.getInceptionYear(), null); - iterateMailingList(innerCount, root, value.getMailingLists(),"mailingLists","mailingList"); - iterateDeveloper(innerCount, root, value.getDevelopers(),"developers","developer"); - iterateContributor(innerCount, root, value.getContributors(),"contributors","contributor"); - iterateLicense(innerCount, root, value.getLicenses(),"licenses","license"); - updateScm( value.getScm(), "scm", innerCount, root); - updateOrganization( value.getOrganization(), "organization", innerCount, root); - updateBuild( value.getBuild(), "build", innerCount, root); - iterateProfile(innerCount, root, value.getProfiles(),"profiles","profile"); - findAndReplaceSimpleLists(innerCount, root, value.getModules(), "modules", "module"); - iterateRepository(innerCount, root, value.getRepositories(),"repositories","repository"); - iterateRepository(innerCount, root, value.getPluginRepositories(),"pluginRepositories","pluginRepository"); - iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); - findAndReplaceXpp3DOM(innerCount, root, "reports", (Xpp3Dom)value.getReports()); - updateReporting( value.getReporting(), "reporting", innerCount, root); - updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root); - updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root); - findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); - } //-- void updateModel(Model, String, Counter, Element) - - /** - * Method updateModelBase - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateModelBase(ModelBase value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleLists(innerCount, root, value.getModules(), "modules", "module"); - iterateRepository(innerCount, root, value.getRepositories(),"repositories","repository"); - iterateRepository(innerCount, root, value.getPluginRepositories(),"pluginRepositories","pluginRepository"); - iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); - findAndReplaceXpp3DOM(innerCount, root, "reports", (Xpp3Dom)value.getReports()); - updateReporting( value.getReporting(), "reporting", innerCount, root); - updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root); - updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root); - findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); - } - } //-- void updateModelBase(ModelBase, String, Counter, Element) - - /** - * Method updateNotifier - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateNotifier(Notifier value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "type", value.getType(), "mail"); - findAndReplaceSimpleElement(innerCount, root, "sendOnError", value.isSendOnError() == true ? null : String.valueOf( value.isSendOnError() ), "true"); - findAndReplaceSimpleElement(innerCount, root, "sendOnFailure", value.isSendOnFailure() == true ? null : String.valueOf( value.isSendOnFailure() ), "true"); - findAndReplaceSimpleElement(innerCount, root, "sendOnSuccess", value.isSendOnSuccess() == true ? null : String.valueOf( value.isSendOnSuccess() ), "true"); - findAndReplaceSimpleElement(innerCount, root, "sendOnWarning", value.isSendOnWarning() == true ? null : String.valueOf( value.isSendOnWarning() ), "true"); - findAndReplaceSimpleElement(innerCount, root, "address", value.getAddress(), null); - findAndReplaceProperties(innerCount, root, "configuration", value.getConfiguration()); - } //-- void updateNotifier(Notifier, String, Counter, Element) - - /** - * Method updateOrganization - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateOrganization(Organization value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - } - } //-- void updateOrganization(Organization, String, Counter, Element) - - /** - * Method updateParent - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateParent(Parent value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - findAndReplaceSimpleElement(innerCount, root, "relativePath", value.getRelativePath(), "../pom.xml"); - } - } //-- void updateParent(Parent, String, Counter, Element) - - /** - * Method updatePatternSet - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updatePatternSet(PatternSet value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleLists(innerCount, root, value.getIncludes(), "includes", "include"); - findAndReplaceSimpleLists(innerCount, root, value.getExcludes(), "excludes", "exclude"); - } - } //-- void updatePatternSet(PatternSet, String, Counter, Element) - - /** - * Method updatePlugin - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updatePlugin(Plugin value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins"); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - findAndReplaceSimpleElement(innerCount, root, "extensions", value.isExtensions() == false ? null : String.valueOf( value.isExtensions() ), "false"); - iteratePluginExecution(innerCount, root, value.getExecutions(),"executions","execution"); - iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); - findAndReplaceXpp3DOM(innerCount, root, "goals", (Xpp3Dom)value.getGoals()); - findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); - findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); - } //-- void updatePlugin(Plugin, String, Counter, Element) - - /** - * Method updatePluginConfiguration - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updatePluginConfiguration(PluginConfiguration value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root); - iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); - } - } //-- void updatePluginConfiguration(PluginConfiguration, String, Counter, Element) - - /** - * Method updatePluginContainer - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updatePluginContainer(PluginContainer value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); - } - } //-- void updatePluginContainer(PluginContainer, String, Counter, Element) - - /** - * Method updatePluginExecution - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updatePluginExecution(PluginExecution value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), "default"); - findAndReplaceSimpleElement(innerCount, root, "phase", value.getPhase(), null); - findAndReplaceSimpleLists(innerCount, root, value.getGoals(), "goals", "goal"); - findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); - findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); - } //-- void updatePluginExecution(PluginExecution, String, Counter, Element) - - /** - * Method updatePluginManagement - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updatePluginManagement(PluginManagement value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); - } - } //-- void updatePluginManagement(PluginManagement, String, Counter, Element) - - /** - * Method updatePrerequisites - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updatePrerequisites(Prerequisites value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "maven", value.getMaven(), "2.0"); - } - } //-- void updatePrerequisites(Prerequisites, String, Counter, Element) - - /** - * Method updateProfile - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateProfile(Profile value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), "default"); - //updateActivation( value.getActivation(), "activation", innerCount, root); - updateBuildBase( value.getBuild(), "build", innerCount, root); - findAndReplaceSimpleLists(innerCount, root, value.getModules(), "modules", "module"); - iterateRepository(innerCount, root, value.getRepositories(),"repositories","repository"); - iterateRepository(innerCount, root, value.getPluginRepositories(),"pluginRepositories","pluginRepository"); - iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); - findAndReplaceXpp3DOM(innerCount, root, "reports", (Xpp3Dom)value.getReports()); - updateReporting( value.getReporting(), "reporting", innerCount, root); - updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root); - updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root); - findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); - } //-- void updateProfile(Profile, String, Counter, Element) - - /** - * Method updateRelocation - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateRelocation(Relocation value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - findAndReplaceSimpleElement(innerCount, root, "message", value.getMessage(), null); - } - } //-- void updateRelocation(Relocation, String, Counter, Element) - - /** - * Method updateReportPlugin - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateReportPlugin(ReportPlugin value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins"); - findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); - findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); - findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); - findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); - iterateReportSet(innerCount, root, value.getReportSets(),"reportSets","reportSet"); - } //-- void updateReportPlugin(ReportPlugin, String, Counter, Element) - - /** - * Method updateReportSet - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateReportSet(ReportSet value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), "default"); - findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); - findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); - findAndReplaceSimpleLists(innerCount, root, value.getReports(), "reports", "report"); - } //-- void updateReportSet(ReportSet, String, Counter, Element) - - /** - * Method updateReporting - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateReporting(Reporting value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "excludeDefaults", value.isExcludeDefaults() == false ? null : String.valueOf( value.isExcludeDefaults() ), "false"); - findAndReplaceSimpleElement(innerCount, root, "outputDirectory", value.getOutputDirectory(), null); - iterateReportPlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); - } - } //-- void updateReporting(Reporting, String, Counter, Element) - - /** - * Method updateRepository - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateRepository(Repository value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - updateRepositoryPolicy( value.getReleases(), "releases", innerCount, root); - updateRepositoryPolicy( value.getSnapshots(), "snapshots", innerCount, root); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - findAndReplaceSimpleElement(innerCount, root, "layout", value.getLayout(), "default"); - } //-- void updateRepository(Repository, String, Counter, Element) - - /** - * Method updateRepositoryBase - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateRepositoryBase(RepositoryBase value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - findAndReplaceSimpleElement(innerCount, root, "layout", value.getLayout(), "default"); - } - } //-- void updateRepositoryBase(RepositoryBase, String, Counter, Element) - - /** - * Method updateRepositoryPolicy - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateRepositoryPolicy(RepositoryPolicy value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "enabled", value.isEnabled() == true ? null : String.valueOf( value.isEnabled() ), "true"); - findAndReplaceSimpleElement(innerCount, root, "updatePolicy", value.getUpdatePolicy(), null); - findAndReplaceSimpleElement(innerCount, root, "checksumPolicy", value.getChecksumPolicy(), null); - } - } //-- void updateRepositoryPolicy(RepositoryPolicy, String, Counter, Element) - - /** - * Method updateResource - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateResource(Resource value, String xmlTag, Counter counter, Element element) - { - Element root = element; - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "targetPath", value.getTargetPath(), null); - findAndReplaceSimpleElement(innerCount, root, "filtering", value.isFiltering() == false ? null : String.valueOf( value.isFiltering() ), "false"); - findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); - findAndReplaceSimpleLists(innerCount, root, value.getIncludes(), "includes", "include"); - findAndReplaceSimpleLists(innerCount, root, value.getExcludes(), "excludes", "exclude"); - } //-- void updateResource(Resource, String, Counter, Element) - - /** - * Method updateScm - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateScm(Scm value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "connection", value.getConnection(), null); - findAndReplaceSimpleElement(innerCount, root, "developerConnection", value.getDeveloperConnection(), null); - findAndReplaceSimpleElement(innerCount, root, "tag", value.getTag(), "HEAD"); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - } - } //-- void updateScm(Scm, String, Counter, Element) - - /** - * Method updateSite - * - * @param value - * @param element - * @param counter - * @param xmlTag - */ - protected void updateSite(Site value, String xmlTag, Counter counter, Element element) - { - boolean shouldExist = value != null; - Element root = updateElement(counter, element, xmlTag, shouldExist); - if (shouldExist) { - Counter innerCount = new Counter(counter.getDepth() + 1); - findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); - findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); - findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); - } - } //-- void updateSite(Site, String, Counter, Element) - - /** - * Method write - * @deprecated - * - * @param project - * @param stream - * @param document - */ - public void write(Model project, Document document, OutputStream stream) - throws java.io.IOException - { - updateModel(project, "project", new Counter(0), document.getRootElement()); - XMLOutputter outputter = new XMLOutputter(); - outputter.setFormat(Format.getPrettyFormat() - .setIndent(" ") - .setLineSeparator(System.getProperty("line.separator"))); - outputter.output(document, stream); - } //-- void write(Model, Document, OutputStream) - - /** - * Method write - * - * @param project - * @param writer - * @param document - */ - public void write(Model project, Document document, OutputStreamWriter writer) - throws java.io.IOException - { - Format format = Format.getRawFormat() - .setEncoding(writer.getEncoding()) - .setLineSeparator(System.getProperty("line.separator")); - write(project, document, writer, format); - } //-- void write(Model, Document, OutputStreamWriter) - - /** - * Method write - * - * @param project - * @param jdomFormat - * @param writer - * @param document - */ - public void write(Model project, Document document, Writer writer, Format jdomFormat) - throws java.io.IOException - { - updateModel(project, "project", new Counter(0), document.getRootElement()); - XMLOutputter outputter = new XMLOutputter(); - outputter.setFormat(jdomFormat); - outputter.output(document, writer); - } //-- void write(Model, Document, Writer, Format) - - - //-----------------/ - //- Inner Classes -/ - //-----------------/ - - /** - * Class Counter. - * - * @version $Revision: 3974 $ $Date: 2007-04-23 19:55:40 -0400 (Mon, 23 Apr 2007) $ - */ - public class Counter { - - - //--------------------------/ - //- Class/Member Variables -/ - //--------------------------/ - - /** - * Field currentIndex - */ - private int currentIndex = 0; - - /** - * Field level - */ - private int level; - - - //----------------/ - //- Constructors -/ - //----------------/ - - public Counter(int depthLevel) { - level = depthLevel; - } //-- org.apache.maven.model.io.jdom.Counter(int) - - - //-----------/ - //- Methods -/ - //-----------/ - - /** - * Method getCurrentIndex - */ - public int getCurrentIndex() - { - return currentIndex; - } //-- int getCurrentIndex() - - /** - * Method getDepth - */ - public int getDepth() - { - return level; - } //-- int getDepth() - - /** - * Method increaseCount - */ - public void increaseCount() - { - currentIndex = currentIndex + 1; - } //-- void increaseCount() - - } - -} +package org.apache.maven.plugins.shade.pom; + +//package org.apache.maven.model.io.jdom; + +/* + * 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. + */ + + //---------------------------------/ + //- Imported classes and packages -/ +//---------------------------------/ + +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.ListIterator; +import java.util.Map; + +import org.apache.maven.model.ActivationFile; +import org.apache.maven.model.ActivationOS; +import org.apache.maven.model.ActivationProperty; +import org.apache.maven.model.Build; +import org.apache.maven.model.BuildBase; +import org.apache.maven.model.CiManagement; +import org.apache.maven.model.ConfigurationContainer; +import org.apache.maven.model.Contributor; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.DeploymentRepository; +import org.apache.maven.model.Developer; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.Exclusion; +import org.apache.maven.model.Extension; +import org.apache.maven.model.FileSet; +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.License; +import org.apache.maven.model.MailingList; +import org.apache.maven.model.Model; +import org.apache.maven.model.ModelBase; +import org.apache.maven.model.Notifier; +import org.apache.maven.model.Organization; +import org.apache.maven.model.Parent; +import org.apache.maven.model.PatternSet; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginConfiguration; +import org.apache.maven.model.PluginContainer; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.model.Profile; +import org.apache.maven.model.Relocation; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.model.ReportSet; +import org.apache.maven.model.Reporting; +import org.apache.maven.model.Repository; +import org.apache.maven.model.RepositoryBase; +import org.apache.maven.model.RepositoryPolicy; +import org.apache.maven.model.Resource; +import org.apache.maven.model.Scm; +import org.apache.maven.model.Site; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.jdom.Content; +import org.jdom.DefaultJDOMFactory; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.Text; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +/** + * Class MavenJDOMWriter. + * + * @version $Revision: 3974 $ $Date: 2007-04-23 19:55:40 -0400 (Mon, 23 Apr 2007) $ + */ +public class MavenJDOMWriter { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field factory + */ + private DefaultJDOMFactory factory; + + /** + * Field lineSeparator + */ + private String lineSeparator; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public MavenJDOMWriter() { + factory = new DefaultJDOMFactory(); + lineSeparator = "\n"; + } //-- org.apache.maven.model.io.jdom.MavenJDOMWriter() + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method findAndReplaceProperties + * + * @param counter + * @param props + * @param name + * @param parent + */ + protected Element findAndReplaceProperties(Counter counter, Element parent, String name, Map props) + { + boolean shouldExist = props != null && ! props.isEmpty(); + Element element = updateElement(counter, parent, name, shouldExist); + if (shouldExist) { + Iterator it = props.keySet().iterator(); + Counter innerCounter = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + String key = (String) it.next(); + findAndReplaceSimpleElement(innerCounter, element, key, (String)props.get(key), null); + } + ArrayList lst = new ArrayList(props.keySet()); + it = element.getChildren().iterator(); + while (it.hasNext()) { + Element elem = (Element) it.next(); + String key = elem.getName(); + if (!lst.contains(key)) { + it.remove(); + } + } + } + return element; + } //-- Element findAndReplaceProperties(Counter, Element, String, Map) + + /** + * Method findAndReplaceSimpleElement + * + * @param counter + * @param defaultValue + * @param text + * @param name + * @param parent + */ + protected Element findAndReplaceSimpleElement(Counter counter, Element parent, String name, String text, String defaultValue) + { + if (defaultValue != null && text != null && defaultValue.equals(text)) { + Element element = parent.getChild(name, parent.getNamespace()); + // if exist and is default value or if doesn't exist.. just keep the way it is.. + if ((element != null && defaultValue.equals(element.getText())) || element == null) { + return element; + } + } + boolean shouldExist = text != null && text.trim().length() > 0; + Element element = updateElement(counter, parent, name, shouldExist); + if (shouldExist) { + element.setText(text); + } + return element; + } //-- Element findAndReplaceSimpleElement(Counter, Element, String, String, String) + + /** + * Method findAndReplaceSimpleLists + * + * @param counter + * @param childName + * @param parentName + * @param list + * @param parent + */ + protected Element findAndReplaceSimpleLists(Counter counter, Element parent, java.util.Collection list, String parentName, String childName) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentName, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childName, element.getNamespace()).iterator(); + if (! elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + String value = (String) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childName, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + el.setText(value); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + return element; + } //-- Element findAndReplaceSimpleLists(Counter, Element, java.util.Collection, String, String) + + /** + * Method findAndReplaceXpp3DOM + * + * @param counter + * @param dom + * @param name + * @param parent + */ + protected Element findAndReplaceXpp3DOM(Counter counter, Element parent, String name, Xpp3Dom dom) + { + boolean shouldExist = dom != null && (dom.getChildCount() > 0 || dom.getValue() != null); + Element element = updateElement(counter, parent, name, shouldExist); + if (shouldExist) { + replaceXpp3DOM(element, dom, new Counter(counter.getDepth() + 1)); + } + return element; + } //-- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom) + + /** + * Method insertAtPreferredLocation + * + * @param parent + * @param counter + * @param child + */ + protected void insertAtPreferredLocation(Element parent, Element child, Counter counter) + { + int contentIndex = 0; + int elementCounter = 0; + Iterator it = parent.getContent().iterator(); + Text lastText = null; + int offset = 0; + while (it.hasNext() && elementCounter <= counter.getCurrentIndex()) { + Object next = it.next(); + offset = offset + 1; + if (next instanceof Element) { + elementCounter = elementCounter + 1; + contentIndex = contentIndex + offset; + offset = 0; + } + if (next instanceof Text && it.hasNext()) { + lastText = (Text)next; + } + } + if (lastText != null && lastText.getTextTrim().length() == 0) { + lastText = (Text)lastText.clone(); + } else { + String starter = lineSeparator; + for (int i = 0; i < counter.getDepth(); i++) { + starter = starter + " "; //TODO make settable? + } + lastText = factory.text(starter); + } + if (parent.getContentSize() == 0) { + Text finalText = (Text)lastText.clone(); + finalText.setText(finalText.getText().substring(0, finalText.getText().length() - " ".length())); + parent.addContent(contentIndex, finalText); + } + parent.addContent(contentIndex, child); + parent.addContent(contentIndex, lastText); + } //-- void insertAtPreferredLocation(Element, Element, Counter) + + /** + * Method iterateContributor + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateContributor(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Contributor value = (Contributor) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateContributor(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateContributor(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateDependency + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateDependency(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Dependency value = (Dependency) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateDependency(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateDependency(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateDeveloper + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateDeveloper(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Developer value = (Developer) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateDeveloper(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateDeveloper(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateExclusion + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateExclusion(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Exclusion value = (Exclusion) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateExclusion(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateExclusion(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateExtension + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateExtension(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Extension value = (Extension) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateExtension(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateExtension(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateLicense + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateLicense(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + License value = (License) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateLicense(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateLicense(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateMailingList + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateMailingList(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + MailingList value = (MailingList) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateMailingList(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateMailingList(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateNotifier + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateNotifier(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Notifier value = (Notifier) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateNotifier(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateNotifier(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iteratePlugin + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iteratePlugin(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Plugin value = (Plugin) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updatePlugin(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iteratePluginExecution + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iteratePluginExecution(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + PluginExecution value = (PluginExecution) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updatePluginExecution(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateProfile + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateProfile(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Profile value = (Profile) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateProfile(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateProfile(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateReportPlugin + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateReportPlugin(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + ReportPlugin value = (ReportPlugin) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateReportPlugin(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateReportPlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateReportSet + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateReportSet(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + ReportSet value = (ReportSet) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateReportSet(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateReportSet(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateRepository + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateRepository(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Repository value = (Repository) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateRepository(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateRepository(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method iterateResource + * + * @param counter + * @param childTag + * @param parentTag + * @param list + * @param parent + */ + protected void iterateResource(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) + { + boolean shouldExist = list != null && list.size() > 0; + Element element = updateElement(counter, parent, parentTag, shouldExist); + if (shouldExist) { + Iterator it = list.iterator(); + Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator(); + if (!elIt.hasNext()) elIt = null; + Counter innerCount = new Counter(counter.getDepth() + 1); + while (it.hasNext()) { + Resource value = (Resource) it.next(); + Element el; + if (elIt != null && elIt.hasNext()) { + el = (Element) elIt.next(); + if (! elIt.hasNext()) elIt = null; + } else { + el = factory.element(childTag, element.getNamespace()); + insertAtPreferredLocation(element, el, innerCount); + } + updateResource(value, childTag, innerCount, el); + innerCount.increaseCount(); + } + if (elIt != null) { + while (elIt.hasNext()) { + elIt.next(); + elIt.remove(); + } + } + } + } //-- void iterateResource(Counter, Element, java.util.Collection, java.lang.String, java.lang.String) + + /** + * Method replaceXpp3DOM + * + * @param parent + * @param counter + * @param parentDom + */ + protected void replaceXpp3DOM(Element parent, Xpp3Dom parentDom, Counter counter) + { + if (parentDom.getChildCount() > 0) { + Xpp3Dom[] childs = parentDom.getChildren(); + Collection domChilds = new ArrayList(); + for (int i = 0; i < childs.length; i++) { + domChilds.add(childs[i]); + } + // int domIndex = 0; + ListIterator it = parent.getChildren().listIterator(); + while (it.hasNext()) { + Element elem = (Element) it.next(); + Iterator it2 = domChilds.iterator(); + Xpp3Dom corrDom = null; + while (it2.hasNext()) { + Xpp3Dom dm = (Xpp3Dom)it2.next(); + if (dm.getName().equals(elem.getName())) { + corrDom = dm; + break; + } + } + if (corrDom != null) { + domChilds.remove(corrDom); + replaceXpp3DOM(elem, corrDom, new Counter(counter.getDepth() + 1)); + counter.increaseCount(); + } else { + parent.removeContent(elem); + } + } + Iterator it2 = domChilds.iterator(); + while (it2.hasNext()) { + Xpp3Dom dm = (Xpp3Dom) it2.next(); + Element elem = factory.element(dm.getName(), parent.getNamespace()); + insertAtPreferredLocation(parent, elem, counter); + counter.increaseCount(); + replaceXpp3DOM(elem, dm, new Counter(counter.getDepth() + 1)); + } + } else if (parentDom.getValue() != null) { + parent.setText(parentDom.getValue()); + } + } //-- void replaceXpp3DOM(Element, Xpp3Dom, Counter) + + /** + * Method updateActivation + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + /* + protected void updateActivation(Activation value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "activeByDefault", value.isActiveByDefault() == false ? null : String.valueOf( value.isActiveByDefault() ), "false"); + findAndReplaceSimpleElement(innerCount, root, "jdk", value.getJdk(), null); + updateActivationOS( value.getOs(), "os", innerCount, root); + updateActivationProperty( value.getProperty(), "property", innerCount, root); + updateActivationFile( value.getFile(), "file", innerCount, root); + updateActivationCustom( value.getCustom(), "custom", innerCount, root); + } + } //-- void updateActivation(Activation, String, Counter, Element) + */ + + /** + * Method updateActivationCustom + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + /* + protected void updateActivationCustom(ActivationCustom value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); + findAndReplaceSimpleElement(innerCount, root, "type", value.getType(), null); + } + } //-- void updateActivationCustom(ActivationCustom, String, Counter, Element) + */ + + /** + * Method updateActivationFile + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateActivationFile(ActivationFile value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "missing", value.getMissing(), null); + findAndReplaceSimpleElement(innerCount, root, "exists", value.getExists(), null); + } + } //-- void updateActivationFile(ActivationFile, String, Counter, Element) + + /** + * Method updateActivationOS + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateActivationOS(ActivationOS value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "family", value.getFamily(), null); + findAndReplaceSimpleElement(innerCount, root, "arch", value.getArch(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + } + } //-- void updateActivationOS(ActivationOS, String, Counter, Element) + + /** + * Method updateActivationProperty + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateActivationProperty(ActivationProperty value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "value", value.getValue(), null); + } + } //-- void updateActivationProperty(ActivationProperty, String, Counter, Element) + + /** + * Method updateBuild + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateBuild(Build value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "sourceDirectory", value.getSourceDirectory(), null); + findAndReplaceSimpleElement(innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(), null); + findAndReplaceSimpleElement(innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(), null); + findAndReplaceSimpleElement(innerCount, root, "outputDirectory", value.getOutputDirectory(), null); + findAndReplaceSimpleElement(innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(), null); + iterateExtension(innerCount, root, value.getExtensions(),"extensions","extension"); + findAndReplaceSimpleElement(innerCount, root, "defaultGoal", value.getDefaultGoal(), null); + iterateResource(innerCount, root, value.getResources(),"resources","resource"); + iterateResource(innerCount, root, value.getTestResources(),"testResources","testResource"); + findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); + findAndReplaceSimpleElement(innerCount, root, "finalName", value.getFinalName(), null); + findAndReplaceSimpleLists(innerCount, root, value.getFilters(), "filters", "filter"); + updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root); + iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); + } + } //-- void updateBuild(Build, String, Counter, Element) + + /** + * Method updateBuildBase + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateBuildBase(BuildBase value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "defaultGoal", value.getDefaultGoal(), null); + iterateResource(innerCount, root, value.getResources(),"resources","resource"); + iterateResource(innerCount, root, value.getTestResources(),"testResources","testResource"); + findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); + findAndReplaceSimpleElement(innerCount, root, "finalName", value.getFinalName(), null); + findAndReplaceSimpleLists(innerCount, root, value.getFilters(), "filters", "filter"); + updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root); + iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); + } + } //-- void updateBuildBase(BuildBase, String, Counter, Element) + + /** + * Method updateCiManagement + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateCiManagement(CiManagement value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "system", value.getSystem(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + iterateNotifier(innerCount, root, value.getNotifiers(),"notifiers","notifier"); + } + } //-- void updateCiManagement(CiManagement, String, Counter, Element) + + /** + * Method updateConfigurationContainer + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateConfigurationContainer(ConfigurationContainer value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); + findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); + } + } //-- void updateConfigurationContainer(ConfigurationContainer, String, Counter, Element) + + /** + * Method updateContributor + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateContributor(Contributor value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "email", value.getEmail(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + findAndReplaceSimpleElement(innerCount, root, "organization", value.getOrganization(), null); + findAndReplaceSimpleElement(innerCount, root, "organizationUrl", value.getOrganizationUrl(), null); + findAndReplaceSimpleLists(innerCount, root, value.getRoles(), "roles", "role"); + findAndReplaceSimpleElement(innerCount, root, "timezone", value.getTimezone(), null); + findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); + } //-- void updateContributor(Contributor, String, Counter, Element) + + /** + * Method updateDependency + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateDependency(Dependency value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + findAndReplaceSimpleElement(innerCount, root, "type", value.getType(), "jar"); + findAndReplaceSimpleElement(innerCount, root, "classifier", value.getClassifier(), null); + findAndReplaceSimpleElement(innerCount, root, "scope", value.getScope(), null); + findAndReplaceSimpleElement(innerCount, root, "systemPath", value.getSystemPath(), null); + iterateExclusion(innerCount, root, value.getExclusions(),"exclusions","exclusion"); + findAndReplaceSimpleElement(innerCount, root, "optional", value.isOptional() == false ? null : String.valueOf( value.isOptional() ), "false"); + } //-- void updateDependency(Dependency, String, Counter, Element) + + /** + * Method updateDependencyManagement + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateDependencyManagement(DependencyManagement value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); + } + } //-- void updateDependencyManagement(DependencyManagement, String, Counter, Element) + + /** + * Method updateDeploymentRepository + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateDeploymentRepository(DeploymentRepository value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "uniqueVersion", value.isUniqueVersion() == true ? null : String.valueOf( value.isUniqueVersion() ), "true"); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + findAndReplaceSimpleElement(innerCount, root, "layout", value.getLayout(), "default"); + } + } //-- void updateDeploymentRepository(DeploymentRepository, String, Counter, Element) + + /** + * Method updateDeveloper + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateDeveloper(Developer value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "email", value.getEmail(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + findAndReplaceSimpleElement(innerCount, root, "organization", value.getOrganization(), null); + findAndReplaceSimpleElement(innerCount, root, "organizationUrl", value.getOrganizationUrl(), null); + findAndReplaceSimpleLists(innerCount, root, value.getRoles(), "roles", "role"); + findAndReplaceSimpleElement(innerCount, root, "timezone", value.getTimezone(), null); + findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); + } //-- void updateDeveloper(Developer, String, Counter, Element) + + /** + * Method updateDistributionManagement + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateDistributionManagement(DistributionManagement value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + updateDeploymentRepository( value.getRepository(), "repository", innerCount, root); + updateDeploymentRepository( value.getSnapshotRepository(), "snapshotRepository", innerCount, root); + updateSite( value.getSite(), "site", innerCount, root); + findAndReplaceSimpleElement(innerCount, root, "downloadUrl", value.getDownloadUrl(), null); + updateRelocation( value.getRelocation(), "relocation", innerCount, root); + findAndReplaceSimpleElement(innerCount, root, "status", value.getStatus(), null); + } + } //-- void updateDistributionManagement(DistributionManagement, String, Counter, Element) + + /** + * Method updateElement + * + * @param counter + * @param shouldExist + * @param name + * @param parent + */ + protected Element updateElement(Counter counter, Element parent, String name, boolean shouldExist) + { + Element element = parent.getChild(name, parent.getNamespace()); + if (element != null && shouldExist) { + counter.increaseCount(); + } + if (element == null && shouldExist) { + element = factory.element(name, parent.getNamespace()); + insertAtPreferredLocation(parent, element, counter); + counter.increaseCount(); + } + if (!shouldExist && element != null) { + int index = parent.indexOf(element); + if (index > 0) { + Content previous = parent.getContent(index - 1); + if (previous instanceof Text) { + Text txt = (Text)previous; + if (txt.getTextTrim().length() == 0) { + parent.removeContent(txt); + } + } + } + parent.removeContent(element); + } + return element; + } //-- Element updateElement(Counter, Element, String, boolean) + + /** + * Method updateExclusion + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateExclusion(Exclusion value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); + } //-- void updateExclusion(Exclusion, String, Counter, Element) + + /** + * Method updateExtension + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateExtension(Extension value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + } //-- void updateExtension(Extension, String, Counter, Element) + + /** + * Method updateFileSet + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateFileSet(FileSet value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); + findAndReplaceSimpleLists(innerCount, root, value.getIncludes(), "includes", "include"); + findAndReplaceSimpleLists(innerCount, root, value.getExcludes(), "excludes", "exclude"); + } + } //-- void updateFileSet(FileSet, String, Counter, Element) + + /** + * Method updateIssueManagement + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateIssueManagement(IssueManagement value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "system", value.getSystem(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + } + } //-- void updateIssueManagement(IssueManagement, String, Counter, Element) + + /** + * Method updateLicense + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateLicense(License value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + findAndReplaceSimpleElement(innerCount, root, "distribution", value.getDistribution(), null); + findAndReplaceSimpleElement(innerCount, root, "comments", value.getComments(), null); + } //-- void updateLicense(License, String, Counter, Element) + + /** + * Method updateMailingList + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateMailingList(MailingList value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "subscribe", value.getSubscribe(), null); + findAndReplaceSimpleElement(innerCount, root, "unsubscribe", value.getUnsubscribe(), null); + findAndReplaceSimpleElement(innerCount, root, "post", value.getPost(), null); + findAndReplaceSimpleElement(innerCount, root, "archive", value.getArchive(), null); + findAndReplaceSimpleLists(innerCount, root, value.getOtherArchives(), "otherArchives", "otherArchive"); + } //-- void updateMailingList(MailingList, String, Counter, Element) + + /** + * Method updateModel + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateModel(Model value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + updateParent( value.getParent(), "parent", innerCount, root); + findAndReplaceSimpleElement(innerCount, root, "modelVersion", value.getModelVersion(), null); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "packaging", value.getPackaging(), "jar"); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + findAndReplaceSimpleElement(innerCount, root, "description", value.getDescription(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + updatePrerequisites( value.getPrerequisites(), "prerequisites", innerCount, root); + updateIssueManagement( value.getIssueManagement(), "issueManagement", innerCount, root); + updateCiManagement( value.getCiManagement(), "ciManagement", innerCount, root); + findAndReplaceSimpleElement(innerCount, root, "inceptionYear", value.getInceptionYear(), null); + iterateMailingList(innerCount, root, value.getMailingLists(),"mailingLists","mailingList"); + iterateDeveloper(innerCount, root, value.getDevelopers(),"developers","developer"); + iterateContributor(innerCount, root, value.getContributors(),"contributors","contributor"); + iterateLicense(innerCount, root, value.getLicenses(),"licenses","license"); + updateScm( value.getScm(), "scm", innerCount, root); + updateOrganization( value.getOrganization(), "organization", innerCount, root); + updateBuild( value.getBuild(), "build", innerCount, root); + iterateProfile(innerCount, root, value.getProfiles(),"profiles","profile"); + findAndReplaceSimpleLists(innerCount, root, value.getModules(), "modules", "module"); + iterateRepository(innerCount, root, value.getRepositories(),"repositories","repository"); + iterateRepository(innerCount, root, value.getPluginRepositories(),"pluginRepositories","pluginRepository"); + iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); + findAndReplaceXpp3DOM(innerCount, root, "reports", (Xpp3Dom)value.getReports()); + updateReporting( value.getReporting(), "reporting", innerCount, root); + updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root); + updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root); + findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); + } //-- void updateModel(Model, String, Counter, Element) + + /** + * Method updateModelBase + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateModelBase(ModelBase value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleLists(innerCount, root, value.getModules(), "modules", "module"); + iterateRepository(innerCount, root, value.getRepositories(),"repositories","repository"); + iterateRepository(innerCount, root, value.getPluginRepositories(),"pluginRepositories","pluginRepository"); + iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); + findAndReplaceXpp3DOM(innerCount, root, "reports", (Xpp3Dom)value.getReports()); + updateReporting( value.getReporting(), "reporting", innerCount, root); + updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root); + updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root); + findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); + } + } //-- void updateModelBase(ModelBase, String, Counter, Element) + + /** + * Method updateNotifier + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateNotifier(Notifier value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "type", value.getType(), "mail"); + findAndReplaceSimpleElement(innerCount, root, "sendOnError", value.isSendOnError() == true ? null : String.valueOf( value.isSendOnError() ), "true"); + findAndReplaceSimpleElement(innerCount, root, "sendOnFailure", value.isSendOnFailure() == true ? null : String.valueOf( value.isSendOnFailure() ), "true"); + findAndReplaceSimpleElement(innerCount, root, "sendOnSuccess", value.isSendOnSuccess() == true ? null : String.valueOf( value.isSendOnSuccess() ), "true"); + findAndReplaceSimpleElement(innerCount, root, "sendOnWarning", value.isSendOnWarning() == true ? null : String.valueOf( value.isSendOnWarning() ), "true"); + findAndReplaceSimpleElement(innerCount, root, "address", value.getAddress(), null); + findAndReplaceProperties(innerCount, root, "configuration", value.getConfiguration()); + } //-- void updateNotifier(Notifier, String, Counter, Element) + + /** + * Method updateOrganization + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateOrganization(Organization value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + } + } //-- void updateOrganization(Organization, String, Counter, Element) + + /** + * Method updateParent + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateParent(Parent value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + findAndReplaceSimpleElement(innerCount, root, "relativePath", value.getRelativePath(), "../pom.xml"); + } + } //-- void updateParent(Parent, String, Counter, Element) + + /** + * Method updatePatternSet + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updatePatternSet(PatternSet value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleLists(innerCount, root, value.getIncludes(), "includes", "include"); + findAndReplaceSimpleLists(innerCount, root, value.getExcludes(), "excludes", "exclude"); + } + } //-- void updatePatternSet(PatternSet, String, Counter, Element) + + /** + * Method updatePlugin + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updatePlugin(Plugin value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins"); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + findAndReplaceSimpleElement(innerCount, root, "extensions", value.isExtensions() == false ? null : String.valueOf( value.isExtensions() ), "false"); + iteratePluginExecution(innerCount, root, value.getExecutions(),"executions","execution"); + iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); + findAndReplaceXpp3DOM(innerCount, root, "goals", (Xpp3Dom)value.getGoals()); + findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); + findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); + } //-- void updatePlugin(Plugin, String, Counter, Element) + + /** + * Method updatePluginConfiguration + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updatePluginConfiguration(PluginConfiguration value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root); + iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); + } + } //-- void updatePluginConfiguration(PluginConfiguration, String, Counter, Element) + + /** + * Method updatePluginContainer + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updatePluginContainer(PluginContainer value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); + } + } //-- void updatePluginContainer(PluginContainer, String, Counter, Element) + + /** + * Method updatePluginExecution + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updatePluginExecution(PluginExecution value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), "default"); + findAndReplaceSimpleElement(innerCount, root, "phase", value.getPhase(), null); + findAndReplaceSimpleLists(innerCount, root, value.getGoals(), "goals", "goal"); + findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); + findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); + } //-- void updatePluginExecution(PluginExecution, String, Counter, Element) + + /** + * Method updatePluginManagement + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updatePluginManagement(PluginManagement value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + iteratePlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); + } + } //-- void updatePluginManagement(PluginManagement, String, Counter, Element) + + /** + * Method updatePrerequisites + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updatePrerequisites(Prerequisites value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "maven", value.getMaven(), "2.0"); + } + } //-- void updatePrerequisites(Prerequisites, String, Counter, Element) + + /** + * Method updateProfile + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateProfile(Profile value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), "default"); + //updateActivation( value.getActivation(), "activation", innerCount, root); + updateBuildBase( value.getBuild(), "build", innerCount, root); + findAndReplaceSimpleLists(innerCount, root, value.getModules(), "modules", "module"); + iterateRepository(innerCount, root, value.getRepositories(),"repositories","repository"); + iterateRepository(innerCount, root, value.getPluginRepositories(),"pluginRepositories","pluginRepository"); + iterateDependency(innerCount, root, value.getDependencies(),"dependencies","dependency"); + findAndReplaceXpp3DOM(innerCount, root, "reports", (Xpp3Dom)value.getReports()); + updateReporting( value.getReporting(), "reporting", innerCount, root); + updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root); + updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root); + findAndReplaceProperties(innerCount, root, "properties", value.getProperties()); + } //-- void updateProfile(Profile, String, Counter, Element) + + /** + * Method updateRelocation + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateRelocation(Relocation value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), null); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + findAndReplaceSimpleElement(innerCount, root, "message", value.getMessage(), null); + } + } //-- void updateRelocation(Relocation, String, Counter, Element) + + /** + * Method updateReportPlugin + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateReportPlugin(ReportPlugin value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins"); + findAndReplaceSimpleElement(innerCount, root, "artifactId", value.getArtifactId(), null); + findAndReplaceSimpleElement(innerCount, root, "version", value.getVersion(), null); + findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); + findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); + iterateReportSet(innerCount, root, value.getReportSets(),"reportSets","reportSet"); + } //-- void updateReportPlugin(ReportPlugin, String, Counter, Element) + + /** + * Method updateReportSet + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateReportSet(ReportSet value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), "default"); + findAndReplaceXpp3DOM(innerCount, root, "configuration", (Xpp3Dom)value.getConfiguration()); + findAndReplaceSimpleElement(innerCount, root, "inherited", value.getInherited(), null); + findAndReplaceSimpleLists(innerCount, root, value.getReports(), "reports", "report"); + } //-- void updateReportSet(ReportSet, String, Counter, Element) + + /** + * Method updateReporting + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateReporting(Reporting value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "excludeDefaults", value.isExcludeDefaults() == false ? null : String.valueOf( value.isExcludeDefaults() ), "false"); + findAndReplaceSimpleElement(innerCount, root, "outputDirectory", value.getOutputDirectory(), null); + iterateReportPlugin(innerCount, root, value.getPlugins(),"plugins","plugin"); + } + } //-- void updateReporting(Reporting, String, Counter, Element) + + /** + * Method updateRepository + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateRepository(Repository value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + updateRepositoryPolicy( value.getReleases(), "releases", innerCount, root); + updateRepositoryPolicy( value.getSnapshots(), "snapshots", innerCount, root); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + findAndReplaceSimpleElement(innerCount, root, "layout", value.getLayout(), "default"); + } //-- void updateRepository(Repository, String, Counter, Element) + + /** + * Method updateRepositoryBase + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateRepositoryBase(RepositoryBase value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + findAndReplaceSimpleElement(innerCount, root, "layout", value.getLayout(), "default"); + } + } //-- void updateRepositoryBase(RepositoryBase, String, Counter, Element) + + /** + * Method updateRepositoryPolicy + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateRepositoryPolicy(RepositoryPolicy value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "enabled", value.isEnabled() == true ? null : String.valueOf( value.isEnabled() ), "true"); + findAndReplaceSimpleElement(innerCount, root, "updatePolicy", value.getUpdatePolicy(), null); + findAndReplaceSimpleElement(innerCount, root, "checksumPolicy", value.getChecksumPolicy(), null); + } + } //-- void updateRepositoryPolicy(RepositoryPolicy, String, Counter, Element) + + /** + * Method updateResource + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateResource(Resource value, String xmlTag, Counter counter, Element element) + { + Element root = element; + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "targetPath", value.getTargetPath(), null); + findAndReplaceSimpleElement(innerCount, root, "filtering", value.isFiltering() == false ? null : String.valueOf( value.isFiltering() ), "false"); + findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null); + findAndReplaceSimpleLists(innerCount, root, value.getIncludes(), "includes", "include"); + findAndReplaceSimpleLists(innerCount, root, value.getExcludes(), "excludes", "exclude"); + } //-- void updateResource(Resource, String, Counter, Element) + + /** + * Method updateScm + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateScm(Scm value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "connection", value.getConnection(), null); + findAndReplaceSimpleElement(innerCount, root, "developerConnection", value.getDeveloperConnection(), null); + findAndReplaceSimpleElement(innerCount, root, "tag", value.getTag(), "HEAD"); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + } + } //-- void updateScm(Scm, String, Counter, Element) + + /** + * Method updateSite + * + * @param value + * @param element + * @param counter + * @param xmlTag + */ + protected void updateSite(Site value, String xmlTag, Counter counter, Element element) + { + boolean shouldExist = value != null; + Element root = updateElement(counter, element, xmlTag, shouldExist); + if (shouldExist) { + Counter innerCount = new Counter(counter.getDepth() + 1); + findAndReplaceSimpleElement(innerCount, root, "id", value.getId(), null); + findAndReplaceSimpleElement(innerCount, root, "name", value.getName(), null); + findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null); + } + } //-- void updateSite(Site, String, Counter, Element) + + /** + * Method write + * @deprecated + * + * @param project + * @param stream + * @param document + */ + public void write(Model project, Document document, OutputStream stream) + throws java.io.IOException + { + updateModel(project, "project", new Counter(0), document.getRootElement()); + XMLOutputter outputter = new XMLOutputter(); + outputter.setFormat(Format.getPrettyFormat() + .setIndent(" ") + .setLineSeparator(System.getProperty("line.separator"))); + outputter.output(document, stream); + } //-- void write(Model, Document, OutputStream) + + /** + * Method write + * + * @param project + * @param writer + * @param document + */ + public void write(Model project, Document document, OutputStreamWriter writer) + throws java.io.IOException + { + Format format = Format.getRawFormat() + .setEncoding(writer.getEncoding()) + .setLineSeparator(System.getProperty("line.separator")); + write(project, document, writer, format); + } //-- void write(Model, Document, OutputStreamWriter) + + /** + * Method write + * + * @param project + * @param jdomFormat + * @param writer + * @param document + */ + public void write(Model project, Document document, Writer writer, Format jdomFormat) + throws java.io.IOException + { + updateModel(project, "project", new Counter(0), document.getRootElement()); + XMLOutputter outputter = new XMLOutputter(); + outputter.setFormat(jdomFormat); + outputter.output(document, writer); + } //-- void write(Model, Document, Writer, Format) + + + //-----------------/ + //- Inner Classes -/ + //-----------------/ + + /** + * Class Counter. + * + * @version $Revision: 3974 $ $Date: 2007-04-23 19:55:40 -0400 (Mon, 23 Apr 2007) $ + */ + public class Counter { + + + //--------------------------/ + //- Class/Member Variables -/ + //--------------------------/ + + /** + * Field currentIndex + */ + private int currentIndex = 0; + + /** + * Field level + */ + private int level; + + + //----------------/ + //- Constructors -/ + //----------------/ + + public Counter(int depthLevel) { + level = depthLevel; + } //-- org.apache.maven.model.io.jdom.Counter(int) + + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method getCurrentIndex + */ + public int getCurrentIndex() + { + return currentIndex; + } //-- int getCurrentIndex() + + /** + * Method getDepth + */ + public int getDepth() + { + return level; + } //-- int getDepth() + + /** + * Method increaseCount + */ + public void increaseCount() + { + currentIndex = currentIndex + 1; + } //-- void increaseCount() + + } + +} diff --git a/src/main/java/org/apache/maven/plugins/shade/pom/PomWriter.java b/src/main/java/org/apache/maven/plugins/shade/pom/PomWriter.java index dc323c8b..bdd28c9e 100644 --- a/src/main/java/org/apache/maven/plugins/shade/pom/PomWriter.java +++ b/src/main/java/org/apache/maven/plugins/shade/pom/PomWriter.java @@ -1,77 +1,77 @@ -package org.apache.maven.plugins.shade.pom; - -/* - * 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.IOException; -import java.io.Writer; - -import org.apache.maven.model.Model; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.Namespace; -import org.jdom.output.Format; - -/** @author Jason van Zyl */ -public class PomWriter -{ - public static void write( Writer w, - Model newModel ) - throws IOException - { - write( w, newModel, false ); - } - - public static void write( Writer w, - Model newModel, - boolean namespaceDeclaration ) - throws IOException - { - Element root = new Element( "project" ); - - if ( namespaceDeclaration ) - { - String modelVersion = newModel.getModelVersion(); - - Namespace pomNamespace = Namespace.getNamespace( "", "http://maven.apache.org/POM/" + modelVersion ); - - root.setNamespace( pomNamespace ); - - Namespace xsiNamespace = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); - - root.addNamespaceDeclaration( xsiNamespace ); - - if ( root.getAttribute( "schemaLocation", xsiNamespace ) == null ) - { - root.setAttribute( "schemaLocation", "http://maven.apache.org/POM/" + modelVersion + - " http://maven.apache.org/maven-v" + modelVersion.replace( '.', '_' ) + ".xsd", xsiNamespace ); - } - } - - Document doc = new Document( root ); - - MavenJDOMWriter writer = new MavenJDOMWriter(); - - String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8"; - - Format format = Format.getPrettyFormat().setEncoding( encoding ); - - writer.write( newModel, doc, w, format ); - } -} +package org.apache.maven.plugins.shade.pom; + +/* + * 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.IOException; +import java.io.Writer; + +import org.apache.maven.model.Model; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.Namespace; +import org.jdom.output.Format; + +/** @author Jason van Zyl */ +public class PomWriter +{ + public static void write( Writer w, + Model newModel ) + throws IOException + { + write( w, newModel, false ); + } + + public static void write( Writer w, + Model newModel, + boolean namespaceDeclaration ) + throws IOException + { + Element root = new Element( "project" ); + + if ( namespaceDeclaration ) + { + String modelVersion = newModel.getModelVersion(); + + Namespace pomNamespace = Namespace.getNamespace( "", "http://maven.apache.org/POM/" + modelVersion ); + + root.setNamespace( pomNamespace ); + + Namespace xsiNamespace = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); + + root.addNamespaceDeclaration( xsiNamespace ); + + if ( root.getAttribute( "schemaLocation", xsiNamespace ) == null ) + { + root.setAttribute( "schemaLocation", "http://maven.apache.org/POM/" + modelVersion + + " http://maven.apache.org/maven-v" + modelVersion.replace( '.', '_' ) + ".xsd", xsiNamespace ); + } + } + + Document doc = new Document( root ); + + MavenJDOMWriter writer = new MavenJDOMWriter(); + + String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8"; + + Format format = Format.getPrettyFormat().setEncoding( encoding ); + + writer.write( newModel, doc, w, format ); + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/relocation/Relocator.java b/src/main/java/org/apache/maven/plugins/shade/relocation/Relocator.java index f162fcbb..835ba822 100644 --- a/src/main/java/org/apache/maven/plugins/shade/relocation/Relocator.java +++ b/src/main/java/org/apache/maven/plugins/shade/relocation/Relocator.java @@ -1,34 +1,34 @@ -package org.apache.maven.plugins.shade.relocation; - -/* - * 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. - */ - -/** @author Jason van Zyl */ -public interface Relocator -{ - String ROLE = Relocator.class.getName(); - - boolean canRelocatePath( String clazz ); - - String relocatePath( String clazz ); - - boolean canRelocateClass( String clazz ); - - String relocateClass( String clazz ); -} +package org.apache.maven.plugins.shade.relocation; + +/* + * 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. + */ + +/** @author Jason van Zyl */ +public interface Relocator +{ + String ROLE = Relocator.class.getName(); + + boolean canRelocatePath( String clazz ); + + String relocatePath( String clazz ); + + boolean canRelocateClass( String clazz ); + + String relocateClass( String clazz ); +} diff --git a/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java b/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java index d4e2b36c..729bb18e 100644 --- a/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java +++ b/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java @@ -1,126 +1,109 @@ -package org.apache.maven.plugins.shade.relocation; - -/* - * 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.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * @author Jason van Zyl - * @author Mauro Talevi - */ -public class SimpleRelocator - implements Relocator -{ - private String pattern; - - private String pathPattern; - - private String shadedPattern; - - private String shadedPathPattern; - - private List excludes; - - public SimpleRelocator(String patt, String shadedPattern, List excludes) - { - this.pattern = patt; - this.pathPattern = patt.replace('.', '/'); - - if ( shadedPattern != null ) - { - this.shadedPattern = shadedPattern; - this.shadedPathPattern = shadedPattern.replace('.', '/'); - } else - { - this.shadedPattern = "hidden." + this.pattern; - this.shadedPathPattern = "hidden/" + this.pathPattern; - } - - if (excludes != null) - { - this.excludes = new ArrayList(); - - for (Iterator i = excludes.iterator(); i.hasNext();) - { - String e = (String) i.next(); - - this.excludes.add(e.replace('.', '/')); - } - } - } - - public boolean canRelocatePath( String clazz ) - { - if ( excludes != null ) - { - for ( Iterator i = excludes.iterator(); i.hasNext(); ) - { - String exclude = (String) i.next(); - - // Remember we have converted "." -> "/" in the constructor. So ".*" is really "/*" - if ( exclude.endsWith( "/*" ) && clazz.startsWith( exclude.substring( 0, exclude.length() - 2 ) ) ) - { - return false; - } - else if ( clazz.equals( exclude ) ) - { - return false; - } - } - } - - return clazz.startsWith( pathPattern ); - } - - public boolean canRelocateClass( String clazz ) - { - if ( excludes != null ) - { - for ( Iterator i = excludes.iterator(); i.hasNext(); ) - { - String exclude = (String) i.next(); - - exclude = exclude.replace( '/', '.' ); - if ( exclude.endsWith( ".*" ) && clazz.startsWith( exclude.substring( 0, exclude.length() - 2 ) ) ) - { - return false; - } - else if ( clazz.equals( exclude ) ) - { - return false; - } - } - } - - return clazz.startsWith( pattern ); - } - - public String relocatePath( String clazz ) - { - return clazz.replaceFirst(pathPattern, shadedPathPattern); - } - - public String relocateClass( String clazz ) - { - return clazz.replaceFirst(pattern, shadedPattern); - } -} +package org.apache.maven.plugins.shade.relocation; + +/* + * 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.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.codehaus.plexus.util.SelectorUtils; + +/** + * @author Jason van Zyl + * @author Mauro Talevi + */ +public class SimpleRelocator + implements Relocator +{ + private String pattern; + + private String pathPattern; + + private String shadedPattern; + + private String shadedPathPattern; + + private List excludes; + + public SimpleRelocator(String patt, String shadedPattern, List excludes) + { + this.pattern = patt; + this.pathPattern = patt.replace('.', '/'); + + if ( shadedPattern != null ) + { + this.shadedPattern = shadedPattern; + this.shadedPathPattern = shadedPattern.replace('.', '/'); + } else + { + this.shadedPattern = "hidden." + this.pattern; + this.shadedPathPattern = "hidden/" + this.pathPattern; + } + + if ( excludes != null && !excludes.isEmpty() ) + { + this.excludes = new ArrayList(); + + for (Iterator i = excludes.iterator(); i.hasNext();) + { + String e = (String) i.next(); + + this.excludes.add(e.replace('.', '/')); + } + } + } + + public boolean canRelocatePath( String path ) + { + if ( path.endsWith( ".class" ) ) + { + path = path.substring( 0, path.length() - 6 ); + } + if ( excludes != null ) + { + for ( Iterator i = excludes.iterator(); i.hasNext(); ) + { + String exclude = (String) i.next(); + + if ( SelectorUtils.matchPath( exclude, path, true ) ) + { + return false; + } + } + } + + return path.startsWith( pathPattern ); + } + + public boolean canRelocateClass( String clazz ) + { + return canRelocatePath( clazz.replace( '.', '/' ) ); + } + + public String relocatePath( String path ) + { + return path.replaceFirst(pathPattern, shadedPathPattern); + } + + public String relocateClass( String clazz ) + { + return clazz.replaceFirst(pattern, shadedPattern); + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformer.java index 6b80d3f2..6047e1c6 100644 --- a/src/main/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformer.java +++ b/src/main/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformer.java @@ -1,64 +1,67 @@ -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.IOException; -import java.io.InputStream; -import java.util.HashSet; -import java.util.Set; -import java.util.jar.JarOutputStream; - -/** - * Prevents duplicate copies of the license - * - */ -public class ApacheLicenseResourceTransformer - implements ResourceTransformer -{ - Set entries = new HashSet(); - - public boolean canTransformResource( String resource ) - { - String s = resource.toLowerCase(); - - if ( s.startsWith( "meta-inf/license.txt" ) || s.equals( "meta-inf/license" )) - { - return true; - } - - return false; - } - - public void processResource( InputStream is ) - throws IOException - { - - } - - public boolean hasTransformedResource() - { - return false; - } - - public void modifyOutputStream( JarOutputStream os ) - throws IOException - { - } -} +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.IOException; +import java.io.InputStream; +import java.util.HashSet; +import java.util.Set; +import java.util.jar.JarOutputStream; + +/** + * Prevents duplicate copies of the license + */ +public class ApacheLicenseResourceTransformer + implements ResourceTransformer +{ + + private static final String LICENSE_PATH = "META-INF/LICENSE"; + + private static final String LICENSE_TXT_PATH = "META-INF/LICENSE.txt"; + + Set entries = new HashSet(); + + public boolean canTransformResource( String resource ) + { + if ( LICENSE_PATH.equalsIgnoreCase( resource ) + || LICENSE_TXT_PATH.regionMatches( true, 0, resource, 0, LICENSE_TXT_PATH.length() ) ) + { + return true; + } + + return false; + } + + public void processResource( InputStream is ) + throws IOException + { + + } + + public boolean hasTransformedResource() + { + return false; + } + + public void modifyOutputStream( JarOutputStream os ) + throws IOException + { + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java index 1456a3db..345e3f10 100644 --- a/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java +++ b/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java @@ -1,234 +1,259 @@ -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.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.jar.JarEntry; -import java.util.jar.JarOutputStream; - -public class ApacheNoticeResourceTransformer - implements ResourceTransformer -{ - Set entries = new LinkedHashSet(); - Map organizationEntries = new LinkedHashMap(); - - String projectName; - boolean addHeader = true; - - String preamble1 = - "// ------------------------------------------------------------------\n" - + "// NOTICE file corresponding to the section 4d of The Apache License,\n" - + "// Version 2.0, in this case for "; - - String preamble2 = "\n// ------------------------------------------------------------------\n"; - - String preamble3 = "This product includes software developed at\n"; - - //defaults overridable via config in pom - String organizationName = "The Apache Software Foundation"; - String organizationURL = "http://www.apache.org/"; - String inceptionYear = "2006"; - - String copyright; - - - public boolean canTransformResource( String resource ) - { - String s = resource.toLowerCase(); - - if (s.equals( "meta-inf/notice.txt" ) || s.equals( "meta-inf/notice" ) ) - { - return true; - } - - return false; - } - - public void processResource( InputStream is ) - throws IOException - { - if ( entries.isEmpty() ) - { - String year = new SimpleDateFormat( "yyyy" ).format( new Date() ); - if ( !inceptionYear.equals( year ) ) - { - year = inceptionYear + "-" + year; - } - - - //add headers - if ( addHeader ) - { - entries.add( preamble1 + projectName + preamble2 ); - } - else - { - entries.add(""); - } - //fake second entry, we'll look for a real one later - entries.add( projectName + "\nCopyright " + year + " " + organizationName + "\n" ); - entries.add( preamble3 + organizationName + " ("+ organizationURL +").\n" ); - } - - - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - - String line = reader.readLine(); - StringBuffer sb = new StringBuffer(); - Set currentOrg = null; - int lineCount = 0; - while ( line != null ) - { - String trimedLine = line.trim(); - - if ( !trimedLine.startsWith( "//" ) ) - { - if ( trimedLine.length() > 0 ) - { - if ( trimedLine.startsWith( "- " ) ) - { - //resource-bundle 1.3 mode - if ( lineCount == 1 - && sb.toString().indexOf( "This product includes/uses software(s) developed by" ) != -1) - { - currentOrg = (Set) organizationEntries.get( sb.toString().trim() ); - if ( currentOrg == null ) - { - currentOrg = new TreeSet(); - organizationEntries.put( sb.toString().trim(), currentOrg ); - } - sb = new StringBuffer(); - } - else if ( sb.length() > 0 && currentOrg != null ) - { - currentOrg.add( sb.toString() ); - sb = new StringBuffer(); - } - - } - sb.append( line ).append( "\n" ); - lineCount++; - } - else - { - String ent = sb.toString(); - if ( ent.startsWith( projectName ) - && ent.indexOf( "Copyright " ) != -1 ) - { - copyright = ent; - } - if ( currentOrg == null ) - { - entries.add( ent ); - } - else - { - currentOrg.add( ent ); - } - sb = new StringBuffer(); - lineCount = 0; - currentOrg = null; - } - } - - line = reader.readLine(); - } - if ( sb.length() > 0 ) - { - if ( currentOrg == null ) - { - entries.add( sb.toString() ); - } - else - { - currentOrg.add( sb.toString() ); - } - } - } - - public boolean hasTransformedResource() - { - return true; - } - - public void modifyOutputStream( JarOutputStream jos ) - throws IOException - { - jos.putNextEntry( new JarEntry( "META-INF/NOTICE" ) ); - - OutputStreamWriter pow = new OutputStreamWriter( jos ); - PrintWriter writer = new PrintWriter(pow); - - int count = 0; - for ( Iterator itr = entries.iterator() ; itr.hasNext() ; ) - { - ++count; - String line = (String) itr.next(); - if ( line.equals( copyright ) && count != 2) - { - continue; - } - - if ( count == 2 && copyright != null ) - { - writer.print( copyright ); - writer.print( '\n' ); - } - else - { - writer.print( line ); - writer.print( '\n' ); - } - if (count == 3) - { - //do org stuff - for (Iterator oit = organizationEntries.entrySet().iterator() ; oit.hasNext();) - { - Map.Entry entry = (Map.Entry) oit.next(); - writer.print( entry.getKey().toString() ); - writer.print( '\n' ); - Set entrySet = (Set)entry.getValue(); - for (Iterator eit = entrySet.iterator() ; eit.hasNext() ;) - { - writer.print( eit.next().toString() ); - } - writer.print( '\n' ); - } - } - } - - writer.flush(); - - entries.clear(); - } -} +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.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Writer; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; + +import org.codehaus.plexus.util.StringUtils; + +public class ApacheNoticeResourceTransformer + implements ResourceTransformer +{ + Set entries = new LinkedHashSet(); + Map organizationEntries = new LinkedHashMap(); + + String projectName; + boolean addHeader = true; + + String preamble1 = + "// ------------------------------------------------------------------\n" + + "// NOTICE file corresponding to the section 4d of The Apache License,\n" + + "// Version 2.0, in this case for "; + + String preamble2 = "\n// ------------------------------------------------------------------\n"; + + String preamble3 = "This product includes software developed at\n"; + + //defaults overridable via config in pom + String organizationName = "The Apache Software Foundation"; + String organizationURL = "http://www.apache.org/"; + String inceptionYear = "2006"; + + String copyright; + + /** + * The file encoding of the NOTICE file. + */ + String encoding; + + private static final String NOTICE_PATH = "META-INF/NOTICE"; + + private static final String NOTICE_TXT_PATH = "META-INF/NOTICE.txt"; + + public boolean canTransformResource( String resource ) + { + if ( NOTICE_PATH.equalsIgnoreCase( resource ) || NOTICE_TXT_PATH.equalsIgnoreCase( resource ) ) + { + return true; + } + + return false; + } + + public void processResource( InputStream is ) + throws IOException + { + if ( entries.isEmpty() ) + { + String year = new SimpleDateFormat( "yyyy" ).format( new Date() ); + if ( !inceptionYear.equals( year ) ) + { + year = inceptionYear + "-" + year; + } + + + //add headers + if ( addHeader ) + { + entries.add( preamble1 + projectName + preamble2 ); + } + else + { + entries.add(""); + } + //fake second entry, we'll look for a real one later + entries.add( projectName + "\nCopyright " + year + " " + organizationName + "\n" ); + entries.add( preamble3 + organizationName + " ("+ organizationURL +").\n" ); + } + + + BufferedReader reader; + if ( StringUtils.isNotEmpty( encoding ) ) + { + reader = new BufferedReader( new InputStreamReader( is, encoding ) ); + } + else + { + reader = new BufferedReader( new InputStreamReader( is ) ); + } + + String line = reader.readLine(); + StringBuffer sb = new StringBuffer(); + Set currentOrg = null; + int lineCount = 0; + while ( line != null ) + { + String trimedLine = line.trim(); + + if ( !trimedLine.startsWith( "//" ) ) + { + if ( trimedLine.length() > 0 ) + { + if ( trimedLine.startsWith( "- " ) ) + { + //resource-bundle 1.3 mode + if ( lineCount == 1 + && sb.toString().indexOf( "This product includes/uses software(s) developed by" ) != -1) + { + currentOrg = (Set) organizationEntries.get( sb.toString().trim() ); + if ( currentOrg == null ) + { + currentOrg = new TreeSet(); + organizationEntries.put( sb.toString().trim(), currentOrg ); + } + sb = new StringBuffer(); + } + else if ( sb.length() > 0 && currentOrg != null ) + { + currentOrg.add( sb.toString() ); + sb = new StringBuffer(); + } + + } + sb.append( line ).append( "\n" ); + lineCount++; + } + else + { + String ent = sb.toString(); + if ( ent.startsWith( projectName ) + && ent.indexOf( "Copyright " ) != -1 ) + { + copyright = ent; + } + if ( currentOrg == null ) + { + entries.add( ent ); + } + else + { + currentOrg.add( ent ); + } + sb = new StringBuffer(); + lineCount = 0; + currentOrg = null; + } + } + + line = reader.readLine(); + } + if ( sb.length() > 0 ) + { + if ( currentOrg == null ) + { + entries.add( sb.toString() ); + } + else + { + currentOrg.add( sb.toString() ); + } + } + } + + public boolean hasTransformedResource() + { + return true; + } + + public void modifyOutputStream( JarOutputStream jos ) + throws IOException + { + jos.putNextEntry( new JarEntry( NOTICE_PATH ) ); + + Writer pow; + if ( StringUtils.isNotEmpty( encoding ) ) + { + pow = new OutputStreamWriter( jos, encoding ); + } + else + { + pow = new OutputStreamWriter( jos ); + } + PrintWriter writer = new PrintWriter( pow ); + + int count = 0; + for ( Iterator itr = entries.iterator() ; itr.hasNext() ; ) + { + ++count; + String line = (String) itr.next(); + if ( line.equals( copyright ) && count != 2) + { + continue; + } + + if ( count == 2 && copyright != null ) + { + writer.print( copyright ); + writer.print( '\n' ); + } + else + { + writer.print( line ); + writer.print( '\n' ); + } + if (count == 3) + { + //do org stuff + for (Iterator oit = organizationEntries.entrySet().iterator() ; oit.hasNext();) + { + Map.Entry entry = (Map.Entry) oit.next(); + writer.print( entry.getKey().toString() ); + writer.print( '\n' ); + Set entrySet = (Set)entry.getValue(); + for (Iterator eit = entrySet.iterator() ; eit.hasNext() ;) + { + writer.print( eit.next().toString() ); + } + writer.print( '\n' ); + } + } + } + + writer.flush(); + + entries.clear(); + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java index 43facc95..78908782 100644 --- a/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java +++ b/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java @@ -1,71 +1,69 @@ -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.jar.JarEntry; -import java.util.jar.JarOutputStream; - -import org.codehaus.plexus.util.IOUtil; - -public class AppendingTransformer - implements ResourceTransformer -{ - String resource; - ByteArrayOutputStream data = new ByteArrayOutputStream(); - - public boolean canTransformResource( String r ) - { - r = r.toLowerCase(); - - if (resource != null && resource.toLowerCase().equals(r)) - { - return true; - } - - return false; - } - - public void processResource( InputStream is ) - throws IOException - { - IOUtil.copy(is, data); - data.write('\n'); - - is.close(); - } - - public boolean hasTransformedResource() - { - return data.size() > 0; - } - - public void modifyOutputStream( JarOutputStream jos ) - throws IOException - { - jos.putNextEntry( new JarEntry( resource ) ); - - IOUtil.copy(new ByteArrayInputStream(data.toByteArray()), jos); - data.reset(); - } -} +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.jar.JarEntry; +import java.util.jar.JarOutputStream; + +import org.codehaus.plexus.util.IOUtil; + +public class AppendingTransformer + implements ResourceTransformer +{ + String resource; + ByteArrayOutputStream data = new ByteArrayOutputStream(); + + public boolean canTransformResource( String r ) + { + if ( resource != null && resource.equalsIgnoreCase( r ) ) + { + return true; + } + + return false; + } + + public void processResource( InputStream is ) + throws IOException + { + IOUtil.copy(is, data); + data.write('\n'); + + is.close(); + } + + public boolean hasTransformedResource() + { + return data.size() > 0; + } + + public void modifyOutputStream( JarOutputStream jos ) + throws IOException + { + jos.putNextEntry( new JarEntry( resource ) ); + + IOUtil.copy(new ByteArrayInputStream(data.toByteArray()), jos); + data.reset(); + } +} diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java index 851cf191..e4230b1c 100644 --- a/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java +++ b/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java @@ -1,167 +1,166 @@ -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.File; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.jar.JarEntry; -import java.util.jar.JarOutputStream; - -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import org.codehaus.plexus.util.xml.Xpp3DomWriter; - -// 1. We want to process all resources that are common in all the JARs that we are processing. -// 2. At the end of processing we want to hand back the transformation of the resources. - -// In my particular case I want to grab all the plexus components.xml files and aggregate them -// and then stick them in one place in the aggregated JAR. - -public class ComponentsXmlResourceTransformer - implements ResourceTransformer -{ - private Map components = new LinkedHashMap(); - - public static final String COMPONENTS_XML_PATH = "META-INF/plexus/components.xml"; - - public boolean canTransformResource( String resource ) - { - return COMPONENTS_XML_PATH.equals( resource ); - } - - public void processResource( InputStream is ) - throws IOException - { - // We can't just read the stream because the plexus dom builder closes the stream - - File f = File.createTempFile( "maven-shade-plugin", "tmp" ); - - f.deleteOnExit(); - - String n = f.getAbsolutePath(); - - OutputStream os = new FileOutputStream( f ); - - IOUtil.copy( is, os ); - - os.close(); - - // - - Reader reader; - - Xpp3Dom newDom; - - try - { - reader = new FileReader( n ); - - newDom = Xpp3DomBuilder.build( reader ); - } - catch ( Exception e ) - { - throw new IOException( "Error parsing components.xml in " + is ); - } - - // Only try to merge in components if there are some elements in the component-set - if ( newDom.getChild( "components" ) == null ) - { - return; - } - - Xpp3Dom[] children = newDom.getChild( "components" ).getChildren( "component" ); - - for ( int i = 0; i < children.length; i++ ) - { - Xpp3Dom component = children[i]; - - String role = component.getChild( "role" ).getValue(); - - Xpp3Dom child = component.getChild( "role-hint" ); - - String roleHint = child != null ? child.getValue() : ""; - - components.put( role + roleHint, component ); - } - } - - public void modifyOutputStream( JarOutputStream jos ) - throws IOException - { - Reader reader = new FileReader( getTransformedResource() ); - - jos.putNextEntry( new JarEntry( COMPONENTS_XML_PATH ) ); - - IOUtil.copy( reader, jos ); - - reader.close(); - - components.clear(); - } - - public boolean hasTransformedResource() - { - return components.size() > 0; - } - - public File getTransformedResource() - throws IOException - { - File f = File.createTempFile( "shade-maven-plugin-plx", "tmp" ); - - f.deleteOnExit(); - - FileWriter fileWriter = new FileWriter( f ); - try - { - Xpp3Dom dom = new Xpp3Dom( "component-set" ); - - Xpp3Dom componentDom = new Xpp3Dom( "components" ); - - dom.addChild( componentDom ); - - for ( Iterator i = components.values().iterator(); i.hasNext(); ) - { - Xpp3Dom component = (Xpp3Dom) i.next(); - componentDom.addChild( component ); - } - - Xpp3DomWriter.write( fileWriter, dom ); - } - finally - { - IOUtil.close( fileWriter ); - } - - return f; - } - - -} +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.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; + +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; + +// 1. We want to process all resources that are common in all the JARs that we are processing. +// 2. At the end of processing we want to hand back the transformation of the resources. + +// In my particular case I want to grab all the plexus components.xml files and aggregate them +// and then stick them in one place in the aggregated JAR. + +public class ComponentsXmlResourceTransformer + implements ResourceTransformer +{ + private Map components = new LinkedHashMap(); + + public static final String COMPONENTS_XML_PATH = "META-INF/plexus/components.xml"; + + public boolean canTransformResource( String resource ) + { + return COMPONENTS_XML_PATH.equals( resource ); + } + + public void processResource( InputStream is ) + throws IOException + { + // We can't just read the stream because the plexus dom builder closes the stream + + File f = File.createTempFile( "maven-shade-plugin", "tmp" ); + + f.deleteOnExit(); + + OutputStream os = new FileOutputStream( f ); + + IOUtil.copy( is, os ); + + os.close(); + + // + + Reader reader; + + Xpp3Dom newDom; + + try + { + reader = ReaderFactory.newXmlReader( f ); + + newDom = Xpp3DomBuilder.build( reader ); + } + catch ( Exception e ) + { + throw new IOException( "Error parsing components.xml in " + is ); + } + + // Only try to merge in components if there are some elements in the component-set + if ( newDom.getChild( "components" ) == null ) + { + return; + } + + Xpp3Dom[] children = newDom.getChild( "components" ).getChildren( "component" ); + + for ( int i = 0; i < children.length; i++ ) + { + Xpp3Dom component = children[i]; + + String role = component.getChild( "role" ).getValue(); + + Xpp3Dom child = component.getChild( "role-hint" ); + + String roleHint = child != null ? child.getValue() : ""; + + components.put( role + roleHint, component ); + } + } + + public void modifyOutputStream( JarOutputStream jos ) + throws IOException + { + Reader reader = ReaderFactory.newXmlReader( getTransformedResource() ); + + jos.putNextEntry( new JarEntry( COMPONENTS_XML_PATH ) ); + + IOUtil.copy( reader, jos ); + + reader.close(); + + components.clear(); + } + + public boolean hasTransformedResource() + { + return components.size() > 0; + } + + public File getTransformedResource() + throws IOException + { + File f = File.createTempFile( "shade-maven-plugin-plx", "tmp" ); + + f.deleteOnExit(); + + Writer writer = WriterFactory.newXmlWriter( f ); + try + { + Xpp3Dom dom = new Xpp3Dom( "component-set" ); + + Xpp3Dom componentDom = new Xpp3Dom( "components" ); + + dom.addChild( componentDom ); + + for ( Iterator i = components.values().iterator(); i.hasNext(); ) + { + Xpp3Dom component = (Xpp3Dom) i.next(); + componentDom.addChild( component ); + } + + Xpp3DomWriter.write( writer, dom ); + } + finally + { + IOUtil.close( writer ); + } + + return f; + } + + +} diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java index 387ea557..de502755 100644 --- a/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java +++ b/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java @@ -1,38 +1,38 @@ -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.IOException; -import java.io.InputStream; -import java.util.jar.JarOutputStream; - -/** @author Jason van Zyl */ -public interface ResourceTransformer -{ - boolean canTransformResource( String resource ); - - void processResource( InputStream is ) - throws IOException; - - boolean hasTransformedResource(); - - void modifyOutputStream( JarOutputStream os ) - throws IOException; -} +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.IOException; +import java.io.InputStream; +import java.util.jar.JarOutputStream; + +/** @author Jason van Zyl */ +public interface ResourceTransformer +{ + boolean canTransformResource( String resource ); + + void processResource( InputStream is ) + throws IOException; + + boolean hasTransformedResource(); + + void modifyOutputStream( JarOutputStream os ) + throws IOException; +} diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformer.java b/src/main/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformer.java index 700bede9..75ce92aa 100644 --- a/src/main/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformer.java +++ b/src/main/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformer.java @@ -1,115 +1,113 @@ -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.IOException; -import java.io.InputStream; -import java.util.Iterator; -import java.util.jar.JarEntry; -import java.util.jar.JarOutputStream; - -import org.jdom.Attribute; -import org.jdom.Content; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.input.SAXBuilder; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; - -public class XmlAppendingTransformer - implements ResourceTransformer -{ - public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance"; - - String resource; - Document doc; - - public boolean canTransformResource( String r ) - { - r = r.toLowerCase(); - - if (resource != null && resource.toLowerCase().equals(r)) - { - return true; - } - - return false; - } - - public void processResource( InputStream is ) - throws IOException - { - Document r; - try - { - r = new SAXBuilder().build(is); - } - catch (JDOMException e) - { - throw new RuntimeException(e); - } - - if (doc == null) - { - doc = r; - } - else - { - Element root = r.getRootElement(); - - for (Iterator itr = root.getAttributes().iterator(); itr.hasNext();) - { - Attribute a = (Attribute) itr.next(); - itr.remove(); - - Element mergedEl = doc.getRootElement(); - Attribute mergedAtt = mergedEl.getAttribute(a.getName(), a.getNamespace()); - if (mergedAtt == null) - { - mergedEl.setAttribute(a); - } - } - - for (Iterator itr = root.getChildren().iterator(); itr.hasNext();) - { - Content n = (Content) itr.next(); - itr.remove(); - - doc.getRootElement().addContent(n); - } - } - } - - public boolean hasTransformedResource() - { - return doc != null; - } - - public void modifyOutputStream( JarOutputStream jos ) - throws IOException - { - jos.putNextEntry( new JarEntry( resource ) ); - - new XMLOutputter(Format.getPrettyFormat()).output(doc, jos); - - doc = null; - } -} +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.IOException; +import java.io.InputStream; +import java.util.Iterator; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; + +import org.jdom.Attribute; +import org.jdom.Content; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +public class XmlAppendingTransformer + implements ResourceTransformer +{ + public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance"; + + String resource; + Document doc; + + public boolean canTransformResource( String r ) + { + if ( resource != null && resource.equalsIgnoreCase( r ) ) + { + return true; + } + + return false; + } + + public void processResource( InputStream is ) + throws IOException + { + Document r; + try + { + r = new SAXBuilder().build(is); + } + catch (JDOMException e) + { + throw new RuntimeException(e); + } + + if (doc == null) + { + doc = r; + } + else + { + Element root = r.getRootElement(); + + for (Iterator itr = root.getAttributes().iterator(); itr.hasNext();) + { + Attribute a = (Attribute) itr.next(); + itr.remove(); + + Element mergedEl = doc.getRootElement(); + Attribute mergedAtt = mergedEl.getAttribute(a.getName(), a.getNamespace()); + if (mergedAtt == null) + { + mergedEl.setAttribute(a); + } + } + + for (Iterator itr = root.getChildren().iterator(); itr.hasNext();) + { + Content n = (Content) itr.next(); + itr.remove(); + + doc.getRootElement().addContent(n); + } + } + } + + public boolean hasTransformedResource() + { + return doc != null; + } + + public void modifyOutputStream( JarOutputStream jos ) + throws IOException + { + jos.putNextEntry( new JarEntry( resource ) ); + + new XMLOutputter(Format.getPrettyFormat()).output(doc, jos); + + doc = null; + } +} diff --git a/src/site/apt/examples.apt b/src/site/apt/examples.apt index d081d5a9..7099e54c 100644 --- a/src/site/apt/examples.apt +++ b/src/site/apt/examples.apt @@ -266,8 +266,8 @@ org/junit/** - org/junit/experimental/** - org/junit/runners/** + org/junit/experimental/** + org/junit/runners/** @@ -318,4 +318,4 @@ ... -+----- \ No newline at end of file ++----- diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt index c02ad1bb..8133832b 100644 --- a/src/site/apt/index.apt +++ b/src/site/apt/index.apt @@ -1,5 +1,5 @@ ------ - Maven 2 Shade Plugin + Introduction ------ Mauro Talevi ------ @@ -21,25 +21,24 @@ ~~ specific language governing permissions and limitations ~~ under the License. -Introduction +Maven 2 Shade Plugin This plugin provides the capability to package the artifact in a uber-jar, including its dependencies and - to "shade" - ie rename - the packages of some of the dependencies. + to - i.e. rename - the packages of some of the dependencies. - * Goals Overview +* Goals Overview The Shade Plugin has a single goal: - * {{{shade-mojo.html}shade:shade}} is bound to the package phase and + * {{{shade-mojo.html}shade:shade}} is bound to the <<>> phase and is used to create a shaded jar. - - * Usage +* Usage Instructions on how to use the Shade Plugin can be found in the {{{usage.html}usage}} page. - * Examples +* Examples To provide you with better understanding on some usages of the Shade Plugin, you can take a look {{{examples.html}examples}} page. diff --git a/src/site/apt/usage.apt b/src/site/apt/usage.apt index 102e9a6c..ae53baa6 100644 --- a/src/site/apt/usage.apt +++ b/src/site/apt/usage.apt @@ -1,5 +1,5 @@ ------ - Maven 2 Shade Plugin + Usage ------ Mauro Talevi ------ @@ -21,16 +21,18 @@ ~~ specific language governing permissions and limitations ~~ under the License. - * Creating a shaded jar +Usage - The goals for the Shade Plugin are bound to the package phase in the +* Creating a Shaded JAR + + The goals for the Shade Plugin are bound to the <<>> phase in the build lifecycle. +----- mvn package +----- - * Configuring Your Shade Plugin +* Configuring Your Shade Plugin +----- @@ -40,6 +42,7 @@ mvn package org.apache.maven.plugins maven-shade-plugin + 1.0.1 @@ -48,4 +51,4 @@ mvn package ... -+----- \ No newline at end of file ++----- diff --git a/src/site/site.xml b/src/site/site.xml index 3f13203f..c0a9d6c9 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -1,28 +1,29 @@ - + diff --git a/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java b/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java index 386fc9bc..b87899ed 100644 --- a/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java +++ b/src/test/java/org/apache/maven/plugins/shade/DefaultShaderTest.java @@ -1,116 +1,116 @@ -package org.apache.maven.plugins.shade; - -/* - * 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.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.net.URLClassLoader; -import java.net.URL; - -import junit.framework.TestCase; - -import org.apache.maven.plugins.shade.relocation.SimpleRelocator; -import org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer; - -/** - * @author Jason van Zyl - * @author Mauro Talevi - */ -public class DefaultShaderTest - extends TestCase -{ - private static final String[] EXCLUDES = new String[] { - "org/codehaus/plexus/util/xml/Xpp3Dom", - "org/codehaus/plexus/util/xml/pull.*" }; - - public void testShaderWithDefaultShadedPattern() - throws Exception - { - shaderWithPattern( null, new File( "target/foo-default.jar" ), EXCLUDES ); - } - - public void testShaderWithStaticInitializedClass() - throws Exception - { - Shader s = new DefaultShader(); - - Set set = new HashSet(); - - set.add( new File( "src/test/jars/test-artifact-1.0-SNAPSHOT.jar" ) ); - - List relocators = new ArrayList(); - - relocators.add( new SimpleRelocator( "org.apache.maven.plugins.shade", null, null ) ); - - List resourceTransformers = new ArrayList(); - - List filters = new ArrayList(); - - File file = new File( "target/testShaderWithStaticInitializedClass.jar" ); - s.shade( set, file, filters, relocators, resourceTransformers ); - - URLClassLoader cl = new URLClassLoader( new URL[]{file.toURL()} ); - Class c = cl.loadClass( "hidden.org.apache.maven.plugins.shade.Lib" ); - Object o = c.newInstance(); - assertEquals( "foo.bar/baz", c.getDeclaredField( "CONSTANT" ).get( o ) ); - } - - public void testShaderWithCustomShadedPattern() - throws Exception - { - shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom.jar" ), EXCLUDES ); - } - - public void testShaderWithoutExcludesShouldRemoveReferencesOfOriginalPattern() - throws Exception - { - //FIXME: shaded jar should not include references to org/codehaus/* (empty dirs) or org.codehaus.* META-INF files. - shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom-without-excludes.jar" ), new String[] {} ); - } - - public void shaderWithPattern( String shadedPattern, File jar, String[] excludes ) - throws Exception - { - Shader s = new DefaultShader(); - - Set set = new HashSet(); - - set.add( new File( "src/test/jars/test-project-1.0-SNAPSHOT.jar" ) ); - - set.add( new File( "src/test/jars/plexus-utils-1.4.1.jar" ) ); - - List relocators = new ArrayList(); - - relocators.add( new SimpleRelocator( "org/codehaus/plexus/util", shadedPattern, Arrays.asList( excludes ) ) ); - - List resourceTransformers = new ArrayList(); - - resourceTransformers.add( new ComponentsXmlResourceTransformer() ); - - List filters = new ArrayList(); - - s.shade( set, jar, filters, relocators, resourceTransformers ); - } - -} +package org.apache.maven.plugins.shade; + +/* + * 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.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.net.URLClassLoader; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.maven.plugins.shade.relocation.SimpleRelocator; +import org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer; + +/** + * @author Jason van Zyl + * @author Mauro Talevi + */ +public class DefaultShaderTest + extends TestCase +{ + private static final String[] EXCLUDES = new String[] { + "org/codehaus/plexus/util/xml/Xpp3Dom", + "org/codehaus/plexus/util/xml/pull.*" }; + + public void testShaderWithDefaultShadedPattern() + throws Exception + { + shaderWithPattern( null, new File( "target/foo-default.jar" ), EXCLUDES ); + } + + public void testShaderWithStaticInitializedClass() + throws Exception + { + Shader s = new DefaultShader(); + + Set set = new HashSet(); + + set.add( new File( "src/test/jars/test-artifact-1.0-SNAPSHOT.jar" ) ); + + List relocators = new ArrayList(); + + relocators.add( new SimpleRelocator( "org.apache.maven.plugins.shade", null, null ) ); + + List resourceTransformers = new ArrayList(); + + List filters = new ArrayList(); + + File file = new File( "target/testShaderWithStaticInitializedClass.jar" ); + s.shade( set, file, filters, relocators, resourceTransformers ); + + URLClassLoader cl = new URLClassLoader( new URL[]{file.toURL()} ); + Class c = cl.loadClass( "hidden.org.apache.maven.plugins.shade.Lib" ); + Object o = c.newInstance(); + assertEquals( "foo.bar/baz", c.getDeclaredField( "CONSTANT" ).get( o ) ); + } + + public void testShaderWithCustomShadedPattern() + throws Exception + { + shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom.jar" ), EXCLUDES ); + } + + public void testShaderWithoutExcludesShouldRemoveReferencesOfOriginalPattern() + throws Exception + { + //FIXME: shaded jar should not include references to org/codehaus/* (empty dirs) or org.codehaus.* META-INF files. + shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom-without-excludes.jar" ), new String[] {} ); + } + + public void shaderWithPattern( String shadedPattern, File jar, String[] excludes ) + throws Exception + { + Shader s = new DefaultShader(); + + Set set = new HashSet(); + + set.add( new File( "src/test/jars/test-project-1.0-SNAPSHOT.jar" ) ); + + set.add( new File( "src/test/jars/plexus-utils-1.4.1.jar" ) ); + + List relocators = new ArrayList(); + + relocators.add( new SimpleRelocator( "org/codehaus/plexus/util", shadedPattern, Arrays.asList( excludes ) ) ); + + List resourceTransformers = new ArrayList(); + + resourceTransformers.add( new ComponentsXmlResourceTransformer() ); + + List filters = new ArrayList(); + + s.shade( set, jar, filters, relocators, resourceTransformers ); + } + +} diff --git a/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java b/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java index 8bf6722f..2e98f728 100644 --- a/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java @@ -1,79 +1,79 @@ -package org.apache.maven.plugins.shade.mojo; - -/* - * 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.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.maven.plugins.shade.Shader; -import org.apache.maven.plugins.shade.relocation.SimpleRelocator; -import org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer; -import org.codehaus.plexus.PlexusTestCase; - - -/** - * @author Jason van Zyl - * @author Mauro Talevi - */ -public class ShadeMojoTest - extends PlexusTestCase -{ - public void testShaderWithDefaultShadedPattern() - throws Exception - { - shaderWithPattern(null, new File( "target/foo-default.jar" )); - } - - public void testShaderWithCustomShadedPattern() - throws Exception - { - shaderWithPattern("org/shaded/plexus/util", new File( "target/foo-custom.jar" )); - } - - public void shaderWithPattern(String shadedPattern, File jar) - throws Exception - { - Shader s = (Shader) lookup( Shader.ROLE ); - - Set set = new HashSet(); - - set.add( new File( getBasedir(), "src/test/jars/test-project-1.0-SNAPSHOT.jar" ) ); - - set.add( new File( getBasedir(), "src/test/jars/plexus-utils-1.4.1.jar" ) ); - - List relocators = new ArrayList(); - - relocators.add( new SimpleRelocator( "org/codehaus/plexus/util", shadedPattern, Arrays.asList( - new String[]{"org/codehaus/plexus/util/xml/Xpp3Dom", "org/codehaus/plexus/util/xml/pull.*"} ) ) ); - - List resourceTransformers = new ArrayList(); - - resourceTransformers.add( new ComponentsXmlResourceTransformer() ); - - List filters = new ArrayList(); - - s.shade( set, jar, filters, relocators, resourceTransformers ); - } - -} +package org.apache.maven.plugins.shade.mojo; + +/* + * 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.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.plugins.shade.Shader; +import org.apache.maven.plugins.shade.relocation.SimpleRelocator; +import org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer; +import org.codehaus.plexus.PlexusTestCase; + + +/** + * @author Jason van Zyl + * @author Mauro Talevi + */ +public class ShadeMojoTest + extends PlexusTestCase +{ + public void testShaderWithDefaultShadedPattern() + throws Exception + { + shaderWithPattern(null, new File( "target/foo-default.jar" )); + } + + public void testShaderWithCustomShadedPattern() + throws Exception + { + shaderWithPattern("org/shaded/plexus/util", new File( "target/foo-custom.jar" )); + } + + public void shaderWithPattern(String shadedPattern, File jar) + throws Exception + { + Shader s = (Shader) lookup( Shader.ROLE ); + + Set set = new HashSet(); + + set.add( new File( getBasedir(), "src/test/jars/test-project-1.0-SNAPSHOT.jar" ) ); + + set.add( new File( getBasedir(), "src/test/jars/plexus-utils-1.4.1.jar" ) ); + + List relocators = new ArrayList(); + + relocators.add( new SimpleRelocator( "org/codehaus/plexus/util", shadedPattern, Arrays.asList( + new String[]{"org/codehaus/plexus/util/xml/Xpp3Dom", "org/codehaus/plexus/util/xml/pull.*"} ) ) ); + + List resourceTransformers = new ArrayList(); + + resourceTransformers.add( new ComponentsXmlResourceTransformer() ); + + List filters = new ArrayList(); + + s.shade( set, jar, filters, relocators, resourceTransformers ); + } + +} diff --git a/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java b/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java new file mode 100644 index 00000000..06595816 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java @@ -0,0 +1,93 @@ +package org.apache.maven.plugins.shade.relocation; + +import java.util.Arrays; + +import junit.framework.TestCase; + +/** + * Test for {@link SimpleRelocator}. + * + * @author Benjamin Bentmann + * @version $Id$ + */ +public class SimpleRelocatorTest + extends TestCase +{ + + public void testCanRelocatePath() + { + SimpleRelocator relocator; + + relocator = new SimpleRelocator( "org.foo", null, null ); + assertEquals( true, relocator.canRelocatePath( "org/foo/Class" ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/Class.class" ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/bar/Class" ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/bar/Class.class" ) ); + assertEquals( false, relocator.canRelocatePath( "com/foo/bar/Class" ) ); + assertEquals( false, relocator.canRelocatePath( "com/foo/bar/Class.class" ) ); + assertEquals( false, relocator.canRelocatePath( "org/Foo/Class" ) ); + assertEquals( false, relocator.canRelocatePath( "org/Foo/Class.class" ) ); + + relocator = + new SimpleRelocator( "org.foo", null, Arrays.asList( new String[] { "org.foo.Excluded", "org.foo.public.*", + "org.foo.Public*Stuff" } ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/Class" ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/Class.class" ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/excluded" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/Excluded" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/Excluded.class" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/public/Class" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/public/Class.class" ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/PrivateStuff" ) ); + assertEquals( true, relocator.canRelocatePath( "org/foo/PrivateStuff.class" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/PublicStuff" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/PublicStuff.class" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/PublicUtilStuff" ) ); + assertEquals( false, relocator.canRelocatePath( "org/foo/PublicUtilStuff.class" ) ); + } + + public void testCanRelocateClass() + { + SimpleRelocator relocator; + + relocator = new SimpleRelocator( "org.foo", null, null ); + assertEquals( true, relocator.canRelocateClass( "org.foo.Class" ) ); + assertEquals( true, relocator.canRelocateClass( "org.foo.bar.Class" ) ); + assertEquals( false, relocator.canRelocateClass( "com.foo.bar.Class" ) ); + assertEquals( false, relocator.canRelocateClass( "org.Foo.Class" ) ); + + relocator = + new SimpleRelocator( "org.foo", null, Arrays.asList( new String[] { "org.foo.Excluded", "org.foo.public.*", + "org.foo.Public*Stuff" } ) ); + assertEquals( true, relocator.canRelocateClass( "org.foo.Class" ) ); + assertEquals( true, relocator.canRelocateClass( "org.foo.excluded" ) ); + assertEquals( false, relocator.canRelocateClass( "org.foo.Excluded" ) ); + assertEquals( false, relocator.canRelocateClass( "org.foo.public.Class" ) ); + assertEquals( true, relocator.canRelocateClass( "org.foo.PrivateStuff" ) ); + assertEquals( false, relocator.canRelocateClass( "org.foo.PublicStuff" ) ); + assertEquals( false, relocator.canRelocateClass( "org.foo.PublicUtilStuff" ) ); + } + + public void testRelocatePath() + { + SimpleRelocator relocator; + + relocator = new SimpleRelocator( "org.foo", null, null ); + assertEquals( "hidden/org/foo/bar/Class.class", relocator.relocatePath( "org/foo/bar/Class.class" ) ); + + relocator = new SimpleRelocator( "org.foo", "private.stuff", null ); + assertEquals( "private/stuff/bar/Class.class", relocator.relocatePath( "org/foo/bar/Class.class" ) ); + } + + public void testRelocateClass() + { + SimpleRelocator relocator; + + relocator = new SimpleRelocator( "org.foo", null, null ); + assertEquals( "hidden.org.foo.bar.Class", relocator.relocateClass( "org.foo.bar.Class" ) ); + + relocator = new SimpleRelocator( "org.foo", "private.stuff", null ); + assertEquals( "private.stuff.bar.Class", relocator.relocateClass( "org.foo.bar.Class" ) ); + } + +} diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformerTest.java b/src/test/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformerTest.java new file mode 100644 index 00000000..c0709095 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformerTest.java @@ -0,0 +1,41 @@ +package org.apache.maven.plugins.shade.resource; + +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Test for {@link ApacheLicenseResourceTransformer}. + * + * @author Benjamin Bentmann + * @version $Id$ + */ +public class ApacheLicenseResourceTransformerTest + extends TestCase +{ + + private ApacheLicenseResourceTransformer transformer; + + static + { + /* + * NOTE: The Turkish locale has an usual case transformation for the letters "I" and "i", making it a prime + * choice to test for improper case-less string comparisions. + */ + Locale.setDefault( new Locale( "tr" ) ); + } + + public void setUp() + { + this.transformer = new ApacheLicenseResourceTransformer(); + } + + public void testCanTransformResource() + { + assertTrue( this.transformer.canTransformResource( "META-INF/LICENSE" ) ); + assertTrue( this.transformer.canTransformResource( "META-INF/LICENSE.TXT" ) ); + assertTrue( this.transformer.canTransformResource( "META-INF/License.txt" ) ); + assertFalse( this.transformer.canTransformResource( "META-INF/MANIFEST.MF" ) ); + } + +} diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerTest.java b/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerTest.java new file mode 100644 index 00000000..9e35a039 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerTest.java @@ -0,0 +1,41 @@ +package org.apache.maven.plugins.shade.resource; + +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Test for {@link ApacheNoticeResourceTransformer}. + * + * @author Benjamin Bentmann + * @version $Id$ + */ +public class ApacheNoticeResourceTransformerTest + extends TestCase +{ + + private ApacheNoticeResourceTransformer transformer; + + static + { + /* + * NOTE: The Turkish locale has an usual case transformation for the letters "I" and "i", making it a prime + * choice to test for improper case-less string comparisions. + */ + Locale.setDefault( new Locale( "tr" ) ); + } + + public void setUp() + { + this.transformer = new ApacheNoticeResourceTransformer(); + } + + public void testCanTransformResource() + { + assertTrue( this.transformer.canTransformResource( "META-INF/NOTICE" ) ); + assertTrue( this.transformer.canTransformResource( "META-INF/NOTICE.TXT" ) ); + assertTrue( this.transformer.canTransformResource( "META-INF/Notice.txt" ) ); + assertFalse( this.transformer.canTransformResource( "META-INF/MANIFEST.MF" ) ); + } + +} diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/AppendingTransformerTest.java b/src/test/java/org/apache/maven/plugins/shade/resource/AppendingTransformerTest.java new file mode 100644 index 00000000..65b39011 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/shade/resource/AppendingTransformerTest.java @@ -0,0 +1,42 @@ +package org.apache.maven.plugins.shade.resource; + +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Test for {@link AppendingTransformer}. + * + * @author Benjamin Bentmann + * @version $Id$ + */ +public class AppendingTransformerTest + extends TestCase +{ + + private AppendingTransformer transformer; + + static + { + /* + * NOTE: The Turkish locale has an usual case transformation for the letters "I" and "i", making it a prime + * choice to test for improper case-less string comparisions. + */ + Locale.setDefault( new Locale( "tr" ) ); + } + + public void setUp() + { + this.transformer = new AppendingTransformer(); + } + + public void testCanTransformResource() + { + this.transformer.resource = "abcdefghijklmnopqrstuvwxyz"; + + assertTrue( this.transformer.canTransformResource( "abcdefghijklmnopqrstuvwxyz" ) ); + assertTrue( this.transformer.canTransformResource( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ); + assertFalse( this.transformer.canTransformResource( "META-INF/MANIFEST.MF" ) ); + } + +} diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformerTest.java b/src/test/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformerTest.java new file mode 100644 index 00000000..6a653e80 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformerTest.java @@ -0,0 +1,42 @@ +package org.apache.maven.plugins.shade.resource; + +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Test for {@link XmlAppendingTransformer}. + * + * @author Benjamin Bentmann + * @version $Id$ + */ +public class XmlAppendingTransformerTest + extends TestCase +{ + + private XmlAppendingTransformer transformer; + + static + { + /* + * NOTE: The Turkish locale has an usual case transformation for the letters "I" and "i", making it a prime + * choice to test for improper case-less string comparisions. + */ + Locale.setDefault( new Locale( "tr" ) ); + } + + public void setUp() + { + this.transformer = new XmlAppendingTransformer(); + } + + public void testCanTransformResource() + { + this.transformer.resource = "abcdefghijklmnopqrstuvwxyz"; + + assertTrue( this.transformer.canTransformResource( "abcdefghijklmnopqrstuvwxyz" ) ); + assertTrue( this.transformer.canTransformResource( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ); + assertFalse( this.transformer.canTransformResource( "META-INF/MANIFEST.MF" ) ); + } + +} diff --git a/src/test/projects/no-relocation-project/pom.xml b/src/test/projects/no-relocation-project/pom.xml index a0e15a07..9fe92293 100644 --- a/src/test/projects/no-relocation-project/pom.xml +++ b/src/test/projects/no-relocation-project/pom.xml @@ -1,66 +1,66 @@ - - - - - 4.0.0 - org.apache.maven.plugins.shade - no-relocation-project - no-relocation-project - jar - 1.0-SNAPSHOT - http://maven.apache.org - - - org.apache.maven.plugins.shade - test-project - ${pom.version} - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - classworlds:classworlds - junit:junit - jmock:jmock - xml-apis:xml-apis - - - - - - - - - - - - + + + + + 4.0.0 + org.apache.maven.plugins.shade + no-relocation-project + no-relocation-project + jar + 1.0-SNAPSHOT + http://maven.apache.org + + + org.apache.maven.plugins.shade + test-project + ${pom.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + classworlds:classworlds + junit:junit + jmock:jmock + xml-apis:xml-apis + + + + + + + + + + + + diff --git a/src/test/projects/shaded-attached-project/pom.xml b/src/test/projects/shaded-attached-project/pom.xml index 0512662f..eccd1558 100644 --- a/src/test/projects/shaded-attached-project/pom.xml +++ b/src/test/projects/shaded-attached-project/pom.xml @@ -1,78 +1,78 @@ - - - - - 4.0.0 - org.apache.maven.plugins.shade - shaded-attached-project - shaded-attached-project - jar - 1.0-SNAPSHOT - http://maven.apache.org - - - org.apache.maven.plugins.shade - test-project - ${pom.version} - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - shaded-artifact - true - jackofall - - - classworlds:classworlds - junit:junit - jmock:jmock - xml-apis:xml-apis - - - - - org.codehaus.plexus.util - - org.codehaus.plexus.util.xml.Xpp3Dom - org.codehaus.plexus.util.xml.pull.* - - - - - - - - - - - - - + + + + + 4.0.0 + org.apache.maven.plugins.shade + shaded-attached-project + shaded-attached-project + jar + 1.0-SNAPSHOT + http://maven.apache.org + + + org.apache.maven.plugins.shade + test-project + ${pom.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + shaded-artifact + true + jackofall + + + classworlds:classworlds + junit:junit + jmock:jmock + xml-apis:xml-apis + + + + + org.codehaus.plexus.util + + org.codehaus.plexus.util.xml.Xpp3Dom + org.codehaus.plexus.util.xml.pull.* + + + + + + + + + + + + + diff --git a/src/test/projects/shaded-project/pom.xml b/src/test/projects/shaded-project/pom.xml index 1304afe9..8775def0 100644 --- a/src/test/projects/shaded-project/pom.xml +++ b/src/test/projects/shaded-project/pom.xml @@ -1,76 +1,76 @@ - - - - - 4.0.0 - org.apache.maven.plugins.shade - shaded-project - shaded-project - jar - 1.0-SNAPSHOT - http://maven.apache.org - - - org.apache.maven.plugins.shade - test-project - ${pom.version} - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - classworlds:classworlds - junit:junit - jmock:jmock - xml-apis:xml-apis - - - - + + + + + 4.0.0 + org.apache.maven.plugins.shade + shaded-project + shaded-project + jar + 1.0-SNAPSHOT + http://maven.apache.org + + + org.apache.maven.plugins.shade + test-project + ${pom.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + classworlds:classworlds + junit:junit + jmock:jmock + xml-apis:xml-apis + + + + org.codehaus.plexus.util - org.shaded.plexus.util - - org.codehaus.plexus.util.xml.Xpp3Dom - org.codehaus.plexus.util.xml.pull.* - - - - - - - - - - - - - + org.shaded.plexus.util + + org.codehaus.plexus.util.xml.Xpp3Dom + org.codehaus.plexus.util.xml.pull.* + + + + + + + + + + + + + diff --git a/src/test/projects/test-project/pom.xml b/src/test/projects/test-project/pom.xml index a65330ca..43360098 100644 --- a/src/test/projects/test-project/pom.xml +++ b/src/test/projects/test-project/pom.xml @@ -1,48 +1,48 @@ - - - - - 4.0.0 - org.apache.maven.plugins.shade - test-project - test-project - jar - 1.0-SNAPSHOT - http://maven.apache.org - - - ${project.groupId} - test-artifact - ${project.version} - - - org.codehaus.plexus - plexus-utils - 1.4.1 - - - junit - junit - 3.8.1 - test - - - + + + + + 4.0.0 + org.apache.maven.plugins.shade + test-project + test-project + jar + 1.0-SNAPSHOT + http://maven.apache.org + + + ${project.groupId} + test-artifact + ${project.version} + + + org.codehaus.plexus + plexus-utils + 1.4.1 + + + junit + junit + 3.8.1 + test + + + diff --git a/src/test/projects/test-project/src/main/java/org/apache/maven/plugins/shade/App.java b/src/test/projects/test-project/src/main/java/org/apache/maven/plugins/shade/App.java index 5cb4aaed..53723e55 100644 --- a/src/test/projects/test-project/src/main/java/org/apache/maven/plugins/shade/App.java +++ b/src/test/projects/test-project/src/main/java/org/apache/maven/plugins/shade/App.java @@ -1,35 +1,35 @@ -/* - * 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 org.apache.maven.plugins.shade; - -import org.codehaus.plexus.util.*; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - - StringUtils.isEmpty( "foo" ); - } -} +/* + * 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 org.apache.maven.plugins.shade; + +import org.codehaus.plexus.util.*; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + + StringUtils.isEmpty( "foo" ); + } +} diff --git a/src/test/projects/test-project/src/main/resources/META-INF/plexus/components.xml b/src/test/projects/test-project/src/main/resources/META-INF/plexus/components.xml index 24103c73..7e5dbfbf 100644 --- a/src/test/projects/test-project/src/main/resources/META-INF/plexus/components.xml +++ b/src/test/projects/test-project/src/main/resources/META-INF/plexus/components.xml @@ -1,209 +1,209 @@ - - - - - - org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout - default - org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout - - - - org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout - legacy - org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout - - - - - org.apache.maven.artifact.handler.manager.ArtifactHandlerManager - org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager - - - org.apache.maven.artifact.handler.ArtifactHandler - artifactHandlers - - - - - - org.apache.maven.artifact.handler.ArtifactHandler - ejb - org.apache.maven.artifact.handler.DefaultArtifactHandler - - ejb - jar - java - true - - - - - org.apache.maven.artifact.handler.ArtifactHandler - jar - org.apache.maven.artifact.handler.DefaultArtifactHandler - - jar - java - true - - - - - org.apache.maven.artifact.handler.ArtifactHandler - test-jar - org.apache.maven.artifact.handler.DefaultArtifactHandler - - tests - jar - test-jar - jar - java - true - - - - - org.apache.maven.artifact.handler.ArtifactHandler - maven-plugin - org.apache.maven.artifact.handler.DefaultArtifactHandler - - maven-plugin - jar - java - true - - - - - org.apache.maven.artifact.handler.ArtifactHandler - pom - org.apache.maven.artifact.handler.DefaultArtifactHandler - - pom - - - - - org.apache.maven.artifact.handler.ArtifactHandler - java-source - org.apache.maven.artifact.handler.DefaultArtifactHandler - - sources - java-source - jar - java - false - - - - - org.apache.maven.artifact.handler.ArtifactHandler - javadoc - org.apache.maven.artifact.handler.DefaultArtifactHandler - - javadoc - javadoc - jar - java - true - - - - - org.apache.maven.artifact.handler.ArtifactHandler - war - org.apache.maven.artifact.handler.DefaultArtifactHandler - - war - true - java - false - - - - - org.apache.maven.artifact.handler.ArtifactHandler - ear - org.apache.maven.artifact.handler.DefaultArtifactHandler - - ear - true - java - false - - - - - org.apache.maven.artifact.handler.ArtifactHandler - ejb-client - org.apache.maven.artifact.handler.DefaultArtifactHandler - - ejb-client - jar - ejb - client - java - true - - - - - org.apache.maven.artifact.handler.ArtifactHandler - par - org.apache.maven.artifact.handler.DefaultArtifactHandler - - par - java - true - - - - - org.apache.maven.artifact.handler.ArtifactHandler - ejb3 - org.apache.maven.artifact.handler.DefaultArtifactHandler - - ejb3 - java - true - - - - - org.apache.maven.artifact.factory.ArtifactFactory - org.apache.maven.artifact.factory.DefaultArtifactFactory - - - org.apache.maven.artifact.handler.manager.ArtifactHandlerManager - - - - - - org.apache.maven.artifact.resolver.ArtifactCollector - org.apache.maven.artifact.resolver.DefaultArtifactCollector - - - + + + + + + org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout + default + org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout + + + + org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout + legacy + org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout + + + + + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager + + + org.apache.maven.artifact.handler.ArtifactHandler + artifactHandlers + + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ejb + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ejb + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + jar + org.apache.maven.artifact.handler.DefaultArtifactHandler + + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + test-jar + org.apache.maven.artifact.handler.DefaultArtifactHandler + + tests + jar + test-jar + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + maven-plugin + org.apache.maven.artifact.handler.DefaultArtifactHandler + + maven-plugin + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + pom + org.apache.maven.artifact.handler.DefaultArtifactHandler + + pom + + + + + org.apache.maven.artifact.handler.ArtifactHandler + java-source + org.apache.maven.artifact.handler.DefaultArtifactHandler + + sources + java-source + jar + java + false + + + + + org.apache.maven.artifact.handler.ArtifactHandler + javadoc + org.apache.maven.artifact.handler.DefaultArtifactHandler + + javadoc + javadoc + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + war + org.apache.maven.artifact.handler.DefaultArtifactHandler + + war + true + java + false + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ear + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ear + true + java + false + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ejb-client + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ejb-client + jar + ejb + client + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + par + org.apache.maven.artifact.handler.DefaultArtifactHandler + + par + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ejb3 + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ejb3 + java + true + + + + + org.apache.maven.artifact.factory.ArtifactFactory + org.apache.maven.artifact.factory.DefaultArtifactFactory + + + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + + + + + org.apache.maven.artifact.resolver.ArtifactCollector + org.apache.maven.artifact.resolver.DefaultArtifactCollector + + + diff --git a/src/test/projects/test-project/src/test/java/org/apache/maven/plugins/shade/AppTest.java b/src/test/projects/test-project/src/test/java/org/apache/maven/plugins/shade/AppTest.java index a1641b16..9dc26f3d 100644 --- a/src/test/projects/test-project/src/test/java/org/apache/maven/plugins/shade/AppTest.java +++ b/src/test/projects/test-project/src/test/java/org/apache/maven/plugins/shade/AppTest.java @@ -1,56 +1,56 @@ -/* - * 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 org.apache.maven.plugins.shade; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} +/* + * 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 org.apache.maven.plugins.shade; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/static-remapper.txt b/static-remapper.txt index 102f984c..b55c19a7 100644 --- a/static-remapper.txt +++ b/static-remapper.txt @@ -1,62 +1,62 @@ - /* - ClassVisitor cv = null; - Remapper remapper = null; - - RemappingClassAdapter a = new RemappingClassAdapter( cv, remapper ) - { - protected MethodVisitor createRemappingMethodAdapter( int access, - String newDesc, - MethodVisitor mv ) - { - final MethodVisitor rmv = super.createRemappingMethodAdapter( access, newDesc, mv ); - return new MethodNode() - { - public void visitEnd() - { - Analyzer an = new Analyzer( new SourceInterpreter() ); - try - { - Frame[] frames = an.analyze( className, this ); - // Elements of the frames array now contains info for each instruction - // from the analyzed method. - for ( int i = 0; i < frames.length; i++ ) - { - Frame frame = frames[i]; - AbstractInsnNode insn = instructions.get( i ); - if ( insn.getOpcode() == Opcodes.INVOKEVIRTUAL ) - { - MethodInsnNode minsn = (MethodInsnNode) insn; - if ( minsn.name.equals( "getResource" ) && minsn.owner.equals( "java/lang/Class" ) ) - { - // now check where params come from (top of the stack) - SourceValue value = (SourceValue) frames[i].getStack( 0 ); - Set sources = value.insns; // instructions that produced this value - for ( Iterator it = sources.iterator(); it.hasNext(); ) - { - AbstractInsnNode source = (AbstractInsnNode) it.next(); - if ( source.getOpcode() == Opcodes.LDC ) - { - LdcInsnNode constant = (LdcInsnNode) source; - // can change constant.cst value here - } - else - { - // can log something about value that came not from the constant - } - } - } - } - } - // got your mapping. can remap now. replaying recorded method - accept( rmv ); - } - catch ( AnalyzerException ex ) - { - // TODO Auto-generated catch block - ex.printStackTrace(); - } - } - }; - } - }; + /* + ClassVisitor cv = null; + Remapper remapper = null; + + RemappingClassAdapter a = new RemappingClassAdapter( cv, remapper ) + { + protected MethodVisitor createRemappingMethodAdapter( int access, + String newDesc, + MethodVisitor mv ) + { + final MethodVisitor rmv = super.createRemappingMethodAdapter( access, newDesc, mv ); + return new MethodNode() + { + public void visitEnd() + { + Analyzer an = new Analyzer( new SourceInterpreter() ); + try + { + Frame[] frames = an.analyze( className, this ); + // Elements of the frames array now contains info for each instruction + // from the analyzed method. + for ( int i = 0; i < frames.length; i++ ) + { + Frame frame = frames[i]; + AbstractInsnNode insn = instructions.get( i ); + if ( insn.getOpcode() == Opcodes.INVOKEVIRTUAL ) + { + MethodInsnNode minsn = (MethodInsnNode) insn; + if ( minsn.name.equals( "getResource" ) && minsn.owner.equals( "java/lang/Class" ) ) + { + // now check where params come from (top of the stack) + SourceValue value = (SourceValue) frames[i].getStack( 0 ); + Set sources = value.insns; // instructions that produced this value + for ( Iterator it = sources.iterator(); it.hasNext(); ) + { + AbstractInsnNode source = (AbstractInsnNode) it.next(); + if ( source.getOpcode() == Opcodes.LDC ) + { + LdcInsnNode constant = (LdcInsnNode) source; + // can change constant.cst value here + } + else + { + // can log something about value that came not from the constant + } + } + } + } + } + // got your mapping. can remap now. replaying recorded method + accept( rmv ); + } + catch ( AnalyzerException ex ) + { + // TODO Auto-generated catch block + ex.printStackTrace(); + } + } + }; + } + }; */ \ No newline at end of file