Search in sources :

Example 26 with UpdateScmResult

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

the class CvsJavaUpdateCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsLogListener logListener = new CvsLogListener();
    CvsUpdateConsumer consumer = new CvsUpdateConsumer(getLogger());
    try {
        boolean isSuccess = CvsConnection.processCommand(cl.getArguments(), cl.getWorkingDirectory().getAbsolutePath(), logListener, getLogger());
        if (!isSuccess) {
            return new UpdateScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
        }
        BufferedReader stream = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(logListener.getStdout().toString().getBytes())));
        String line;
        while ((line = stream.readLine()) != null) {
            consumer.consumeLine(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return new UpdateScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
    }
    return new UpdateScmResult(cl.toString(), consumer.getUpdatedFiles());
}
Also used : CvsUpdateConsumer(org.apache.maven.scm.provider.cvslib.command.update.CvsUpdateConsumer) CvsLogListener(org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) BufferedReader(java.io.BufferedReader) ScmException(org.apache.maven.scm.ScmException)

Example 27 with UpdateScmResult

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

the class CvsUpdateCommandTest method testCvsUpdate.

/**
 * @todo merge into tck
 */
public void testCvsUpdate() throws Exception {
    FileWriter writer = null;
    try {
        if (!isSystemCmd(CvsScmTestUtils.CVS_COMMAND_LINE)) {
            System.err.println("'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + ".");
            return;
        }
        ScmManager scmManager = getScmManager();
        String scmUrl = CvsScmTestUtils.getScmUrl(repository, getModule());
        // Check out the repo to a working directory where files will be modified and committed
        String arguments = "-f -d " + repository.getAbsolutePath() + " " + "co -d " + workingDirectory.getName() + " " + getModule();
        CvsScmTestUtils.executeCVS(workingDirectory.getParentFile(), arguments);
        // Check out the repo to a assertion directory where the command will be used
        arguments = "-f -d " + repository.getAbsolutePath() + " " + "co -d " + assertionDirectory.getName() + " " + getModule();
        CvsScmTestUtils.executeCVS(assertionDirectory.getParentFile(), arguments);
        // A new check out should return 0 updated files.
        ScmRepository scmRepository = scmManager.makeScmRepository(scmUrl);
        UpdateScmResult result = scmManager.update(scmRepository, new ScmFileSet(assertionDirectory));
        assertNotNull(result);
        if (!result.isSuccess()) {
            System.out.println("result.providerMessage: " + result.getProviderMessage());
            System.out.println("result.commandOutput: " + result.getCommandOutput());
            fail("Command failed");
        }
        assertNull(result.getProviderMessage());
        assertNull(result.getCommandOutput());
        assertNotNull(result.getUpdatedFiles());
        assertEquals(0, result.getUpdatedFiles().size());
        // Modifing a file
        File fooJava = new File(workingDirectory, "Foo.java");
        String content = FileUtils.fileRead(fooJava);
        writer = new FileWriter(fooJava);
        writer.write(content + System.getProperty("line.separator"));
        writer.write("extra line");
        writer.close();
        // Adding a new file
        writer = new FileWriter(new File(workingDirectory, "New.txt"));
        writer.write("new file");
        writer.close();
        arguments = "-f -d " + repository.getAbsolutePath() + " add New.txt";
        CvsScmTestUtils.executeCVS(workingDirectory, arguments);
        // Committing
        arguments = "-f -d " + repository.getAbsolutePath() + " commit -m .";
        CvsScmTestUtils.executeCVS(workingDirectory, arguments);
        // Check the updated files
        result = scmManager.update(scmRepository, new ScmFileSet(assertionDirectory));
        assertNotNull(result);
        if (!result.isSuccess()) {
            System.out.println("result.providerMessage: " + result.getProviderMessage());
            System.out.println("result.commandOutput: " + result.getCommandOutput());
            fail("Command failed");
        }
        assertNull(result.getProviderMessage());
        assertNull(result.getCommandOutput());
        assertNotNull(result.getUpdatedFiles());
        assertEquals(2, result.getUpdatedFiles().size());
        ScmFile file1 = result.getUpdatedFiles().get(0);
        assertPath("Foo.java", file1.getPath());
        assertEquals(ScmFileStatus.UPDATED, file1.getStatus());
        ScmFile file2 = result.getUpdatedFiles().get(1);
        assertPath("New.txt", file2.getPath());
        assertEquals(ScmFileStatus.UPDATED, file2.getStatus());
    } finally {
        IOUtil.close(writer);
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) FileWriter(java.io.FileWriter) 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) ScmFile(org.apache.maven.scm.ScmFile)

Example 28 with UpdateScmResult

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

the class IntegrityUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
@Override
public UpdateScmResult executeUpdateCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
    getLogger().info("Attempting to synchronize sandbox in " + fileSet.getBasedir().getAbsolutePath());
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    Sandbox siSandbox = iRepo.getSandbox();
    try {
        // Make sure we've got a valid sandbox, otherwise create it...
        if (siSandbox.create()) {
            Response res = siSandbox.resync();
            // Lets capture what we got from running this resync
            WorkItemIterator wit = res.getWorkItems();
            while (wit.hasNext()) {
                WorkItem wi = wit.next();
                if (wi.getModelType().equals(SIModelTypeName.MEMBER)) {
                    Result message = wi.getResult();
                    getLogger().debug(wi.getDisplayId() + " " + (null != message ? message.getMessage() : ""));
                    if (null != message && message.getMessage().length() > 0) {
                        updatedFiles.add(new ScmFile(wi.getDisplayId(), message.getMessage().equalsIgnoreCase("removed") ? ScmFileStatus.DELETED : ScmFileStatus.UPDATED));
                    }
                }
            }
            return new UpdateScmResult(res.getCommandString(), updatedFiles);
        } else {
            return new UpdateScmResult("si resync", "Failed to synchronize workspace", "", false);
        }
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
        return new UpdateScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
}
Also used : Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) WorkItemIterator(com.mks.api.response.WorkItemIterator) WorkItem(com.mks.api.response.WorkItem) ScmFile(org.apache.maven.scm.ScmFile) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) Result(com.mks.api.response.Result)

Example 29 with UpdateScmResult

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

the class SvnUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version);
    SvnUpdateConsumer consumer = new SvnUpdateConsumer(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 UpdateScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    UpdateScmResultWithRevision result = new UpdateScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
    result.setChanges(consumer.getChangeSets());
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("changeSets " + consumer.getChangeSets());
    }
    return result;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 30 with UpdateScmResult

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

the class SynergyScmProvider method update.

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

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