0

When using cargo to deploy to a remote server I would like to check with cargo or maven that the generated war have it's properties files filtered like expected.

Some phase in between should test a property file from war against some strings and so deploy or stop deployment.

there's built in on cargo to achieve this?

Ruben Trancoso
  • 1,444
  • 5
  • 27
  • 55

1 Answers1

1

Not sure what are the properties files you're referring to therefore I assume that you refer to typical java *.properties files.

Anyway, I believe you should use: maven-enforcer-plugin and it's goal: enforce as that is the common way in maven to enforce some condition (the plugin uses term: rule) to be fulfilled.

I think you have more options here.

Option 1

Maybe you could check that prio to packaging to your war using:

maven-property-plugin - goal: read-project-properties (http://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>

where you should:

And afterwards go for maven-enforcer-plugin goal: enforce and the rule: requireProperty (http://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>

where:

  • your_property_to_check should be replaced with the real one as well as
  • regex should be defined

Option 2

If that is not feasible and you want to check property inside war file, you might need to write your own rule.

That should not be a big deal as java has zip reading as well as properties files loading in it's standard API. To learn how to write custom rule, see: http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html

Btw. I'd be quite curious to understand why would someone want to do check some property on each deployment? Is the case that your input (property files you filter) are dynamically generated/changed? Otherwise I doubt you need it once you check it works.

Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81
  • Thanks Peter. I should not rely on this I theoretically agree. My real problem lays on the 'build' cycle. I'm quite new to maven and the process of clean, pack and deploy is giving me some headaches. I expected to have a one click solution to this, including remote deploy check. But I would to split catalina.out per application, thing I didn't already. My first production deploy, despite the fact was gen by a profile, came to happen with a proprerty filtered by -Pdev packed within war. (...) – Ruben Trancoso Aug 13 '13 at 09:10
  • Besides that, I don't understand yet, I was forced to clean before 'pack and deploy' but error came in on compilaton for which the solution was a maven update project.Since there's also time involved, I thought it can be a provisory solution till I master the whole thing. Need to test. – Ruben Trancoso Aug 13 '13 at 09:11
  • Another thing I think worth mention is that I could use such solution to run just the deploy from inside the production server relying on the war already packed and copied to some folder that I could watch and not directly via /manager/txt – Ruben Trancoso Aug 13 '13 at 09:21
  • @RubenTrancoso I'm afraid I'm lost in your comments. The best way to tackle them would be maybe to raise one question per problem where you would describe what is your goal to achieve as well as what you tried. But as far as I could follow you, in general: you can achieve quite nice separation via different profiles (dev/production one); clean for maven is good to achieve starting from scratch and deployment with cargo plugin is a good practice. – Peter Butkovic Aug 13 '13 at 18:42