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

Set build schedule

I have tried below to turn off/on the build schedule on a build definition. I'm getting an error that the method property is immutable. Error description below. I'm using RTC 4.0.5 Please advise.

 IBuildDefinition definition = ...

IBuildSchedule schedule = definition.getBuildSchedule();
schedule.setScheduleEnabled(true);
schedule.setBuildOnMonday(true);
schedule.setBuildInterval(30); // every 30 minutes

Exception in thread "main" com.ibm.team.repository.common.internal.ImmutablePropertyException
	at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2001)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:280)
	at com.ibm.team.build.internal.common.model.impl.BuildScheduleImpl.setScheduleEnabled(BuildScheduleImpl.java:1073)
	at SetSchedule.main(SetSchedule.java:130)

Regards
Sunil

0 votes



One answer

Permanent link
Hi Sunil, my apologies for the delay on responding. The normal pattern for modifying an item is:
- read it from the repo (e.g. using IItemManager.fetch*)
- create a working copy (using IItem.getWorkingCopy()), casting back down to the specific item interface type
- make the changes
- save the item (the API for this differs depending on the item type, but for Build items it's usually ITeamBuildClient.save)

The error here looks like you're missing the getWorkingCopy step.
Cheers,
Nick

0 votes

Comments

The item here is the build definition, not its schedule (which is a 'helper' under the main build definition item, not separately stored). So you should have a line before the sets like:

definition = (IBuildDefinition) definition.getWorkingCopy()
Then at the end save with:
definition = ClientFactory.getBuildClient().save(definition, progressMonitor)
Be sure to use the returned definition as the basis for any further changes, or it will complain that you're trying to base your changes off of a state that is no longer the current one (a StaleDataException is thrown in this case).

This worked. Many Thanks Nick!

Good to hear, Sunil. Could you please mark my answer as accepted, so this topic can get cleared from our tracking dashboards?

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
× 562

Question asked: Nov 13 '14, 4:13 p.m.

Question was seen: 3,920 times

Last updated: Feb 10 '15, 3:45 p.m.

Confirmation Cancel Confirm