use of org.codehaus.plexus.util.cli.DefaultConsumer in project maven-scm by apache.
the class BootstrapMojo method runGoals.
/**
* @param relativePathProjectDirectory the project directory's path relative to the checkout
* directory; or "" if they are the same
* @throws MojoExecutionException if any
*/
private void runGoals(String relativePathProjectDirectory) throws MojoExecutionException {
Commandline cl = new Commandline();
try {
cl.addSystemEnvironment();
} catch (Exception e) {
throw new MojoExecutionException("Can't add system environment variables to mvn command line.", e);
}
cl.addEnvironment("MAVEN_TERMINATE_CMD", "on");
if (this.mavenHome == null) {
// none windows only
cl.setExecutable("mvn");
} else {
String mvnPath = this.mavenHome.getAbsolutePath() + "/bin/mvn";
if (Os.isFamily("windows")) {
String winMvnPath = mvnPath + ".cmd";
if (!new File(winMvnPath).exists()) {
winMvnPath = mvnPath + ".bat";
}
mvnPath = winMvnPath;
}
cl.setExecutable(mvnPath);
}
cl.setWorkingDirectory(determineWorkingDirectoryPath(//
this.getCheckoutDirectory(), relativePathProjectDirectory, goalsDirectory));
if (this.goals != null) {
String[] tokens = StringUtils.split(this.goals, ", ");
for (int i = 0; i < tokens.length; ++i) {
cl.createArg().setValue(tokens[i]);
}
}
if (!StringUtils.isEmpty(this.profiles)) {
cl.createArg().setValue("-P" + this.profiles);
}
StreamConsumer consumer = new DefaultConsumer();
try {
int result = CommandLineUtils.executeCommandLine(cl, consumer, consumer);
if (result != 0) {
throw new MojoExecutionException("Result of mvn execution is: \'" + result + "\'. Release failed.");
}
} catch (CommandLineException e) {
throw new MojoExecutionException("Can't run goal " + goals, e);
}
}
use of org.codehaus.plexus.util.cli.DefaultConsumer in project tycho by eclipse.
the class SymbolicLinkTest method createSymbolicLink.
private static boolean createSymbolicLink(File target, File link) {
Commandline commandline = new Commandline();
commandline.setWorkingDirectory(link.getParentFile());
commandline.addArguments(new String[] { "ln", "-s", target.getAbsolutePath(), link.getAbsolutePath() });
try {
int result = CommandLineUtils.executeCommandLine(commandline, new DefaultConsumer(), new DefaultConsumer());
return 0 == result && link.exists();
} catch (Throwable e) {
return false;
}
}
use of org.codehaus.plexus.util.cli.DefaultConsumer in project maven-scm by apache.
the class StarteamUpdateCommand method deleteLocal.
private void deleteLocal(StarteamScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
if (fileSet.getFileList().size() != 0) {
return;
}
Commandline cl = createDeleteLocalCommand(repo, fileSet, version);
StreamConsumer consumer = new DefaultConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode = StarteamCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
if (exitCode != 0) {
throw new ScmException("Error executing delete-local: " + stderr.toString());
}
}
use of org.codehaus.plexus.util.cli.DefaultConsumer in project maven-plugins by apache.
the class GpgSigner method generateSignatureForFile.
/**
* {@inheritDoc}
*/
@Override
protected void generateSignatureForFile(File file, File signature) throws MojoExecutionException {
// ----------------------------------------------------------------------------
// Set up the command line
// ----------------------------------------------------------------------------
Commandline cmd = new Commandline();
if (StringUtils.isNotEmpty(executable)) {
cmd.setExecutable(executable);
} else {
cmd.setExecutable("gpg" + (Os.isFamily(Os.FAMILY_WINDOWS) ? ".exe" : ""));
}
if (args != null) {
for (String arg : args) {
cmd.createArg().setValue(arg);
}
}
if (homeDir != null) {
cmd.createArg().setValue("--homedir");
cmd.createArg().setFile(homeDir);
}
if (useAgent) {
cmd.createArg().setValue("--use-agent");
} else {
cmd.createArg().setValue("--no-use-agent");
}
InputStream in = null;
if (null != passphrase) {
// make --passphrase-fd effective in gpg2
cmd.createArg().setValue("--batch");
cmd.createArg().setValue("--passphrase-fd");
cmd.createArg().setValue("0");
// Prepare the input stream which will be used to pass the passphrase to the executable
in = new ByteArrayInputStream(passphrase.getBytes());
}
if (null != keyname) {
cmd.createArg().setValue("--local-user");
cmd.createArg().setValue(keyname);
}
cmd.createArg().setValue("--armor");
cmd.createArg().setValue("--detach-sign");
if (!isInteractive) {
cmd.createArg().setValue("--no-tty");
}
if (!defaultKeyring) {
cmd.createArg().setValue("--no-default-keyring");
}
if (StringUtils.isNotEmpty(secretKeyring)) {
cmd.createArg().setValue("--secret-keyring");
cmd.createArg().setValue(secretKeyring);
}
if (StringUtils.isNotEmpty(publicKeyring)) {
cmd.createArg().setValue("--keyring");
cmd.createArg().setValue(publicKeyring);
}
if ("once".equalsIgnoreCase(lockMode)) {
cmd.createArg().setValue("--lock-once");
} else if ("multiple".equalsIgnoreCase(lockMode)) {
cmd.createArg().setValue("--lock-multiple");
} else if ("never".equalsIgnoreCase(lockMode)) {
cmd.createArg().setValue("--lock-never");
}
cmd.createArg().setValue("--output");
cmd.createArg().setFile(signature);
cmd.createArg().setFile(file);
try {
int exitCode = CommandLineUtils.executeCommandLine(cmd, in, new DefaultConsumer(), new DefaultConsumer());
if (exitCode != 0) {
throw new MojoExecutionException("Exit code: " + exitCode);
}
} catch (CommandLineException e) {
throw new MojoExecutionException("Unable to execute gpg command", e);
}
}
Aggregations