SONAR FORTIFY插件导入

时间:2014-09-05 11:32:18

标签: sonarqube fortify

全部, 我想让声纳进口强化分析报告。 我正面临代码源目录的问题。

我在另一台机器上运行的分析并生成如下报告

 <SourceBasePath>C:/STA/Source/src</SourceBasePath>
  <SourceFiles>
    <File size="2409" timestamp="1409914148012" loc="12" type="java" encoding="windows-1252">
      <Name>main/java/com/test/Test/TestRequest.java</Name>
      <LOC type="Fortify">12</LOC>
      <LOC type="Line Count">135</LOC>
      <LOC type="Source Code">57</LOC>
      <LOC type="Comments">59</LOC>
      <LOC type="Comments and Source Code">0</LOC>
      <LOC type="White Space">19</LOC>

当插件尝试导入时,显示如下 [DEBUG] [10:34:42.947]无法找到&#34; C:/STA/Source/src/main/java/com/test/Test/TestRequest.java"。尝试相对路径。 [DEBUG] [10:34:42.947]无法找到&#34; /opt/mount/jenkins/jobs/02-TestFortify/workspace/main/java/com/test/TestRequest.java"。您的Fortify分析......

查看导入过程代码,首先检查 sourceBasePath + vulnerability.getPath() 那么 基础项目目录+ vulnerability.getPath()

问题,源路径在$ {project.build.sourceDirectory}中,这是不同的。

我可以考虑在继续之前构建到源路径的sym链接的解决方法,但我想知道是否有更好的解决方案。

安托

1 个答案:

答案 0 :(得分:1)

以下是一些有用的代码。请注意,您不会从结果中获得签名的FPR。这应该没问题,因为你只是将它用于Sonar。

import java.io.*;
import com.fortify.io.fvdl.FVDL;
import com.fortify.io.fvdl.FVDLUtil;
import org.exolab.castor.xml.XMLContext;
import com.fortify.ui.model.Project;
import com.fortify.ui.model.util.integration.IntegrationStubFactory;
import com.fortify.ui.model.util.integration.IntegrationUtil;
import com.fortify.ui.model.xml.interfaces.Product;
import com.fortify.util.SystemUtil;

public class FPRMod{
  public static void SetFPRSourceBasePath(String FPRPath, String NewSourceBasePath) throws Exception {
    //Initialize Fortify
    SystemUtil.setInstallRoot();
    IntegrationUtil.initializeFrameworkIntegration(IntegrationStubFactory.getFrameworkIntegrationUtil(), null, false);

    //Load the FPR and FVDL
    Project fpr = IntegrationUtil.loadProjectWithProgress(new File(FPRPath));
    FVDL fvdl = FVDL.unmarshalFVDL(FVDLUtil.getFVDLReader(FPRPath));

    //Set the SourceBasePath in the FPR and FVDL
    fpr.setSourceBasePath(NewSourceBasePath, true);
    fvdl.getBuild().setSourceBasePath(NewSourceBasePath);

    //Save the new FVDL
    fvdl.marshal(new FileWriter(FPRPath + ".mod.fvdl"));

    //Set the FPR to use the new FVDL
    fpr.getProjectInfo(Product.SCA).setEntryName(null);
    fpr.getProjectInfo(Product.SCA).setPath(new File(FPRPath + ".mod.fvdl"));

    //Save the new FPR
    fpr.saveProjectAs(new File(FPRPath + ".mod.fpr"));
  }
}
相关问题