我在RTC / Jazz中有几个构建定义,我使用变量在各种构建定义中设置DB-Release
在所有定义中我使用Property DB_SCHEMA,
DB_SCHEMA = 8.1
一旦我们更新我们的数据库并使用新的模式,我必须将构建属性设置为
DB_SCHEMA = 8.2
现在我必须更新所有构建定义...如果我忘记了一个或我拼错了一些东西,那么我的老板会生我的气 - 开玩笑,老实说,我不想犯错误
- >如何定义可在所有构建定义中使用的全局属性?
答案 0 :(得分:1)
我没有看到any global property in the help page,因此您可能会考虑开发一个程序:
,将属性设置为期望值(in this thread)
IBuildDefinition definition = (IBuildDefinition) buildDefinition.getWorkingCopy();
definition.setProperty("propertyName","");
definition = buildClient.save(definition, monitor);
答案 1 :(得分:1)
Ok VonC这是我的解决方案:
一个部件是一个RTC适配器,它处理来自RTC基站的连接:
(它提供了与此解决方案无关的其他getter / setter - 我已将其清除)
public class RtcAdapter {
//yes i know - having hardcoded user/pass is bad, ignore this - image it's in a property file or set by a popup dialog
private static final String repositoryURI = "https://xxxxxxxxxxxx/ccm";
private static final String userId = "xxxxxxxxxxx";
private static final String password = "xxxxxxxxxx";
private static final String projectAreaName = "xxxxxxxxxx";
private ITeamRepository teamRepository = null;
private IProgressMonitor monitor = new NullProgressMonitor();
private IProjectArea projectArea = null;
private ITeamBuildClient buildClient = null;
//i'm implementing a singleton class - you can argue with mie if it's a good approach
private static final RtcAdapter inst = new RtcAdapter();
private RtcAdapter(){
super();
}
public ITeamRepository getTeamRepository() {
return teamRepository;
}
public IProgressMonitor getMonitor() {
return monitor;
}
public IProjectArea getProjctArea(){
return projectArea;
}
public ITeamBuildClient getBuildClient(){
return buildClient;
}
private void setTeamRepository(ITeamRepository teamRepositoryIn) {
teamRepository = teamRepositoryIn;
}
/**
*
* @param repositoryURI
* @param userId
* @param password
* @param monitor
* @return
* @throws TeamRepositoryException
*/
private ITeamRepository login(String repositoryURI, String userId,String password, IProgressMonitor monitor) throws TeamRepositoryException {
ITeamRepository teamRepository = TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(monitor);
return teamRepository;
}
/**
* LoginHandler required by login function
*
*/
private static class LoginHandler implements ILoginHandler, ILoginInfo {
private String fUserId;
private String fPassword;
private LoginHandler(String userId, String password) {
fUserId = userId;
fPassword = password;
}
public String getUserId() {
return fUserId;
}
public String getPassword() {
return fPassword;
}
public ILoginInfo challenge(ITeamRepository repository) {
return this;
}
}
public static RtcAdapter inst() {
return inst;
}
public boolean connect() {
TeamPlatform.startup();
System.out.println("Team Platform Startup");
try {
IProgressMonitor monitor = new NullProgressMonitor();
setTeamRepository(login(repositoryURI, userId, password, monitor));
System.out.println("Logged in");
IProcessClientService processClient= (IProcessClientService) getTeamRepository().getClientLibrary(IProcessClientService.class);
URI uri= URI.create(projectAreaName.replaceAll(" ", "%20"));
projectArea = (IProjectArea) processClient.findProcessArea(uri, null, RtcAdapter.inst().getMonitor() );
buildClient = (ITeamBuildClient) getTeamRepository().getClientLibrary(ITeamBuildClient.class);
System.out.println("projet area = "+projectArea.getName() );
} catch (TeamRepositoryException e) {
System.out.println("TeamRepositoryException : " + e.getMessage());
e.printStackTrace();
return false;
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
return false;
}
return true;
}
public void disconnect(){
System.out.println("Logged out");
TeamPlatform.shutdown();
}
}
另一部分是工作类,我称之为BuildDefinitionHelper(多么好的名字,哈哈)
public class BuildDefinitionHelper {
/**
* @param args
*/
public static void main(String[] args) {
new BuildDefinitionHelper().startUp(); //not-so-nice startup, but i don't mind
}
private final String[] adaPublishDefinitionList = new String[]{
"publish ada develop-40",
"publish ada develop-40 nightly",
"publish ada develop-54",
"publish ada develop-54 nightly",
"publish ada develop-56",
"publish ada develop-56 nightly",
"publish ada develop-58",
"publish ada develop-58 nightly",
};
private final String BUILD_NR = "BUILD_NR";
private final String MAJOR = "MAJOR";
private final String MINOR = "MINOR";
private void startUp() {
final int major = 57;
final int minor = 11;
final int build = 1;
//connect
if (RtcAdapter.inst().connect() ){
//getting required resources - a singleton is helpful here (look above)
IProgressMonitor pMon = RtcAdapter.inst().getMonitor();
ITeamBuildClient buildClient = RtcAdapter.inst().getBuildClient();
try {
for (String adaPublish: adaPublishDefinitionList ){
//get build definition
IBuildDefinition workingCopy = getBuildDefinition(adaPublish, buildClient, pMon);
//seting properties
String propMajor = getFormattededInteger(major);
String propMinor = getFormattededInteger(minor);
String propBuild = getFormattededInteger(build);
setBuildProperty(MAJOR, propMajor, workingCopy);
setBuildProperty(MINOR, propMinor, workingCopy);
setBuildProperty(BUILD_NR, propBuild, workingCopy);
//store changes
saveBuildDefinition(workingCopy, buildClient, pMon);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (TeamRepositoryException e) {
e.printStackTrace();
}
//at the end: disconnect
RtcAdapter.inst().disconnect();
}
}
private void saveBuildDefinition(IBuildDefinition definition, ITeamBuildClient buildClient, IProgressMonitor progressMonitor) throws TeamBuildDuplicateItemException, IllegalArgumentException, TeamRepositoryException {
buildClient.save(definition, progressMonitor);
}
private String getFormattededInteger(int value) {
if (value >= 0 && value <= 9){
return "00"+value;
}
if (value >= 10 && value <= 99){
return "0"+value;
}
return ""+value;
}
private IBuildDefinition getBuildDefinition(String buildDefinitionName, ITeamBuildClient buildClient, IProgressMonitor progressMonitor) throws IllegalArgumentException, TeamRepositoryException {
IBuildDefinition buildDefinition = buildClient.getBuildDefinition(buildDefinitionName, progressMonitor );
IBuildDefinition definition = (IBuildDefinition) buildDefinition.getWorkingCopy();
return definition;
}
private void setBuildProperty(String propertyName, String propertyValue, IBuildDefinition definition ) throws TeamBuildDuplicateItemException, IllegalArgumentException, TeamRepositoryException {
definition.setProperty(propertyName,propertyValue);
System.out.println("set "+propertyName+" to "+ propertyValue+" in Build Definition "+definition.getId() );
}
private void printBuildDefinition(String[] buildDefinitionList, ITeamBuildClient buildClient, IProgressMonitor progressMonitor) throws IllegalArgumentException, TeamRepositoryException {
for (String buildDefinitionName: buildDefinitionList ){
IBuildDefinition buildDefinition = buildClient.getBuildDefinition(buildDefinitionName, progressMonitor );
IBuildDefinition definition = (IBuildDefinition) buildDefinition.getWorkingCopy();
System.out.println("name = "+buildDefinitionName+" definition = "+definition);
}
}
}