It's all about the answers!

Ask a question

Rehashing RTC Build Definition programmatically

EclipseTalk . (32735961) | asked Feb 04 '15, 10:09 a.m.
Is it possible to get the list of Build definitions (I'm using Build Forge engine) for an RTC project and rehash them programmatically?
Every time something changes in the Build Forge definition, one needs to re-save the RTC build definition in order for the changes to take place.
Thank you in advance for any help

Accepted answer

permanent link
sam detweiler (12.5k6195201) | answered Feb 04 '15, 10:25 a.m.
yes and yes..

here is a routine to find build defs in  a project

    private static ArrayList<IBuildDefinition> getBuildDefinitionsforProjectArea(
            IProjectAreaHandle iprja)
        Boolean allProperties = true;
        // allocate space for results
        ArrayList<IBuildDefinition> allbd = new ArrayList<IBuildDefinition>();
        ITeamRepository repo = (ITeamRepository) iprja.getOrigin();
        // get the data interface
        ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);

            IBuildDefinitionQueryModel queryModel = IBuildDefinitionQueryModel.ROOT;
            // create a query for build engines
            IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
            // objects of build engine type
            IPredicate isBuildDefType = queryModel._isTypeOf(IBuildDefinition.ITEM_TYPE);
            // allocate space for the parameter
            IItemHandleInputArg[] itemHandleArgs = new IItemHandleInputArg[] { query.newItemHandleArg() };
            // the query filter
            IPredicate filter = ((BuildDefinitionQueryModel) queryModel).processArea()._in(itemHandleArgs);
            // set the combined filter
            // no parameters required
            IItemQueryPage queryPage = buildClient.queryItems(query,
            new Object[] { iprja }, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);

            // if there are build definitions defined

            if (queryPage.getResultSize() != 0)
                while (queryPage != null)
                    IFetchResult fetchResult = null;
                    if (allProperties == true)
                        fetchResult = repo.itemManager().fetchCompleteItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, null);
                        // print out a page of IDs of the retrieved build definitions
                        // needs to be fixed for build defs
                        final String[] all_properties = new String[] {
                                IBuildEngine.PROPERTY_CONFIGURATION_ELEMENTS };

                        fetchResult = repo.itemManager().fetchPartialItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, Arrays.asList(all_properties), null);

                    // add these to the list

                    if (queryPage.hasNext())
                        queryPage = (IItemQueryPage) buildClient.fetchPage(queryPage.getToken(), queryPage.getNextStartPosition(), queryPage.getSize(), null);
                        queryPage = null;
        catch (Exception ex)
            System.out.println("build exception=" + ex.getMessage());
        return allbd;
EclipseTalk . selected this answer as the correct answer

EclipseTalk . commented Feb 05 '15, 10:20 a.m.

 Thanks Sam. I can get the list of build definitions!

Which method should I invoke now for each IBuildDefinition instance to rehash them?

Thank you

sam detweiler commented Feb 05 '15, 10:39 a.m.

sorry does 'rehash' mean save?

I save the build engine with related build defs

ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);, null);
same call for defs, null);

EclipseTalk . commented Feb 05 '15, 11:36 a.m.

  Thanks Sam - 

The issue I'm having is with the synchronization between Build Forge and RTC build definition. For instance when I change an environment variable on Build Forge, the change is not reflected in the RTC Build definition. I need to connect it to some random BF project, save, then connect to the real one and save again for the changes to be reflected in RTC Build Definition. I was hoping that re-saving the RTC build Definition will update the Build Forge env variables but it doesn't, hence the need to "rehash" the RTC build definition.
Any idea how to force an refresh from Build Forge to RTC build definition?

sam detweiler commented Feb 05 '15, 11:40 a.m.

sorry, no idea.

Your answer

Register or to post your answer.