How to get the contents of the artifact download files in plain java api?
Accepted answer
i have got it working
IBuildResultQueryModel buildResultQueryModel = IBuildResultQueryModel.
ROOT;IItemQuery query = IItemQuery.
FACTORY.newInstance(buildResultQueryModel);query.filter(buildResultQueryModel._eq(query.newItemHandleArg()));
query.orderByDsc(buildResultQueryModel.buildStartTime());
ITeamBuildClient buildClient = ClientFactory.getTeamBuildClient(
iTeamRepository);UUID[] parameters =
new UUID[1];parameters[0]=UUID.valueOf(
"_A1h9oa47EeGW7pvup4pIzw");IItemQueryPage queryPage = buildClient.queryItems(query, parameters, IQueryService.
ITEM_QUERY_MAX_PAGE_SIZE, monitor); // print out the labels of the retrieved buildsString[] properties =
new String[] { IBuildResult.PROPERTY_LABEL , IBuildResult.PROPERTY_BUILD_DEFINITION, IBuildResult.PROPERTY_TAGS, IBuildResult.PROPERTY_BUILD_RESULT_CONTRIBUTIONS,IBuildResult.PROPERTY_BUILD_REQUESTS};List buildResults =
iTeamRepository.itemManager().fetchPartialItems(queryPage.getItemHandles(),IItemManager.
DEFAULT, Arrays.asList(properties), monitor); int nr=0; for (Object result : buildResults) {IBuildResult buildResult = (IBuildResult) result;
IBuildResultContribution[] buildresultContribution=buildClient.getBuildResultContributions((IBuildResultHandle) buildResult.getItemHandle(), IBuildResultContribution.
ARTIFACT_EXTENDED_CONTRIBUTION_ID, monitor); for (IBuildResultContribution iBuildResultContribution:buildresultContribution) {System.
out.println("label=" + iBuildResultContribution.getLabel());IContent ic=iBuildResultContribution.getExtendedContributionData();
InputStream is=
iTeamRepository.contentManager().retrieveContentStream(ic, monitor);OutputStream os=
new FileOutputStream("c:\\temp\\test.ear"); int c; while ((c=is.read())!=-1) {os.write(c);
}
is.close();
}