use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class HgCheckInCommand method executeCheckInCommand.
/**
* {@inheritDoc}
*/
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion tag) throws ScmException {
if (tag != null && !StringUtils.isEmpty(tag.getName())) {
throw new ScmException("This provider can't handle tags for this operation");
}
File workingDir = fileSet.getBasedir();
String branchName = HgUtils.getCurrentBranchName(getLogger(), workingDir);
boolean differentOutgoingBranch = repo.isPushChanges() ? HgUtils.differentOutgoingBranchFound(getLogger(), workingDir, branchName) : false;
// Get files that will be committed (if not specified in fileSet)
List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
List<File> files = fileSet.getFileList();
if (files.isEmpty()) {
// Either commit all changes
HgStatusCommand statusCmd = new HgStatusCommand();
statusCmd.setLogger(getLogger());
StatusScmResult status = statusCmd.executeStatusCommand(repo, fileSet);
List<ScmFile> statusFiles = status.getChangedFiles();
for (ScmFile file : statusFiles) {
if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
}
}
} else {
// Or commit spesific files
for (File file : files) {
commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
}
}
// Commit to local branch
String[] commitCmd = new String[] { HgCommandConstants.COMMIT_CMD, HgCommandConstants.MESSAGE_OPTION, message };
commitCmd = HgUtils.expandCommandLine(commitCmd, fileSet);
ScmResult result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), commitCmd);
// Push to parent branch if any
HgScmProviderRepository repository = (HgScmProviderRepository) repo;
if (repo.isPushChanges()) {
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName : null, repository.getURI() };
result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
}
return new CheckInScmResult(commitedFiles, result);
}
return new CheckInScmResult(commitedFiles, result);
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class HgDiffConsumer method consumeLine.
// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void consumeLine(String line) {
if (line.startsWith(INDEX_TOKEN)) {
// start a new file
currentFile = line.substring(INDEX_TOKEN.length() + HASH_ID_LEN + 1);
changedFiles.add(new ScmFile(currentFile, ScmFileStatus.MODIFIED));
currentDifference = new StringBuilder();
differences.put(currentFile, currentDifference);
patch.append(line).append("\n");
return;
}
if (currentFile == null) {
if (logger.isWarnEnabled()) {
logger.warn("Unparseable line: '" + line + "'");
}
patch.append(line).append("\n");
return;
}
if (line.startsWith(FILE_SEPARATOR_TOKEN)) {
// skip
patch.append(line).append("\n");
} else if (line.startsWith(START_REVISION_TOKEN)) {
// skip, though could parse to verify filename, start revision
patch.append(line).append("\n");
} else if (line.startsWith(END_REVISION_TOKEN)) {
// skip, though could parse to verify filename, end revision
patch.append(line).append("\n");
} else if (line.startsWith(ADDED_LINE_TOKEN) || line.startsWith(REMOVED_LINE_TOKEN) || line.startsWith(UNCHANGED_LINE_TOKEN) || line.startsWith(CHANGE_SEPARATOR_TOKEN) || line.equals(NO_NEWLINE_TOKEN)) {
// add to buffer
currentDifference.append(line).append("\n");
patch.append(line).append("\n");
} else {
if (logger.isWarnEnabled()) {
logger.warn("Unparseable line: '" + line + "'");
}
patch.append(line).append("\n");
// skip to next file
currentFile = null;
currentDifference = null;
}
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class HgRemoveConsumer method doConsume.
/**
* {@inheritDoc}
*/
public void doConsume(ScmFileStatus status, String trimmedLine) {
if (status != null && status == ScmFileStatus.DELETED) {
// Only include real files (not directories)
File tmpFile = new File(workingDir, trimmedLine);
if (!tmpFile.exists()) {
if (getLogger().isWarnEnabled()) {
getLogger().warn("Not a file: " + tmpFile + ". Ignored");
}
} else {
ScmFile scmFile = new ScmFile(trimmedLine, ScmFileStatus.DELETED);
if (getLogger().isInfoEnabled()) {
getLogger().info(scmFile.toString());
}
removedFiles.add(scmFile);
}
}
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class ClearCaseAddConsumerTest method testConsumer.
public void testConsumer() throws IOException {
InputStream inputStream = getResourceAsStream("/clearcase/add/add.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
String s = in.readLine();
ClearCaseAddConsumer consumer = new ClearCaseAddConsumer(new DefaultLog());
while (s != null) {
consumer.consumeLine(s);
s = in.readLine();
}
Collection<ScmFile> entries = consumer.getAddedFiles();
assertEquals("Wrong number of entries returned", 1, entries.size());
ScmFile scmFile = entries.iterator().next();
assertEquals("test.java", scmFile.getPath());
assertEquals(ScmFileStatus.ADDED, scmFile.getStatus());
}
use of org.apache.maven.scm.ScmFile in project maven-scm by apache.
the class ClearCaseUnEditConsumerTest method testConsumer.
public void testConsumer() throws IOException {
InputStream inputStream = getResourceAsStream("/clearcase/unedit/unedit.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
String s = in.readLine();
ClearCaseUnEditConsumer consumer = new ClearCaseUnEditConsumer(new DefaultLog());
while (s != null) {
consumer.consumeLine(s);
s = in.readLine();
}
Collection<ScmFile> entries = consumer.getUnEditFiles();
assertEquals("Wrong number of entries returned", 1, entries.size());
ScmFile scmFile = entries.iterator().next();
assertEquals("test.java", scmFile.getPath());
assertEquals(ScmFileStatus.UNKNOWN, scmFile.getStatus());
}
Aggregations