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 scheduleI 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
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 scheduleI 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
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
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:
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.
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.