It's all about the answers!

Ask a question

Trying to disable BuildSchedule using setScheduleEnabled


Kelly Anakwe (6198) | asked Nov 10 '10, 11:40 a.m.
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

2 answers



permanent link
Nick Edgar (6.5k711) | answered Nov 10 '10, 11:58 a.m.
JAZZ DEVELOPER
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.

permanent link
Kelly Anakwe (6198) | answered Nov 10 '10, 2:45 p.m.
Thanks Nick, that has worked perfectly for me

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.