Search in sources :

Example 16 with UpdateScmResult

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

the class StarteamScmProvider method update.

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

Example 17 with UpdateScmResult

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

the class SynergyUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing update command...");
    }
    SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("basedir: " + fileSet.getBasedir());
    }
    String ccmAddr = SynergyUtil.start(getLogger(), repo.getUser(), repo.getPassword(), null);
    File waPath;
    try {
        String projectSpec = SynergyUtil.getWorkingProject(getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr);
        SynergyUtil.reconfigureProperties(getLogger(), projectSpec, ccmAddr);
        SynergyUtil.reconfigure(getLogger(), projectSpec, ccmAddr);
        // We need to get WA path
        waPath = SynergyUtil.getWorkArea(getLogger(), projectSpec, ccmAddr);
    } finally {
        SynergyUtil.stop(getLogger(), ccmAddr);
    }
    File source = new File(waPath, repo.getProjectName());
    // Move file from work area to expected dir if not the same
    List<ScmFile> modifications = new ArrayList<ScmFile>();
    if (!source.equals(fileSet.getBasedir())) {
        if (getLogger().isInfoEnabled()) {
            getLogger().info("We will copy modified files from Synergy Work Area [" + source + "] to expected folder [" + fileSet.getBasedir() + "]");
        }
        try {
            copyDirectoryStructure(source, fileSet.getBasedir(), modifications);
        } catch (IOException e1) {
            throw new ScmException("Unable to copy directory structure", e1);
        }
    }
    return new UpdateScmResult("ccm reconcile -uwa ...", modifications);
}
Also used : ScmException(org.apache.maven.scm.ScmException) SynergyScmProviderRepository(org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository) ArrayList(java.util.ArrayList) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) IOException(java.io.IOException) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 18 with UpdateScmResult

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

the class AccurevUpdateCommandTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final File keptFile = new File("updated/file");
    final File keptAdded = new File("new/file");
    List<File> files = Arrays.asList(keptFile, keptAdded);
    when(accurev.update(eq(basedir), any(String.class))).thenReturn(files);
    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(true));
    assertThat(result.getUpdatedFiles().size(), is(2));
    assertHasScmFile(result.getUpdatedFiles(), "updated/file", ScmFileStatus.UPDATED);
    assertHasScmFile(result.getUpdatedFiles(), "new/file", ScmFileStatus.UPDATED);
}
Also used : 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 19 with UpdateScmResult

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

the class AccurevUpdateCommandTest method testUpdateWithChangeLog.

@Test
public void testUpdateWithChangeLog() throws Exception {
    final WorkSpace wsBefore = new WorkSpace("theWorkSpace", 123);
    Map<String, WorkSpace> workspaces = Collections.singletonMap("theWorkSpace", wsBefore);
    when(accurev.showWorkSpaces()).thenReturn(workspaces);
    List<File> emptyList = Collections.emptyList();
    when(accurev.update(eq(basedir), any(String.class))).thenReturn(emptyList);
    final Date currentDate = new Date();
    List<Transaction> transactions = Collections.singletonList(new Transaction(197L, currentDate, "type", "user"));
    when(accurev.history(any(String.class), any(String.class), any(String.class), eq(1), eq(true), eq(true))).thenReturn(transactions);
    AccuRevUpdateCommand command = new AccuRevUpdateCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString(true));
    UpdateScmResult result = command.update(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    assertThat(result, IsInstanceOf.instanceOf(AccuRevUpdateScmResult.class));
    AccuRevUpdateScmResult accuRevResult = (AccuRevUpdateScmResult) result;
    assertThat(accuRevResult.getFromRevision(), is("theWorkSpace/123"));
    assertThat(accuRevResult.getToRevision(), is("theWorkSpace/197"));
}
Also used : WorkSpace(org.apache.maven.scm.provider.accurev.WorkSpace) Transaction(org.apache.maven.scm.provider.accurev.Transaction) 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) Date(java.util.Date) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 20 with UpdateScmResult

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

the class BazaarUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        throw new ScmException("This provider can't handle tags.");
    }
    File workingDir = fileSet.getBasedir();
    // Update branch
    String[] updateCmd = new String[] { BazaarConstants.PULL_CMD };
    ScmResult updateResult = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = BazaarUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision };
    BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = BazaarUtils.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 (Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); ) {
        ScmFile file = it.next();
        changes.add(diffChanges.get(file));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : ScmException(org.apache.maven.scm.ScmException) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) BazaarDiffConsumer(org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

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