use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class CvsJavaUpdateCommand method executeCvsCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeCvsCommand(Commandline cl) throws ScmException {
CvsLogListener logListener = new CvsLogListener();
CvsUpdateConsumer consumer = new CvsUpdateConsumer(getLogger());
try {
boolean isSuccess = CvsConnection.processCommand(cl.getArguments(), cl.getWorkingDirectory().getAbsolutePath(), logListener, getLogger());
if (!isSuccess) {
return new UpdateScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
}
BufferedReader stream = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(logListener.getStdout().toString().getBytes())));
String line;
while ((line = stream.readLine()) != null) {
consumer.consumeLine(line);
}
} catch (Exception e) {
e.printStackTrace();
return new UpdateScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
}
return new UpdateScmResult(cl.toString(), consumer.getUpdatedFiles());
}
use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class CvsUpdateCommandTest method testCvsUpdate.
/**
* @todo merge into tck
*/
public void testCvsUpdate() throws Exception {
FileWriter writer = null;
try {
if (!isSystemCmd(CvsScmTestUtils.CVS_COMMAND_LINE)) {
System.err.println("'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + ".");
return;
}
ScmManager scmManager = getScmManager();
String scmUrl = CvsScmTestUtils.getScmUrl(repository, getModule());
// Check out the repo to a working directory where files will be modified and committed
String arguments = "-f -d " + repository.getAbsolutePath() + " " + "co -d " + workingDirectory.getName() + " " + getModule();
CvsScmTestUtils.executeCVS(workingDirectory.getParentFile(), arguments);
// Check out the repo to a assertion directory where the command will be used
arguments = "-f -d " + repository.getAbsolutePath() + " " + "co -d " + assertionDirectory.getName() + " " + getModule();
CvsScmTestUtils.executeCVS(assertionDirectory.getParentFile(), arguments);
// A new check out should return 0 updated files.
ScmRepository scmRepository = scmManager.makeScmRepository(scmUrl);
UpdateScmResult result = scmManager.update(scmRepository, new ScmFileSet(assertionDirectory));
assertNotNull(result);
if (!result.isSuccess()) {
System.out.println("result.providerMessage: " + result.getProviderMessage());
System.out.println("result.commandOutput: " + result.getCommandOutput());
fail("Command failed");
}
assertNull(result.getProviderMessage());
assertNull(result.getCommandOutput());
assertNotNull(result.getUpdatedFiles());
assertEquals(0, result.getUpdatedFiles().size());
// Modifing a file
File fooJava = new File(workingDirectory, "Foo.java");
String content = FileUtils.fileRead(fooJava);
writer = new FileWriter(fooJava);
writer.write(content + System.getProperty("line.separator"));
writer.write("extra line");
writer.close();
// Adding a new file
writer = new FileWriter(new File(workingDirectory, "New.txt"));
writer.write("new file");
writer.close();
arguments = "-f -d " + repository.getAbsolutePath() + " add New.txt";
CvsScmTestUtils.executeCVS(workingDirectory, arguments);
// Committing
arguments = "-f -d " + repository.getAbsolutePath() + " commit -m .";
CvsScmTestUtils.executeCVS(workingDirectory, arguments);
// Check the updated files
result = scmManager.update(scmRepository, new ScmFileSet(assertionDirectory));
assertNotNull(result);
if (!result.isSuccess()) {
System.out.println("result.providerMessage: " + result.getProviderMessage());
System.out.println("result.commandOutput: " + result.getCommandOutput());
fail("Command failed");
}
assertNull(result.getProviderMessage());
assertNull(result.getCommandOutput());
assertNotNull(result.getUpdatedFiles());
assertEquals(2, result.getUpdatedFiles().size());
ScmFile file1 = result.getUpdatedFiles().get(0);
assertPath("Foo.java", file1.getPath());
assertEquals(ScmFileStatus.UPDATED, file1.getStatus());
ScmFile file2 = result.getUpdatedFiles().get(1);
assertPath("New.txt", file2.getPath());
assertEquals(ScmFileStatus.UPDATED, file2.getStatus());
} finally {
IOUtil.close(writer);
}
}
use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class IntegrityUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
@Override
public UpdateScmResult executeUpdateCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
getLogger().info("Attempting to synchronize sandbox in " + fileSet.getBasedir().getAbsolutePath());
List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
Sandbox siSandbox = iRepo.getSandbox();
try {
// Make sure we've got a valid sandbox, otherwise create it...
if (siSandbox.create()) {
Response res = siSandbox.resync();
// Lets capture what we got from running this resync
WorkItemIterator wit = res.getWorkItems();
while (wit.hasNext()) {
WorkItem wi = wit.next();
if (wi.getModelType().equals(SIModelTypeName.MEMBER)) {
Result message = wi.getResult();
getLogger().debug(wi.getDisplayId() + " " + (null != message ? message.getMessage() : ""));
if (null != message && message.getMessage().length() > 0) {
updatedFiles.add(new ScmFile(wi.getDisplayId(), message.getMessage().equalsIgnoreCase("removed") ? ScmFileStatus.DELETED : ScmFileStatus.UPDATED));
}
}
}
return new UpdateScmResult(res.getCommandString(), updatedFiles);
} else {
return new UpdateScmResult("si resync", "Failed to synchronize workspace", "", false);
}
} catch (APIException aex) {
ExceptionHandler eh = new ExceptionHandler(aex);
getLogger().error("MKS API Exception: " + eh.getMessage());
getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
return new UpdateScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
}
use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class SvnUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version);
SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
}
}
int exitCode;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new UpdateScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
UpdateScmResultWithRevision result = new UpdateScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
result.setChanges(consumer.getChangeSets());
if (getLogger().isDebugEnabled()) {
getLogger().debug("changeSets " + consumer.getChangeSets());
}
return result;
}
use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class SynergyScmProvider method update.
/**
* {@inheritDoc}
*/
public UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
SynergyUpdateCommand command = new SynergyUpdateCommand();
command.setLogger(getLogger());
return (UpdateScmResult) command.execute(repository, fileSet, parameters);
}
Aggregations