CM Adapter SDK Guide
CM Adapter SDK Guide
Contents
Introduction ............................................................................................................................................ 2
Terminology ........................................................................................................................................ 2
REQUIREMENTS ...................................................................................................................................... 2
CMLINK API ............................................................................................................................................. 2
Interfaces ............................................................................................................................................ 2
Javadoc................................................................................................................................................ 4
Jar Dependencies ................................................................................................................................ 4
Sandbox Detection .............................................................................................................................. 4
Supported Features ............................................................................................................................ 5
Manifest .............................................................................................................................................. 5
MATLAB Classpath .......................................................................................................................... 6
JUnit Tests ............................................................................................................................................... 6
Source Code ........................................................................................................................................ 7
Jar Dependencies ................................................................................................................................ 7
Locking CM Systems ............................................................................................................................ 7
Example Source Control Adapter ............................................................................................................ 7
Building with Ant................................................................................................................................. 7
Using the Example Adapter in MATLAB .......................................................................................... 8
Source Code ........................................................................................................................................ 8
Jar Dependencies ................................................................................................................................ 9
Introduction
You can use this Software Development Kit (SDK) to integrate Simulink Projects with a source
control tool that has a published API that can be called from Java. You must create a jar file which
implements a collection of Java interfaces and a Java Manifest file which defines a set of required
properties.
The SDK consists of two parts: this document, and a zip-file containing
Javadoc for the com.mathworks.cmlink API. This API contains all of the Java interfaces you
need to implement to produce a source control adapter for the Simulink Project.
JUnit tests to validate your source control adapter.
Example source code for an Apache Subversion (SVN) source control adapter. Use this
example to guide you in creating your own integration with the Simulink Project.
Files for use with the MATLAB programming language that can assist with building and
testing a source control adapter.
Terminology
Within this SDK we use the following terms:
Adapter: the software that provides an interface between an external source control tool and
Simulink projects.
Repository: a location where files are stored when they are under the control of a source control
tool.
Sandbox: a folder containing a working copy of files copied out of a source control repository.
Matlabroot: the folder where MATLAB is installed. Find the location of your MATLAB root by
running the command matlabroot at the MATLAB command line.
REQUIREMENTS
The use of this SDK requires version 1.7 of the Oracle JDK.
CMLINK API
Interfaces
The Simulink Project interacts with an external source control system through three Java interfaces:
CMAdapter, CMRepository, and CMAdapterFactory. You need to implement all three interfaces in
order to create a source control adapter. This section provides an overview of the role of the
interfaces you need to implement, and how the interfaces fit together.
CMAdapter
All sandbox level actions are done through this interface. For example, adding files, deleting
files, updating files, committing files, reverting files etc.
It is called CMAdapter because it provides an Adapter layer between a source control tool
and a common interface which can be used by the Simulink Project.
CMRepository
All repository level actions, where a valid sandbox doesnt need to exist, are handled
through this interface.
This provides functionality to create a sandbox, check out files from a repository, etc.
CMAdapterFactory
Instantiates CMAdpater and CMRepository instances
The Simulink Project loads all implementations of CMAdapterFactory that are registered
using an OSGi Manifest in their Jar file.
If only sandbox level integration is to be provided by the source control adapter the method
getRepository() can return null, rather than an instance of CMRepository.
CMInteractor
Both the CMAdapter and CMRepository interfaces extend the CMInteractor interface. This interface
handles user interaction with MATLAB, such as:
Progress reporting
Cancellation
Status change events
Version information
Connection handling (optional)
Javadoc
For more information on each interface, refer to the Javadoc supplied with the SDK in the Javadoc
folder. You need to familiarise yourself with the Java interfaces in the package
com.mathworks.cmlink.api. You can find the Javadoc for this package in the SDK in the top level
folder Javadoc.
Jar Dependencies
These interfaces are declared in the jar file <matlabroot>/java/jar/cmlink/api.jar. This jar file will be
required when setting up your development environment. matlabroot is described in the
Terminology section.
Sandbox Detection
The Simulink Project needs to know which Source Control adapters are suitable for managing the
files within the root folder of a project. It does this by asking each source control adapter, through its
CMAdapterFactory implementation, whether or not it can manage that project root folder. This is
done through the isDirSandboxForThisAdapter method of
com.mathworks.cmlink.api.CMAdapterFactory.
If a CMAdapterFactory states that it can handle source control operations for a specified folder then
the Simulink Project will request the CMAdapterFactory to produce an implementation of
com.mathworks.cmlink.api.CMAdapter for the specified folder. This is done using the
getAdapterForThisSandboxDir method of CMAdapterFactory.
It is possible for multiple CMAdapterFactory implementations to state that they can manage a given
folder. In this case it will be up to the user of Simulink Projects to choose the adapter they want to
use, via existing features of the Simulink Project user interface, and the relevant CMAdapterFactory
will be called upon to provide a CMAdapter instance.
Supported Features
Source control adapters can implement a sub-set of the full functionality of the API. This is done
through supported features enumerations, which are described below. There are three supported
feature enumerations which are detailed below.
CMAdapter Supported Features
The interface CMAdapter has the method
boolean isFeatureSupported(AdapterSupportedFeature feature)
where AdapterSupportedFeature is an enumeration. Each member of this enumeration represents a
supported feature. To support a feature, the implementation of CMAdapter should return true for
the appropriate member of AdapterSupportedFeature. The Javadoc for AdapterSupportedFeature
describes each individual feature. The methods that implement a supported feature, such as move
for the MOVE member of AdapterSupportedFeature, will not be called by the Simulink Project if they
are not supported by the implementation.
CMRespository Supported Features
The interface CMRepository has the method
boolean isFeatureSupported(RepositorySupportedFeature feature)
where RepositorySupportedFeature is an enumeration. Each member of this enumeration
represents a supported feature.
CMInteractor Supported Features
The interface CMInteractor has the method
boolean isFeatureSupported(InteractorSupportedFeature feature)
where InteractorSupportedFeature is an enumeration. Each member of this enumeration represents
a supported feature.
Manifest
The Simulink Project uses OSGi to detect implementations of the com.mathworks.cmlink.api
interface on the MATLAB Java class-path. To ensure your adapter implementation is detectable
requires the following:
1. The class files must be stored in a jar file.
2. The manifest file in your jar file must declare which class implements the interface
cmlink.api.CMAdapterFactory.. This enables the MATLAB OSGi server to instantiate all available
CMAdapterFactory implementations.
2011-2013 The MathWorks, Inc
JUnit Tests
The SDK includes a JUnit test class that you can use to test new source control adapters.
In order to test an implementation the JUnit test class must be constructed with an implementation
of CMTestEnviornment.
This interface provides the following functionality:
Instantiates a CMAdapterFactory
Creates a test repository
Creating a sandbox given a repository specifier String.
The next section describes how to execute this example test using an ant script provided with the
SDK.
Source Code
The source code for the JUnit test is in the folder src/com/mathworks/cmlink/sdk/tests/ of the SDK
folder.
Jar Dependencies
The JUnit test TAdapter.java has the following dependencies
<matlabroot>/java/jar/cmlink/api.jar
<matlabroot>/java/jar/cmlink/util.jar
Locking CM Systems
Locking source control systems will fail the test TAdapter.testConflictResolution(). This is expected
and passing this test is not required for creating a Simulink Project source control adapter for a
locking source control.
To run the ant script from the command line, rather than inside MATLAB, the MATLAB root must be
specified. Add the switch Dmatlab=<matlab install location>.
e.g. ant Dmatlab=<matlabroot> compile.
After installing Ant, you can use the following commands at the command line or within MATLAB in
the root sdk folder:
ant compile
o Compiles the sources in sdk/src to jar files
testBase.jar Contains cmlink JUnit tests.
testSVN.jar contains SVN example configures tests in testBase.jar to be run
by SVN adapter code.
svnIntegration.jar Contains SVN Simulink Project Adapter
ant runTests
o Runs the JUnit unit tests found in testSVN.jar.
To get live information on the currently running tests use:
ant junit -verbose
ant clean
o Deletes any compiled jar files.
Source Code
The source code for the example is in the src/com/mathworks/cmlink/sdk/example folder of the SDK
folder.
Jar Dependencies
All cmlink integrations must link against the interfaces found in the jar file:
<matlabroot>/java/jar/cmlink/api.jar
The example SVN adapter requires the following jar files.
<matlabroot>/java/jar/cmlink/api.jar
<matlabroot>/java/jar/cmlink/util.jar
<matlabroot>/java/jar/toolbox/slproject.jar
<matlabroot>/java/jar/util.jar
<matlabroot>/java/jar/mwswing.jar
<matlabroot>/java/jar/widgets.jar
<matlabroot>/java/jarext/commons-io.jar
The test TSVNAdapter.java also requires a JUnit 4 JUnit.jar file.