Search in sources :

Example 21 with ScmFile

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);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmException(org.apache.maven.scm.ScmException) ScmResult(org.apache.maven.scm.ScmResult) StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) ArrayList(java.util.ArrayList) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmFile(org.apache.maven.scm.ScmFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) HgStatusCommand(org.apache.maven.scm.provider.hg.command.status.HgStatusCommand) HgScmProviderRepository(org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository)

Example 22 with ScmFile

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

Example 23 with ScmFile

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

Example 24 with 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());
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) DefaultLog(org.apache.maven.scm.log.DefaultLog) BufferedReader(java.io.BufferedReader) ScmFile(org.apache.maven.scm.ScmFile)

Example 25 with ScmFile

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());
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) DefaultLog(org.apache.maven.scm.log.DefaultLog) BufferedReader(java.io.BufferedReader) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

ScmFile (org.apache.maven.scm.ScmFile)198 File (java.io.File)102 ArrayList (java.util.ArrayList)51 ScmException (org.apache.maven.scm.ScmException)34 BufferedReader (java.io.BufferedReader)21 DefaultLog (org.apache.maven.scm.log.DefaultLog)20 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)19 ScmFileSet (org.apache.maven.scm.ScmFileSet)17 InputStreamReader (java.io.InputStreamReader)16 ScmResult (org.apache.maven.scm.ScmResult)15 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)15 IOException (java.io.IOException)14 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)13 Matcher (java.util.regex.Matcher)11 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)11 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)10 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)10 Commandline (org.codehaus.plexus.util.cli.Commandline)10 SynergyScmProviderRepository (org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository)9 FileInputStream (java.io.FileInputStream)8