It's all about the answers!

Ask a question

RTC API


Judy Yi (41133) | asked Aug 16 '10, 7:58 p.m.
Are there sample snippets to create build definitions, add users to administrator role in RTC Project using RTC JAVA API's? We were able to use the following link https://jazz.net/wiki/bin/view/Main/RTCSDK20_DevelopmentEnvironmentSetup to create stream, project areas, work items...

Thanks,
Judy

21 answers



permanent link
Nick Edgar (6.5k711) | answered Aug 19 '10, 4:47 p.m.
JAZZ DEVELOPER
Hi Judy,

For some Build examples, please see:
https://jazz.net/wiki/bin/view/Main/BuildJavaProgrammingExamples

If you let me know what you're trying to do, I might be able to provide more specific guidance.

Regards,
Nick

permanent link
Judy Yi (41133) | answered Aug 19 '10, 5:34 p.m.
Hi Nick,

Thanks for your reply. What we want to do is programmically on-board project teams to RTC. We were able to write scripts to create RTC project, initailze the project with a defined process template, and add users to administrator group thus far. We are currently having a bit of an isse with writing a script to create Build Definitions. Appreciate if you could send an exmaple snippet on how to do his.

Also, can a RTC Work item be customized to execute a script on a server - for example, if a state field of a work item changes to a certain value - kick off a script to request a build.

Again, thanks for your help.
Juy

Hi Judy,

For some Build examples, please see:
https://jazz.net/wiki/bin/view/Main/BuildJavaProgrammingExamples

If you let me know what you're trying to do, I might be able to provide more specific guidance.

Regards,
Nick

permanent link
Nick Edgar (6.5k711) | answered Aug 19 '10, 7:51 p.m.
JAZZ DEVELOPER
Something like the following should work (not tested):

import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.build.client.ClientFactory;
import com.ibm.team.build.common.BuildItemFactory;
import com.ibm.team.build.common.builddefinition.BuildConfigurationRegistry;
import com.ibm.team.build.common.builddefinition.IBuildDefinitionTemplate;
import com.ibm.team.build.common.model.IBuildDefinition;
import com.ibm.team.process.common.IProcessAreaHandle;
import com.ibm.team.repository.client.ITeamRepository;

public class CreateBuildDefinitionSnippet {

public static void main(String[] args) throws Exception {
ITeamRepository repo = null;
IProcessAreaHandle processAreaHandle = null;
String templateId = "com.ibm.team.build.ant";
new CreateBuildDefinitionSnippet().createBuildDefinition(repo, processAreaHandle, templateId, "some.id");
}

private IBuildDefinition createBuildDefinition(ITeamRepository repo, IProcessAreaHandle processAreaHandle, String templateId, String definitionId) throws Exception {
IBuildDefinition definition = null;
IBuildDefinitionTemplate template = BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplate(templateId);
if (template != null) {
definition = BuildItemFactory.createBuildDefinition();
definition.setProcessArea(processAreaHandle);
definition.setId(definitionId);
definition.initializeConfiguration(template);
definition = ClientFactory.getTeamBuildClient(repo).save(definition, new NullProgressMonitor());
}
return definition;
}
}

I've omitted exception handling and progress monitoring for clarity.

For relevant build definition ids, see the plugin.xml for com.ibm.team.build.common.

