CLI parsing got you down? Good news, we’ve got an API for that. We introduced a cross-platform C API with Java and .NET wrappers in the Surround SCM 2010.0 release. All three versions of the API have the same functionality – anything you can do from the C API you can do from either Java or .NET. “What can I do with the API?”, you ask. Well,  you can Add a file, Checkin, Checkout, Get, Undo Checkout, Search, Create repository, Create branch, Promote, Rebase, Manage labels, Add user, Rollback files, Share, Break share, and much more.

Getting started with the API is easy. For the C API, all you need is the header file and libsscmapi. For the Java API, you’ll need the JAR and libsscmapi. For the .NET API, you’ll just need libsscmapi.

Regardless of which language you choose, everything you’ll need can be found in your “Surround SCM/API” directory (if the directory is missing, try re-running the installer, make sure you select the option to install the API). You will also find the API documentation there (“Surround SCM/API/docs”).

Can’t think of anything to do with the API? Here’s a few ideas to get you started:

  • DIY Webclient: Both .NET and Java have rich web application frameworks.
  • Cronjob: The CLI would work fine for this, but you’re a programmer and code rules!
  • Automation: Find yourself performing the same set of SCM tasks? Automate it.
  • GUI Plugin: If you didn’t already know, you can add menu options to the SCM GUI. When clicked, the menu option will launch your executable. Use the API to combine a 2 or 3 step process into a single step.

Here is an example of getting a file from Surround SCM (shown in all three APIs).

C API:

//////////////////////////////////////////////////////
#include <stdio.h>
#include "sscmapi.h"
int main(int argc, char *argv[])
{
   struct SSCMContext context;
   context.cbSize = sizeof(struct SSCMContext);
   SSCMResult result = sscm_connect("localhost",     // Server address
                                    4900,            // Port number
                                    "Administrator", // Username
                                    "adminIS1337",   // Password
                                    &context);
   if (SSCM_API_OK == result)
   {
      context.pBranch = "Branch";
      context.pMainline = "Mainline";
      unsigned int version = 0;
      result = sscm_get_file(&context,
                                      "Mainline/Repo1",
                                      "test.c",
                                      "/tmp",
                                      currentDate,
                                      &version,
                                      0);
      if (SSCM_API_OK == result)
         printf("Retrieved file version: %d\n", version);
      sscm_disconnect(&context);
   }
   else
   {
     char *pError = sscm_get_last_error(result);
     printf("Unable to connect: %s\n", pError);
     sscm_free_string(pError);
   }
   return 0;
}
//////////////////////////////////////////////////////

C# API:

//////////////////////////////////////////////////////
using System;
using System.Text;
using Seapine.SurroundSCM.API;
static class SurroundSCMAPIExample
{
   static void Main()
   {
      SSCMContext context;
      SSCMResult result = SSCMAPI.Connect("localhost",     // Server Address
                                          4900,            // Port number
                                          "Administrator", // Username
                                          "adminIS1337",   // Password
                                          out context);
      if (result.IsOk())
      {
         context.SetBranch("Branch");
         context.SetMainline("Mainline");
         UInt32 version = 0;
         result = SSCMAPI.GetFile(context,
                                  "Mainline/Repo1",
                                  "test.c",
                                  "/tmp",
                                  TimestampType.CurrentDate,
                                  ref version,
                                  false);
         if (result.IsOk())
            Console.WriteLine("Retrieved file version: " + version);
         SSCMAPI.Disconnect(context);
      }
      else
      {
         String sError = SSCMAPI.GetLastError(result);
         Console.WriteLine("Unable to connect: " + sError);
      }
   }
}
//////////////////////////////////////////////////////

Java API:

//////////////////////////////////////////////////////
import com.seapine.surroundscm.api.*;
public class SurroundSCMAPIExample {
    public static void main(String[] args)
    {
        SSCMContext context = new SSCMContext();
        SSCMResult result = SSCMAPI.connect("localhost",     // Server Address
                                            4900,            // Port number
                                            "Administrator", // Username
                                            "adminIS1337",   // Password
                                            context);
        if(SSCMAPI.SSCM_API_OK == result.result)
        {
            context.Mainline = "Mainline";
            context.Branch = "Branch";
            SSCMGetFileResult getResult;
            getResult = SSCMAPI.getFile(context,
                                        "Mainline/Repo1",
                                        "test.c",
                                        "/tmp",
                                        SSCMAPI.eTimestampType.currentDate,
                                        0,
                                        false);
            if(SSCMAPI.SSCM_API_OK == getResult.result)
                System.out.println("Retrieved file version: " + getResult.version);
            SSCMAPI.disconnect(context);
        }
        else
        {
            String sError = SSCMAPI.getLastError(result.result);
            System.out.println("Unable to connect: " + sError);
        }
    }
}
//////////////////////////////////////////////////////

Any ideas you want to share? Leave a comment!

Share on Technorati . del.icio.us . Digg . Reddit . Slashdot . Facebook . StumbleUpon

Related posts:

  1. Surround SCM API and Plugin Samples
  2. About Surround SCM Rollbacks
  3. Adding Users During Your Surround SCM Evaluation
  4. Automating A .NET Build With MSBuild and Surround SCM
  5. Surround SCM Custom Client Menus
6 Comments

Tags: , , ,

6 Comments to Surround SCM: We’ve Got an API for That

Dan Woerner
June 29, 2010

Looks good, but is this API anywhere I can download? (C#.NET 2008)

Wesley Workman
June 30, 2010

@Dan Woerner
Each new version of Surround SCM contains changes in the client/server communication protocol, because of that it’s crucial you get the matching API library for your installed version. You can find it under “C:\Program Files\Seapine\Surround SCM\API\lib”. If your missing the API folder please re-run your Surround SCM installer and make sure you check to install the “Surround SCM API” on the “Installation Type” screen of the installer. If you are not yet a Surround SCM customer please let me know and I’ll get you more information.

Anna
August 9, 2010

Hey Wesley,

I am checking into evaluating Surround SCM and I have a question. Part of my development team is using GNAT Programming Studio (GNAT/GPS)for Ada development and I don’t see a Ada plugin. Is there an API that will provide an interface from Surround SCM GUI to GNAT/GPS so the developers can muniplate (ci, co, commit, update, etc…) files.

Thank you for your support. I’m looking forward to your comments.

Anna

Wesley Workman
August 9, 2010

@Anna

Unfortunately at the current time we do not provide a GUI integration for GNAT. You can use the Surround SCM API (mentioned in this blog post) to create your own GNAT integration to fit the needs of your team.

We are always looking to provide new integrations, you can make an official request for GNAT integration by visiting the following link: http://www.seapine.com/requestfeature.php

– Wesley

Malcolm Howlett
October 1, 2010

Hallo Wesley,

any chance of extending the API to include setting custom fields and changing state?

We are still stuck with the cli which is cumbersome and slow.

Malcolm

Wesley Workman
October 1, 2010

@Malcolm

It sounds like a good idea to me. I have just submitted a formal feature request to add API functions for setting custom fields and changing states, however I cannot say when these functions will be added to the API.

– Wesley

Leave a comment

WP_Big_City

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree

Page optimized by WP Minify WordPress Plugin