Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Trying to disable BuildSchedule using setScheduleEnabled

Hello,

I'm writing some code to programmatically disable a build definition schedule I had set up earlier and am not ables to use the method to do this.

The code chunk that carries out the action is below:

public IBuildDefinition disableBuildSchedule(ITeamRepository repo) throws Exception
{
IProgressMonitor monitor = new NullProgressMonitor();

// code for getting specific RTC build definition
ITeamBuildClient teamBuildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
IBuildDefinition definition= teamBuildClient.getBuildDefinition(buildDefName,monitor);

if (definition != null) {

// START : set build schedule
IBuildSchedule schedule = definition.getBuildSchedule();
if ( schedule != null){
System.out.println("Schedule enabled? "+schedule.isScheduleEnabled());
schedule.setScheduleEnabled(false);
}
else {
System.out.println("Unable to extract schedule");
}
// END : set build schedule
I get into the schedule != null code and can print out Schedule enabled? true. However when I add the line to disable the schedule, schedule.setScheduleEnabled(false);
and run the code again, I get an ImmutableProperty Exception

com.ibm.team.repository.common.internal.ImmutablePropertyException
at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2026)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:247)
at com.ibm.team.build.internal.common.model.impl.BuildScheduleImpl.setScheduleEnabled(BuildScheduleImpl.java:984)
at DisableRTCBuildSchedule.disableBuildSchedule(DisableRTCBuildSchedule.java:167)
at DisableRTCBuildSchedule.main(DisableRTCBuildSchedule.java:221)


has anyone got any ideas on how I can use this mthod (or any others) to diable the schedule.

Thanks,
Kelly

0 votes



2 answers

Permanent link
Hi Kelly.

Before making modifications to an item, you need to get a working copy of it. Then, when done, you need to save the working copy. This is a general pattern throughout the Jazz/RTC API (both client and server).

Try:

ITeamBuildClient teamBuildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
IBuildDefinition definition= teamBuildClient.getBuildDefinition(buildDefName, monitor);
definition = (IBuildDefinition) definition.getWorkingCopy();
IBuildSchedule schedule = definition.getBuildSchedule();
schedule.setScheduleEnabled(false);
definition = teamBuildClient.save(definition, monitor);


Note that we're getting a working copy of the definition here, and saving that, not the schedule. That's because the schedule is a helper within the definition, not a separately stored item. IBuildDefinition inherits from IItem, but IBuildSchedule does not.

0 votes


Permanent link
Thanks Nick, that has worked perfectly for me

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Nov 10 '10, 11:40 a.m.

Question was seen: 5,490 times

Last updated: Nov 10 '10, 11:40 a.m.

Confirmation Cancel Confirm