If you want to make further tweaks to the definition before saving (i.e. setting build properties or configuration properties, you can do so using the methods on IBuildDefinition.


For triggering code on the server for a work item save (or other operation), I don't think there's any support for scripting, but you could write a process operation participant for the work item save operation.

See https://jazz.net/wiki/bin/view/Main/TeamProcessDeveloperGuide#Adding_New_Operation_Participant

I'm sure this has been discussed elsewhere in this forum too.

permanent link
Judy Yi (41133) | answered Aug 26 '10, 12:08 p.m.
Hi Nick -

Thanks for your help on this. We have tried to create a build definition using RTC JAVA API's based off of the snippet you provided but getting the below loading the BuildDefinitionTemplate error. The plugin.xml should help to resolve this - can you help advise where I can get my hands on this file please?

Error:

Exception in thread "main" java.lang.NullPointerException
at com.ibm.team.build.internal.common.builddefinition.BuildDefinitionTemplateExtensionManager.loadBuildDefinitionTemplateExtensions(BuildDefinitionTemplateExtensionManager.java:105)
at com.ibm.team.build.internal.common.builddefinition.BuildDefinitionTemplateExtensionManager.getBuildDefinitionTemplate(BuildDefinitionTemplateExtensionManager.java:89)
at com.ibm.team.build.common.builddefinition.BuildConfigurationRegistry.getBuildDefinitionTemplate(BuildConfigurationRegistry.java:74)
at snippets.CreateBuildDefinitionSnippet.createBuildDefinition(CreateBuildDefinitionSnippet.java:74)
at snippets.CreateBuildDefinitionSnippet.main(CreateBuildDefinitionSnippet.java:56).

Thanks,
Judy


Something like the following should work (not tested):

import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.build.client.ClientFactory;
import com.ibm.team.build.common.BuildItemFactory;
import com.ibm.team.build.common.builddefinition.BuildConfigurationRegistry;
import com.ibm.team.build.common.builddefinition.IBuildDefinitionTemplate;
import com.ibm.team.build.common.model.IBuildDefinition;
import com.ibm.team.process.common.IProcessAreaHandle;
import com.ibm.team.repository.client.ITeamRepository;

public class CreateBuildDefinitionSnippet {

public static void main(String[] args) throws Exception {
ITeamRepository repo = null;
IProcessAreaHandle processAreaHandle = null;
String templateId = "com.ibm.team.build.ant";
new CreateBuildDefinitionSnippet().createBuildDefinition(repo, processAreaHandle, templateId, "some.id");
}

private IBuildDefinition createBuildDefinition(ITeamRepository repo, IProcessAreaHandle processAreaHandle, String templateId, String definitionId) throws Exception {
IBuildDefinition definition = null;
IBuildDefinitionTemplate template = BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplate(templateId);
if (template != null) {
definition = BuildItemFactory.createBuildDefinition();
definition.setProcessArea(processAreaHandle);
definition.setId(definitionId);
definition.initializeConfiguration(template);
definition = ClientFactory.getTeamBuildClient(repo).save(definition, new NullProgressMonitor());
}
return definition;
}
}

I've omitted exception handling and progress monitoring for clarity.

For relevant build definition ids, see the plugin.xml for com.ibm.team.build.common.

If you want to make further tweaks to the definition before saving (i.e. setting build properties or configuration properties, you can do so using the methods on IBuildDefinition.


For triggering code on the server for a work item save (or other operation), I don't think there's any support for scripting, but you could write a process operation participant for the work item save operation.

See https://jazz.net/wiki/bin/view/Main/TeamProcessDeveloperGuide#Adding_New_Operation_Participant

I'm sure this has been discussed elsewhere in this forum too.

permanent link
Nick Edgar (6.5k711) | answered Aug 26 '10, 4:27 p.m.
JAZZ DEVELOPER
The NPE is probably due to the extension registry not being initialized.
If running a plain Java client (not running under OSGi), you need to run:
com.ibm.team.repository.client.TeamPlatform.startup();
as the first thing your program does.

The plugin.xml for com.ibm.team.build.common can be found in the jar for that plugin under <rtc client>/eclipse/plugins

You could also list them all using:
BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplates()

permanent link
Dashrath Kale (1542723) | answered Aug 30 '10, 2:21 a.m.
The NPE is probably due to the extension registry not being initialized.
If running a plain Java client (not running under OSGi), you need to run:
com.ibm.team.repository.client.TeamPlatform.startup();
as the first thing your program does.

The plugin.xml for com.ibm.team.build.common can be found in the jar for that plugin under <rtc>/eclipse/plugins

You could also list them all using:
BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplates()


Hi Nick

Below is the snippet which I am running to create the build definition.

package snippets;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.build.client.ClientFactory;
import com.ibm.team.build.common.BuildItemFactory;
import com.ibm.team.build.common.builddefinition.BuildConfigurationRegistry;
import com.ibm.team.build.common.builddefinition.IBuildDefinitionTemplate;
import com.ibm.team.build.common.model.IBuildDefinition;
import com.ibm.team.process.common.IProcessAreaHandle;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo;
import com.ibm.team.repository.common.TeamRepositoryException;

/**
* Plain Java Snippet: Connecting to a repository
*/
@SuppressWarnings("restriction")
public class createRTCBuildDefinition {

private static String REPOSITORY_ADDRESS = "**********";
private static String userId = "********";
private static String password = "*********";
private static ITeamRepository teamRepository;

private static class LoginHandler implements ILoginHandler, ILoginInfo {

private final String userId;
private final String password;

private LoginHandler(final String userId, final String password) {
this.userId = userId;
this.password = password;
}

public String getUserId() {
return userId;
}

public String getPassword() {
return password;
}

public ILoginInfo challenge(final ITeamRepository repository) {
return this;
}
}

public static void main(String[] args) throws Exception {
TeamPlatform.startup();

try {
IProgressMonitor monitor = new SysoutProgressMonitor();
teamRepository = TeamPlatform.getTeamRepositoryService()
.getTeamRepository(REPOSITORY_ADDRESS);
teamRepository.registerLoginHandler(new LoginHandler(userId,
password));
teamRepository.login(monitor);
IProcessAreaHandle processAreaHandle = null;
String templateId = "com.ibm.team.build.ant";

new createRTCBuildDefinition().createBuildDefinition(
teamRepository, processAreaHandle, templateId,
"RTC API Build Definition");
} catch (TeamRepositoryException e) {
System.out.println("Unable to login: " + e.getMessage());
} finally {
TeamPlatform.shutdown();
}
}

public static ITeamRepository login(IProgressMonitor monitor)
throws TeamRepositoryException {
ITeamRepository repository = TeamPlatform.getTeamRepositoryService()
.getTeamRepository(REPOSITORY_ADDRESS);
repository.registerLoginHandler(new ITeamRepository.ILoginHandler() {
public ILoginInfo challenge(ITeamRepository repository) {
return new ILoginInfo() {
public String getUserId() {
return userId;
}

public String getPassword() {
return password;
}
};
}
});
monitor.subTask("Contacting " + repository.getRepositoryURI() + "...");
repository.login(monitor);
monitor.subTask("Connected");
System.out.println("Connected");
return repository;
}

private IBuildDefinition createBuildDefinition(ITeamRepository repo, IProcessAreaHandle processAreaHandle, String templateId, String definitionId) throws Exception {
IBuildDefinition definition = null;
IBuildDefinitionTemplate template = BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplate(templateId);
if (template != null) {
definition = BuildItemFactory.createBuildDefinition();
definition.setProcessArea(processAreaHandle);
definition.setId(definitionId);
definition.initializeConfiguration(template);
definition.setDescription("TESTBUID");
definition = ClientFactory.getTeamBuildClient(repo).save(
definition, new NullProgressMonitor());
}
return definition;
}

------------------------
ERROR:Getting below error while execution: Could you please help me to resolve this issue.


Exception in thread "main" java.lang.IllegalArgumentException: Item Handle must not be null
at com.ibm.team.repository.service.internal.RepositoryItemService.fetchItem(RepositoryItemService.java:616)
at sun.reflect.GeneratedMethodAccessor102.invoke(null)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.invoke(ExportProxyServiceRecord.java:370)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.access$0(ExportProxyServiceRecord.java:356)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord$ExportedServiceInvocationHandler.invoke(ExportProxyServiceRecord.java:56)
at $Proxy73.fetchItem(null)
at com.ibm.team.repository.service.internal.ComponentRepositoryItemService.fetchItem(ComponentRepositoryItemService.java:489)
at com.ibm.team.build.internal.service.AbstractTeamBuildService.getProcessArea(AbstractTeamBuildService.java:569)
at com.ibm.team.build.internal.service.AbstractTeamBuildService.doSave(AbstractTeamBuildService.java:1227)
at com.ibm.team.build.internal.service.AbstractTeamBuildService.save(AbstractTeamBuildService.java:1002)
at sun.reflect.GeneratedMethodAccessor254.invoke(null)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.invoke(ExportProxyServiceRecord.java:370)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.access$0(ExportProxyServiceRecord.java:356)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord$ExportedServiceInvocationHandler.invoke(ExportProxyServiceRecord.java:56)
at $Proxy206.save(null)
at sun.reflect.GeneratedMethodAccessor254.invoke(null)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.servlet.AbstractTeamServerServlet.handleMethod(AbstractTeamServerServlet.java:1170)
at com.ibm.team.repository.servlet.AbstractTeamServerServlet.executeMethod(AbstractTeamServerServlet.java:926)
at com.ibm.team.repository.servlet.AbstractTeamServerServlet.doPost(AbstractTeamServerServlet.java:728)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at com.ibm.team.repository.servlet.AbstractTeamServerServlet.handleRequest2(AbstractTeamServerServlet.java:1773)
at com.ibm.team.repository.servlet.AbstractTeamServerServlet.handleRequest(AbstractTeamServerServlet.java:1642)
at com.ibm.team.repository.servlet.AbstractTeamServerServlet.service(AbstractTeamServerServlet.java:1555)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.eclipse.equinox.servletbridge.BridgeServlet.service(BridgeServlet.java:121)
at com.ibm.team.repository.server.servletbridge.JazzServlet.service(JazzServlet.java:54)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:811)
at com.ibm.team.repository.common.internal.marshal.util.MarshallerUtil.decodeExceptions(MarshallerUtil.java:326)
at com.ibm.team.repository.common.internal.marshal.util.MarshallerUtil.decodeExceptions(MarshallerUtil.java:296)
at com.ibm.team.repository.common.internal.marshal.util.MarshallerUtil.decodeFault(MarshallerUtil.java:261)
at com.ibm.team.repository.transport.client.RemoteTeamService.constructExceptionFromFault(RemoteTeamService.java:613)
at com.ibm.team.repository.transport.client.RemoteTeamService.executeMethod(RemoteTeamService.java:483)
at com.ibm.team.repository.transport.client.RemoteTeamService.invoke(RemoteTeamService.java:201)
at com.ibm.team.repository.transport.client.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:43)
at $Proxy12.save(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invokeServiceCall(ServiceInterfaceProxy.java:149)
at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invoke(ServiceInterfaceProxy.java:84)
at $Proxy12.save(Unknown Source)
at com.ibm.team.build.internal.client.AbstractTeamBuildClient$1SaveBuildItemRunnable.run(AbstractTeamBuildClient.java:433)
at com.ibm.team.process.internal.common.advice.runtime.OperationAdviceManager.runRunnable(OperationAdviceManager.java:1318)
at com.ibm.team.process.internal.common.advice.runtime.OperationAdviceManager.execute(OperationAdviceManager.java:190)
at com.ibm.team.process.internal.client.ProcessClientService.execute(ProcessClientService.java:764)
at com.ibm.team.build.internal.client.AbstractTeamBuildClient$1.run(AbstractTeamBuildClient.java:445)
at com.ibm.team.repository.client.internal.TeamRepository$3.run(TeamRepository.java:1169)
at com.ibm.team.repository.common.transport.CancelableCaller.call(CancelableCaller.java:79)
at com.ibm.team.repository.client.internal.TeamRepository.callCancelableService(TeamRepository.java:1162)
at com.ibm.team.build.internal.client.AbstractTeamBuildClient.callCancelableService(AbstractTeamBuildClient.java:266)
at com.ibm.team.build.internal.client.AbstractTeamBuildClient.internalSave(AbstractTeamBuildClient.java:439)
at com.ibm.team.build.internal.client.AbstractTeamBuildClient.save(AbstractTeamBuildClient.java:274)
at snippets.createRTCBuildDefinition.createBuildDefinition(createRTCBuildDefinition.java:117)
at snippets.createRTCBuildDefinition.main(createRTCBuildDefinition.java:74)

Thanks,
Dashrath

permanent link
Nick Edgar (6.5k711) | answered Aug 30 '10, 11:38 a.m.
JAZZ DEVELOPER
This is due to the build definition having a null process area. The build definition must have a valid process area in order to be saved.

permanent link
Dashrath Kale (1542723) | answered Aug 31 '10, 1:42 a.m.
This is due to the build definition having a null process area. The build definition must have a valid process area in order to be saved.



Nick,

Thanks for your reply, Yes I can see that the PorcessArea us null. Actually I am trying create the new build definition and add that in existing project Area. But I am not getting any method using which I can get the Process Area of that projectArea , also createBuildDefinition() method accepts the IProcessAreaHandle as argument. Are there any RTC JAVA API methods or snippets available for getting above information?

permanent link
Nick Edgar (6.5k711) | answered Aug 31 '10, 1:36 p.m.
JAZZ DEVELOPER
The team areas in a project area can be obtained via:
com.ibm.team.process.common.IProjectArea.getTeamAreas()
which returns a list of ITeamAreaHandle.

If the hierarchy info is important, use com.ibm.team.process.common.IProjectArea.getTeamAreaHierarchy()
which returns an ITeamAreaHierarchy.

Note that IProjectArea and ITeamArea extend IProcessArea, and likewise for their handles. So you could use the project area handle directly when creating the build definition, if that makes sense for your scenario.

BuildItemFactory.createBuildDefinition(IProcessArea) is basically just a convenience for doing BuildItemFactory.createBuildDefinition() then setProcessArea on the result.

For other snippets (using the client API), see the wiki page mentioned above in comment 2.

permanent link
Dashrath Kale (1542723) | answered Sep 01 '10, 10:36 a.m.
The team areas in a project area can be obtained via:
com.ibm.team.process.common.IProjectArea.getTeamAreas()
which returns a list of ITeamAreaHandle.

If the hierarchy info is important, use com.ibm.team.process.common.IProjectArea.getTeamAreaHierarchy()
which returns an ITeamAreaHierarchy.

Note that IProjectArea and ITeamArea extend IProcessArea, and likewise for their handles. So you could use the project area handle directly when creating the build definition, if that makes sense for your scenario.

BuildItemFactory.createBuildDefinition(IProcessArea) is basically just a convenience for doing BuildItemFactory.createBuildDefinition() then setProcessArea on the result.

For other snippets (using the client API), see the wiki page mentioned above in comment 2.


Hi Nick,
Thanks for you suggestions we can create the build definition but still we need below enhancements in creating the build definition.

1. currently there is an ANT tab for the Build Definition - we need a BuildForge tab.
2. in Overview - we need to connect to RationalBuildForgeConnector
3. in BuildForge tab - connect to BuildForge and connect to the BF project with correct BF account.
4. we need to be able to set the schedule for the build ie: trigger every 3 hours.

Thanks,
Dashrath

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.