use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class PerforceRemoveConsumerTest method testParse.
public void testParse() throws Exception {
File testFile = getTestFile("src/test/resources/perforce/removelog.txt");
PerforceRemoveConsumer consumer = new PerforceRemoveConsumer();
FileInputStream fis = new FileInputStream(testFile);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String s = in.readLine();
while (s != null) {
consumer.consumeLine(s);
s = in.readLine();
}
List<ScmFile> removes = consumer.getRemovals();
assertEquals("Wrong number of entries returned", 2, removes.size());
String entry = removes.get(0).getPath();
assertTrue(entry.startsWith("//"));
assertTrue(entry.endsWith("foo.xml"));
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class PerforceAddConsumerTest method testParse.
public void testParse() throws Exception {
File testFile = getTestFile("src/test/resources/perforce/addlog.txt");
PerforceAddConsumer consumer = new PerforceAddConsumer();
FileInputStream fis = new FileInputStream(testFile);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String s = in.readLine();
while (s != null) {
consumer.consumeLine(s);
s = in.readLine();
}
List<ScmFile> adds = consumer.getAdditions();
assertEquals("Wrong number of entries returned", 3, adds.size());
String entry = adds.get(0).getPath();
assertTrue(entry.startsWith("//"));
assertTrue(entry.endsWith("foo.xml"));
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class LocalUpdateCommand method update.
private List<ScmFile> update(File source, File baseDestination, List<File> files) throws ScmException, IOException {
String sourcePath = source.getAbsolutePath();
List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
File repositoryFile = i.next();
File repositoryDirectory = repositoryFile.getParentFile();
// TODO: Add more excludes here
if (repositoryDirectory != null && repositoryDirectory.getName().equals("CVS")) {
continue;
}
String dest = repositoryFile.getAbsolutePath().substring(sourcePath.length() + 1);
File destinationFile = new File(baseDestination, dest);
String repositoryFileContents = FileUtils.fileRead(repositoryFile);
if (destinationFile.exists()) {
String destionationFileContents = FileUtils.fileRead(destinationFile);
if (repositoryFileContents.equals(destionationFileContents)) {
continue;
}
}
File destinationDirectory = destinationFile.getParentFile();
if (!destinationDirectory.exists() && !destinationDirectory.mkdirs()) {
throw new ScmException("Could not create destination directory '" + destinationDirectory.getAbsolutePath() + "'.");
}
ScmFileStatus status;
if (destinationFile.exists()) {
status = ScmFileStatus.UPDATED;
} else {
status = ScmFileStatus.ADDED;
}
FileUtils.copyFileToDirectory(repositoryFile, destinationDirectory);
int chop = baseDestination.getAbsolutePath().length();
String fileName = "/" + destinationFile.getAbsolutePath().substring(chop + 1);
updatedFiles.add(new ScmFile(fileName, status));
}
return updatedFiles;
}
use of org.apache.maven.scm.ScmFile 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.ScmFile in project maven-scm by apache.
the class HgBranchCommand method executeBranchCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeBranchCommand(ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String branch, ScmBranchParameters scmBranchParameters) throws ScmException {
if (StringUtils.isBlank(branch)) {
throw new ScmException("branch must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support branchging subsets of a directory");
}
File workingDir = fileSet.getBasedir();
// build the command
String[] branchCmd = new String[] { HgCommandConstants.BRANCH_CMD, branch };
// keep the command about in string form for reporting
HgConsumer branchConsumer = new HgConsumer(getLogger()) {
public void doConsume(ScmFileStatus status, String trimmedLine) {
// noop
}
};
ScmResult result = HgUtils.execute(branchConsumer, getLogger(), workingDir, branchCmd);
HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(branchCmd));
}
// First commit.
String[] commitCmd = new String[] { HgCommandConstants.COMMIT_CMD, HgCommandConstants.MESSAGE_OPTION, scmBranchParameters.getMessage() };
result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, commitCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(commitCmd));
}
if (repository.isPushChanges()) {
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, HgCommandConstants.NEW_BRANCH_OPTION, repository.getURI() };
result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(pushCmd));
}
}
}
// do an inventory to return the files branched (all of them)
String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
HgListConsumer listconsumer = new HgListConsumer(getLogger());
result = HgUtils.execute(listconsumer, getLogger(), fileSet.getBasedir(), listCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(listCmd));
}
List<ScmFile> files = listconsumer.getFiles();
List<ScmFile> fileList = new ArrayList<ScmFile>();
for (ScmFile f : files) {
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
return new BranchScmResult(fileList, result);
}
Aggregations