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);
}
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);
}
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);
}
}
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());
}
Aggregations