Search in sources :

Example 6 with BranchScmResult

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

the class IntegrityBranchCommand method executeBranchCommand.

/**
 * {@inheritDoc}
 */
@Override
public BranchScmResult executeBranchCommand(ScmProviderRepository repository, ScmFileSet fileSet, String branchName, String message) throws ScmException {
    BranchScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    Project siProject = iRepo.getProject();
    getLogger().info("Attempting to branch project " + siProject.getProjectName() + " using branch name '" + branchName + "'");
    try {
        Project.validateTag(branchName);
        Response res = siProject.createDevPath(branchName);
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        ScmResult scmResult = new ScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
        result = new BranchScmResult(new ArrayList<ScmFile>(), scmResult);
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new BranchScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    } catch (Exception e) {
        getLogger().error("Failed to checkpoint project! " + e.getMessage());
        result = new BranchScmResult("si createdevpath", e.getMessage(), "", false);
    }
    return result;
}
Also used : Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) Project(org.apache.maven.scm.provider.integrity.Project) APIException(com.mks.api.response.APIException) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmException(org.apache.maven.scm.ScmException) APIException(com.mks.api.response.APIException)

Example 7 with BranchScmResult

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

the class BranchCommandTckTest method testBranchCommandTest.

public void testBranchCommandTest() throws Exception {
    String branch = getBranch();
    @SuppressWarnings("deprecation") BranchScmResult branchResult = getScmManager().getProviderByUrl(getScmUrl()).branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
    assertResultIsSuccess(branchResult);
    // see https://issues.apache.org/jira/browse/SCM-754
    // assertEquals( "check all 4 files branched", 4, branchResult.getBranchedFiles().size() );
    File readmeTxt = new File(getWorkingCopy(), "readme.txt");
    assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    changeReadmeTxt(readmeTxt);
    CheckInScmResult checkinResult = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), "commit message");
    assertResultIsSuccess(checkinResult);
    CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
    assertResultIsSuccess(checkoutResult);
    readmeTxt = new File(getAssertionCopy(), "readme.txt");
    assertEquals("check readme.txt contents", "changed file", FileUtils.fileRead(readmeTxt));
    deleteDirectory(getAssertionCopy());
    assertFalse("check previous assertion copy deleted", getAssertionCopy().exists());
    checkoutResult = getScmManager().getProviderByUrl(getScmUrl()).checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmBranch(branch));
    assertResultIsSuccess(checkoutResult);
    assertEquals("check readme.txt contents is from branched version", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 8 with BranchScmResult

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

the class BranchMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException {
    super.execute();
    try {
        ScmRepository repository = getScmRepository();
        ScmProvider provider = getScmManager().getProviderByRepository(repository);
        String finalBranch = provider.sanitizeTagName(branch);
        getLog().info("Final Branch Name: '" + finalBranch + "'");
        ScmBranchParameters scmBranchParameters = new ScmBranchParameters(message);
        scmBranchParameters.setRemoteBranching(remoteBranching);
        BranchScmResult result = provider.branch(repository, getFileSet(), finalBranch, scmBranchParameters);
        checkResult(result);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot run branch command : ", e);
    } catch (ScmException e) {
        throw new MojoExecutionException("Cannot run branch command : ", e);
    }
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmBranchParameters(org.apache.maven.scm.ScmBranchParameters)

Example 9 with BranchScmResult

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

the class TfsScmProvider method branch.

protected BranchScmResult branch(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    TfsBranchCommand command = new TfsBranchCommand();
    command.setLogger(getLogger());
    return (BranchScmResult) command.execute(repository, fileSet, parameters);
}
Also used : TfsBranchCommand(org.apache.maven.scm.provider.tfs.command.TfsBranchCommand) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult)

Example 10 with BranchScmResult

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

the class CvsJavaBranchCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected BranchScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsLogListener logListener = new CvsLogListener();
    CvsBranchConsumer consumer = new CvsBranchConsumer(getLogger());
    try {
        boolean isSuccess = CvsConnection.processCommand(cl.getArguments(), cl.getWorkingDirectory().getAbsolutePath(), logListener, getLogger());
        if (!isSuccess) {
            return new BranchScmResult(cl.toString(), "The cvs branch command failed.", logListener.getStderr().toString(), false);
        }
        BufferedReader stream = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(logListener.getStdout().toString().getBytes())));
        String line;
        while ((line = stream.readLine()) != null) {
            consumer.consumeLine(line);
        }
    } catch (Exception e) {
        getLogger().error(e.getMessage(), e);
        return new BranchScmResult(cl.toString(), "The cvs branch command failed.", logListener.getStderr().toString(), false);
    }
    return new BranchScmResult(cl.toString(), consumer.getTaggedFiles());
}
Also used : CvsLogListener(org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) CvsBranchConsumer(org.apache.maven.scm.provider.cvslib.command.branch.CvsBranchConsumer) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmException(org.apache.maven.scm.ScmException)

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