将 JTidy 与 Maven2 结合使用

发布于 2024-08-13 01:09:55 字数 444 浏览 5 评论 0原文

我正在使用 spring2 和 Maven 开发一个 Java 项目。

我已经将 JSLint4Java 合并到 Maven 中,但现在发现自己需要做一些进一步的验证。

构建中有许多核心页面,即主页、搜索页面等,我想自动测试最终 HTML 输出的规范有效性,即 Maven 构建中严格的有效 XHTML 1.1。生成最终 HTML 输出的 html 模板文件都是模块化和分离的,因此单独验证组件将不起作用,因为它们在作为一个整体执行之前不会变得有效。

我不想测试构建中的每个页面,因为这会大大减慢速度,我的偏好是拥有一个 XML 配置文件,其中包含我希望运行验证过程的 URL 列表。

我已经找到了 Jtidy 项目,但不确定如何将其合并到 Maven 构建中并让它调用特定的 URLS 进行验证。

以前有人这样做过吗?有人可以提供我需要执行此操作的各个阶段的简要演练吗?

干杯

I am working on a Java project using spring2 and Maven.

I have already incorporated JSLint4Java into Maven, but now find myself needing to do some further validation.

There are a number of core pages in the build i.e. home page, search page etc. that I want to automatically test the final HTML output for specification validity i.e. Valid XHTML 1.1 strict from the Maven build. The html template files that generate the final HTML output are all modularised and separated so validating the components individually will not work as they do not become valid until executed as one.

I do not want to test each of the pages in the build as this would slow it down considerably, my preference would be to have an XML config file with a list of the URL's I wish to run through the validation process.

I have found the Jtidy project, but am unsure of how to incorporate this into the Maven build and get it call specific URLS to validate against.

Has anybody ever done this before? Could someone provide a brief walkthrough of the stages I would need to do this?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别念他 2024-08-20 01:09:55

如果 JTidy 确实是您想要的,那么有一个 Maven JTidy 插件 。它似乎适用于文件,而不是 URL:

  <build>    
    <plugins> 
      <plugin>    
        <groupId>jtidy</groupId>   
        <artifactId>maven-jtidy-plugin</artifactId>    
        <configuration>    
          <srcdir>src/main/resources/html</srcdir>    
          <destdir>target/html</destdir>    
          <properties>src/main/resources/jtidy.properties</properties>    
        </configuration>
        <executions>
          <execution>    
            <goals>    
              <goal>jtidy</goal>    
            </goals>    
          </execution>    
        </executions>    
      </plugin>    
    </plugins>    
  </build>

除非插件没有执行您想要的操作,否则我不建议使用 exec() (这需要安装 Tidy,从而损害可移植性)。

(编辑:实际上,我不确定您想要实现什么确切,如果您是否想要一个完全自动化的解决方案,如果您需要自动化应用程序的部署等,但这里还有一些提示。

对于手动操作,您可以使用 wget 来保存生成的 HTML:对于 GET:

wget http://www.mypage.com/index.jsp?foo=bar

或使用 --post-data 选项进行 POST:

wget http://www.mypage.com/index.jsp --post-data="foo=bar"

然后运行 ​​JTidy。 。
如果您想实现自动化,则必须首先使用 maven Cargo 插件。然后,您可以将 Ant 的 Get Task 与 antrun 插件一起使用。最后,执行 jtidy 验证。

如果您想在构建期间验证生成的 HTML,您需要部署应用程序并针对它运行一些工具。您应该查看 w3c-markup-validation-filter。使用 maven Cargo 插件 使用过滤器部署您的应用程序(Cargo 允许合并 web.xml 因此您可以仅添加用于验证测试的过滤器)并运行一组基本的 Selenium 测试来浏览您的页面并检查 W3cMarkupValidationFilter 注入 HTML 页面的小框是否为绿色。)

If JTidy is really what you want, there is a Maven JTidy Plugin. It seems to work on files, not on URLs:

  <build>    
    <plugins> 
      <plugin>    
        <groupId>jtidy</groupId>   
        <artifactId>maven-jtidy-plugin</artifactId>    
        <configuration>    
          <srcdir>src/main/resources/html</srcdir>    
          <destdir>target/html</destdir>    
          <properties>src/main/resources/jtidy.properties</properties>    
        </configuration>
        <executions>
          <execution>    
            <goals>    
              <goal>jtidy</goal>    
            </goals>    
          </execution>    
        </executions>    
      </plugin>    
    </plugins>    
  </build>

Unless the plugin is not doing what you want, I wouldn't recommend using exec() (which would need Tidy installed and thus harm portability).

(EDIT: Actually, I'm not sure of what you are trying to achieve exactly, if you want a fully automated solution or not, if you'll need to automate the deployment of application, etc, but here are some more hints.

For something manual, you could maybe use wget to save the generated HTML. For GET:

wget http://www.mypage.com/index.jsp?foo=bar

Or POST with the --post-data option:

wget http://www.mypage.com/index.jsp --post-data="foo=bar"

And then run JTidy.
If you want to automate things, you'll have to deploy your application first with the maven cargo plugin. Then, you could use the Ant's Get Task with the antrun plugin. And finally, perform the jtidy validation.

If you want to validate the generated HTML during the build, you'll need to deploy your application and to run some tool against it. You should look at the w3c-markup-validation-filter. Use the maven cargo plugin to deploy your application with the filter (cargo allows to merge web.xml so you can add the filter only for the validation test) and run a set of basic selenium tests to browse your pages and check if the little box injected by the W3cMarkupValidationFilter into the HTML page is green.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文