Understanding the common Maven plugin code format

冷暖自知 提交于 2019-12-12 03:30:17

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13650098/understanding-the-common-maven-plugin-code-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!