Search in sources :

Example 1 with UpdateScmResult

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

the class AccurevUpdateCommandTest method testAccuRevFailure.

@Test
public void testAccuRevFailure() throws Exception {
    final ScmFileSet testFileSet = new ScmFileSet(new File("/my/workspace/project/dir"));
    final File basedir = testFileSet.getBasedir();
    info.setWorkSpace("theWorkSpace");
    when(accurev.update(eq(basedir), any(String.class))).thenReturn(null);
    AccuRevUpdateCommand command = new AccuRevUpdateCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString(false));
    UpdateScmResult result = command.update(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(false));
    assertThat(result.getProviderMessage(), notNullValue());
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 2 with UpdateScmResult

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

the class LocalUpdateCommandTckTest method testDeletion.

/**
 * Tests that a file that has been deleted from repository after checkout will be removed by scm-local. Local
 * additions must not be deleted.
 */
public void testDeletion() throws Exception {
    FileUtils.deleteDirectory(getUpdatingCopy());
    ScmRepository repository = makeScmRepository(getScmUrl());
    checkOut(getUpdatingCopy(), repository);
    // Check preconditions
    File readmeFileLocal = new File(getUpdatingCopy(), "readme.txt");
    assertTrue(readmeFileLocal.exists());
    File newFileLocal = new File(getUpdatingCopy(), "newfile.xml");
    assertTrue(!newFileLocal.exists());
    // Delete readme.txt from repository
    File readmeFileRepo = new File(getRepositoryRoot(), moduleName + "/readme.txt");
    assertTrue(readmeFileRepo.exists());
    assertTrue("Could not delete", readmeFileRepo.delete());
    assertFalse(readmeFileRepo.exists());
    // Make local addition to updating copy - this one must not be touched
    ScmTestCase.makeFile(getUpdatingCopy(), "newfile.xml", "added newfile.xml locally");
    assertTrue(newFileLocal.exists());
    // ----------------------------------------------------------------------
    // Update the project
    // ----------------------------------------------------------------------
    ScmManager scmManager = getScmManager();
    Date lastUpdate = new Date(System.currentTimeMillis());
    Thread.sleep(1000);
    UpdateScmResult result = scmManager.update(repository, new ScmFileSet(getUpdatingCopy()), lastUpdate);
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    List<ScmFile> updatedFiles = result.getUpdatedFiles();
    assertEquals("Expected 1 files in the updated files list " + updatedFiles, 1, updatedFiles.size());
    // ----------------------------------------------------------------------
    // Assert the files in the updated files list
    // ----------------------------------------------------------------------
    Iterator<ScmFile> files = new TreeSet<ScmFile>(updatedFiles).iterator();
    // readme.txt
    ScmFile file = (ScmFile) files.next();
    assertPath("/readme.txt", file.getPath());
    assertTrue(file.getStatus().isUpdate());
    // ----------------------------------------------------------------------
    // Assert working directory contents
    // ----------------------------------------------------------------------
    // readme.txt
    assertTrue("Expected local copy of readme.txt to be deleted", !readmeFileLocal.exists());
    // newfile.xml
    assertTrue("Expected local copy of newfile.xml NOT to be deleted", newFileLocal.exists());
    // ----------------------------------------------------------------------
    // Assert metadata file
    // ----------------------------------------------------------------------
    File metadataFile = new File(getUpdatingCopy(), ".maven-scm-local");
    assertTrue("Expected metadata file .maven-scm-local does not exist", metadataFile.exists());
    Reader reader = new FileReader(metadataFile);
    LocalScmMetadata metadata;
    try {
        metadata = new LocalScmMetadataXpp3Reader().read(reader);
    } finally {
        IOUtil.close(reader);
    }
    File root = new File(getRepositoryRoot() + "/" + moduleName);
    @SuppressWarnings("unchecked") List<String> fileNames = FileUtils.getFileNames(root, "**", null, false);
    assertEquals(fileNames, metadata.getRepositoryFileNames());
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) LocalScmMetadata(org.apache.maven.scm.provider.local.metadata.LocalScmMetadata) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) Reader(java.io.Reader) FileReader(java.io.FileReader) LocalScmMetadataXpp3Reader(org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader) Date(java.util.Date) ScmFile(org.apache.maven.scm.ScmFile) LocalScmMetadataXpp3Reader(org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader) ScmManager(org.apache.maven.scm.manager.ScmManager) FileReader(java.io.FileReader) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 3 with UpdateScmResult

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

