use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class AccurevUpdateCommandTest method testAccuRevFailure.
@Test
public void testAccuRevFailure() throws Exception {
final ScmFileSet testFileSet = new ScmFileSet(new File("/my/workspace/project/dir"));
final File basedir = testFileSet.getBasedir();
info.setWorkSpace("theWorkSpace");
when(accurev.update(eq(basedir), any(String.class))).thenReturn(null);
AccuRevUpdateCommand command = new AccuRevUpdateCommand(getLogger());
CommandParameters commandParameters = new CommandParameters();
commandParameters.setString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString(false));
UpdateScmResult result = command.update(repo, testFileSet, commandParameters);
assertThat(result.isSuccess(), is(false));
assertThat(result.getProviderMessage(), notNullValue());
}
use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class LocalUpdateCommandTckTest method testDeletion.
/**
* Tests that a file that has been deleted from repository after checkout will be removed by scm-local. Local
* additions must not be deleted.
*/
public void testDeletion() throws Exception {
FileUtils.deleteDirectory(getUpdatingCopy());
ScmRepository repository = makeScmRepository(getScmUrl());
checkOut(getUpdatingCopy(), repository);
// Check preconditions
File readmeFileLocal = new File(getUpdatingCopy(), "readme.txt");
assertTrue(readmeFileLocal.exists());
File newFileLocal = new File(getUpdatingCopy(), "newfile.xml");
assertTrue(!newFileLocal.exists());
// Delete readme.txt from repository
File readmeFileRepo = new File(getRepositoryRoot(), moduleName + "/readme.txt");
assertTrue(readmeFileRepo.exists());
assertTrue("Could not delete", readmeFileRepo.delete());
assertFalse(readmeFileRepo.exists());
// Make local addition to updating copy - this one must not be touched
ScmTestCase.makeFile(getUpdatingCopy(), "newfile.xml", "added newfile.xml locally");
assertTrue(newFileLocal.exists());
// ----------------------------------------------------------------------
// Update the project
// ----------------------------------------------------------------------
ScmManager scmManager = getScmManager();
Date lastUpdate = new Date(System.currentTimeMillis());
Thread.sleep(1000);
UpdateScmResult result = scmManager.update(repository, new ScmFileSet(getUpdatingCopy()), lastUpdate);
assertNotNull("The command returned a null result.", result);
assertResultIsSuccess(result);
List<ScmFile> updatedFiles = result.getUpdatedFiles();
assertEquals("Expected 1 files in the updated files list " + updatedFiles, 1, updatedFiles.size());
// ----------------------------------------------------------------------
// Assert the files in the updated files list
// ----------------------------------------------------------------------
Iterator<ScmFile> files = new TreeSet<ScmFile>(updatedFiles).iterator();
// readme.txt
ScmFile file = (ScmFile) files.next();
assertPath("/readme.txt", file.getPath());
assertTrue(file.getStatus().isUpdate());
// ----------------------------------------------------------------------
// Assert working directory contents
// ----------------------------------------------------------------------
// readme.txt
assertTrue("Expected local copy of readme.txt to be deleted", !readmeFileLocal.exists());
// newfile.xml
assertTrue("Expected local copy of newfile.xml NOT to be deleted", newFileLocal.exists());
// ----------------------------------------------------------------------
// Assert metadata file
// ----------------------------------------------------------------------
File metadataFile = new File(getUpdatingCopy(), ".maven-scm-local");
assertTrue("Expected metadata file .maven-scm-local does not exist", metadataFile.exists());
Reader reader = new FileReader(metadataFile);
LocalScmMetadata metadata;
try {
metadata = new LocalScmMetadataXpp3Reader().read(reader);
} finally {
IOUtil.close(reader);
}
File root = new File(getRepositoryRoot() + "/" + moduleName);
@SuppressWarnings("unchecked") List<String> fileNames = FileUtils.getFileNames(root, "**", null, false);
assertEquals(fileNames, metadata.getRepositoryFileNames());
}
use of org.apache.maven.scm.command.update.UpdateScmResult 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.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class HgUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion tag) throws ScmException {
File workingDir = fileSet.getBasedir();
String[] updateCmd;
// Update branch
if (repo.isPushChanges()) {
updateCmd = new String[] { HgCommandConstants.PULL_CMD, HgCommandConstants.REVISION_OPTION, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
} else {
updateCmd = new String[] { HgCommandConstants.UPDATE_CMD, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip", HgCommandConstants.CLEAN_OPTION };
}
ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
if (!updateResult.isSuccess()) {
return new UpdateScmResult(null, null, updateResult);
}
// Find changes from last revision
int currentRevision = HgUtils.getCurrentRevisionNumber(getLogger(), workingDir);
int previousRevision = currentRevision - 1;
String[] diffCmd = new String[] { HgCommandConstants.DIFF_CMD, HgCommandConstants.REVISION_OPTION, "" + previousRevision };
HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
ScmResult diffResult = HgUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
// Now translate between diff and update file status
List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
List<CharSequence> changes = new ArrayList<CharSequence>();
List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
for (ScmFile file : diffFiles) {
changes.add(diffChanges.get(file.getPath()));
if (file.getStatus() == ScmFileStatus.MODIFIED) {
updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
} else {
updatedFiles.add(file);
}
}
if (repo.isPushChanges()) {
String[] hgUpdateCmd = new String[] { HgCommandConstants.UPDATE_CMD };
HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, hgUpdateCmd);
}
return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.
the class IntegrityScmProvider method update.
/**
* Maps to si resync
*/
@Override
protected UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
IntegrityUpdateCommand command = new IntegrityUpdateCommand();
command.setLogger(getLogger());
return (UpdateScmResult) command.execute(repository, fileSet, params);
}
Aggregations