@@ -0,0 +1,3779 @@
+package org.apache.maven.plugins.shade.resource;%0A%0A/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more contributor license%0A * agreements. See the NOTICE file distributed with this work for additional information regarding%0A * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance with the License. You may obtain a%0A * copy of the License at%0A * %0A * http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software distributed under the License%0A * is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express%0A * or implied. See the License for the specific language governing permissions and limitations under%0A * the License.%0A */%0A%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Iterator;%0Aimport java.util.Properties;%0Aimport java.util.jar.Attributes;%0Aimport java.util.jar.JarEntry;%0Aimport java.util.jar.JarOutputStream;%0Aimport java.util.jar.Manifest;%0A%0Aimport org.codehaus.plexus.util.IOUtil;%0Aimport org.codehaus.plexus.util.StringInputStream;%0A%0Apublic class ManifestResourceTransformer%0A    implements ResourceTransformer%0A%7B%0A    private static final String MANIFEST_PATH = %22META-INF/MANIFEST.MF%22;%0A%0A    // Configuration%0A    private String mainClass;%0A    private Properties additionalAttributes;%0A    %0A    // Fields%0A    private boolean manifestDiscovered;%0A    private Manifest manifest;%0A    %0A    public boolean canTransformResource( String resource )%0A    %7B%0A        if ( MANIFEST_PATH.equalsIgnoreCase( resource ) )%0A        %7B%0A            return true;%0A        %7D%0A%0A        return false;%0A    %7D%0A%0A    public void processResource( InputStream is )%0A        throws IOException%0A    %7B%0A        // We just want to take the first manifest we come across as that's our project's manifest. This is the behavior now%0A        // which is situational at best. Right now there is no context passed in with the processing so we cannot tell what%0A        // artifact is being processed.%0A        if ( !manifestDiscovered )%0A        %7B%0A            manifest = new Manifest( is );%0A            manifestDiscovered = true;%0A        %7D%0A    %7D%0A%0A    public boolean hasTransformedResource()%0A    %7B%0A        return true;%0A    %7D%0A%0A    public void modifyOutputStream( JarOutputStream jos )%0A        throws IOException%0A    %7B%0A        System.out.println( additionalAttributes );%0A        %0A        // If we didn't find a manifest, then let's create one.%0A        if ( manifest == null )%0A        %7B            %0A            manifest = new Manifest();%0A        %7D%0A%0A        Attributes attributes = manifest.getMainAttributes();%0A        %0A        if ( mainClass != null )%0A        %7B%0A            attributes.put( Attributes.Name.MAIN_CLASS, mainClass );                    %0A        %7D%0A        %0A        if ( additionalAttributes != null )%0A        %7B%0A            for ( Iterator i = additionalAttributes.keySet().iterator(); i.hasNext(); )%0A            %7B%0A                String key = (String) i.next();%0A                attributes.put( new Attributes.Name( key ), additionalAttributes.get( key ) );                                    %0A            %7D%0A        %7D%0A        %0A        jos.putNextEntry( new JarEntry( MANIFEST_PATH ) );%0A        StringBuffer sb = new StringBuffer();%0A        for ( Iterator i = attributes.keySet().iterator(); i.hasNext(); )%0A        %7B%0A            Attributes.Name a = (Attributes.Name) i.next();%0A            sb.append( a.toString() ).append(  %22: %22 ).append( attributes.getValue(  a ) ).append( %22%5Cn%22 );%0A        %7D       %0A        InputStream is = new StringInputStream( sb.toString() );%0A        IOUtil.copy( is, jos );%0A        is.close();%0A    %7D    %0A%7D%0A

add a resource transformer that takes care of MANIFEST.MF files