Sunday, 7 August 2011

OSLC Development using C/C++ and Rational Team Concert (Part 2)

This is the second part in what i hope will be a series of posts on C/C++ development in Rational Team Concert (RTC).

In Part 1 I showed how to set up the CDT environment in RTC 3.0.1. If you haven't gone through the steps in Part 1 you should do so before doing this part. You should be able to build simple code now. 
In this part you will import an OSLC client written in C++ (see my post on OSLC). In order to do so we need to introduce some libraries into our environment to be able to make HTTP requests (libcurl) and parse the returning XML (libxml2).

You'll need the following:

(Latest as of publishing)
1. libcurl:
2. libxml2:
3. libiconv:
4. RTC OSLC C++ Project: OSLC

Configure and Install:

1. First lets download some dependencies into prep our MinGW environment. Open up a command prompt and type the following commands:
mingw-get install zlib
mingw-get install libiconv
2. Unzip the Ensure that the contents of bin,include,lib, etc. are extracted into the corresponding directories in the MinGW home (usually C:\MinGW)

3. Now unzip the Again, Ensure that the contents of bin,include,lib, etc. are extracted into the corresponding directories in the MinGW home (usually C:\MinGW). 
As libxml2 is a generic win32 package, we need to prep it from MinGW.  Open a command prompt and type:
cd C:\mingw\bin (or wherever you MinGW home is)
pexports libxml2.dll > libxml2.def
dlltool --dllname libxml2.dll --def libxml2.def --output-lib ../lib/libxml2.a

4. One more dependency is missing that is needed by libxml2. Open the and extract bin\iconv.dll into C:\mingw\bin (or wherever you MinGW home is)

5. Now we are going to import the sample project into RTC.
-Launch RTC Client
-General->Existing Projects Into Workspace
-Click Next
-Select Archive File: Browse for the OSLC file downloaded earlier
-Click Finish

You can to build and run the project at this point by right clicking on the newly imported project and selecting "Build Project". It should build without errors or warnings. Unless you have exactly the same host,port,username and password you will get some kind of connect error if you try to run it using the run button ().

If you take a look at the source code the first thing you will notice is that this is neither proper C nor C++ code. As this is just a code sample to convey the general idea, it was written up in a very simple linear fashion with no classes or many parameters.
In order for the code to connect to your Jazz Server you will need to change the hostname, port and username/password in the OSLCPAFetch.h file.
const std::string server = "https://localhost:9443/ccm"; <-your Jazz server
const std::string login = "username"; <-your user name
const std::string password = "password"; <- your password

This code demonstrates a few things:

1. A set up build environment that has extra libraries (take a look at the project properties for the linking, C/C++ Build->Settings->MinGW C++ Linker->General)
2. How to create OSLC requests (note the header parsing).
3. How to do form based authentication with Jazz
4. How to fetch Project areas using the xml2 XPath functionality.

If you need to have more in depth information about how this code functionality works I suggest to take a look at the OSLC workshop as this code sample is loosely based on it. Enjoy!

Next up (part 3)... creating an automated build environment for our new code using RTC SCM and automated builds!

1 comment:

  1. Boris, could you please put a license on your code (preferably MIT or EDL), please?