Determining Build Definitions Associated with a Specific Project Area
Using the 4.0.5 Client API's, I have a handle to a specific ProjectArea. I am having difficulty using the API's to list the names of all the Build Definitions associated with this particular Project Area. Lots of scouring of this forum and other sources have haven't helped me connect the dots yet.
Any advice and guidance is greatly appreciated.
12 answers
Here is a simple stand-alone program to demonstrate the issue. When running as a Java Application, it takes 4 parameters in this order:
- Repository URI
- username
- password
- Name of the Project area
This is contains all of the work from above, but it still does not work with RTC 4.0.5:
package rtc.test;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.build.client.ITeamBuildClient;
import com.ibm.team.build.common.model.IBuildDefinition;
import com.ibm.team.build.common.model.IBuildEngine;
import com.ibm.team.build.common.model.query.IBaseBuildDefinitionQueryModel.IBuildDefinitionQueryModel;
import com.ibm.team.build.internal.common.model.query.BaseBuildDefinitionQueryModel.BuildDefinitionQueryModel;
import com.ibm.team.process.client.IProcessClientService;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.process.common.IProjectAreaHandle;
import com.ibm.team.repository.client.IItemManager;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.IFetchResult;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.common.query.IItemQuery;
import com.ibm.team.repository.common.query.IItemQueryPage;
import com.ibm.team.repository.common.query.ast.IItemHandleInputArg;
import com.ibm.team.repository.common.query.ast.IPredicate;
import com.ibm.team.repository.common.service.IQueryService;
import com.ibm.ws.bpm.build.rtc.RTCLoginHandler;
import com.ibm.ws.bpm.build.rtc.SysoutProgressMonitor;
public class ProjectAreaBuildDefs {
private String username = null;
private String password = null;
private String repoUri = null;
private String projectAreaName = null;
// RTC CLient API Objects
private IProgressMonitor myProgressMonitor;
private ITeamRepository repo;
public ProjectAreaBuildDefs() throws Exception {
super();
}
public static void main(String[] args) {
try {
ProjectAreaBuildDefs engine = new ProjectAreaBuildDefs();
engine.setRepository(args[0]);
engine.setUsername(args[1]);
engine.setPassword(args[2]);
engine.setProjectAreaName(args[3]);
engine.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
private void init() throws Exception {
try {
myProgressMonitor = new SysoutProgressMonitor();
TeamPlatform.startup();
repo = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoUri);
repo.registerLoginHandler(new RTCLoginHandler(username, password));
repo.login(myProgressMonitor);
} catch (TeamRepositoryException e) {
System.out.println(e.getMessage());
TeamPlatform.shutdown();
throw new Exception("Could not initialize the RTC Client API...");
}
}
private void displayParameters() {
System.out.println("Specified Repository: " + this.repoUri);
System.out.println("User: " + this.username);
System.out.println("Password: xxxxxxxx");
System.out.println("Project Area Name: " + this.projectAreaName);
System.out.println();
}
private void execute() throws Exception {
displayParameters();
try {
init();
IProcessClientService processClient = (IProcessClientService) repo.getClientLibrary(IProcessClientService.class);
URI uri = URI.create(this.projectAreaName.replaceAll(" ", "%20"));
IProjectArea iprja = (IProjectArea) processClient.findProcessArea(uri, null, null);
listProjectAreaBuildDefinitions(iprja);
} catch (TeamRepositoryException e) {
e.printStackTrace();
/* Handle repository exceptions such as login problems here. */
} finally {
repo.logout();
TeamPlatform.shutdown();
}
}
// Working with support to fix this
private ArrayList<IBuildDefinition> listProjectAreaBuildDefinitions(IProjectAreaHandle iprja) throws TeamRepositoryException {
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;
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
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
int numResults = queryPage.getResultSize();
//System.out.println("Num Results: " + numResults);
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());
}
System.out.println("*****Returned: " + allbe.size());
return allbe;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setRepository(String repository) {
this.repoUri = repository;
}
public void setProjectAreaName(String projectAreaName) {
this.projectAreaName = projectAreaName;
}
}
page 2of 1 pagesof 2 pages