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

How to get the ITeamBuildService

Hi, I use the following code to get the   ITeamBuildService, but it has null value. the pa object is gotten. 
Do I use the wrong API? Please help. Thanks!

ITeamRepository repo = login(monitor);           
 IProjectArea pa = getProjArea(repo,monitor);
            
 ITeamBuildService service = (ITeamBuildService) repo.getClientLibrary(ITeamBuildService.class); 
 IBuildDefinition[] buildDefs = service.getBuildDefinitions();

0 votes


Accepted answer

Permanent link
 ok, here is the routine which will get the current set of build engines from a repo 
ugly programming model. this returns all the properties of each build engine. 
one could reduce the data if desired, by removing some of the properties in the
all_properties list

also provided is a routine to filter that by a specific project area. 
this needs the process_area property to be returned


private void processBuilds(ITeamRepository repo, IProjectArea owning_project)
{
for (IBuildEngine buildEngine : getBuildEngines(repo)) {
if(buildEngine.getProcessArea().sameItemId(owning_project))
System.out.println(buildEngine.getId()+ " = "+ buildEngine.getDescription());
}
}
private  ArrayList<IBuildEngine> getBuildEngines(ITeamRepository repo)
{
// allocate space for results
ArrayList<IBuildEngine> allbe=new ArrayList<IBuildEngine>();
// get the data interface
ITeamBuildClient  buildClient = (ITeamBuildClient) repo
.getClientLibrary(ITeamBuildClient.class);

try
{
IBuildEngineQueryModel queryModel = IBuildEngineQueryModel.ROOT;
// create a query for build engines
IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
// objects of build engine type
IPredicate isBuildEngineType = queryModel._isTypeOf(IBuildEngine.ITEM_TYPE);
// the query filter
query.filter(isBuildEngineType);
// no parameters required
IItemQueryPage queryPage = buildClient.queryItems(query, 
com.ibm.team.repository.common.service.IQueryService.EMPTY_PARAMETERS,
   IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
// if there are buildengines defined
if (queryPage.getResultSize() != 0) {

while (queryPage != null) {

// print out a page of IDs of the retrieved build engines
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
};
IFetchResult 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;
}
Ralph Schoon selected this answer as the correct answer

1 vote

Comments

Sam, thanks so much for sharing!

I will try to blog about this, so others can use it too.

my pleasure..


supposedly there is a way to use the query filter with the _in predicate to filter based on project area, instead of the code loop in the above.  but I haven't figured it out yet. 
(get 0 results). 

one argument
<code>
IPredicate filter = queryModel._in(new IItemHandleInputArg[] {query.newItemHandleArg()});
IItemQueryPage queryPage = buildClient.queryItems(query,
new Object[]{project_area_handle},
IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
</code>

That is used in my code snippet. I will try to find out how it works.

 yes, your snippet is using BuildDefinitions not BuildEngines.


build defs have a processarea() method. engines do not


2 other answers

Permanent link
Jia, please download the javadoc for the Plain Java Client Libraries. You will notice that the service you refer to is not available there. It is a server side service. So you can't get it as a client library. See https://jazz.net/library/article/807 for more information on the API.

I would assume you have to use the ITeamBuildClient.

0 votes

Comments

Thanks for your information Ralph. My requirement is to get all the build definitions. I find ITeamBuildService has the getBuildDefinitions() function. So I asked how to get ITeamBuildService object. Or if you know any other method to get all the build definitions, it is useful for me. Thanks !


Permanent link
Jia,

please have a look into the JavaDoc of the Plain Java client library and try to use the basic search functionality in the Eclipse PDE with Eclipse set up for SDK and Plain Java development (see my article on how to).

 I could find a method to get the build definitions from the ITeamBuildClient in less than 3 minutes. This is a client library that you cen get using getClientLibrary().

0 votes

Comments

Ok, you are better than me. I cannot find a method to get the list of build engines or builds. 

I can see the source for ITeamBuildClient and ITeamBuildService, and I can search, but don't see what I would be searching on. (or where)..

I dug a bit deeper. I was also not able to instantiate the ITeamBuildService. The implementation of TeamBuildClient implements a getService() method that is private and does not appear in ITeamBuildClient to get the ITeamBuildService.

    private ITeamBuildService getService() {
        return (ITeamBuildService) getContext().getServiceInterface(ITeamBuildService.class);
    }

I think Jia did what you attempt as well, maybe she has a better answer. Otherwise I would suggest to use the https://jazz.net/wiki/bin/view/Main/BuildJavaProgrammingExamples to get at the data you need and then try to dig deeper.

yes, I saw that in the buildclient code.  Your prior note link shows how to get build engines for a build def. nice, but then I need all buid defs..  :-)

i need to copy everything. build engines are supposedly the top of the tree.

Sam, i have not the time today to poke through the API. You might be able to find query examples and be able to query for what you are looking at. Jia might be able to provide some hints.

I do not expect u to spend time to research solutions for me.
thanks for the pointers..

there is a ton of pressure to get this project moved from their old 3.0.1 system to the production landscape on 4.0.4. like week before last.. I've got everything but builds, and my coworker is building the links reconstruction tool and he is close as well.

I think in my answer I refered to

ITeamBuildClient teamBuildClient = (ITeamBuildClient) teamRepository.getClientLibrary(ITeamBuildClient.class);
teamBuildClient.getBuildDefinition(buildDefinitionId, monitor);

Unfortunately, this does only provide you with what you want, if you know the ID already.

showing 5 of 7 show 2 more comments

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,936

Question asked: Sep 25 '12, 2:10 a.m.

Question was seen: 5,321 times

Last updated: Jan 09 '14, 9:16 p.m.

Confirmation Cancel Confirm