It's all about the answers!

Ask a question

IBuildEngine and IBuildDefinition, client side java api, how to ?


0
1
sam detweiler (12.5k6189201) | asked Jan 07 '14, 5:58 p.m.
 I have looked thru the forum for some guidance on how to get the list of BuildEngines and associated BuildDefinitions from a client side (plain java) app.. 
https://jazz.net/wiki/bin/view/Main/BuildJavaProgrammingExamples

clearly I am missing something. 

I see that I can run a 'query' to get build definitions that match certain criteria,  but I don't think this is the approach to use. 

I am on the last step of our copy project utility, and I need to copy the build engines and definitions.

can someone turn the light on and point to the page of enlightenment?


Accepted answer


permanent link
Ralph Schoon (61.8k33643) | answered Jan 08 '14, 9:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Sam, I found this code in com.ibm.team.build.internal.ui.dialogs.definitions.FetchBuildDefinitionsInConnectedProjectAreasJob. Maybe that helps sorting it out?
   protected IBuildDefinition[] fetchBuildDefinitions(ITeamRepository repository, IProgressMonitor monitor)
            throws TeamRepositoryException {
        
        IItemQuery itemQuery = IItemQuery.FACTORY.newInstance(IBuildDefinitionQueryModel.ROOT);

        // get the team areas for the connected project areas in the repo and
        // use them to narrow the search
        IProcessAreaHandle[] processAreaHandles = getProcessAreaHandles(repository, monitor);

        IItemHandleInputArg[] itemHandleArgs = new IItemHandleInputArg[processAreaHandles.length];
        for (int i = 0; i < processAreaHandles.length; i++) {
            itemHandleArgs[i] = itemQuery.newItemHandleArg();
        }

        // create the query
        IBuildDefinitionQueryModel buildDefinitionQueryModel = IBuildDefinitionQueryModel.ROOT;
        final IItemQuery query = IItemQuery.FACTORY.newInstance(buildDefinitionQueryModel);

        IPredicate filter = ((BuildDefinitionQueryModel) buildDefinitionQueryModel).processArea()._in(itemHandleArgs);
        query.filter(filter);
        query.orderByDscUsingLocale(buildDefinitionQueryModel.id());

        // get the results
        IItemManager itemManager = repository.itemManager();
        ItemQueryIterator iter = new ItemQueryIterator(
                ClientFactory.getTeamBuildClient(repository), itemQuery, new Object[0]);
        LinkedList buildDefinitions = new LinkedList();
        while (iter.hasNext(monitor)) {
            List definitionHandles = iter.next(IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, monitor);
            buildDefinitions.addAll(itemManager.fetchCompleteItems(definitionHandles, IItemManager.DEFAULT, monitor));
        }
        Iterator definitionsIter = buildDefinitions.iterator();
        while (definitionsIter.hasNext()) {
            Object next = definitionsIter.next();
            if (next == null) {
                definitionsIter.remove();
            }
        }
        return buildDefinitions.toArray(new IBuildDefinition[buildDefinitions.size()]);
    }
   protected IBuildDefinition[] fetchBuildDefinitions(ITeamRepository repository, IProgressMonitor monitor)
            throws TeamRepositoryException {
        
        IItemQuery itemQuery = IItemQuery.FACTORY.newInstance(IBuildDefinitionQueryModel.ROOT);

        // get the team areas for the connected project areas in the repo and
        // use them to narrow the search
        IProcessAreaHandle[] processAreaHandles = getProcessAreaHandles(repository, monitor);

        IItemHandleInputArg[] itemHandleArgs = new IItemHandleInputArg[processAreaHandles.length];
        for (int i = 0; i < processAreaHandles.length; i++) {
            itemHandleArgs[i] = itemQuery.newItemHandleArg();
        }

        // create the query
        IBuildDefinitionQueryModel buildDefinitionQueryModel = IBuildDefinitionQueryModel.ROOT;
        final IItemQuery query = IItemQuery.FACTORY.newInstance(buildDefinitionQueryModel);

        IPredicate filter = ((BuildDefinitionQueryModel) buildDefinitionQueryModel).processArea()._in(itemHandleArgs);
        query.filter(filter);
        query.orderByDscUsingLocale(buildDefinitionQueryModel.id());

        // get the results
        IItemManager itemManager = repository.itemManager();
        ItemQueryIterator iter = new ItemQueryIterator(
                ClientFactory.getTeamBuildClient(repository), itemQuery, new Object[0]);
        LinkedList buildDefinitions = new LinkedList();
        while (iter.hasNext(monitor)) {
            List definitionHandles = iter.next(IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, monitor);
            buildDefinitions.addAll(itemManager.fetchCompleteItems(definitionHandles, IItemManager.DEFAULT, monitor));
        }
        Iterator definitionsIter = buildDefinitions.iterator();
        while (definitionsIter.hasNext()) {
            Object next = definitionsIter.next();
            if (next == null) {
                definitionsIter.remove();
            }
        }
        return buildDefinitions.toArray(new IBuildDefinition[buildDefinitions.size()]);
    }

		                                        
sam detweiler selected this answer as the correct answer

Comments
sam detweiler commented Jan 08 '14, 10:17 a.m.

funny.. look at my other answer and that is the code I built!..


thank you.. 

Your answer


Register or to post your answer.