Ngrinder支持Maven结构的测试脚本。使用ScriptHandlerFactory来个脚本选择处理器handler,目前有JythonScriptHandler, GroovyScriptHandler和GroovyMavenProjectHandler三种。 ScriptHandlerFactory初始化的时候会按各个handler的order和displayOrder排序(升序)。

	public void init() {
// Sort by the order of scriptHandlers..
Collections.sort(scriptHandlers, new Comparator<ScriptHandler>() {
@Override
public int compare(ScriptHandler o1, ScriptHandler o2) {
return o1.order().compareTo(o2.order());
}
}); // Sort by the order of scriptHandlers.. visibleHandlers = newArrayList();
for (ScriptHandler each : this.scriptHandlers) {
if (!(each instanceof NullScriptHandler)) {
visibleHandlers.add(each);
}
}
Collections.sort(visibleHandlers, new Comparator<ScriptHandler>() {
@Override
public int compare(ScriptHandler o1, ScriptHandler o2) {
return o1.displayOrder().compareTo(o2.displayOrder());
}
}); }
然后选择handler的时候按order升序,找到第一个canHandler为true的处理器返回。 public ScriptHandler getHandler(FileEntry fileEntry) {
for (ScriptHandler handler : scriptHandlers) {
if (handler.canHandle(fileEntry)) {
return handler;
}
}
// Actually nothing is reach here.
throw processException("no matching handler for " + fileEntry.getPath());
}

MavenScriptProjectHandler 判断canhandle就是看根目录下有没有.pom文件

return getFileEntryRepository().hasOne(fileEntry.getCreatedUser(), getBasePath(path) + "/pom.xml");

Maven项目运行时,maven里面依赖的包会自动拷贝到./lib文件夹下

	@Override
protected void prepareDistMore(Long testId, User user, FileEntry script, File distDir,
PropertiesWrapper properties, ProcessingResultPrintStream processingResult) {
String pomPathInSVN = PathUtils.join(getBasePath(script), "pom.xml");
MavenCli cli = new MavenCli();
processingResult.println("\nCopy dependencies by running 'mvn dependency:copy-dependencies"
+ " -DoutputDirectory=./lib -DexcludeScope=provided'"); int result = cli.doMain(new String[]{ // goal specification
"dependency:copy-dependencies", // run dependency goal
"-DoutputDirectory=./lib", // to the lib folder
"-DexcludeScope=provided" // but exclude the provided
// library
}, distDir.getAbsolutePath(), processingResult, processingResult);
boolean success = (result == 0);
if (success) {
processingResult.printf("\nDependencies in %s was copied.\n", pomPathInSVN);
LOGGER.info("Dependencies in {} is copied into {}/lib folder", pomPathInSVN, distDir.getAbsolutePath());
} else {
processingResult.printf("\nDependencies copy in %s is failed.\n", pomPathInSVN);
LOGGER.info("Dependencies copy in {} is failed.", pomPathInSVN);
}
// Then it's not necessary to include pom.xml anymore.
FileUtils.deleteQuietly(new File(distDir, "pom.xml"));
processingResult.setSuccess(result == 0);
}

这里有两个注意的地方。

  1. Ngrinder使用MavenCli来运行maven命令,所以跟本机的maven环境不一样,如果有特殊的maven setting要配置的话要手动给maven指定setting.xml的位置。
public static final File DEFAULT_GLOBAL_SETTINGS_FILE =
new File( System.getProperty( "maven.home", System.getProperty( "user.dir", "" ) ), "conf/settings.xml" );

ngrinder通过获取环境变量maven.home来查找setting.xml, 可以启动的时候加参数-Dmaven.home=xxxxx来指定maven 的配置。

  1. Ngrinder会把pom文件里面的provided scope的依赖包自动过滤掉,所以对于一些会导致包冲突的artifact可以用scope来exclude掉。

Ngrinder 源码之Maven 项目的更多相关文章

  1. Springboot源码分析之项目结构

    Springboot源码分析之项目结构 摘要: 无论是从IDEA还是其他的SDS开发工具亦或是https://start.spring.io/ 进行解压,我们都会得到同样的一个pom.xml文件 4. ...

  2. gperftools源码分析和项目应用 - CPU Profiler

    gperftools源码分析和项目应用 - CPU Profiler 原文:https://blog.csdn.net/yubo112002/article/details/81076821 原文链接 ...

  3. IdentityServer4源码解析_1_项目结构

    目录 IdentityServer4源码解析_1_项目结构 IdentityServer4源码解析_2_元数据接口 IdentityServer4源码解析_3_认证接口 IdentityServer4 ...

  4. JAVA上百实例源码以及开源项目

    简介 笔者当初为了学习JAVA,收集了很多经典源码,源码难易程度分为初级.中级.高级等,详情看源码列表,需要的可以直接下载! 这些源码反映了那时那景笔者对未来的盲目,对代码的热情.执着,对IT的憧憬. ...

  5. 谷歌开源项目Chromium的源码获取与项目构建(Win7+vs10/vs13)

    转自:http://blog.csdn.net/kuerjinjin/article/details/23563059 从12年那会儿开始获取源码和构建chromium项目都是按照那时候的官方要求用w ...

  6. 个人从源码理解angular项目在JIT模式下的启动过程

    通常一个angular项目会有一个个模块(Module)来管理各自的业务,并且必须有一个根模块(AppModule)作为应用的入口模块,整个应用都围绕AppModule展开.可以这么说,AppModu ...

  7. elementUi源码解析(1)--项目结构篇

    因为在忙其他事情好久没有更新iview的源码,也是因为后面的一些组件有点复杂在考虑用什么方式把复杂的功能逻辑简单的展示出来,还没想到方法,突然想到element的组件基本也差不多,内部功能的逻辑也差不 ...

  8. Robotium实践之路源码创建测试项目

    1.JDK安装及环境配置 2.Eclipse安装 3.ADT插件安装 4.模拟器安装 5.准备源码 6.引进源码置项目中 .文件 .导入 .选择现有项目置工作空间中 .浏览 .选择项目,选择模拟器版本 ...

  9. 拼图游戏源码-swift版项目源码

    作者fanyinan,源码PuzzleProject,公司的项目中需要一个拼图游戏,之前有手动拼图和随机打乱的功能,近期又由于个(xian)人(zhe)爱(dan)好(teng)自己加入了自动拼图功能 ...

随机推荐

  1. Linux之用户相关操作

    1. 创建用户 useradd -m wolf #即创建一个用户并且创建同名的家目录 2. 设置密码 passwd wolf

  2. centos 查看ip

    1.现象: 通过ip addr 查找Ip时,发现ens33中没有inet属性,如下图: 2.解决方法 打开网卡配置文件 /etc/sysconfig/network-scripts/ifcfg-ens ...

  3. 关于SQL查询某年数据 和DATEPART 函数的使用

    数据库查询某年数据(sql server)select *from 表名 where YEAR(存时间的字段名) =某年select *from News where YEAR(addDate) =2 ...

  4. get获取后台数据

    let url = $.getCookie('prefixUrl')+'/currencyRatesManage/getCurrency'; let vm=this; $.ajax({ url: ur ...

  5. Java面向对象(一)

    面向对象(Object Oriented) 面向过程:事物比较简单.将问题分解为若干个步骤.按照步骤依次执行.面向对象:事物比较复杂.在解决面向对象的过程中,最后的执行部分还是面向过程方式,面向过程和 ...

  6. goquery 解析不了noscript

    今天在用goquery的时候 解析noscript标签的时候.发现一直获取不到里面的元素. google得到.需要去除noscript标签. s.Find("noscript"). ...

  7. Python Memcached、Redis & RabbitMQ使用

    一.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的 ...

  8. Matrix Factorization in RecSys

    矩阵分解在推荐系统中的应用. 参考链接:知乎. 传统SVD,Funk-SVD,Bias-SVD,SVD++. SVD奇异值分解及其意义. 漫谈奇异值分解.

  9. unbutu apt-get update失败及解决办法

    今天在用apt-get update更新时一直失败,报的错误为”Failed to fetch 404 Not Found”,因为我的镜像改为了mirrors.aliyun.com 我试着ping了一 ...

  10. Python标准库: turtle--海龟绘图。

    turtle --- 海龟绘图 (点击查看官方文档.) 简介 import turtle # 调用该库.Turtle的实例对象,默认命名为turtle. turtle.forward(10) from ...