maven – Grey Panthers Savannah https://grey-panther.net Just another WordPress site Thu, 13 Oct 2011 15:16:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.9 206299117 Using Jython from Maven https://grey-panther.net/2011/10/using-jython-from-maven.html https://grey-panther.net/2011/10/using-jython-from-maven.html#respond Thu, 13 Oct 2011 15:16:00 +0000 https://grey-panther.net/?p=40 This blogpost was originally posted to the Transylvania JUG blog.

On the surface it looks simple: just add the dependency and you can run the example code.

However what the jython artifact doesn’t get you are the standard python libraries like re. This means that as soon as you try to do something like the code below, it will error out:

PythonInterpreter interp = new PythonInterpreter();
try {
  interp.exec("import re");
} 
catch (PyException ex) {
  ex.printStackTrace();
}

The solution? Use the jython-standalone artifact which includes the standard libraries. An other advantage is that it has the latest release (2.5.2) while jython lags two minor revisions behind (2.5.0) in Maven Central. A possible downside is the larger size of the jar.

<dependency>
    <groupId>org.python</groupId>
    <artifactId>jython-standalone</artifactId>
    <version>2.5.2</version>
</dependency>
]]>
https://grey-panther.net/2011/10/using-jython-from-maven.html/feed 0 40
Integrating Maven with Ivy https://grey-panther.net/2011/10/integrating-maven-with-ivy.html https://grey-panther.net/2011/10/integrating-maven-with-ivy.html#respond Tue, 11 Oct 2011 08:18:00 +0000 https://grey-panther.net/?p=42 This post was originally published on the Transylvania JUG blog.

The problem: you have some resources in an Ivy repository (and only there) which you would like to use in a project based on Maven. Possible solutions:

  • Migrate the repository to Maven (Nexus for example) since Ivy can easily use Maven-style repositories (so your Ivy clients can continue to use Ivy with some slight configuration changes and Maven clients will also work – also the push-to-repo process needs to be changed)
  • Try JFrog Artifactory since it reportedly can serve the same resources to both Ivy and Maven (disclaimer: I haven’t tried to use it actually and I don’t know if the Open Source version includes this feature or not)
  • or read on…

My goal for the solution (as complex as it may be) was:

  • It should be as simple and self-explanatory as possible
  • It should respect the DRY principle (Don’t Repeat Yourself)
  • It shouldn’t have other dependencies than Maven itself

The solution looks like the following (for the full source check out the code-repo):

Have two Maven profiles: ivy-dependencies activates when the dependencies have already been downloaded and ivy-resolve when there are yet to download. This is based on checking the directory where the dependencies are to be copied ultimately:

...
<id>ivy-dependencies</id>
<activation>
  <activeByDefault>false</activeByDefault>
  <file>
    <exists>${basedir}/ivy-lib</exists>
  </file>
</activation>
...
<id>ivy-resolve</id>
<activation>
  <activeByDefault>false</activeByDefault>
  <file>
    <missing>${basedir}/ivy-lib</missing>
  </file>
</activation>
...

Unfortunately there is a small repetition here, since Maven doesn’t seem to expand user-defined properties like ${ivy.target.lib.dir} in the profile activation section. The profiles also serve an other role: to avoid the consideration of the dependencies until they are actually resolved.

When the build is first run, it creates the target directory, writes the files needed for an Ivy build there (ivy.xml, ivysettings.xml and build.xml – for this example I’ve used some parts from corresponding files of the Red5 repo), runs the build and tries to clean up after itself. It also creates adependencies.txt file containing the chunck of text which needs to be added to the dependencies list. Finally, it bails out (fails) instructing the user to run the command again.

On the second (third, fourth, etc) run the dependencies will already be present, so the resolution process won’t be run repeteadly. This approach was chosen instead of running the resolution at every build because – even though the resolution process is quick quick – it can take tens seconds in some more complicated cases and I didn’t want to slow the build down.

And, Ivy, the Apache BSF framework, etc are fetched from the Maven central repository, so they need not be preinstalled for build to complete successfully.

A couple of words about choosing ${ivy.target.lib.dir}: if you choose it inside your Maven tree (like it was chose in the example), you will receive warnings from Maven that this might not be supported in the future. Also, be sure to add the directory to the ignore mechanism of your VCS (.gitignore, .hgignore, .cvsignore, svn:ignore, etc), as to avoid accidentally committing the libraries to VCS.

If you need to add a new (Ivy) dependency to the project, the steps are as follows:

  • Delete the current ${ivy.target.lib.dir} directory
  • Update the part of your pom.xml which writes out the ivy.xml file to include the new dependency
  • Run a build and watch the new dependency being resolved
  • Update the dependencies section of the ivy-dependencies profile to include the new dependency (possibly copying from dependencies.txt)

