0

I am writing a JAR file that acts as a client to the Jenkins CI webapp. Therefore, my project has jar packaging, not war packaging. However, for integration testing, I need to deploy the Jenkins WAR to test my JAR classes against.

I am using the cargo-maven2-plugin, and have it set up so that I can launch Jenkins from the command line with "mvn cargo:run" However, running "mvn install" gets into the integration-test phase without attempting to launch Jenkins with Cargo. In fact, the output of "mvn install -X" doesn't even mention the word "cargo".

It looks like I have bound cargo to pre-integration-test and post-integration-test correctly, but it just won't fire off.

POM below:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.phoenix.build</groupId>
<artifactId>HostOp</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jetty.port>53657</jetty.port><!-- mnemonic: 'JENKS' on a telephone -->
</properties>
<name>Host Operations</name>
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7.2</version>
                <configuration>
                    <systemProperties>
                        <property>
                            <name>maven.output.dir</name>
                            <value>${project.build.directory}</value>
                        </property>
                    </systemProperties>
                    <excludes>
                        <exclude>**/*IntegrationTest.java</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                            <excludes>
                                <exclude>none</exclude>
                            </excludes>
                            <includes>
                                <include>**/*IntegrationTest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-container</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-container</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <container>
                        <containerId>jetty6x</containerId>
                        <type>embedded</type>
                        <systemProperties>
                            <JENKINS_HOME>target/test-classes/jenkins_home</JENKINS_HOME>
                        </systemProperties>
                    </container>
                    <configuration>
                        <properties>
                            <cargo.servlet.port>53657</cargo.servlet.port>
                            <cargo.jvmargs>-DJENKINS_HOME=target/test-classes/jenkins_home</cargo.jvmargs>
                        </properties>
                        <deployables>
                            <deployable>
                                <type>war</type>
                                <location>target/test-classes/jenkins.war</location>
                                <pingURL>http://localhost:53657/jenkins/view/All/newJob</pingURL>
                            </deployable>
                        </deployables>
                    </configuration>
                </configuration>
            </plugin>
        </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
    </dependency>
</dependencies>
</project>

How can I get this to fire as needed?

1 Answers1

1

Your posted pom works as expected for me. I just dropped it into an empty project, and:

$ mvn install
[...]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ cargo-plugin-test ---
[...]
[INFO] --- maven-surefire-plugin:2.7.2:test (integration-tests) @ cargo-plugin-test ---
[...]
[INFO] --- cargo-maven2-plugin:1.2.1:start (start-container) @ cargo-plugin-test ---
[INFO] [2.ContainerStartMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-jetty:jar:1.2.1 for container jetty6x
[INFO] [beddedLocalContainer] Jetty 6.x Embedded starting...
[...]
2012-04-27 15:01:02.457:WARN::Web application not found target/test-classes/jenkins.war
2012-04-27 15:01:02.457:WARN::Failed startup of context 
[...]
2012-04-27 15:01:02.741:INFO::Started SelectChannelConnector@0.0.0.0:53657
[INFO] [beddedLocalContainer] Jetty 6.x Embedded started on port [53657]
[...]

That's with Maven 3.0.3:

$ mvn --version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: /home/ryan/dev/tools/maven
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: /home/ryan/dev/tools/jdk1.7.0_03/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.0.0-17-generic", arch: "amd64", family: "unix"

I'm not sure what else it might be.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
  • I'm using the same Maven version. If I get rid of my integration tests (rm /src/test/java/com/phoenix/build/jenkins/*IntegrationTest.java), then Cargo launches and shuts down. So it apparently works only when I don't actually need it to. – Robert Mandeville Apr 27 '12 at 20:26
  • It gets better. I found out that if I wrote a test that didn't really do anything, and diked out the rest of them, I could get Cargo to launch. So I took one of my other tests and commented out everything, then uncommented things one by one. There's one place where the test runs a semi-infinite loop (a while(true) with a break inside). So long as that stays semi-infinite, Cargo won't launch. If I make it a finite for loop with a counter, it will launch Cargo. How is the pre-integration-testing phase depending on the code itself? – Robert Mandeville May 01 '12 at 20:14
  • Starvation? If Maven is forking the Cargo startup into another thread or process, maybe it hits your loop before Cargo can start, which ties up the CPU and prevents anything else from happening. Can you try a Thread.sleep(50) somewhere in your loop to let make it less resource-hungry? (This is just a shot in the dark, really.) – Ryan Stewart May 01 '12 at 20:22
  • Finally got it. Rookie mistake. If you look at the pom above, you will see that I bound cargo:start to the integration-test phase, not the pre-integration-test phase. Sorry for the waste of bandwidth. – Robert Mandeville May 01 '12 at 20:34