use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceBlameCommand method executeBlameCommand.
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
// Call annotate command
PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, workingDirectory.getBasedir());
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, workingDirectory.getBasedir(), filename, clientspec);
PerforceBlameConsumer blameConsumer = new PerforceBlameConsumer(getLogger());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cl, blameConsumer, stderr);
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new BlameScmResult(cl.toString(), "The perforce command failed.", stderr.getOutput(), false);
}
// Call filelog command
cl = createFilelogCommandLine((PerforceScmProviderRepository) repo, workingDirectory.getBasedir(), filename, clientspec);
PerforceFilelogConsumer filelogConsumer = new PerforceFilelogConsumer(getLogger());
try {
exitCode = CommandLineUtils.executeCommandLine(cl, filelogConsumer, stderr);
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new BlameScmResult(cl.toString(), "The perforce command failed.", stderr.getOutput(), false);
}
// Combine results
List<BlameLine> lines = blameConsumer.getLines();
for (int i = 0; i < lines.size(); i++) {
BlameLine line = lines.get(i);
String revision = line.getRevision();
line.setAuthor(filelogConsumer.getAuthor(revision));
line.setDate(filelogConsumer.getDate(revision));
}
return new BlameScmResult(cl.toString(), lines);
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceBlameCommand method createFilelogCommandLine.
public static Commandline createFilelogCommandLine(PerforceScmProviderRepository repo, File workingDirectory, String filename, final String clientspec) {
Commandline cl = PerforceScmProvider.createP4Command(repo, workingDirectory);
if (clientspec != null) {
cl.createArg().setValue("-c");
cl.createArg().setValue(clientspec);
}
cl.createArg().setValue("filelog");
cl.createArg().setValue(filename);
return cl;
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceChangeLogCommand method executeChangeLogCommand.
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion) throws ScmException {
PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, fileSet.getBasedir());
Commandline cl = createCommandLine(p4repo, fileSet.getBasedir(), clientspec, null, startDate, endDate, startVersion, endVersion);
String location = PerforceScmProvider.getRepoPath(getLogger(), p4repo, fileSet.getBasedir());
PerforceChangesConsumer consumer = new PerforceChangesConsumer(getLogger());
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);
}
}
List<String> changes = consumer.getChanges();
cl = PerforceScmProvider.createP4Command(p4repo, fileSet.getBasedir());
cl.createArg().setValue("describe");
cl.createArg().setValue("-s");
for (String change : changes) {
cl.createArg().setValue(change);
}
PerforceDescribeConsumer describeConsumer = new PerforceDescribeConsumer(location, datePattern, getLogger());
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, describeConsumer, 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);
}
}
ChangeLogSet cls = new ChangeLogSet(describeConsumer.getModifications(), null, null);
cls.setStartVersion(startVersion);
cls.setEndVersion(endVersion);
return new ChangeLogScmResult(cl.toString(), cls);
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion scmVersion) throws ScmException {
// In Perforce, there is no difference between update and checkout.
// Here we just run the checkout command and map the result onto an
// UpdateScmResult.
PerforceCheckOutCommand command = new PerforceCheckOutCommand();
command.setLogger(getLogger());
CommandParameters params = new CommandParameters();
params.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
CheckOutScmResult cosr = (CheckOutScmResult) command.execute(repo, files, params);
if (!cosr.isSuccess()) {
return new UpdateScmResult(cosr.getCommandLine(), cosr.getProviderMessage(), cosr.getCommandOutput(), false);
}
PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, files.getBasedir());
Commandline cl = createCommandLine(p4repo, files.getBasedir(), clientspec);
@SuppressWarnings("unused") String location = PerforceScmProvider.getRepoPath(getLogger(), p4repo, files.getBasedir());
PerforceHaveConsumer consumer = new PerforceHaveConsumer(getLogger());
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 new UpdateScmResultWithRevision(cosr.getCommandLine(), cosr.getCheckedOutFiles(), String.valueOf(consumer.getHave()));
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceChangeLogCommandTest method testCommandLineRevs.
private void testCommandLineRevs(String commandLine, ScmVersion version1, ScmVersion version2) throws Exception {
ScmRepository repository = getScmManager().makeScmRepository("scm:perforce://depot/projects/pathname");
PerforceScmProviderRepository repo = (PerforceScmProviderRepository) repository.getProviderRepository();
Commandline cl = PerforceChangeLogCommand.createCommandLine(repo, workingDirectory, System.getProperty(PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY), null, null, null, version1, version2);
assertCommandLine(commandLine, null, cl);
}
Aggregations