use of org.apache.maven.scm.ScmFileStatus 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);
}
use of org.apache.maven.scm.ScmFileStatus in project maven-scm by apache.
the class ChangedFileConsumer method extractChangedFile.
private void extractChangedFile() {
String change = getChange();
if (change != null) {
ScmFileStatus stat = ScmFileStatus.UNKNOWN;
if (change.equals(ChangedFileConsumer.CHANGE_EDIT)) {
stat = ScmFileStatus.MODIFIED;
}
if (change.equals(ChangedFileConsumer.CHANGE_ADD)) {
stat = ScmFileStatus.ADDED;
}
changedFiles.add(new ScmFile(getLocalPath(), stat));
values.clear();
}
}
use of org.apache.maven.scm.ScmFileStatus in project maven-scm by apache.
the class GitStatusConsumer method consumeLine.
// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void consumeLine(String line) {
if (logger.isDebugEnabled()) {
logger.debug(line);
}
if (StringUtils.isEmpty(line)) {
return;
}
ScmFileStatus status = null;
List<String> files = new ArrayList<String>();
Matcher matcher;
if ((matcher = ADDED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.ADDED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
} else if ((matcher = MODIFIED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.MODIFIED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
} else if ((matcher = DELETED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.DELETED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
} else if ((matcher = RENAMED_PATTERN.matcher(line)).find()) {
status = ScmFileStatus.RENAMED;
files.add(resolvePath(matcher.group(1), relativeRepositoryPath));
files.add(resolvePath(matcher.group(2), relativeRepositoryPath));
logger.debug("RENAMED status for line '" + line + "' files added '" + matcher.group(1) + "' '" + matcher.group(2));
} else {
logger.warn("Ignoring unrecognized line: " + line);
return;
}
// If the file isn't a file; don't add it.
if (!files.isEmpty() && status != null) {
if (workingDirectory != null) {
if (status == ScmFileStatus.RENAMED) {
String oldFilePath = files.get(0);
String newFilePath = files.get(1);
if (isFile(oldFilePath)) {
logger.debug("file '" + oldFilePath + "' is a file");
return;
} else {
logger.debug("file '" + oldFilePath + "' not a file");
}
if (!isFile(newFilePath)) {
logger.debug("file '" + newFilePath + "' not a file");
return;
} else {
logger.debug("file '" + newFilePath + "' is a file");
}
} else if (status == ScmFileStatus.DELETED) {
if (isFile(files.get(0))) {
return;
}
} else {
if (!isFile(files.get(0))) {
return;
}
}
}
for (String file : files) {
changedFiles.add(new ScmFile(file, status));
}
}
}
use of org.apache.maven.scm.ScmFileStatus in project maven-scm by apache.
the class VssAddConsumer method consumeLine.
// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void consumeLine(String line) {
if (line.length() <= 3) {
if (logger.isWarnEnabled()) {
logger.warn("Unexpected input, the line must be at least three characters long. Line: '" + line + "'.");
}
return;
}
String statusString = line.substring(0, 1);
String file = line.substring(3);
ScmFileStatus status;
if (statusString.equals("A")) {
status = ScmFileStatus.ADDED;
} else {
if (logger.isInfoEnabled()) {
logger.info("Unknown file status: '" + statusString + "'.");
}
return;
}
addedFiles.add(new ScmFile(file, status));
}
use of org.apache.maven.scm.ScmFileStatus in project maven-scm by apache.
the class CvsStatusConsumer method consumeLine.
// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void consumeLine(String line) {
if (logger.isDebugEnabled()) {
logger.debug(line);
}
if (line.length() < 3) {
if (StringUtils.isNotEmpty(line)) {
if (logger.isWarnEnabled()) {
logger.warn("Unable to parse output from command: line length must be bigger than 3. (" + line + ").");
}
}
return;
}
String statusString = line.substring(0, 1);
String file = line.substring(2);
ScmFileStatus status;
if (statusString.equals("A")) {
status = ScmFileStatus.ADDED;
} else if (statusString.equals("M")) {
status = ScmFileStatus.MODIFIED;
} else if (statusString.equals("D")) {
status = ScmFileStatus.DELETED;
} else if (statusString.equals("C")) {
status = ScmFileStatus.CONFLICT;
} else if (statusString.equals("?")) {
status = ScmFileStatus.UNKNOWN;
} else if (statusString.equals("U") || statusString.equals("P")) {
// skip remote changes
return;
} else {
if (logger.isInfoEnabled()) {
logger.info("Unknown file status: '" + statusString + "'.");
}
return;
}
// If the file isn't a file; don't add it.
if (!status.equals(ScmFileStatus.DELETED) && !new File(workingDirectory, file).isFile()) {
return;
}
changedFiles.add(new ScmFile(file, status));
}
Aggregations