Search in sources :

Example 6 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class SvnCheckInConsumer method parseLine.

// ----------------------------------------------------------------------
// StreamConsumer Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
protected void parseLine(String line) {
    String file;
    if (line.startsWith(COMMITTED_REVISION_TOKEN)) {
        String revisionString = line.substring(COMMITTED_REVISION_TOKEN.length() + 1, line.length() - 1);
        revision = parseInt(revisionString);
        return;
    } else if (line.startsWith(SENDING_TOKEN)) {
        file = line.substring(SENDING_TOKEN.length());
    } else if (line.startsWith(ADDING_TOKEN)) {
        file = line.substring(ADDING_TOKEN.length());
    } else if (line.startsWith(ADDING_BIN_TOKEN)) {
        file = line.substring(ADDING_BIN_TOKEN.length());
    } else if (line.startsWith(DELETING_TOKEN)) {
        file = line.substring(DELETING_TOKEN.length());
    } else if (line.startsWith(TRANSMITTING_TOKEN)) {
        // ignore
        return;
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Unknown line: '" + line + "'");
        }
        return;
    }
    addFile(new ScmFile(file, ScmFileStatus.CHECKED_IN));
}
Also used : ScmFile(org.apache.maven.scm.ScmFile)

Example 7 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class JGitListCommand method executeListCommand.

@Override
protected ListScmResult executeListCommand(ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive, ScmVersion scmVersion) throws ScmException {
    Git git = null;
    try {
        git = JGitUtils.openRepo(fileSet.getBasedir());
        CredentialsProvider credentials = JGitUtils.prepareSession(getLogger(), git, (GitScmProviderRepository) repo);
        List<ScmFile> list = new ArrayList<ScmFile>();
        Collection<Ref> lsResult = git.lsRemote().setCredentialsProvider(credentials).call();
        for (Ref ref : lsResult) {
            getLogger().debug(ref.getObjectId().getName() + "  " + ref.getTarget().getName());
            list.add(new ScmFile(ref.getName(), ScmFileStatus.CHECKED_IN));
        }
        return new ListScmResult("JGit ls-remote", list);
    } catch (Exception e) {
        throw new ScmException("JGit ls-remote failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) ArrayList(java.util.ArrayList) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile)

Example 8 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class JGitStatusCommand method executeStatusCommand.

/**
 * {@inheritDoc}
 */
protected StatusScmResult executeStatusCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
    Git git = null;
    try {
        git = JGitUtils.openRepo(fileSet.getBasedir());
        Status status = git.status().call();
        List<ScmFile> changedFiles = getFileStati(status);
        return new StatusScmResult("JGit status", changedFiles);
    } catch (Exception e) {
        throw new ScmException("JGit status failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : Status(org.eclipse.jgit.api.Status) ScmFileStatus(org.apache.maven.scm.ScmFileStatus) StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile)

Example 9 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class SvnDiffConsumer 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());
        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 10 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class LocalListCommand method getFiles.

private List<ScmFile> getFiles(File source, File directory, boolean recursive) throws Exception {
    if (!directory.exists()) {
        throw new Exception("Directory '" + directory.getAbsolutePath() + "' doesn't exist.");
    }
    List<ScmFile> files = new ArrayList<ScmFile>();
    File[] filesArray = directory.listFiles();
    if (filesArray != null) {
        for (int i = 0; i < filesArray.length; i++) {
            File f = filesArray[i];
            String path = f.getAbsolutePath().substring(source.getAbsolutePath().length());
            path = StringUtils.replace(path, "\\", "/");
            path = StringUtils.replace(path, "/./", "/");
            files.add(new ScmFile(path, ScmFileStatus.CHECKED_IN));
            if (f.isDirectory() && recursive) {
                files.addAll(getFiles(source, f, recursive));
            }
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmException(org.apache.maven.scm.ScmException) 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