Search in sources :

Example 6 with ScmFileStatus

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);
}
Also used : ScmException(org.apache.maven.scm.ScmException) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmResult(org.apache.maven.scm.ScmResult) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) ArrayList(java.util.ArrayList) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmFile(org.apache.maven.scm.ScmFile) ScmFileStatus(org.apache.maven.scm.ScmFileStatus) HgListConsumer(org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) HgScmProviderRepository(org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository)

Example 7 with ScmFileStatus

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();
    }
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmFile(org.apache.maven.scm.ScmFile)

Example 8 with ScmFileStatus

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));
        }
    }
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile)

Example 9 with ScmFileStatus

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));
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmFile(org.apache.maven.scm.ScmFile)

Example 10 with ScmFileStatus

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));
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

ScmFileStatus (org.apache.maven.scm.ScmFileStatus)24 ScmFile (org.apache.maven.scm.ScmFile)17 File (java.io.File)7 Matcher (java.util.regex.Matcher)6 ChangeFile (org.apache.maven.scm.ChangeFile)6 ArrayList (java.util.ArrayList)4 ChangeSet (org.apache.maven.scm.ChangeSet)4 ScmException (org.apache.maven.scm.ScmException)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 ScmResult (org.apache.maven.scm.ScmResult)1 BranchScmResult (org.apache.maven.scm.command.branch.BranchScmResult)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 DefaultLog (org.apache.maven.scm.log.DefaultLog)1