我正在尝试从已编辑的类中检索完整的文件路径。我可以检索注释,版本号,作者和日期,但似乎无法获得在项目中包含多个类时已编辑的完整文件路径。
我用这些来检索评论和作者:
String comments = pc.getPendingChanges().getComment();
System.out.println("Comments: " + comments);
String author = pc.getPendingChanges().getAllPendingChanges()[0].getPendingSetOwnerDisplay();
System.out.println("Author: " + author);
我用它来检索路径:
String fileName = pc.getPendingChanges().getAllPendingChanges()[0].getLocalItem();
System.out.println("FileName: " + fileName);
但我只获得此输出:
FileName:C:\ VS2013 \ Plugin \ PluginTest \ HelloWorld.classpath
我需要显示类名称的完整路径,例如
FileName:C:\ VS2013 \ Plugin \ PluginTest \ HelloWorld.Test.java
以下显示的完整方法:
@Override
public PolicyFailure[] evaluate(PolicyContext context)
throws PolicyEvaluationCancelledException {
final PendingCheckin pc = getPendingCheckin();
final List<PolicyFailure> failures = new ArrayList<PolicyFailure>();
final WorkItemCheckinInfo[] AssociatedWorkItems = pc.getWorkItems().getCheckedWorkItems();
WorkItem AssociatedCodeReview = null;
String failureReason = "";
for (int i=0; i<AssociatedWorkItems.length; i++) {
AssociatedCodeReview = AssociatedWorkItems[i].getWorkItem();
if (AssociatedCodeReview.getType().getName() == "Code Review") {
break;
}
}
if (AssociatedCodeReview != null) {
if (AssociatedCodeReview.getFields().getField("System.State").getValue()
.toString().equals("Not Approved")) {
failureReason = "Code Review Work Item associated but that is not approved by expert";
failures.add(new PolicyFailure(failureReason, this));
}
} else {
String fileName = pc.getPendingChanges().getAllPendingChanges()[0].getLocalItem();
System.out.println("FileName: " + fileName);
String fileName2 = pc.getPendingChanges().getAllPendingChanges()[0].getServerItem();
System.out.println("FileName2: " + fileName2);
String[] fileName3 = pc.getPendingChanges().getAffectedTeamProjectPaths();
System.out.println("FileName3: " + fileName3[0]);
//System.out.println("Found " + pc.getPendingChanges().getAffectedTeamProjectPaths()[0] + " work items.");
String comments = pc.getPendingChanges().getComment();
System.out.println("Comments: " + comments);
String author = pc.getPendingChanges().getAllPendingChanges()[0].getPendingSetOwnerDisplay();
System.out.println("Author: " + author);
String version = String.valueOf(pc.getPendingChanges().getAllPendingChanges()[0].getVersion());
System.out.println("Version: " + version);
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println("Date Time: " + dateFormat.format(date));
}
return failures.toArray(new PolicyFailure[failures.size()]);
}
答案 0 :(得分:0)
它确实有效,我的Eclipse安装出错了。
String fileName = pc.getPendingChanges().getAllPendingChanges()[x].getLocalItem();