Search in sources :

Example 11 with UpdateScmResult

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

the class VssScmProvider method update.

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

Example 12 with UpdateScmResult

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

the class MavenScmCli method update.

private void update(ScmRepository scmRepository, File workingDirectory, ScmVersion version) throws ScmException {
    if (!workingDirectory.exists()) {
        System.err.println("The working directory doesn't exist: '" + workingDirectory.getAbsolutePath() + "'.");
        return;
    }
    UpdateScmResult result = scmManager.update(scmRepository, new ScmFileSet(workingDirectory), version);
    if (!result.isSuccess()) {
        showError(result);
        return;
    }
    List<ScmFile> updatedFiles = result.getUpdatedFiles();
    System.out.println("Updated these files: ");
    for (ScmFile file : updatedFiles) {
        System.out.println(" " + file.getPath());
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 13 with UpdateScmResult

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

the class JazzUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing update command...");
    }
    JazzUpdateConsumer updateConsumer = new JazzUpdateConsumer(repo, getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    JazzScmCommand updateCmd = createAcceptCommand(repo, fileSet);
    int status = updateCmd.execute(updateConsumer, errConsumer);
    if (status != 0) {
        return new UpdateScmResult(updateCmd.getCommandString(), "Error code for Jazz SCM update command - " + status, errConsumer.getOutput(), false);
    }
    if (getLogger().isDebugEnabled()) {
        if (!updateConsumer.getUpdatedFiles().isEmpty()) {
            getLogger().debug("Iterating over \"Update\" results");
            for (ScmFile file : updateConsumer.getUpdatedFiles()) {
                getLogger().debug(file.getPath() + " : " + file.getStatus());
            }
        } else {
            getLogger().debug("There are no updated files");
        }
    }
    // We can use the checkout directory for this.
    return new UpdateScmResult(updateCmd.getCommandString(), updateConsumer.getUpdatedFiles());
}
Also used : ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) ScmFile(org.apache.maven.scm.ScmFile)

Example 14 with UpdateScmResult

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

the class JazzScmProvider method update.

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

Example 15 with UpdateScmResult

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

the class UpdateCommandTckTest method testUpdateCommand.

public void testUpdateCommand() throws Exception {
    deleteDirectory(getUpdatingCopy());
    assertFalse(getUpdatingCopy().exists());
    // deleteDirectory( getWorkingCopy() );
    // assertFalse( getUpdatingCopy().exists() );
    ScmRepository repository = makeScmRepository(getScmUrl());
    checkOut(getUpdatingCopy(), repository);
    // ----------------------------------------------------------------------
    // Change the files
    // ----------------------------------------------------------------------
    /*
         * readme.txt is changed (changed file in the root directory)
         * project.xml is added (added file in the root directory)
         * src/test/resources is untouched (a empty directory is left untouched)
         * src/test/java is untouched (a non empty directory is left untouched)
         * src/test/java/org (a empty directory is added)
         * src/main/java/org/Foo.java (a non empty directory is added)
         */
    // /readme.txt
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    // /project.xml
    ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
    addToWorkingTree(getWorkingCopy(), new File("project.xml"), getScmRepository());
    // /src/test/java/org
    ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org");
    addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"), getScmRepository());
    // /src/main/java/org/Foo.java
    ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java");
    addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"), getScmRepository());
    // src/main/java/org/Foo.java
    addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), getScmRepository());
    ScmManager scmManager = getScmManager();
    Date lastUpdate = new Date(System.currentTimeMillis() - 1000000);
    commit(getWorkingCopy(), getScmRepository());
    Thread.sleep(5000);
    // ----------------------------------------------------------------------
    // Update the project
    // ----------------------------------------------------------------------
    UpdateScmResult result = scmManager.update(repository, new ScmFileSet(getUpdatingCopy()), lastUpdate);
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    List<ScmFile> updatedFiles = result.getUpdatedFiles();
    List<ChangeSet> changedSets = result.getChanges();
    assertEquals("Expected 3 files in the updated files list " + updatedFiles, 3, updatedFiles.size());
    assertNotNull("The changed files list is null", changedSets);
    assertFalse("The changed files list is empty ", changedSets.isEmpty());
    for (ChangeSet changeSet : changedSets) {
        System.out.println(changeSet.toXML());
    }
    // ----------------------------------------------------------------------
    // Assert the files in the updated files list
    // ----------------------------------------------------------------------
    Iterator<ScmFile> files = new TreeSet<ScmFile>(updatedFiles).iterator();
    // Foo.java
    ScmFile file = files.next();
    assertPath("/src/main/java/org/Foo.java", file.getPath());
    // TODO : Consolidate file status so that we can remove "|| ADDED" term
    assertTrue(file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED);
    // readme.txt
    file = files.next();
    assertPath("/readme.txt", file.getPath());
    assertTrue(file.getStatus().isUpdate());
    // project.xml
    file = files.next();
    assertPath("/project.xml", file.getPath());
    // TODO : Consolidate file status so that we can remove "|| ADDED" term
    assertTrue(file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmManager(org.apache.maven.scm.manager.ScmManager) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date) ScmFile(org.apache.maven.scm.ScmFile)

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