本文整理汇总了Java中org.codehaus.plexus.util.cli.CommandLineException类的典型用法代码示例。如果您正苦于以下问题:Java CommandLineException类的具体用法?Java CommandLineException怎么用?Java CommandLineException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandLineException类属于org.codehaus.plexus.util.cli包,在下文中一共展示了CommandLineException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
/**
* Run the build, push, and generate dockerrun.aws.json file goals sequentially.
* @throws MojoExecutionException if execution fails.
*/
public void execute() throws MojoExecutionException {
final Properties properties = initializePropertiesForGoals();
final List<String> goals = Arrays.asList(
"magic-beanstalk:build",
"magic-beanstalk:push",
"magic-beanstalk:genCustomDockerrun",
"magic-beanstalk:zip");
final InvocationRequest invocationRequest = createInvocationRequestWithGoals(goals, properties);
final Invoker invoker = new DefaultInvoker();
setupInvokerLogger(invoker);
try {
final InvocationResult invocationResult = invoker.execute(invocationRequest);
if (invocationResult.getExitCode() != 0) {
String msg = "Invocation Exception";
if (invocationResult.getExecutionException() != null) {
msg = invocationResult.getExecutionException().getMessage();
}
throw new CommandLineException(msg);
}
} catch (MavenInvocationException | CommandLineException e) {
throw new MojoExecutionException("Failed to execute goals", e);
}
}
示例2: execute
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
this.log.info("Starting release build.");
try {
InvocationRequest request = setupInvocationRequest();
Invoker invoker = setupInvoker();
InvocationResult result = invoker.execute(request);
if (result.getExitCode() != 0) {
CommandLineException executionException = result.getExecutionException();
if (executionException != null) {
throw new MojoFailureException("Error during project build: " + executionException.getMessage(),
executionException);
} else {
throw new MojoFailureException("Error during project build: " + result.getExitCode());
}
}
} catch (MavenInvocationException e) {
throw new MojoFailureException(e.getMessage(), e);
}
}
示例3: invokeMaven
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
private void invokeMaven(File pomFile, String goal) throws CommandLineException, MavenInvocationException
{
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(pomFile);
request.setGoals(Collections.singletonList(goal));
request.setJavaHome(javaHome);
request.setShowErrors(true);
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(mavenHome);
InvocationResult result = invoker.execute(request);
// check status
CommandLineException executionException = result.getExecutionException();
if (executionException != null)
{
throw executionException;
}
assertEquals(0, result.getExitCode());
}
示例4: execute
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
public static void execute( Commandline cl, Logger logger )
throws NativeBuildException
{
int ok;
try
{
DefaultConsumer stdout = new DefaultConsumer();
DefaultConsumer stderr = stdout;
logger.info( cl.toString() );
ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr );
}
catch ( CommandLineException ecx )
{
throw new NativeBuildException( "Error executing command line", ecx );
}
if ( ok != 0 )
{
throw new NativeBuildException( "Error executing command line. Exit code:" + ok );
}
}
示例5: execute
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
private void execute(Commandline jDepsCommand) throws CommandLineException {
StringStreamConsumer errorConsoleConsumer = new StringStreamConsumer();
MojoLogging.logger().debug(format("Running JDeps: %s", jDepsCommand));
MojoLogging.logger().debug(String.format(
"(JDeps output is forwarded here. "
+ "Lines are marked: %s = recognized as dependency; %s = not recognized.)",
ViolationParser.MESSAGE_MARKER_JDEPS_LINE,
ViolationParser.MESSAGE_MARKER_UNKNOWN_LINE));
int exitCode = CommandLineUtils.executeCommandLine(
jDepsCommand, jDepsOutputConsumer::accept, errorConsoleConsumer);
MojoLogging.logger().debug(format("JDeps completed with exit code %d.", exitCode));
if (exitCode != 0)
throwCommandLineException(jDepsCommand, exitCode, errorConsoleConsumer.getOutput());
}
示例6: isSvn18
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
private static boolean isSvn18()
{
Commandline cl = new Commandline();
cl.setExecutable( "svn" );
StringStreamConsumer stdout = new StringStreamConsumer();
StringStreamConsumer stderr = new StringStreamConsumer();
try
{
CommandLineUtils.executeCommandLine( cl, stdout, stderr );
return stdout.getOutput().contains( "svn, version 1.8." );
}
catch ( CommandLineException e )
{
}
return false;
}
示例7: getDotExecutable
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
private static String getDotExecutable() {
Commandline cmd = new Commandline();
String finderExecutable = isWindows() ? "where.exe" : "which";
cmd.setExecutable(finderExecutable);
cmd.addArguments(new String[]{"dot"});
CommandLineUtils.StringStreamConsumer systemOut = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer systemErr = new CommandLineUtils.StringStreamConsumer();
try {
int exitCode = CommandLineUtils.executeCommandLine(cmd, systemOut, systemErr);
if (exitCode != 0) {
return null;
}
} catch (CommandLineException e) {
return null;
}
return systemOut.getOutput();
}
示例8: initGitFlowConfig
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
/**
* Executes git config commands to set Git Flow configuration.
*
* @throws MojoFailureException
* @throws CommandLineException
*/
protected void initGitFlowConfig() throws MojoFailureException,
CommandLineException {
gitSetConfig("gitflow.branch.master",
gitFlowConfig.getProductionBranch());
gitSetConfig("gitflow.branch.develop",
gitFlowConfig.getDevelopmentBranch());
gitSetConfig("gitflow.prefix.feature",
gitFlowConfig.getFeatureBranchPrefix());
gitSetConfig("gitflow.prefix.release",
gitFlowConfig.getReleaseBranchPrefix());
gitSetConfig("gitflow.prefix.hotfix",
gitFlowConfig.getHotfixBranchPrefix());
gitSetConfig("gitflow.prefix.support",
gitFlowConfig.getSupportBranchPrefix());
gitSetConfig("gitflow.prefix.versiontag",
gitFlowConfig.getVersionTagPrefix());
gitSetConfig("gitflow.origin", gitFlowConfig.getOrigin());
}
示例9: gitCommit
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
/**
* Executes git commit -a -m, replacing <code>@{map.key}</code> with
* <code>map.value</code>.
*
* @param message
* Commit message.
* @param map
* Key is a string to replace wrapped in <code>@{...}</code>.
* Value is a string to replace with.
* @throws MojoFailureException
* @throws CommandLineException
*/
protected void gitCommit(String message, Map<String, String> map)
throws MojoFailureException, CommandLineException {
if (map != null) {
for (Entry<String, String> entr : map.entrySet()) {
message = StringUtils.replace(message, "@{" + entr.getKey()
+ "}", entr.getValue());
}
}
if (gpgSignCommit) {
getLog().info("Committing changes. GPG-signed.");
executeGitCommand("commit", "-a", "-S", "-m", message);
} else {
getLog().info("Committing changes.");
executeGitCommand("commit", "-a", "-m", message);
}
}
示例10: gitMerge
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
/**
* Executes git rebase or git merge --ff-only or git merge --no-ff or git merge.
*
* @param branchName
* Branch name to merge.
* @param rebase
* Do rebase.
* @param noff
* Merge with --no-ff.
* @param ffonly
* Merge with --ff-only.
* @throws MojoFailureException
* @throws CommandLineException
*/
protected void gitMerge(final String branchName, boolean rebase, boolean noff, boolean ffonly)
throws MojoFailureException, CommandLineException {
String sign = "";
if (gpgSignCommit) {
sign = "-S";
}
if (rebase) {
getLog().info("Rebasing '" + branchName + "' branch.");
executeGitCommand("rebase", sign, branchName);
} else if (ffonly) {
getLog().info("Merging (--ff-only) '" + branchName + "' branch.");
executeGitCommand("merge", "--ff-only", sign, branchName);
} else if (noff) {
getLog().info("Merging (--no-ff) '" + branchName + "' branch.");
executeGitCommand("merge", "--no-ff", sign, branchName);
} else {
getLog().info("Merging '" + branchName + "' branch.");
executeGitCommand("merge", sign, branchName);
}
}
示例11: gitFetchRemoteAndCompare
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
/**
* Executes git fetch and compares local branch with the remote.
*
* @param branchName
* Branch name to fetch and compare.
* @throws MojoFailureException
* @throws CommandLineException
*/
protected void gitFetchRemoteAndCompare(final String branchName)
throws MojoFailureException, CommandLineException {
if (gitFetchRemote(branchName)) {
getLog().info(
"Comparing local branch '" + branchName + "' with remote '"
+ gitFlowConfig.getOrigin() + "/" + branchName
+ "'.");
String revlistout = executeGitCommandReturn("rev-list",
"--left-right", "--count", branchName + "..."
+ gitFlowConfig.getOrigin() + "/" + branchName);
String[] counts = org.apache.commons.lang3.StringUtils.split(
revlistout, '\t');
if (counts != null && counts.length > 1) {
if (!"0".equals(org.apache.commons.lang3.StringUtils
.deleteWhitespace(counts[1]))) {
throw new MojoFailureException("Remote branch '"
+ gitFlowConfig.getOrigin() + "/" + branchName
+ "' is ahead of the local branch '" + branchName
+ "'. Execute git pull.");
}
}
}
}
示例12: gitFetchRemote
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
/**
* Executes git fetch.
*
* @param branchName
* Branch name to fetch.
* @return <code>true</code> if git fetch returned success exit code,
* <code>false</code> otherwise.
* @throws MojoFailureException
* @throws CommandLineException
*/
private boolean gitFetchRemote(final String branchName)
throws MojoFailureException, CommandLineException {
getLog().info(
"Fetching remote branch '" + gitFlowConfig.getOrigin() + " "
+ branchName + "'.");
CommandResult result = executeGitCommandExitCode("fetch", "--quiet",
gitFlowConfig.getOrigin(), branchName);
boolean success = result.getExitCode() == SUCCESS_EXIT_CODE;
if (!success) {
getLog().warn(
"There were some problems fetching remote branch '"
+ gitFlowConfig.getOrigin()
+ " "
+ branchName
+ "'. You can turn off remote branch fetching by setting the 'fetchRemote' parameter to false.");
}
return success;
}
示例13: gitPushDelete
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
protected void gitPushDelete(final String branchName)
throws MojoFailureException, CommandLineException {
getLog().info(
"Deleting remote branch '" + branchName + "' from '"
+ gitFlowConfig.getOrigin() + "'.");
CommandResult result = executeGitCommandExitCode("push", "--delete",
gitFlowConfig.getOrigin(), branchName);
if (result.getExitCode() != SUCCESS_EXIT_CODE) {
getLog().warn(
"There were some problems deleting remote branch '"
+ branchName + "' from '"
+ gitFlowConfig.getOrigin() + "'.");
}
}
示例14: isInvokerExceptionWithNullDataIfNonZeroExitCodeAndHandlerGetResultThrows
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
@Test
public void isInvokerExceptionWithNullDataIfNonZeroExitCodeAndHandlerGetResultThrows() throws MavenInvocationException {
InvocationResult r = Mockito.mock(InvocationResult.class);
CommandLineException invokerException = new CommandLineException("test error");
IllegalStateException resultException = new IllegalStateException("exception");
Mockito.when(multipleOutputHandler.getResult()).thenThrow(resultException);
Mockito.when(r.getExitCode()).thenReturn(1);
Mockito.when(r.getExecutionException()).thenReturn(invokerException);
Mockito.when(invoker.execute(request)).thenReturn(r);
mavenGoal.setOutputHandlers(new GenericErrorsOutputHandler());
TUExecutionResult result = mavenGoal.execution(new File("/blah/pom.xml"), null);
Assert.assertEquals(result.getException(), invokerException);
Assert.assertEquals(result.getValue(), null);
}
示例15: isInvokerExceptionWithResultDataIfNonZeroExitCodeAndHandlerGetResultIsValid
import org.codehaus.plexus.util.cli.CommandLineException; //导入依赖的package包/类
@Test
public void isInvokerExceptionWithResultDataIfNonZeroExitCodeAndHandlerGetResultIsValid() throws MavenInvocationException {
InvocationResult r = Mockito.mock(InvocationResult.class);
Map<Class<? extends MavenInvocationOutputHandler>, Object> value = new HashMap<Class<? extends MavenInvocationOutputHandler>, Object>();
value.put(new GenericErrorsOutputHandler().getClass(), "Hello!");
CommandLineException invokerException = new CommandLineException("test error");
Mockito.when(multipleOutputHandler.getResult()).thenReturn(value);
Mockito.when(r.getExitCode()).thenReturn(1);
Mockito.when(r.getExecutionException()).thenReturn(invokerException);
Mockito.when(invoker.execute(request)).thenReturn(r);
TUExecutionResult result = mavenGoal.execution(new File("/blah/pom.xml"), null);
Assert.assertEquals(result.getException(), invokerException);
Assert.assertEquals(result.getValue(), value);
}