Added result image as archive to the project so
an mvn install/deploy now works.


git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1799963 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/filtered-resources/META-INF/plexus/components.xml b/src/main/filtered-resources/META-INF/plexus/components.xml
index 3a964b9..b98030d 100644
--- a/src/main/filtered-resources/META-INF/plexus/components.xml
+++ b/src/main/filtered-resources/META-INF/plexus/components.xml
@@ -31,7 +31,6 @@
       <configuration>
         <type>jlink</type>
         <extension>zip</extension>
-        <!-- Need to check the following? -->
         <includesDependencies>true</includesDependencies>
         <language>java</language>
         <addedToClasspath>false</addedToClasspath>
@@ -59,8 +58,6 @@
               <package>
                 org.apache.maven.plugins:maven-jlink-plugin:${project.version}:jlink
               </package>
-              <!-- What should be installed?
-              JRE image in zip/tar format? -->
               <install>
                 org.apache.maven.plugins:maven-install-plugin:2.5.2:install
               </install>
diff --git a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
index 271e71a..d4540c5 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
@@ -251,6 +251,7 @@
 

         if ( tc == null )

         {

+            // TODO: Check if we should make the type configurable?

             tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );

         }

 

diff --git a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
index 3b0ba15..1a3e9ed 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -204,7 +204,7 @@
     private ArchiverManager manager;
 
     /**
-     * The kind of archive we should produce.
+     * The kind of archive we will produce.
      */
     @Parameter( defaultValue = "zip", required = true )
     private String archiveType;
@@ -246,7 +246,7 @@
 
         failIfParametersAreNotInTheirValidValueRanges();
 
-        deleteOutputDirectoryIfItAlreadyExists();
+        ifOutputDirectoryExistsDelteIt();
 
         List<Dependency> dependencies = getSession().getCurrentProject().getDependencies();
 
@@ -284,13 +284,25 @@
 
         File createZipArchiveFromImage = createZipArchiveFromImage( outputDirectory, outputDirectoryImage );
 
-        // Set main artifact.
-        getProject().getArtifact().setFile( createZipArchiveFromImage );
-        // artifact.setFile( createZipArchiveFromImage );
-        // getProject().setFile( createZipArchiveFromImage );
-        // packaging is something different than type..
-        // projectHelper.attachArtifact( getProject(), "image", "image", createZipArchiveFromImage );
+        if ( projectHasAlreadySetAnArtifact() )
+        {
+            throw new MojoExecutionException( "You have to use a classifier "
+                + "to attach supplemental artifacts to the project instead of replacing them." );
+        }
 
+        getProject().getArtifact().setFile( createZipArchiveFromImage );
+    }
+
+    private boolean projectHasAlreadySetAnArtifact()
+    {
+        if ( getProject().getArtifact().getFile() != null )
+        {
+            return getProject().getArtifact().getFile().isFile();
+        }
+        else
+        {
+            return false;
+        }
     }
 
     private File createZipArchiveFromImage( File outputDirectory, File outputDirectoryImage )
@@ -396,7 +408,7 @@
         // }
     }
 
-    private void deleteOutputDirectoryIfItAlreadyExists()
+    private void ifOutputDirectoryExistsDelteIt()
         throws MojoExecutionException
     {
         if ( outputDirectoryImage.exists() )