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

com.greenpepper.util.cmdline.CommandLineBuilder Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
package com.greenpepper.util.cmdline;

import java.io.File;
import java.util.Collection;

import org.apache.commons.lang3.StringUtils;

import com.greenpepper.server.GreenPepperServerException;

import static org.apache.commons.lang3.StringUtils.splitByWholeSeparator;

/**
 * 

CommandLineBuilder class.

* * @author oaouattara * @version $Id: $Id */ public class CommandLineBuilder { private String[] cmdLine; /** *

Constructor for CommandLineBuilder.

* * @param cmdLineTemplate a {@link java.lang.String} object. */ public CommandLineBuilder(String cmdLineTemplate) { this.cmdLine = splitByWholeSeparator(cmdLineTemplate," "); } /** *

Getter for the field cmdLine.

* * @return an array of {@link java.lang.String} objects. */ public String[] getCmdLine() { return cmdLine; } /** *

setMainClass.

* * @param mainClass a {@link java.lang.String} object. */ public void setMainClass(String mainClass) { replace("${mainClass}", mainClass); } /** *

setInputPath.

* * @param inputPath a {@link java.lang.String} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ public void setInputPath(String inputPath) throws GreenPepperServerException { replace("${inputPath}", inputPath); } /** *

setOutpuPath.

* * @param outputPath a {@link java.lang.String} object. */ public void setOutpuPath(String outputPath) { replace("${outputPath}", outputPath); } /** *

setDependencies.

* * @param dependencies a {@link java.util.Collection} object. */ public void setDependencies(Collection dependencies) { StringBuilder sb = new StringBuilder(""); for(String dependency : dependencies) { sb.append(dependency); sb.append(File.pathSeparator); } replace("${classpaths}", sb.toString()); } /** *

setSections.

* * @param sections a {@link java.lang.String} object. */ public void setSections(String sections) { if(!StringUtils.isEmpty(sections)) addOption("-t", sections); } /** *

setLocale.

* * @param locale a {@link java.lang.String} object. */ public void setLocale(String locale) { replace("${locale}", locale); } /** *

setRepository.

* * @param repository a {@link java.lang.String} object. */ public void setRepository(String repository) { replace("${repository}", repository); } /** *

setFixtureFactory.

* * @param fixtureFactory a {@link java.lang.String} object. */ public void setFixtureFactory(String fixtureFactory) { replace("${fixtureFactory}", fixtureFactory); } /** * * @param fixtureFactoryArgs the argument of the fixture factory */ public void setFixtureFactoryArgs(String fixtureFactoryArgs) { replace("${fixtureFactoryArgs}", fixtureFactoryArgs); } /** *

setProjectDependencyDescriptor.

* * @param projectDependencyDescriptor a {@link java.lang.String} object. */ public void setProjectDependencyDescriptor(String projectDependencyDescriptor) { replace("${projectDependencyDescriptor}", projectDependencyDescriptor); } private void addOption(String cmd, String args) { String[] newCmdLine = new String[cmdLine.length + 2]; System.arraycopy(cmdLine, 0, newCmdLine, 0, cmdLine.length); newCmdLine[newCmdLine.length - 2] = cmd; newCmdLine[newCmdLine.length - 1] = args; cmdLine = newCmdLine; } private void replace(String name, String value) { final String replacement = value == null ? "" : value; for(int i = 0; i < cmdLine.length; i++) { cmdLine[i] = cmdLine[i].replace(name, replacement); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy