0

我正在尝试从已编辑的类中检索完整的文件路径。我可以检索评论、版本号、作者和日期,但是当项目中包含多个类时,我似乎无法获得已编辑的完整文件路径。

我使用这些来检索评论和作者:

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);

但我只得到这个输出:

文件名:C:\VS2013\Plugin\PluginTest\HelloWorld.classpath

需要显示带有类名的完整路径,例如

文件名: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()]);
}
4

1 回答 1

0

它确实有效,这是我的 Eclipse 安装错误。

String fileName =  pc.getPendingChanges().getAllPendingChanges()[x].getLocalItem();
于 2014-08-20T15:48:21.727 回答