Search in sources :

Example 31 with UpdateScmResult

use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.

the class StarteamUpdateCommand method executeUpdateCommand.

// ----------------------------------------------------------------------
// AbstractUpdateCommand Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Working directory: " + fileSet.getBasedir().getAbsolutePath());
    }
    StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
    StarteamCheckOutConsumer consumer = new StarteamCheckOutConsumer(getLogger(), fileSet.getBasedir());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    List<File> updateFiles = fileSet.getFileList();
    if (updateFiles.size() == 0) {
        // update everything
        Commandline cl = createCommandLine(repository, fileSet, version);
        int exitCode = StarteamCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
        if (exitCode != 0) {
            return new UpdateScmResult(cl.toString(), "The starteam command failed.", stderr.getOutput(), false);
        } else {
            // hiden feature to allow Continuous Integration machine to
            // delete local files. It affectively remove all build ouput as well
            String doDeleteLocal = System.getProperty("maven.scm.starteam.deleteLocal");
            if ("true".equalsIgnoreCase(doDeleteLocal)) {
                this.deleteLocal(repository, fileSet, version);
            }
        }
    } else {
        // update only interested files already on the local disk
        for (int i = 0; i < updateFiles.size(); ++i) {
            File updateFile = (File) updateFiles.get(i);
            ScmFileSet scmFileSet = new ScmFileSet(fileSet.getBasedir(), updateFile);
            Commandline cl = createCommandLine(repository, scmFileSet, version);
            int exitCode = StarteamCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
            if (exitCode != 0) {
                return new UpdateScmResult(cl.toString(), "The starteam command failed.", stderr.getOutput(), false);
            }
        }
    }
    return new UpdateScmResult(null, consumer.getCheckedOutFiles());
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) Commandline(org.codehaus.plexus.util.cli.Commandline) StarteamScmProviderRepository(org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository) StarteamCommandLineUtils(org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) StarteamCheckOutConsumer(org.apache.maven.scm.provider.starteam.command.checkout.StarteamCheckOutConsumer) File(java.io.File)

Example 32 with UpdateScmResult

use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.

the class UpdateMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException {
    super.execute();
    try {
        ScmRepository repository = getScmRepository();
        UpdateScmResult result = getScmManager().update(repository, getFileSet(), getScmVersion(scmVersionType, scmVersion), runChangelog);
        checkResult(result);
        if (result instanceof UpdateScmResultWithRevision) {
            String revision = ((UpdateScmResultWithRevision) result).getRevision();
            getLog().info("Storing revision in '" + revisionKey + "' project property.");
            if (// Remove the test when we'll use plugin-test-harness 1.0-alpha-2
            project.getProperties() != null) {
                project.getProperties().put(revisionKey, revision);
            }
            getLog().info("Project at revision " + revision);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot run update command : ", e);
    } catch (ScmException e) {
        throw new MojoExecutionException("Cannot run update command : ", e);
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) IOException(java.io.IOException)

Example 33 with UpdateScmResult

use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.

the class LocalScmProvider method update.

/**
 * {@inheritDoc}
 */
public UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    LocalUpdateCommand command = new LocalUpdateCommand();
    command.setLogger(getLogger());
    return (UpdateScmResult) command.execute(repository, fileSet, parameters);
}
Also used : UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) LocalUpdateCommand(org.apache.maven.scm.provider.local.command.update.LocalUpdateCommand)

Example 34 with UpdateScmResult

use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.

the class PerforceScmProvider method update.

protected UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    PerforceUpdateCommand command = new PerforceUpdateCommand();
    command.setLogger(getLogger());
    return (UpdateScmResult) command.execute(repository, fileSet, params);
}
Also used : PerforceUpdateCommand(org.apache.maven.scm.provider.perforce.command.update.PerforceUpdateCommand) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult)

Example 35 with UpdateScmResult

use of org.apache.maven.scm.command.update.UpdateScmResult in project maven-scm by apache.

the class GitUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    if (GitScmProviderRepository.PROTOCOL_FILE.equals(repository.getFetchInfo().getProtocol()) && repository.getFetchInfo().getPath().indexOf(fileSet.getBasedir().getPath()) >= 0) {
        throw new ScmException("remote repository must not be the working directory");
    }
    int exitCode;
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    // fir we need to get the current reversion
    Commandline clRev = createLatestRevisionCommandLine(repository, fileSet.getBasedir(), scmVersion);
    GitLatestRevisionCommandConsumer consumerRev = new GitLatestRevisionCommandConsumer(getLogger());
    exitCode = GitCommandLineUtils.execute(clRev, consumerRev, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(clRev.toString(), "The git-log command failed.", stderr.getOutput(), false);
    }
    String origSha1 = consumerRev.getLatestRevision();
    Commandline cl = createCommandLine(repository, fileSet.getBasedir(), scmVersion);
    exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(cl.toString(), "The git-pull command failed.", stderr.getOutput(), false);
    }
    // we also need to log exactly what has been updated
    GitDiffRawConsumer diffRawConsumer = new GitDiffRawConsumer(getLogger());
    Commandline clDiffRaw = GitDiffCommand.createDiffRawCommandLine(fileSet.getBasedir(), origSha1);
    exitCode = GitCommandLineUtils.execute(clDiffRaw, diffRawConsumer, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(clDiffRaw.toString(), "The git-diff --raw command failed.", stderr.getOutput(), false);
    }
    // now let's get the latest version
    consumerRev = new GitLatestRevisionCommandConsumer(getLogger());
    exitCode = GitCommandLineUtils.execute(clRev, consumerRev, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(clRev.toString(), "The git-log command failed.", stderr.getOutput(), false);
    }
    String latestRevision = consumerRev.getLatestRevision();
    return new UpdateScmResultWithRevision(cl.toString(), diffRawConsumer.getChangedFiles(), latestRevision);
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) GitDiffRawConsumer(org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffRawConsumer)

Aggregations

UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)35 File (java.io.File)10 ScmFile (org.apache.maven.scm.ScmFile)10 ScmException (org.apache.maven.scm.ScmException)9 UpdateScmResultWithRevision (org.apache.maven.scm.command.update.UpdateScmResultWithRevision)7 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 ScmFileSet (org.apache.maven.scm.ScmFileSet)6 ArrayList (java.util.ArrayList)5 ScmRepository (org.apache.maven.scm.repository.ScmRepository)5 Commandline (org.codehaus.plexus.util.cli.Commandline)5 Date (java.util.Date)4 ChangeSet (org.apache.maven.scm.ChangeSet)4 CommandParameters (org.apache.maven.scm.CommandParameters)4 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)4 IOException (java.io.IOException)3 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)3 ScmManager (org.apache.maven.scm.manager.ScmManager)3 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ScmResult (org.apache.maven.scm.ScmResult)2