how to get after state name
Now I am writing a server precondition using RTC-SDK.
When a source file renamed to the other name, I want to get it new name.
For example, a source file Test1.java was named to Test2.java, and then deliver the change to the stream.
So In my server deliver precondition trigger, how can I use IChange to get the Test2.java name?
I have try below source:
//I found RENAME value is 4, but change.kind() get 6, so I assume change.kind()= MODIFIED(2) + RENAME(4) = 6, and
// the rename kind will get in the if condition statement.
if (change.kind() == IChange.MODIFIED || change.kind() == (IChange.MODIFIED + IChange.RENAME)) {
IVersionableHandle versionableHandle = change.afterState();
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(
data.getDestWorkspace(), changeSet.getComponent());
IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null);
IAncestorReport reports[] = scmService.configurationLocateAncestors(
configProvider, new IVersionableHandle[] {versionableHandle}, null, null);
String path = toFullPath(item, reports[0].getNameItemPairs())
IAdvisorInfo info = collector.createProblemInfo(
"Deliver of rename or modified files is prohibited",
"The file " + toFullPath(item, reports[0].getNameItemPairs()) + " is not allowed to be modified or deleted.",
"error");
collector.addInfo(info);
}
private String toFullPath(IVersionable versionable, List<INameItemPair> segments) {
StringBuffer path = new StringBuffer();
if(segments.isEmpty()) {
return versionable.getName();
}
for (INameItemPair nameItemPair : segments) {
if(path.length() != 0) {
path.append(Path.SEPARATOR);
}
// ignore the root folder which doesn't have a name
if(nameItemPair.getName() != null)
path.append(nameItemPair.getName());
}
return path.toString();
}
question 1:
I found whatever I used versionableHandle = change.afterState(); or change.beforeState(), the path always return Test2.java to me, I do not know why. So, How can I get Test3.java name?
question 2:
the function toFullPath only can get full path in MODIFIED and DELETED kind. If kind =ADD kind, segments.isEmpty()) will be true, so full path can not be get when ADD kind. So, How can I get Test2 or Test3 full path?
This two question confuse me so long! Please give me some advise.
Comments
silencehill wu
Nov 13 '12, 10:28 a.m.For question 2 addition:
for example, path is com.ibm.test.Test2.java
In actual, I can get com.ibm.test.Test2.java when kind = DELETE or MODIFED. But when kind= ADD, I only get Test2.java. So how I can get com.ibm.test.Test2.java when kind = ADD
Jia Jia Li
Nov 13 '12, 10:35 a.m.I have asked the same question here question