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

com.nathanaelrota.cmmi.maven.requirements.RequirementExec Maven / Gradle / Ivy

The newest version!
package com.nathanaelrota.cmmi.maven.requirements;

import java.io.File;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

public class RequirementExec {
	   /**
	    * @parameter expression="traceability" 
	    */
	   static private String traceability="traceability";
	   
	   /**
	    * @parameter expression="html"
	    */
	   static private String format="html";
	   
	   /**
	    * @parameter expression="${project.reporting.outputDirectory}"
	    */
	   static private String outputDirectory="target/site";

	   /**
	    * @parameter expression="${project.build.directory}/test-classes/"
	    */
	   static private String testDirectory="target/test-classes";

	   /**
	    * TestCase File Pattern
	    */
	   static private String testPattern = ".*Test.class";
	   
	   /**
	    * @parameter expression="${project.build.directory}/classes/"
	    */
	   static private String mainDirectory="target/classes";

	   /**
	    * TestCase File Pattern
	    */
	   static private String classPattern = ".*.class";
	   
	   /**
	    * @parameter expression="${basedir}/src/main/resources"
	    */
	   static private String inputDirectory="src/main/resources";
	   
	   /**
	    * @parameter expression="${project.name}"
	    */
	   static private String project="Project";
	   
	   /**
	    * @parameter expression="requirements.xml"
	    */
	   static private String requirements="requirements.xml";
	   
	   /**
	    * @parameter expression="false"
	    */
	   static private Boolean surefireReport = true;
	   
	static CommandLineParser parser = new PosixParser();
	
	public static void usageAndExit(Options options) {
		HelpFormatter helpFormatter = new HelpFormatter();
		helpFormatter.printHelp("Maven Migration Tool", options);
		System.exit(0);
	}
	
	public static void parseOptions(String[] args) {
		Options options = new Options();
		options.addOption("t", true, " : traceability (default: traceability)");
		options.addOption("f", true, " : format (default: html)");
		options.addOption("o", true, " : outputDirectory (default: target/site/)");
		options.addOption("k", true, " : testDirectory (default: target/test-classes)");
		options.addOption("c", true, " : mainDirectory (default: target/classes)");
		options.addOption("i", true, " : inputDirectory (default: src/main/resources)");
		options.addOption("p", true, " : project (default: Project)");
		options.addOption("r", true, " : requirements (default: requirements.xml)");
		options.addOption("s", false, "         : surefireReport=false (default: true)");
		
		options.addOption("h", false, "Give this Help");

		try {
			CommandLine commandLine = parser.parse(options, args);
			if (commandLine.hasOption('h')) {
				usageAndExit(options);
			}
			if (commandLine.hasOption('t')) {
				traceability = commandLine.getOptionValue('t');
			}
			if (commandLine.hasOption('f')) {
				format = commandLine.getOptionValue('f');
			}
			if (commandLine.hasOption('o')) {
				outputDirectory = commandLine.getOptionValue('o');
			}
			if (commandLine.hasOption('k')) {
				testDirectory = commandLine.getOptionValue('k');
			}
			if (commandLine.hasOption('c')) {
				mainDirectory = commandLine.getOptionValue('c');
			}
			if (commandLine.hasOption('i')) {
				inputDirectory = commandLine.getOptionValue('i');
			}
			if (commandLine.hasOption('p')) {
				project = commandLine.getOptionValue('p');
			}
			if (commandLine.hasOption('r')) {
				requirements = commandLine.getOptionValue('r');
			}
			if (commandLine.hasOption('s')) {
				surefireReport = false;
			}

		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
	      File f = new File(outputDirectory);
	      if (!f.exists()) {
	         f.mkdirs();
	      }
	      String traceabilityFilename = outputDirectory + File.separator + traceability + "." + format;
	      String requirementsFilename = inputDirectory + File.separator + requirements;
	      RequirementMojoDelegate delegate = new RequirementMojoDelegate();
	      delegate.setSurefireReport(surefireReport.booleanValue());
	      delegate.setFormat(format);
	      delegate.setProjectName(project);
	      delegate.execute(requirementsFilename, testDirectory, testPattern, mainDirectory, classPattern, traceabilityFilename);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy