It's all about the answers!

Ask a question

Retrieve properties from a build request


Michele Pegoraro (1.8k12114101) | asked Aug 31 '09, 6:56 a.m.
Hi, I'm developing a pre-condition plugin on Request build operation. I'd like to retrieve a specific property of the build. I've tried the method IBuildDefinition.getProperty and it runs but gets only the default value of the BuildDefinition and not a new value insert by the user which requires the build.

I've already find this kind of problem, but in that case I've resolved it using IBuildResult.getBuildRequests() and IBuildRequst.getBuildDefinitionProperties() methods. In this case I was expecting that operation data return by request operation was IBuildRequest but now I've discovered that is IBuildDefinition and so I cannot use the previous method.
How can I get the new value of the property insert by a user requesting a build?

10 answers



permanent link
Daniele Menon (2643) | answered Sep 01 '09, 12:11 p.m.
Hi, I have the same problem.
I'm expecting to find the new values for the properties from the field "operation", but I don't know how it is possible.
Any help?


Hi, I'm developing a pre-condition plugin on Request build operation. I'd like to retrieve a specific property of the build. I've tried the method IBuildDefinition.getProperty and it runs but gets only the default value of the BuildDefinition and not a new value insert by the user which requires the build.

I've already find this kind of problem, but in that case I've resolved it using IBuildResult.getBuildRequests() and IBuildRequst.getBuildDefinitionProperties() methods. In this case I was expecting that operation data return by request operation was IBuildRequest but now I've discovered that is IBuildDefinition and so I cannot use the previous method.
How can I get the new value of the property insert by a user requesting a build?

permanent link
Michele Pegoraro (1.8k12114101) | answered Sep 07 '09, 10:21 a.m.
Nobody has already had this problem?? Any idea on how can I retrieve the new build property?

I'm quite blocked on this point, so any help will be appreciate...

permanent link
Nick Edgar (6.5k711) | answered Sep 08 '09, 9:41 a.m.
JAZZ DEVELOPER
Yes, to get the properties for a build, you follow: IBuildResult.getBuildRequests() -> IBuildRequest.getBuildDefinitionInstance() -> IBuildDefinitionInstance.getProperties().

Or you can use the helper methods:
IBuildRequest.getBuildDefinitionProperties(): returns a map of the properties (computed each time)
IBuildDefinitionInstance.getProperty(String): look up a given property (O(N) search)

The IBuildDefinitionInstance captures the state of the build definition and its properties, plus any property changes, at the time of the request.

> In this case I was expecting that operation data return by request operation was IBuildRequest but now I've discovered that is IBuildDefinition and so I cannot use the previous method.

Which API method are you using? ITeamBuildRequestClient.requestBuild returns the IBuildRequest, as does getNextRequest.

permanent link
Michele Pegoraro (1.8k12114101) | answered Sep 08 '09, 10:32 a.m.
Yes, to get the properties for a build, you follow: IBuildResult.getBuildRequests() -> IBuildRequest.getBuildDefinitionInstance() -> IBuildDefinitionInstance.getProperties().

Or you can use the helper methods:
IBuildRequest.getBuildDefinitionProperties(): returns a map of the properties (computed each time)
IBuildDefinitionInstance.getProperty(String): look up a given property (O(N) search)

The IBuildDefinitionInstance captures the state of the build definition and its properties, plus any property changes, at the time of the request.

> In this case I was expecting that operation data return by request operation was IBuildRequest but now I've discovered that is IBuildDefinition and so I cannot use the previous method.

Which API method are you using? ITeamBuildRequestClient.requestBuild returns the IBuildRequest, as does getNextRequest.


Thank you very much for the answer.
Unfortunately I can't use the method from IBuildResult because I've not got this object. I've already tried this way and it works correctly. But in this case I'm developing a pre-condition plugin so the only thing I got is the AdvisableOperation.getOperationData() method which gives me an IBuildDefinition object. So my problem is how to get IBuildRequest or IBuildDefinitionInstance (which I'had not seen before, thank you) from this IBuildDefinition object.

Or, maybe, there is another method of AdvisableOperation which can give me the new properties information.

permanent link
Michele Pegoraro (1.8k12114101) | answered Sep 08 '09, 11:07 a.m.
Using debug I also see that AdvisableOperation given by the system (operation) contains the information I need in a private variable named "val$newOrModifiedBuildProperties" but I'm not able to retrieve it using methods...

permanent link
Nick Edgar (6.5k711) | answered Sep 08 '09, 2:00 p.m.
JAZZ DEVELOPER
Oh, I see the problem. The issue is that at the time your advisor (aka precondition) gets called, the build request hasn't been created yet. The only Buildspecific information it has is the handle to the build definition.

The code in question, in TeamBuildRequestService.requestBuild does:

IProcessArea processArea = getProcessArea(buildDefinitionHandle);
IProcessServerService processService = (IProcessServerService) getService(IProcessServerService.class);
IServerProcess serverProcess = processService.getServerProcess(processArea);

IOperationReport report = serverProcess.adviseAndExecute(new AdvisableOperation(
ProcessConstants.REQUEST_BUILD_OPERATION_ID, buildDefinitionHandle, processArea) {
public IOperationReport run(IBehaviorConfiguration configuration, IProgressMonitor monitor)
throws TeamRepositoryException {
IBuildRequest buildRequest = requestBuildWithoutProcess(buildDefinitionHandle,
newOrModifiedBuildProperties, deletedBuildProperties, allowDuplicateRequests, personalBuild);


The second argument to the AdvisableOperation constructor is the operationData argument, and currently we only pass the buildDefinitionHandle.

For you to get the info you want, we would need to pass a richer object encapsulating the build definition handle and the other arguments to requestBuild, such as the new/modified properties and the properties to remove. Or alternatively, we could compute the resulting set of properties and pass that (still before creating the build result, in case the precondition fails).

If you need this support, please file an enhancement request against RTC/Build.

permanent link
Nick Edgar (6.5k711) | answered Sep 08 '09, 2:54 p.m.
JAZZ DEVELOPER
The private variable val$newOrModifiedBuildProperties is generated by the Java compiler, since the newOrModifiedBuildProperties argument is accessed from within the AdvisableOperation anonymous subclass. It's certainly not part of the API, though you could try accessing it using a reflection hack, e.g.

Field field = advisableOperation.getClass().getDeclaredField("val$newOrModifiedBuildProperties");
field.setAccessible(true);
String[] newOrModifiedProps = (String[]) field.get(advisableOperation);
.

permanent link
Michele Pegoraro (1.8k12114101) | answered Sep 09 '09, 4:12 a.m.
Thank you very much for your useful answer, I'm finally able to retrieve this operation. For everyone else which could have this problem this is the snippet (the only difference with the previous one is the type of object):

Field field = operation.getClass().getDeclaredField("val$newOrModifiedBuildProperties");
field.setAccessible(true);
IBuildProperty[] newProps = (IBuildProperty[])field.get(operation);


I've also open an enhancement on this point, as you have suggested, because I think this could be very useful on pre-condition plugins creation.
The link is:
https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=94006

permanent link
Nick Edgar (6.5k711) | answered Sep 09 '09, 11:16 a.m.
JAZZ DEVELOPER
Glad you were able to get it working, but note that this is a horrendous hack, and is fragile. E.g. your code would be broken if we simply were to rename the newOrModifiedBuildProperties parameter (normally parameter names have no impact on API). So please ensure you have appropriate checks or try/catch blocks in your code, and fall back to safe behaviour (e.g. just checking the build definition properties) if there's a problem.

permanent link
Michele Pegoraro (1.8k12114101) | answered Sep 09 '09, 12:04 p.m.
Yes, I know. Unfortunately I have other class which uses internal stuff, so I must be attent to new release modify.

Thanks again, best regards,
Michele.

Your answer


Register or to post your answer.