September 2009

Passing System Properties and Environment Variables to unit tests in Maven – Update

Unfortunately there was an bug in my previous post.

I had naively assumed that the syntax for environment variables was the same as for system properties but alas not.

The correct code is:


 <build>
        <defaultGoal>package</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.4.2</version>
                <configuration>
                    <environmentVariables>
                        <SOME_ENV_VARIABLE>some value</SOME_ENV_VARIABLE>
                    </environmentVariables>
                    <systemProperties>
                        <property>
                            <name>acceptance.test.host</name>
                            <value>${acceptance.test.host}</value>
                        </property>
                    </systemProperties>
                 </configuration>
            </plugin>
        </plugins>
    </build>
  • Share/Bookmark

build
maven
sysadmin
testing
thoughtblog

Comments (0)

Permalink

Passing System Properties and Environment Variables to unit tests in Maven

This is a bit of dark magic …

<pre>
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<environmentVariables>
<SOME_ENV_VARIABLE>some value</SOME_ENV_VARIABLE>
</environmentVariables>
<systemProperties>
<property>
<name>someSystemProperty</name>
<value>${thisCanBePassedIn}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>

I'm afraid I had to update this post as initially I naively assumed that the syntax for environment variables was the same as for system properties. As you can see from above, you have to actually put a separate xml tag in there for the variable.

By putting the value in ${} you can then pass it in with -DsomeSystemProperty from the command line when you do mvn clean install

e.g. :

mvn -DsomeSystemProperty=foobar clean install
  • Share/Bookmark

build
code
maven
testing
thoughtblog

Comments (0)

Permalink

YourKit: The best thing since sliced bread!

What is it?

A Java / .NET profiling tool.

YourKit, LLC is a technology leader, creator of the most innovative and intelligent tools for profiling Java & .NET applications. The YourKit Java Profiler has been already recognized by the IT professionals and analysts as the best profiling tool.

With YourKit solutions, both CPU and memory profiling have come to the highest professional level, where one can profile even huge applications with maximum productivity and zero overhead.

There are several, recent innovations to profiling that have gained well-deserved popularity among professional Java developers, both in big and small companies.

YourKit is the standard-setter in the evolution of profiling tools.

It is incredibly slick and easy to use. Thanks to Felix for putting me on to it.

Simply download it (Java, .NET), copy it to your Applications folder and add the following to your java startup options (on a mac, that is):

JAVA_PROFILING_OPTIONS="\
-agentpath:/Applications/YourKit_Java_Profiler_8.0.15.app/bin/mac/libyjpagent.jnilib\
 -agentlib:yjpagent "

Then kick back and enjoy!

  • Share/Bookmark

code
performance
testing
thoughtblog

Comments (0)

Permalink

Check if an command was successful in bash

When scripting gigantic build scripts with bash, its important that if anything fails you halt the script.

Heres how:

function checkResult() {
	RESULT=$1
	if [ $RESULT -ne 0 ] ; then
		echo
		echo "!!!!!!!!!!!  Build Failed !!!!!!!!!!!!!!!!!"
		echo
		exit $RESULT
	fi
}

You call it like this:

./someCommandOrScript.sh
checkResult $?
  • Share/Bookmark

bash
code
linux commands
sysadmin

Comments (0)

Permalink