1 /* 2 * $HeadURL: https://mindtreeinsight.svn.sourceforge.net/svnroot/mindtreeinsight/releng/maven-nsis-plugin/branches/maven-nsis-plugin-0.2.0/src/main/java/com/mindtree/techworks/insight/releng/mvn/nsis/mojos/AbstractNsisMojo.java $ 3 * 4 * Copyright (c) 2007 MindTree Consulting Ltd. 5 * 6 * This file is part of Insight Release Engineering Tools. 7 * 8 * Insight Release Engineering Tools is free software: you can redistribute it 9 * and/or modify it under the terms of the GNU General Public License as 10 * published by the Free Software Foundation, either version 3 of the License, 11 * or (at your option) any later version. 12 * 13 * Insight Release Engineering Tools is distributed in the hope that it will be 14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 16 * Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License along with 19 * Insight Release Engineering Tools. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package com.mindtree.techworks.insight.releng.mvn.nsis.mojos; 22 23 import java.io.File; 24 import java.io.IOException; 25 26 import org.apache.maven.plugin.AbstractMojo; 27 import org.apache.maven.plugin.MojoExecutionException; 28 import org.apache.maven.plugin.MojoFailureException; 29 import org.apache.maven.project.MavenProject; 30 import org.apache.maven.project.MavenProjectHelper; 31 32 import com.mindtree.techworks.insight.releng.mvn.nsis.actions.MojoInfo; 33 import com.mindtree.techworks.insight.releng.mvn.nsis.actions.NsisAction; 34 import com.mindtree.techworks.insight.releng.mvn.nsis.io.ProjectFileReader; 35 import com.mindtree.techworks.insight.releng.mvn.nsis.model.NsisProject; 36 37 /** 38 * Abstract mojo to share common configuration 39 * 40 * @author <a href="mailto:bindul_bhowmik@mindtree.com">Bindul Bhowmik</a> 41 * @version $Revision: 233 $ $Date: 2009-03-27 09:44:18 -0600 (Fri, 27 Mar 2009) $ 42 * 43 */ 44 public abstract class AbstractNsisMojo extends AbstractMojo implements MojoInfo { 45 46 /** 47 * The project file reader to parse the xml file 48 * @component 49 */ 50 private ProjectFileReader projectFileReader; 51 52 /** 53 * The NSIS project file 54 * @parameter 55 * @required 56 */ 57 private File projectFile; 58 59 /** 60 * The maven project we are working in 61 * 62 * @parameter default-value="${project}" 63 * @required 64 * @readonly 65 */ 66 private MavenProject project; 67 68 /** 69 * The maven project helper to attach the artifacts 70 * 71 * @component 72 */ 73 private MavenProjectHelper projectHelper; 74 75 /** 76 * The temporary build directory 77 * 78 * @parameter default-value="${project.build.directory}/nsis-work" 79 */ 80 private File workDirectory; 81 82 /** 83 * Nsis Project parsed 84 */ 85 protected NsisProject nsisProject; 86 87 /** 88 * The action to load the defaults 89 * 90 * @component role-hint="load-default" 91 */ 92 private NsisAction loadDefaultsAction; 93 94 /** 95 * Specifies the location where the makensis.exe executable is present 96 * 97 * @parameter expression="${nsisPath}" 98 */ 99 private File nsisPath; 100 101 /** 102 * The NSIS executable. On windows systems this is usually 103 * <code>makensis.exe</code>, and the parameter defaults to that value. This 104 * parameter allows the mojo to be run on *nix systems where the compiled 105 * NSIS filename may not have the <i>.exe</i> extension; the user can 106 * override the executable name. Even on a windows if someone has renamed 107 * the makensis file, this parameter can be used to pass that value. 108 * 109 * @parameter expression="${nsisExec}" default-value="makensis" 110 */ 111 private String nsisExec; 112 113 /* (non-Javadoc) 114 * @see org.apache.maven.plugin.Mojo#execute() 115 */ 116 public void execute() throws MojoExecutionException, MojoFailureException { 117 // Get the location of the project file and parse it. 118 getLog().info("Using project file: " + projectFile.getAbsolutePath()); 119 120 try { 121 getLog().debug("Parsing project file- " + projectFile.getAbsolutePath()); 122 nsisProject = projectFileReader.readProject(projectFile); 123 } catch (IOException e) { 124 // Failed to parse the project xml file 125 getLog().error("Invalid Project Xml file", e); 126 throw new MojoExecutionException("Invalid Project Xml file"); 127 } 128 129 // Generate the temporary directory 130 if (!workDirectory.exists()) { 131 boolean tempDirCreationResult = workDirectory.mkdirs(); 132 if (!tempDirCreationResult) { 133 throw new MojoExecutionException( 134 "Unable to create temporary directory: " 135 + workDirectory.getAbsolutePath()); 136 } 137 } 138 139 // Load the defaults into the nsis project 140 loadDefaultsAction.execute(this); 141 142 // Call the Mojo 143 executeNsisMojo(); 144 } 145 146 /** 147 * Executes the mojo actions 148 * 149 * @see org.apache.maven.plugin.Mojo#execute() 150 */ 151 public abstract void executeNsisMojo() throws MojoExecutionException, MojoFailureException; 152 153 /* (non-Javadoc) 154 * @see com.mindtree.techworks.insight.releng.mvn.nsis.actions.MojoInfo#getNsisProject() 155 */ 156 public NsisProject getNsisProject() { 157 return nsisProject; 158 } 159 160 /* (non-Javadoc) 161 * @see com.mindtree.techworks.insight.releng.mvn.nsis.actions.MojoInfo#getProject() 162 */ 163 public MavenProject getProject() { 164 return project; 165 } 166 167 /* (non-Javadoc) 168 * @see com.mindtree.techworks.insight.releng.mvn.nsis.actions.MojoInfo#getWorkDirectory() 169 */ 170 public File getWorkDirectory() { 171 return workDirectory; 172 } 173 174 /* (non-Javadoc) 175 * @see com.mindtree.techworks.insight.releng.mvn.nsis.actions.MojoInfo#getNsisPath() 176 */ 177 public File getNsisPath() { 178 return nsisPath; 179 } 180 181 /* (non-Javadoc) 182 * @see com.mindtree.techworks.insight.releng.mvn.nsis.actions.MojoInfo#getProjectHelper() 183 */ 184 public MavenProjectHelper getProjectHelper() { 185 return projectHelper; 186 } 187 188 /* (non-Javadoc) 189 * @see com.mindtree.techworks.insight.releng.mvn.nsis.actions.MojoInfo#getNsisExecutable() 190 */ 191 public String getNsisExecutable() { 192 return nsisExec; 193 } 194 }