了解通用的Maven插件代码格式

了解通用的Maven插件代码格式

本文介绍了了解通用的Maven插件代码格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览Maven插件源代码(例如清洁插件" ),我遇到了 verify.bsh 文件,其内容为

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;

我想知道,这到底是什么?这似乎是Java代码,但在这里看不到任何classmethodmain.请帮助我理解这一点.

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.

推荐答案

如第一个答案中所述,这是 beanshell 用于通过maven-invoker-plugin运行集成测试的代码. BeanShell的问题在于,似乎不再有活跃的开发了(svn存储库无法访问等).我更喜欢Groovy编写与集成测试相关的集成测试.

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.

通过执行maven调用的maven-invoker-plugin设置maven环境来完成对代码的调用,然后您可以检查目标文件夹的内容,也可以是build.log(mvn在运行过程中输出)是否包含预期的内容.

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.

在插件中,您通常具有以下结构:

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

src/it 包含插件的集成测试.例如,第二个包含一个带有pom.xml文件等的单独的maven项目,该项目将在集成测试期间通过maven运行.在Maven调用结束后,将调用verify.bsh,以检查一切是否都按预期进行.

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.

这篇关于了解通用的Maven插件代码格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:53