One drawback of this method is the fact that advanced functionalities of systems based on Maven will not work with these dependencies (for example dependency analisys / graphing plugins, automated downloading of sources / javadocs, etc). A possible workaround (and a good idea in general) is to use this method for the minimal subset – just the jars which can’t be found in Maven central. All the rests (even if they are actually dependencies of the code fetched from Ivy) should be declared as a normal dependency, to be fetched from the Maven repository.

Finally I would like to say that this endeavour once again showed me how flexible both Maven and Ivy/Ant can be and clarified many cornercases (like how we escape ]] inside of CDATA – we split it in two). And it can also be further tweaked (for example: adding a clean target to the ivy-resolve profile, so you can remove the directory with mvn clean -P ivy-resolve or re-jar-ing all the downloaded jars into a single one for example like this, thus avoiding the need to modify the pom file every time the list of Ivy dependencies gets changed – then again signed JARs can’t be re-jarred so it is not an universal solution either).

]]>
https://grey-panther.net/2011/10/integrating-maven-with-ivy.html/feed 0 42
Recording test performance with Jenkins https://grey-panther.net/2011/09/recording-test-performance-with-jenkins.html https://grey-panther.net/2011/09/recording-test-performance-with-jenkins.html#respond Tue, 20 Sep 2011 16:16:00 +0000 https://grey-panther.net/?p=48 In many (most?) systems performance is an important non-functional requirement. And even if you attained the required performance, it is useful to keep an eye on it to detect if a codechange involuntarily deteriorates it. Enter the Performance plugin for Jenkins. Using it you can record the performance (as in: speed of execution) of your test runs and set alter thresholds which cause the build to fail. Also it can generate graphs like the one below:

To do this:

  • Have Jenkins installed
  • Intstall the Performance plugin (or upgrade to the latest version, since there was a bug in earlier versions which prevented the parsing of the JUnit reports)
  • For your build check “Publish Performance test result report” and add locations where the reports should be collected from.
  • That’s it! Future builds will collect the performance data and you can access it using the “Performance Trend” link (at the job level) or the “Performance Report” link (at the build level)

More details / caveats:

  • The paths are defined as ANT file expressions (that is you can use “**” to specify an arbitrary level of directories, for example: target/surefire-reports/**/TEST*.xml)
  • JUnit performance is grouped at the test-class level, thus it probably makes sense create separate project / module which group the performance test cases.
  • Benchmarking is hard and JUnit doesn’t give you any provisions to do warmup or to repeat the tests multiple times. To make your test as relevant as possible you should do this manually (warmup code can be placed in the @Before method for example). A properly set up JMeter task accounts for this already.
  • TestNG tests can also be parsed as long as the test run is set to produce a JUnit compatible report.
  • Slightly off-topic: to integrate a JMeter run into your maven build, you can use the AntRun plugin:
    <build>
     <plugins>
      <plugin>
       <artifactId>maven-antrun-plugin</artifactId>
       <version>1.6</version>
       <executions>
        <execution>
         <phase>test</phase>
         <configuration>
          <target>
           <taskdef name="jmeter" classpath="C:workantlibant-jmeter-1.1.0.jar"
            classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
           <jmeter jmeterhome="C:jakarta-jmeter-2.5"
            testplan="${basedir}/src/test/resources/example.jmx"
            resultlog="${basedir}/target/JMeterResults.jtl"/>
          </target>
         </configuration>
         <goals>
          <goal>run</goal>
         </goals>
        </execution>
       </executions>
      </plugin>
     </plugins>
    </build>

Article originally posted to the Transylvania JUG blog.

]]>
https://grey-panther.net/2011/09/recording-test-performance-with-jenkins.html/feed 0 48
Adding tab completition to Maven3 under Ubuntu https://grey-panther.net/2011/06/adding-tab-completition-to-maven3-under-ubuntu.html https://grey-panther.net/2011/06/adding-tab-completition-to-maven3-under-ubuntu.html#respond Wed, 01 Jun 2011 17:10:00 +0000 https://grey-panther.net/?p=62

Maven 3 was released recently (depending on your definition of recent), but is not yet packaged for Ubuntu. This is generally not a problem, since the installation instructions are easy to follow (alternatively here are the installation instructions from the Sonatype maven book), but you don’t get tab completion in your terminal, which is quite a bummer, since I don’t know how to write correctly without a spellchecker.

Fortunately the steps to add it are simple:

  • Download an older Maven2 package
  • Extract from it the /etc/bash_completion.d/maven2 file (take care not to install the package by mistake)
  • Put the extracted file into /etc/bash_completion.d/maven3
  • Restart your terminal

These steps should also work with other Linux distributions if they have bash-completion installed.

This is a cross-post from the Transylvania-JUG blog.

]]>
https://grey-panther.net/2011/06/adding-tab-completition-to-maven3-under-ubuntu.html/feed 0 62