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

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

 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?


1

0 votes


Accepted answer

Permanent link
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

1 vote

Comments

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


thank you.. 

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
× 10,938

Question asked: Jan 07 '14, 5:58 p.m.

Question was seen: 4,303 times

Last updated: Jan 08 '14, 10:17 a.m.

Confirmation Cancel Confirm