Search in sources :

Example 1 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.

the class AccuRevStatusCommandTest method testFailure.

@Test
public void testFailure() throws Exception {
    final ScmFileSet testFileSet = getScmFileSet();
    when(accurev.stat(basedir, testFileSet.getFileList(), AccuRevStat.MODIFIED)).thenReturn(null);
    AccuRevStatusCommand command = new AccuRevStatusCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    StatusScmResult result = command.status(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(false));
    assertThat(result.getProviderMessage(), notNullValue());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmFileSet(org.apache.maven.scm.ScmFileSet) CommandParameters(org.apache.maven.scm.CommandParameters) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 2 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.

the class BazaarCheckInCommand method executeCheckInCommand.

/**
 * {@inheritDoc}
 */
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion version) throws ScmException {
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        throw new ScmException("This provider can't handle tags.");
    }
    // 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
        BazaarStatusCommand statusCmd = new BazaarStatusCommand();
        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[] { BazaarConstants.COMMIT_CMD, BazaarConstants.MESSAGE_OPTION, message };
    commitCmd = BazaarUtils.expandCommandLine(commitCmd, fileSet);
    ScmResult result = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), commitCmd);
    // Push to parent branch if any
    BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
    if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath()) && repo.isPushChanges()) {
        String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, BazaarConstants.NO_STRICT_OPTION, repository.getURI() };
        result = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
    }
    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) ArrayList(java.util.ArrayList) BazaarStatusCommand(org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmFile(org.apache.maven.scm.ScmFile) BazaarScmProviderRepository(org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 3 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.

the class BazaarStatusCommand method executeStatusCommand.

/**
 * {@inheritDoc}
 */
public StatusScmResult executeStatusCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
    File workingDir = fileSet.getBasedir();
    BazaarStatusConsumer consumer = new BazaarStatusConsumer(getLogger(), workingDir);
    String[] statusCmd = new String[] { BazaarConstants.STATUS_CMD };
    ScmResult result = BazaarUtils.execute(consumer, getLogger(), workingDir, statusCmd);
    return new StatusScmResult(consumer.getStatus(), result);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmResult(org.apache.maven.scm.ScmResult) StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) File(java.io.File)

Example 4 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.

the class SvnStatusCommand method executeStatusCommand.

/**
 * {@inheritDoc}
 */
protected StatusScmResult executeStatusCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet);
    SvnStatusConsumer consumer = new SvnStatusConsumer(getLogger(), fileSet.getBasedir());
    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, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new StatusScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new StatusScmResult(cl.toString(), consumer.getChangedFiles());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 5 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult 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)

Aggregations

StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)40 ScmFile (org.apache.maven.scm.ScmFile)15 ScmException (org.apache.maven.scm.ScmException)14 File (java.io.File)12 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)9 Commandline (org.codehaus.plexus.util.cli.Commandline)9 ArrayList (java.util.ArrayList)6 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)6 ScmResult (org.apache.maven.scm.ScmResult)5 ScmFileSet (org.apache.maven.scm.ScmFileSet)4 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)3 ErrorConsumer (org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer)3 JazzStatusCommand (org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand)3 ScmRepository (org.apache.maven.scm.repository.ScmRepository)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 CommandParameters (org.apache.maven.scm.CommandParameters)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 CategorisedElements (org.apache.maven.scm.provider.accurev.CategorisedElements)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 BazaarStatusCommand (org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand)2