Search in sources :

Example 11 with BranchScmResult

use of org.apache.maven.scm.command.branch.BranchScmResult in project maven-scm by apache.

the class JazzScmProvider method branch.

/**
 * {@inheritDoc}
 */
protected BranchScmResult branch(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    getLogger().debug("JazzScmProvider:branch()");
    JazzBranchCommand command = new JazzBranchCommand();
    command.setLogger(getLogger());
    return (BranchScmResult) command.execute(repository, fileSet, parameters);
}
Also used : JazzBranchCommand(org.apache.maven.scm.provider.jazz.command.branch.JazzBranchCommand) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult)

Example 12 with BranchScmResult

use of org.apache.maven.scm.command.branch.BranchScmResult in project maven-scm by apache.

the class SvnBranchCommand method executeBranchCommand.

public ScmResult executeBranchCommand(ScmProviderRepository repo, ScmFileSet fileSet, String branch, ScmBranchParameters scmBranchParameters) throws ScmException {
    if (branch == null || StringUtils.isEmpty(branch.trim())) {
        throw new ScmException("branch name must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support branching subsets of a directory");
    }
    SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), scmBranchParameters.getMessage());
    } catch (IOException ex) {
        return new BranchScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
    }
    Commandline cl = createCommandLine(repository, fileSet.getBasedir(), branch, messageFile, scmBranchParameters);
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, stdout, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    } finally {
        try {
            FileUtils.forceDelete(messageFile);
        } catch (IOException ex) {
        // ignore
        }
    }
    if (exitCode != 0) {
        return new BranchScmResult(cl.toString(), "The svn branch command failed.", stderr.getOutput(), false);
    }
    List<ScmFile> fileList = new ArrayList<ScmFile>();
    List<File> files = null;
    try {
        @SuppressWarnings("unchecked") List<File> listFiles = FileUtils.getFiles(fileSet.getBasedir(), "**", "**/.svn/**", false);
        files = listFiles;
    } catch (IOException e) {
        throw new ScmException("Error while executing command.", e);
    }
    for (File f : files) {
        fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
    }
    return new BranchScmResult(cl.toString(), fileList);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 13 with BranchScmResult

use of org.apache.maven.scm.command.branch.BranchScmResult in project maven-scm by apache.

the class JGitBranchCommand method executeBranchCommand.

/**
 * {@inheritDoc}
 */
@Override
protected ScmResult executeBranchCommand(ScmProviderRepository repo, ScmFileSet fileSet, String branch, String message) throws ScmException {
    if (branch == null || StringUtils.isEmpty(branch.trim())) {
        throw new ScmException("branch name must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support branching subsets of a directory");
    }
    Git git = null;
    try {
        git = JGitUtils.openRepo(fileSet.getBasedir());
        Ref branchResult = git.branchCreate().setName(branch).call();
        getLogger().info("created [" + branchResult.getName() + "]");
        if (getLogger().isDebugEnabled()) {
            for (String branchName : getShortLocalBranchNames(git)) {
                getLogger().debug("local branch available: " + branchName);
            }
        }
        if (repo.isPushChanges()) {
            getLogger().info("push branch [" + branch + "] to remote...");
            JGitUtils.push(getLogger(), git, (GitScmProviderRepository) repo, new RefSpec(Constants.R_HEADS + branch));
        }
        // search for the tagged files
        final RevWalk revWalk = new RevWalk(git.getRepository());
        RevCommit commit = revWalk.parseCommit(branchResult.getObjectId());
        revWalk.release();
        final TreeWalk walk = new TreeWalk(git.getRepository());
        // drop the first empty tree, which we do not need here
        walk.reset();
        walk.setRecursive(true);
        walk.addTree(commit.getTree());
        List<ScmFile> files = new ArrayList<ScmFile>();
        while (walk.next()) {
            files.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
        }
        walk.release();
        return new BranchScmResult("JGit branch", files);
    } catch (Exception e) {
        throw new ScmException("JGit branch failed!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) RefSpec(org.eclipse.jgit.transport.RefSpec) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 14 with BranchScmResult

use of org.apache.maven.scm.command.branch.BranchScmResult in project maven-scm by apache.

the class GitBranchCommand method executeBranchCommand.

/**
 * {@inheritDoc}
 */
public ScmResult executeBranchCommand(ScmProviderRepository repo, ScmFileSet fileSet, String branch, String message) throws ScmException {
    if (branch == null || StringUtils.isEmpty(branch.trim())) {
        throw new ScmException("branch name must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support branching subsets of a directory");
    }
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    Commandline cl = createCommandLine(repository, fileSet.getBasedir(), branch);
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
    if (exitCode != 0) {
        return new BranchScmResult(cl.toString(), "The git-branch command failed.", stderr.getOutput(), false);
    }
    if (repo.isPushChanges()) {
        // and now push the branch to the upstream repository
        Commandline clPush = createPushCommandLine(repository, fileSet, branch);
        exitCode = GitCommandLineUtils.execute(clPush, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new BranchScmResult(clPush.toString(), "The git-push command failed.", stderr.getOutput(), false);
        }
    }
    // as last action we search for the branched files
    GitListConsumer listConsumer = new GitListConsumer(getLogger(), fileSet.getBasedir(), ScmFileStatus.TAGGED);
    Commandline clList = GitListCommand.createCommandLine(repository, fileSet.getBasedir());
    exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr, getLogger());
    if (exitCode != 0) {
        return new BranchScmResult(clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false);
    }
    return new BranchScmResult(cl.toString(), listConsumer.getListedFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) GitListConsumer(org.apache.maven.scm.provider.git.gitexe.command.list.GitListConsumer) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult)

Aggregations

BranchScmResult (org.apache.maven.scm.command.branch.BranchScmResult)14 ScmException (org.apache.maven.scm.ScmException)8 ArrayList (java.util.ArrayList)4 ScmFile (org.apache.maven.scm.ScmFile)4 File (java.io.File)3 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)3 IOException (java.io.IOException)2 ScmResult (org.apache.maven.scm.ScmResult)2 CvsBranchConsumer (org.apache.maven.scm.provider.cvslib.command.branch.CvsBranchConsumer)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 Commandline (org.codehaus.plexus.util.cli.Commandline)2 APIException (com.mks.api.response.APIException)1 Response (com.mks.api.response.Response)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ScmBranch (org.apache.maven.scm.ScmBranch)1 ScmBranchParameters (org.apache.maven.scm.ScmBranchParameters)1 ScmFileSet (org.apache.maven.scm.ScmFileSet)1