the class PerforceUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion scmVersion) throws ScmException {
    // In Perforce, there is no difference between update and checkout.
    // Here we just run the checkout command and map the result onto an
    // UpdateScmResult.
    PerforceCheckOutCommand command = new PerforceCheckOutCommand();
    command.setLogger(getLogger());
    CommandParameters params = new CommandParameters();
    params.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
    CheckOutScmResult cosr = (CheckOutScmResult) command.execute(repo, files, params);
    if (!cosr.isSuccess()) {
        return new UpdateScmResult(cosr.getCommandLine(), cosr.getProviderMessage(), cosr.getCommandOutput(), false);
    }
    PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
    String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, files.getBasedir());
    Commandline cl = createCommandLine(p4repo, files.getBasedir(), clientspec);
    @SuppressWarnings("unused") String location = PerforceScmProvider.getRepoPath(getLogger(), p4repo, files.getBasedir());
    PerforceHaveConsumer consumer = new PerforceHaveConsumer(getLogger());
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
        }
        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
        int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
        if (exitCode != 0) {
            String cmdLine = CommandLineUtils.toString(cl.getCommandline());
            StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
            msg.append('\n');
            msg.append("Command line was:" + cmdLine);
            throw new CommandLineException(msg.toString());
        }
    } catch (CommandLineException e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("CommandLineException " + e.getMessage(), e);
        }
    }
    return new UpdateScmResultWithRevision(cosr.getCommandLine(), cosr.getCheckedOutFiles(), String.valueOf(consumer.getHave()));
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) PerforceScmProviderRepository(org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository) PerforceCheckOutCommand(org.apache.maven.scm.provider.perforce.command.checkout.PerforceCheckOutCommand)

Example 4 with UpdateScmResult

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

the class HgUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion tag) throws ScmException {
    File workingDir = fileSet.getBasedir();
    String[] updateCmd;
    // Update branch
    if (repo.isPushChanges()) {
        updateCmd = new String[] { HgCommandConstants.PULL_CMD, HgCommandConstants.REVISION_OPTION, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
    } else {
        updateCmd = new String[] { HgCommandConstants.UPDATE_CMD, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip", HgCommandConstants.CLEAN_OPTION };
    }
    ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = HgUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { HgCommandConstants.DIFF_CMD, HgCommandConstants.REVISION_OPTION, "" + previousRevision };
    HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = HgUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
    // Now translate between diff and update file status
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    List<CharSequence> changes = new ArrayList<CharSequence>();
    List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
    Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
    for (ScmFile file : diffFiles) {
        changes.add(diffChanges.get(file.getPath()));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    if (repo.isPushChanges()) {
        String[] hgUpdateCmd = new String[] { HgCommandConstants.UPDATE_CMD };
        HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, hgUpdateCmd);
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) HgDiffConsumer(org.apache.maven.scm.provider.hg.command.diff.HgDiffConsumer) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 5 with UpdateScmResult

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

the class IntegrityScmProvider method update.

/**
 * Maps to si resync
 */
@Override
protected UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    IntegrityUpdateCommand command = new IntegrityUpdateCommand();
    command.setLogger(getLogger());
    return (UpdateScmResult) command.execute(repository, fileSet, params);
}
Also used : UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) IntegrityUpdateCommand(org.apache.maven.scm.provider.integrity.command.update.IntegrityUpdateCommand)

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