Determining Build Definitions Associated with a Specific Project Area
12 answers
ItemQueryIterator<ibuilddefinitionhandle> iter = new ItemQueryIterator<ibuilddefinitionhandle>(
ClientFactory.getTeamBuildClient(repository), query, processAreaHandles);
processAreaHandles isn't available. Substituting with itemHandleArgs compiles, but ultimately results in a ClassCastException during run-time.
Compiled. No ClassCastException. Got '0'.
private static ArrayList<IBuildDefinition> getBuildDefinitionsforProjectArea(IProjectAreaHandle iprja)
{
Boolean allProperties = true;
// allocate space for results
ArrayList<IBuildDefinition> allbe = new ArrayList<IBuildDefinition>();
ITeamRepository repo= (ITeamRepository)iprja.getOrigin();
// get the data interface
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
try
{
IBuildDefinitionQueryModel queryModel = IBuildDefinitionQueryModel.ROOT;
// create a query for build engines
IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
// 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
query.filter(filter);
// no parameters required
IItemQueryPage queryPage = buildClient.queryItems(query,
// com.ibm.team.repository.common.service.IQueryService.EMPTY_PARAMETERS,
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);
}
else
{
final String[] all_properties = new String[]
{ IBuildEngine.PROPERTY_ACTIVE, IBuildEngine.PROPERTY_BUILD_ENGINE_ACTIVITY,
IBuildEngine.PROPERTY_DESCRIPTION, IBuildEngine.PROPERTY_ENGINE_CONTACT_INTERVAL,
IBuildEngine.PROPERTY_ID, IBuildEngine.PROPERTY_PROCESS_AREA,
IBuildEngine.PROPERTY_SUPPORTED_BUILD_DEFINITIONS,
IBuildEngine.PROPERTY_SUPPORTS_CANCELLATION, IBuildEngine.PROPERTY_USE_TEAM_SCHEDULER,
IBuildEngine.PROPERTY_PROPERTIES, IBuildEngine.PROPERTY_CONFIGURATION_ELEMENTS };
fetchResult = repo.itemManager().fetchPartialItemsPermissionAware(queryPage.getItemHandles(),
IItemManager.DEFAULT, Arrays.asList(all_properties), null);
}
// add these to the list
allbe.addAll(fetchResult.getRetrievedItems());
if (queryPage.hasNext())
{
queryPage = (IItemQueryPage) buildClient.fetchPage(queryPage.getToken(),
queryPage.getNextStartPosition(), queryPage.getSize(), null);
}
else
{
queryPage = null;
}
}
}
}
catch (Exception ex)
{
System.out.println("build exception=" + ex.getMessage());
}
return allbe;
}
try this little change.. (the 1st and last lines are the same, section in the middle changes a tiny bit )
IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
// objects of build definition type, shouldn't be needed
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
query.filter(filter._and(isBuildDefType));
// no parameters required
Comments
well, nice to know you have some results at last.. similar code has been working fine on 3.0 and 4.0
so, it sounds like the project area handle is wrong.. how did u get that?
this is what my code usually does
ITeamRepository Server = TeamPlatform.getTeamRepositoryService().getTeamRepository(serverURI);
processClient = (IProcessClientService) Server
.getClientLibrary(IProcessClientService.class);
IProjectArea iprja = null;
URI projuri = URI.create(projectAreaName.replaceAll(" ", "%20"));
iprja= (IProjectArea) processClient.findProcessArea(projuri, null, null);