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?
Accepted answer
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()]);
}