It's all about the answers!

Ask a question

RTC Java Api Remove Build Engine from Build Definition


Gérard Langevin (111) | asked Sep 08 '16, 11:08 a.m.

I try to remove BuildEngine from BuildDefinition and it doesn't work!

My code:
String id = someBuildEngineId;
IBuildDefinition buildDefinition = someBuildDefinition;

IBuildEngine be = client.getBuildEngine(id, monitor)
IBuildEngine workingCopy = (IBuildEngine) be.getWorkingCopy();
workingCopy.getSupportedBuildDefinitions().remove(buildDefinition);
client.save(workingCopy, monitor);

If I use following add, it's work fine:
workingCopy.getSupportedBuildDefinitions().add(buildDefinition);

The following code return false:
workingCopy.getSupportedBuildDefinitions().contains(buildDefinition);

I am very confuse...

Someone have an idea?

Thanks in advance.


Comments
Sridevi Sangaiah commented Sep 12 '16, 12:03 a.m. | edited Sep 12 '16, 12:03 a.m.
JAZZ DEVELOPER

If "workingCopy.getSupportedBuildDefinitions().contains(buildDefinition)" returns false then there is a possibility that the build definition is not supported by the build engine.

Can you please confirm from the UI that when you add a build definition, in your code, it gets added to the build engine and then when you programatically remove the build definition it is not removed?

Thanks,
Sridevi


Gérard Langevin commented Sep 12 '16, 9:46 a.m.

Hello Sridevi,

Thanks for your quick response. I can confirm from UI that I can add new Build Engine X but I can't remove them.

I use artifact com.ibm.team.build.common:3.1.400.v20130415_0257

Thanks a lot it's very appreciate it.

3 answers



permanent link
sam detweiler (12.4k6182201) | answered Sep 12 '16, 8:31 a.m.
I think its an api issue.. add() and remove()  will use the IBuildDefinitionHandle..

Contains() is a java object list method.. 

getSupportedBuildDefinitions()  returns a list of HANDLES.(IBuildDefinitionHandle). not objects (IBuildDefinition)

but then you asked does this IBuildDefinition (object address, NOT HANDLE), exist in the list of HANDLES..(IBuildDefinitionHandle) and it does not..

permanent link
Sridevi Sangaiah (59179) | answered Sep 12 '16, 9:03 p.m.
JAZZ DEVELOPER
edited Sep 12 '16, 9:04 p.m.
Remove could also be failing for the same reason like contains, unless BuildDefinitionHandleImpl implements the equals and hashcode methods, which I doubt. Can you please try the following snippet for remove?

String id = someBuildEngineId;
IBuildDefinition buildDefinition = someBuildDefinition;
IBuildEngine be = client.getBuildEngine(id, monitor)
IBuildEngine workingCopy = (IBuildEngine) be.getWorkingCopy();
List buildDefinitionHandles = workingCopy .getSupportedBuildDefinitions();
for (int j = 0; j < buildDefinitionHandles.size(); j++) {
      IBuildDefinitionHandle handle = (IBuildDefinitionHandle) buildDefinitionHandles.get(j);
      if (buildDefinition .getItemId().getUuidValue().equals(buildDefinitionHandle.getItemId().getUuidValue())) {
                workingCopy.getSupportedBuildDefinitions().remove(j);
                client.save(workingCopy, monitor);
                break;
        }
}

Thanks,
Sridevi

Comments
sam detweiler commented Sep 13 '16, 8:10 a.m.

I think it could have been done with

workingCopy.getSupportedBuildDefinitions().contains(buildDefinition.getItemHandle());

contains cannot be overridden because the raw java list object is exposed..

add and remove also are raw list methods..


permanent link
Gérard Langevin (111) | answered Sep 13 '16, 8:02 a.m.

Good morning,

It's work fine!

Thanks you very much for your help, it's very appreciate it.

Have a good day.

Your answer


Register or to post your answer.