package com.github.sixro;

import java.io.*;

import org.apache.commons.io.*;
import org.apache.maven.plugin.*;

/**
 * Goal which touches a timestamp file.
 *
 * @goal package
 * @phase install
 */
public class PackageMojo extends AbstractMojo {
	
	/**
	 * The system.
	 * 
	 * @parameter expression="${vodafonecanvass.system}"
	 * @required
	 */
	private String system;

	/**
	 * The version.
	 * 
	 * @parameter expression="${vodafonecanvass.version}"
	 * @required
	 */
	private String version;

	/**
	 * The canvass date in format {@code yyyyMMdd}.
	 * 
	 * @parameter expression="${vodafonecanvass.date}"
	 * @required
	 */
	private String date;

    /**
     * Location of the output directory.
     * 
     * @parameter expression="${project.build.directory}/vodafonecanvass"
     * @required
     */
    private File outputDirectory;
    
    /**
     * Release notes template.
     * 
     * <p>
     * It is a word document where some parts has to be changed. E.g. version, system 
     * the list of files released, etc...
     * </p>
     * 
     * @parameter expression="${vodafonecanvass.releasenotes.template}"
     * @required
     */
    private File releaseNotesTemplate;
    
    private VodafoneCanvass vodafoneCanvass = new VodafoneCanvass();    

	public void execute() throws MojoExecutionException {
    	getLog().info("Packaging for Vodafone Canvass");
    	getLog().info("  Release Notes Template .......: " + releaseNotesTemplate);
    	
    	if (! outputDirectory.exists())
    		outputDirectory.mkdirs();
    	
    	File releaseNotes = new File(outputDirectory, vodafoneCanvass.standardFileName(releaseNotesTemplate.getName(), system, version, date));
    	if (releaseNotes.exists()) delete(releaseNotes);
    	copy(releaseNotesTemplate, releaseNotes);
    }

	private void copy(File source, File dest) {
		try {
			FileUtils.copyFile(source, dest);
		} catch (IOException e) {
			throw new RuntimeException("unable to copy source file " + source + " to dest file " + dest, e);
		}
	}

	private void delete(File file) {
		if (! file.delete())
			throw new RuntimeException("unable to delete file " + file);
	}
    
}

@@ -152,16 +152,17 @@
 file.%0A *
+ 
 %0A * @goa
@@ -241,17 +241,16 @@
 tMojo %7B%0A
-%09
 %0A%09/**%0A%09 
@@ -646,28 +646,22 @@
  date;%0A%0A
-    /**%0A    
+%09/**%0A%09
  * Locat
@@ -689,28 +689,22 @@
 ectory.%0A
-     * %0A    
+%09 * %0A%09
  * @para
@@ -765,20 +765,17 @@
 anvass%22%0A
-    
+%09
  * @requ
@@ -775,36 +775,30 @@
 * @required%0A
-     */%0A    
+%09 */%0A%09
 private File
@@ -819,25 +819,15 @@
 ry;%0A
-    %0A    /**%0A    
+%0A%09/**%0A%09
  * R
@@ -853,31 +853,22 @@
 te.%0A
-     * %0A    
+%09 * %0A%09
  * %3Cp%3E%0A
-    
+%09
  * I
@@ -941,16 +941,20 @@
 ion,
+%0A%09 *
  system 
 %0A   
@@ -949,24 +949,16 @@
  system 
-%0A     * 
 the list
@@ -988,20 +988,17 @@
 ...%0A
-    
+%09
  * %3C/p%3E%0A
     
@@ -997,20 +997,14 @@
 /p%3E%0A
-     * %0A    
+%09 * %0A%09
  * @
@@ -1067,20 +1067,17 @@
 plate%7D%22%0A
-    
+%09
  * @requ
@@ -1085,20 +1085,14 @@
 red%0A
-     */%0A    
+%09 */%0A%09
 priv
@@ -1126,17 +1126,10 @@
 te;%0A
-    %0A    
+%0A%09
 priv
@@ -1188,20 +1188,16 @@
 nvass();
-    
 %0A%0A%09publi
@@ -1245,20 +1245,17 @@
 ption %7B%0A
-    
+%09
 %09getLog(
@@ -1296,20 +1296,17 @@
 vass%22);%0A
-    
+%09
 %09getLog(
@@ -1378,25 +1378,16 @@
 e);%0A
-    %09%0A    
+%0A%09
 %09if (!
- 
 outp
@@ -1408,20 +1408,17 @@
 ists())%0A
-    
+%09
 %09%09output
@@ -1441,18 +1441,10 @@
 ();%0A
-    %09%0A    
+%0A%09
 %09Fil
@@ -1576,20 +1576,17 @@
 date));%0A
-    
+%09
 %09if (rel
@@ -1604,17 +1604,20 @@
 xists())
- 
+%0A%09%09%09
 delete(r
@@ -1630,20 +1630,17 @@
 Notes);%0A
-    
+%09
 %09copy(re
@@ -1674,20 +1674,17 @@
 Notes);%0A
-    
+%09
 %7D%0A%0A%09priv
@@ -1945,17 +1945,16 @@
 %0A%09%09if (!
- 
 file.del
@@ -2031,11 +2031,7 @@
 %0A%09%7D%0A
-    
 %0A%7D%0A

Reformat of the code