0

当使用 cargo 部署到远程服务器时,我想用 cargo 或 maven 检查生成的战争是否像预期的那样过滤了它的属性文件。

中间的某个阶段应该针对某些字符串测试属性文件,然后部署或停止部署。

有内置的货物来实现这一点吗?

4

1 回答 1

1

不确定您指的是什么属性文件,因此我假设您指的是典型java *.properties文件。

无论如何,我相信你应该使用:maven-enforcer-plugin它的目标:enforce因为这是 maven 中强制执行某些条件(插件使用 term: rule)的常用方法。

我认为您在这里有更多选择。

选项1

也许您可以使用以下命令检查打包到您的战争的优先级:

maven-property-plugin- 目标:read-project-propertieshttp://mojo.codehaus.org/properties-maven-plugin/usage.html

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
      <execution>
        <phase>???</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>your_file_to_check.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

你应该在哪里:

然后去maven-enforcer-plugin目标:enforce和规则:requirePropertyhttp://maven.apache.org/enforcer/enforcer-rules/requireProperty.html

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <executions>
      <execution>
        <id>enforce-property</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <requireProperty>
              <property>your_property_to_check</property>
              <message>You must set a your_property_to_check property!</message>
              <regex>regex</regex>
              <regexMessage>violation txt</regexMessage>
            </requireProperty>               
          </rules>
          <fail>true</fail>
        </configuration>
      </execution>
    </executions>
  </plugin>

在哪里:

  • your_property_to_check应该替换为真实的以及
  • regex应该定义

选项 2

如果这不可行并且您想检查war文件内的属性,您可能需要编写自己的rule.

这应该没什么大不了的,因为 java 具有 zip 读取以及在其标准 API 中加载的属性文件。要了解如何编写自定义规则,请参阅:http ://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html

顺便提一句。我很想知道为什么有人想在每次部署时检查一些属性?您的输入(您过滤的属性文件)是动态生成/更改的吗?否则,一旦您检查它是否有效,我怀疑您是否需要它。

于 2013-08-13T06:29:07.223 回答