Author: jfallows
Date: Sat Aug 27 04:20:30 2011
New Revision: 1162294

URL: http://svn.apache.org/viewvc?rev=1162294&view=rev
Log:
Add support for overlapping input assembly with output assembly which triggered 
a bug in ILMerge (but not ILRepack).  Also add more configuration to drive 
command line flags.

Modified:
    
incubator/npanday/trunk/plugins/maven-ilmerge-plugin/src/main/java/npanday/plugin/ilmerge/AssemblyMerger.java

Modified: 
incubator/npanday/trunk/plugins/maven-ilmerge-plugin/src/main/java/npanday/plugin/ilmerge/AssemblyMerger.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/maven-ilmerge-plugin/src/main/java/npanday/plugin/ilmerge/AssemblyMerger.java?rev=1162294&r1=1162293&r2=1162294&view=diff
==============================================================================
--- 
incubator/npanday/trunk/plugins/maven-ilmerge-plugin/src/main/java/npanday/plugin/ilmerge/AssemblyMerger.java
 (original)
+++ 
incubator/npanday/trunk/plugins/maven-ilmerge-plugin/src/main/java/npanday/plugin/ilmerge/AssemblyMerger.java
 Sat Aug 27 04:20:30 2011
@@ -104,6 +104,14 @@ public class AssemblyMerger extends Abst
      */
     private String keycontainer;
 
+
+    /**
+     * Copy assembly attributes into the merged assembly. Only the primary 
assembly attributes are copied.
+     *
+     * @parameter default-value = "false"
+     */
+    private boolean copyAttributes;
+
     /**
      * The profile that the compiler should use to compile classes: FULL, 
COMPACT, (or a custom one specified in a
      * compiler-plugins.xml).
@@ -177,6 +185,11 @@ public class AssemblyMerger extends Abst
     private boolean mergeDebugSymbols;
 
     /**
+     * @parameter default-value="true"
+     */
+    private boolean mergeDocumentation;
+
+    /**
      * Defines whether the merged artifact should be attached as classifier to
      * the original artifact.  If false, the merged assembly will be the main 
artifact
      * of the project
@@ -261,7 +274,6 @@ public class AssemblyMerger extends Abst
 
             }
 
-
             ArtifactType packagingType = 
ArtifactType.getArtifactTypeForPackagingName(project.getPackaging());
             File mergedArtifactFile = new File(outputDirectory, 
project.getArtifactId() + "." + packagingType.getExtension());
 
@@ -318,7 +330,15 @@ public class AssemblyMerger extends Abst
             // to avoid a problem during the merge process where it is unable 
to locate the primary assembly
             File artifactFile = (File) artifacts.iterator().next();
             Collection<String> searchDirectoryPaths = Arrays.asList( 
artifactFile.getParent() );
-    
+
+            // ILMerge cannot tolerate overwriting an input assembly with the 
output assembly
+            File mergedArtifactTempDirectory = null;
+            if ( artifacts.contains( mergedArtifactFile ) || 
internalizeArtifacts.contains( mergedArtifactFile ) )
+            {
+                mergedArtifactTempDirectory = new File( 
mergedArtifactFile.getParentFile(), "temp" );
+                mergedArtifactTempDirectory.mkdirs();
+            }
+
             List commands = new ArrayList();
             commands.add("/lib:" + assemblyPath);
 
@@ -327,15 +347,31 @@ public class AssemblyMerger extends Abst
                 commands.add("/lib:" + searchDirectoryPath);
             }
 
-            commands.add("/out:" + mergedArtifactFile);
+            if ( mergedArtifactTempDirectory != null )
+            {
+                File mergedArtifactTempFile = new File( 
mergedArtifactTempDirectory, mergedArtifactFile.getName() );
+                commands.add("/out:" + mergedArtifactTempFile );
+            }
+            else
+            {
+                commands.add("/out:" + mergedArtifactFile);
+            }
+
+            if ( copyAttributes )
+            {
+                commands.add("/copyattrs");
+            }
 
-            // TODO: workaround bug in ILMerge when merged .pdb output would 
overwrite an input .pdb
-            // Note: ILRepack does not have this issue
             if (!mergeDebugSymbols)
             {
                 commands.add("/ndebug");
             }
 
+            if (mergeDocumentation)
+            {
+                commands.add("/xmldocs");
+            }
+
             for ( Iterator it = artifacts.iterator(); it.hasNext(); )
             {
                 File artifact = (File)it.next();
@@ -352,6 +388,22 @@ public class AssemblyMerger extends Abst
             netExecutableFactory.getNetExecutableFor( vendor, 
frameworkVersion, executable, commands,
                                                       netHome ).execute();
 
+            if ( mergedArtifactTempDirectory != null )
+            {
+                File mergedArtifactTempFile = new File( 
mergedArtifactTempDirectory, mergedArtifactFile.getName() );
+                FileUtils.rename( mergedArtifactTempFile, mergedArtifactFile );
+
+                if ( mergeDebugSymbols )
+                {
+                    String mergedArtifactSymbolFileName = 
mergedArtifactFile.getName().replace( ".dll", ".pdb" );
+                    File mergedArtifactSymbolFile = new File( 
mergedArtifactFile.getParentFile(), mergedArtifactSymbolFileName );
+                    File mergedArtifactTempSymbolFile = new File( 
mergedArtifactTempDirectory, mergedArtifactSymbolFileName );
+                    FileUtils.rename( mergedArtifactTempSymbolFile, 
mergedArtifactSymbolFile );
+                }
+
+                FileUtils.deleteDirectory( mergedArtifactTempDirectory );
+            }
+
             if ( mergedArtifactAttached )
             {
                 getLog().info( "Attaching merged artifact." );


Reply via email to