mtk
mtk

Reputation: 13709

Understanding the common Maven plugin code format

Browsing the maven-plugin source code (for example 'clean-plugin'), I came across verify.bsh file, which has contents as

import java.io.*;
import java.util.*;
import java.util.jar.*;
import java.util.regex.*;

try
{
    File targetDir = new File( basedir, "target" );
    System.out.println( "Checking for absence of " + targetDir );
    if ( targetDir.exists() )
    {
        System.out.println( "FAILURE!" );
        return false;
    }
}
catch( Throwable t )
{
    t.printStackTrace();
    return false;
}

return true;

I would like to know, what is this exactly? This seems to be Java code, but I don't see any class or method or a main here. Please help me understand this.

Upvotes: 0

Views: 277

Answers (2)

khmarbaise
khmarbaise

Reputation: 97437

As mentioned in the first answer this is beanshell code which is used to run an integration test via maven-invoker-plugin. The problem with BeanShell is that it seemed to be the case there is no more active development anymore (svn repository not accessible etc.). I prefer Groovy for writing integration tests in relationship with integration tests.

The calling of the code done by setting up an maven environment via the maven-invoker-plugin which executes a complete maven call and afterwards you can check the contents of the target folder or may be contents of the build.log (mvn output during running) if it contains the expected things or not.

Within a plugin you usually have the following structure:

./
+- pom.xml
+- src/
   +- it/
      +- settings.xml
      +- first-it/
      |  +- pom.xml
      |  +- src/
      +- second-it/
         +- pom.xml
         +- invoker.properties
         +- test.properties
         +- verify.bsh
         +- src/

src/it contains the integration tests for the plugin. For example second-it contains a separate maven project with a pom.xml file etc. which will be run through maven during the integration tests. The verify.bsh will be called after the Maven call has ended to check if everything is as expected.

Upvotes: 0

Andrew Logvinov
Andrew Logvinov

Reputation: 21831

It seems to be a part of integration test that is launched with maven-invoker-plugin.

The test that you've mentioned creates symlink and checks if after build clean plugin actually removes the directory that has symlink in it.

Upvotes: 1

Related Questions