All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.processpuzzle.maven.plugin.fitnesse.mojo.SetUpMojo Maven / Gradle / Ivy

The newest version!
package com.processpuzzle.maven.plugin.fitnesse.mojo;

import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;

import java.util.ArrayList;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.twdata.maven.mojoexecutor.MojoExecutor.Attribute;
import org.twdata.maven.mojoexecutor.MojoExecutor.Attributes;
import org.twdata.maven.mojoexecutor.MojoExecutor.Element;

import com.processpuzzle.maven.plugin.fitnesse.util.FitNesseHelper;

/**
 * This Mojo is devoted simply to fetching and unpacking
 * FitNesse into a correct working directory structure, and
 * making sure everything is cleanly setup for running FitNesse.
 *
 * @goal set-up
 * @phase pre-integration-test
 */
public class SetUpMojo extends AbstractSetupsMojo {
	
	static final String FIT_ROOT = "Resources/" + FitNesseHelper.DEFAULT_ROOT;
    
	static final String FIT_FILES = "fitnesse/resources";
    
	/**
	 * If set, fitnesse-launcher-maven-plugin will delete any existing plugins.properties
	 * file as part of setting up a clean fitnesse environment.
	 * If you need to retain the plugin.properties file, set this property to false.
	 * 
	 * @parameter property="fitnesse.deletePluginsProperties" default-value="false"
	 */
    protected boolean deletePluginsProperties;
    
	/**
	 * If set, fitnesse-launcher-maven-plugin will always freshly unpack
	 * the FitNesse jar, as part of setting up a clean fitnesse environment.
	 * 
	 * @parameter property="fitnesse.alwaysUnpackFitnesse" default-value="false"
	 */
    protected boolean alwaysUnpackFitnesse;
    
	@Override
    public final void execute() throws MojoExecutionException {
    	if(this.deletePluginsProperties) {
		    clean();
    	}
		unpack();
		move();
    }
    
	/**
	 * 
	 * {@code
	 * 
	 * 		maven-clean-plugin
	 * 		
	 * 			
	 * 				pre-integration-test
	 * 				
	 * 					clean
	 * 				
	 * 				
	 * 					true
	 * 					
	 * 						
	 * 							${fitnesse.working}
	 * 							
	 * 								plugins.properties
	 * 							
	 * 							false
	 * 						
	 * 					
	 * 				
	 * 			
	 * 		
	 * 
	 * }
	 * 
*/ final void clean() throws MojoExecutionException { executeMojo( plugin("org.apache.maven.plugins:maven-clean-plugin"), goal("clean"), configuration( element("excludeDefaultDirectories", "true"), element("filesets", element("fileset", element("directory", this.workingDir), element("includes", element("include", "plugins.properties")), element("followSymlinks", "false")))), executionEnvironment(project, session, pluginManager) ); } /** *
	 * {@code
	 * 
	 * 		maven-dependency-plugin
	 * 		2.4
	 * 		
	 * 			
	 * 				pre-integration-test
	 * 				
	 * 					unpack
	 * 				
	 * 				
	 * 					
	 * 						
	 * 							org.fitnesse
	 * 							fitnesse
	 * 							20130530
	 * 							jar
	 * 							false
	 * 							${fitnesse.working}
	 * 							Resources/FitNesseRoot/**
	 * 						
	 * 						
	 * 							org.fitnesse
	 * 							fitnesse
	 * 							20130530
	 * 							jar
	 * 							false
	 * 							${fitnesse.working}/${fitnesse.root}/files
	 * 							fitnesse/resources/**
	 * 						
	 * 					
	 * 				
	 * 			
	 * 		
	 * 
	 * }
	 * 
*/ final void unpack() throws MojoExecutionException { final Artifact artifact = this.pluginDescriptor.getArtifactMap().get(FitNesseMavenCoordinate.artifactKey); executeMojo( plugin("org.apache.maven.plugins:maven-dependency-plugin"), goal("unpack"), configuration( element("artifactItems", artifactItem(this.workingDir, includes(FIT_ROOT), artifact), artifactItem(workingFiles(null), includes(FIT_FILES), artifact))), executionEnvironment(project, session, pluginManager) ); } private Element artifactItem(final String outputDirectory, final String includes, final Artifact artifact) { return element("artifactItem", element("groupId", artifact.getGroupId()), element("artifactId", artifact.getArtifactId()), element("version", artifact.getVersion()), element("type", "jar"), element("overWrite", Boolean.toString(this.alwaysUnpackFitnesse)), element("outputDirectory", outputDirectory), element("includes", includes)); } private String includes(final String includes) { return includes + "/**"; } /** *
	 * {@code
	 * 
	 *     org.apache.maven.plugins
	 *     maven-antrun-plugin
	 *     
	 *         
	 *             pre-integration-test
	 *             
	 *                 run
	 *             
	 *             
	 *                 
	 *                     
	 *                     
	 *                         
	 *                             
	 *                         
	 *                     
	 *                 
	 *             
	 *         
	 *     
	 * 
	 * }
	 * 
*/ final void move() throws MojoExecutionException { executeMojo( plugin("org.apache.maven.plugins:maven-antrun-plugin"), goal("run"), //config, configuration( element("target", element("move", move(this.workingDir, new Attribute("file", this.workingDir + "/" + FIT_ROOT))), element("move", move(workingFiles(null)), element("fileset", new Attribute("dir", workingFiles(FIT_FILES)), element("include", new Attribute("name", "**/*")))))), executionEnvironment(project, session, pluginManager) ); } private Attributes move(final String todir, final Attribute... additional) { final List list = new ArrayList(); list.add(new Attribute("todir", todir)); list.add(new Attribute("failonerror", "false")); list.add(new Attribute("overwrite", "false")); for(Attribute a : additional) { list.add(a); } return new Attributes(list.toArray(new Attribute[list.size()])); } private String workingFiles(final String additional) { final StringBuilder sb = new StringBuilder(this.workingDir); sb.append("/"); sb.append(this.root); sb.append("/files"); if(additional != null) { sb.append("/"); sb.append(additional); } return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy