【问题标题】:relative links not working in CruiseControl.NET HtmlReportPlugin相对链接在 CruiseControl.NET HtmlReportPlugin 中不起作用
【发布时间】:2012-08-10 21:07:28
【问题描述】:

我的 CruiseControl.NET 项目的发布者区域中有一个合并任务,它成功地将一组 html 和 png 文件复制到工件目录。我在仪表板中启用了HtmlReportPlugin,如下所示:

   <buildPlugins>
      <buildReportBuildPlugin>
        <xslFileNames>
          <xslFile>xsl\header.xsl</xslFile>
          <xslFile>xsl\compile.xsl</xslFile>
          <xslFile>xsl\modifications.xsl</xslFile>
          <xslFile>xsl\MsTestSummary2010.xsl</xslFile>
        </xslFileNames>
      </buildReportBuildPlugin>
      <buildLogBuildPlugin />
      <xslReportBuildPlugin description="MSTest2010 Report" actionName="MSTestBuildReport2010" xslFileName="xsl\MsTestReport2010.xsl"></xslReportBuildPlugin>
      <xslReportBuildPlugin description="MSTest Coverage 2010" actionName="MSTestBuildCoverReport2010" xslFileName="xsl\MsTestCover2010.xsl"></xslReportBuildPlugin>
      <htmlReportPlugin description="Html Report" actionName="HtmlReport" htmlFileName="index.html" />
    </buildPlugins>

index.html 提供得很好,但 index.html 中的相关链接似乎不起作用。这是 index.html 的源代码:

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN'
 'http://www.w3.org/TR/html4/frameset.dtd'>
<html><head><title>
all.cov
</title>
<meta http-equiv=Content-Type content='text/html;charset=utf-8'>
</head>
<frameset cols='25%,75%'>
    <frame src=nav-folder.html>
    <frame name=right src=p0.html>
    <noframes>
    <p>Your browser does not support frames. See <a href=nav-folder.html>nav-folder.html</a>
    </noframes>
</frameset>
</html>

这是我在加载 index.html 时遇到的错误之一(将 'nav-folder' 替换为 'p0' 以获得其他错误消息):

“/”应用程序中的服务器错误。

未知对象名称:导航文件夹

描述:执行过程中发生了未处理的异常 当前的网络请求。请查看堆栈跟踪以获取更多信息 有关错误的信息以及它在代码中的来源。

异常详细信息:System.ApplicationException:未知对象名称: 导航文件夹

来源错误:

在执行过程中产生了一个未处理的异常 当前的网络请求。有关原产地和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。

堆栈跟踪:

[ApplicationException:未知对象名称:导航文件夹]
Objection.ObjectionStore.GetByName(字符串名称) +307
ThoughtWorks.CruiseControl.WebDashboard.MVC.Cruise.CruiseActionFactory.CreateHandler(字符串 行动名称)+231
ThoughtWorks.CruiseControl.WebDashboard.MVC.Cruise.CruiseActionFactory.Create(IRequest 请求)+38
ThoughtWorks.CruiseControl.WebDashboard.MVC.RequestController.Do() +155 ThoughtWorks.CruiseControl.WebDashboard.MVC.ASPNET.HttpHandler.ProcessRequest(HttpContext 上下文)+651
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +625 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +27

如果我在任一参考文件(例如,http://localhost/server/local/project/Code_Coverage/build/log20120809181334Lbuild.168.xml/RetrieveBuildFile.aspx?file=p0.html)上使用 RetrieveBuildFile.aspx,文件加载没有问题,但与第一个示例一样,任何相关文件都将无法加载。

我必须在 CruiseControl.NET web.config 中做些什么来让 IIS 正确解析相对文件路径?我正在使用 CruiseControl.NET 1.8.0 并且我正在运行在 Windows 2008 上运行的 IIS 7,并且我已验证在 CruiseControl.NET 1.6 上发生了同样的问题?在 Windows 7 上运行的 IIS 上。

【问题讨论】:

    标签: iis iis-7 cruisecontrol.net


    【解决方案1】:

    不幸的是,HTML tidy 不喜欢 Bullseye CodeCoverage HTML,因为它包含无效的 HTML。所以这个解决方案行不通。

    CruiseControl 使用正则表达式来查找源链接,但这并不完美,因为它错过了 HTML 属性没有引号的情况,并且它可以匹配不是 HTML 属性的字符串片段。我修改了 CruiseControl.NET 源代码以使用 HtmlAgilityPack 解析 HTML,这似乎工作得很好(至少在我的测试用例中)。

    【讨论】:

      【解决方案2】:

      如果您需要解决此问题(无需自行查看 CCnet 解析 html 的位置)。我将 ReportGenerator 与 CCnet 一起使用。这是一个例子:

      在课堂上:

      BuildFileDownload (namespace ThoughtWorks.CruiseControl.WebDashboard.Plugins.BuildReport)
      

      使用此代码修改执行过程:

      HtmlDocument doc = new HtmlDocument();
      doc.OptionAddDebuggingAttributes = false;
      doc.OptionAutoCloseOnEnd = false;
      doc.OptionCheckSyntax = false;
      doc.OptionFixNestedTags = false;
      doc.OptionOutputOptimizeAttributeValues = false;
      doc.LoadHtml(htmlData);
      
      var nodes = doc.DocumentNode.SelectNodes("//a[@href]");
      if (nodes != null)
      {
          foreach (var link in nodes)
          {
              HtmlAttribute att = link.Attributes["href"];
              if (!att.Value.StartsWith("data:") && !att.Value.StartsWith("#") && !att.Value.StartsWith("http://"))
                  att.Value = @"RetrieveBuildFile.aspx?file=coverageReport\" + att.Value;
          }
          htmlData = doc.DocumentNode.WriteTo();
      }
      
      nodes = doc.DocumentNode.SelectNodes("//link[@href]");
      if (nodes != null)
      {
          foreach (var link in nodes)
          {
              HtmlAttribute att = link.Attributes["href"];
              if (!att.Value.StartsWith("data:") && !att.Value.StartsWith("#") && !att.Value.StartsWith("http://"))
                  att.Value = @"RetrieveBuildFile.aspx?file=coverageReport\" + att.Value;
          }
          htmlData = doc.DocumentNode.WriteTo();
      }
      

      记得首先摆脱旧的正则表达式解析。这是一个示例代码,但它满足我的所有需求。此解决方案使用 HtmlAgilityPack。请注意,作为新属性值前缀的路径可能不同。

      【讨论】:

        【解决方案3】:

        问题在于 CruiseControl.NET 不喜欢带有未引用值的属性的 HTML。我正在使用 Bullseye CodeCoverage 生成的输出,并且该输出具有未引用的值的属性。我正在使用HTML Tidy 添加引号。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-12-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-25
          • 1970-01-01
          相关资源
          最近更新 更多