use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceStatusCommand method readOpened.
private Commandline readOpened(PerforceScmProviderRepository prepo, ScmFileSet files, PerforceStatusConsumer consumer) {
Commandline cl = createOpenedCommandLine(prepo, files.getBasedir(), actualLocation);
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
if (exitCode != 0) {
String cmdLine = CommandLineUtils.toString(cl.getCommandline());
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
msg.append('\n');
msg.append("Command line was:" + cmdLine);
throw new CommandLineException(msg.toString());
}
} catch (CommandLineException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("CommandLineException " + e.getMessage(), e);
}
}
return cl;
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceTagCommand method createLabel.
private void createLabel(ScmProviderRepository repo, ScmFileSet files, String tag, PerforceTagConsumer consumer, boolean lock) {
Commandline cl = createLabelCommandLine((PerforceScmProviderRepository) repo, files.getBasedir());
DataOutputStream dos = null;
InputStreamReader isReader = null;
InputStreamReader isReaderErr = null;
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing: " + cl.toString()));
}
Process proc = cl.execute();
OutputStream out = proc.getOutputStream();
dos = new DataOutputStream(out);
String label = createLabelSpecification((PerforceScmProviderRepository) repo, tag, lock);
if (getLogger().isDebugEnabled()) {
getLogger().debug("LabelSpec: " + NEWLINE + label);
}
dos.write(label.getBytes());
dos.close();
out.close();
// TODO find & use a less naive InputStream multiplexer
isReader = new InputStreamReader(proc.getInputStream());
isReaderErr = new InputStreamReader(proc.getErrorStream());
BufferedReader stdout = new BufferedReader(isReader);
BufferedReader stderr = new BufferedReader(isReaderErr);
String line;
while ((line = stdout.readLine()) != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Consuming stdout: " + line);
}
consumer.consumeLine(line);
}
while ((line = stderr.readLine()) != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Consuming stderr: " + line);
}
consumer.consumeLine(line);
}
stderr.close();
stdout.close();
} catch (CommandLineException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("CommandLineException " + e.getMessage(), e);
}
} catch (IOException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("IOException " + e.getMessage(), e);
}
} finally {
IOUtil.close(dos);
IOUtil.close(isReader);
IOUtil.close(isReaderErr);
}
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceTagCommand method createLabelsyncCommandLine.
public static Commandline createLabelsyncCommandLine(PerforceScmProviderRepository repo, File workingDirectory, ScmFileSet files, String tag) {
Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
command.createArg().setValue("labelsync");
command.createArg().setValue("-l");
command.createArg().setValue(tag);
List<File> fs = files.getFileList();
for (File file : fs) {
command.createArg().setValue(file.getPath());
}
return command;
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceTagCommand method syncLabel.
private void syncLabel(ScmProviderRepository repo, ScmFileSet files, String tag, PerforceTagConsumer consumer) {
Commandline cl = createLabelsyncCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files, tag);
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing: " + cl.toString()));
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
if (exitCode != 0) {
String cmdLine = CommandLineUtils.toString(cl.getCommandline());
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
msg.append('\n');
msg.append("Command line was:" + cmdLine);
throw new CommandLineException(msg.toString());
}
} catch (CommandLineException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("CommandLineException " + e.getMessage(), e);
}
}
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceTagCommand method createLabelCommandLine.
public static Commandline createLabelCommandLine(PerforceScmProviderRepository repo, File workingDirectory) {
Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
command.createArg().setValue("label");
command.createArg().setValue("-i");
return command;
}
Aggregations