From e6910b648253737b407b77f83c1f486dc9376f9f Mon Sep 17 00:00:00 2001 From: Rancho-7 <1027229497@qq.com> Date: Wed, 6 Dec 2023 23:19:04 +0800 Subject: [PATCH] Support for JMeter test script maven-plugin support for JMeter test script --- CHANGELOG.md | 4 ++ .../ly/doc/plugin/constant/MojoConstants.java | 2 + .../com/ly/doc/plugin/mojo/JMeterMojo.java | 52 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/main/java/com/ly/doc/plugin/mojo/JMeterMojo.java diff --git a/CHANGELOG.md b/CHANGELOG.md index a811985..798fedb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,3 +17,7 @@ - 更新日期:2020-10-12 - 更新内容: 1. 此版本优化了插件源码加载逻辑,提升用户体验 + +- 更新日期:2023-12-6 +- 更新内容: + 1. 支持JMeter测试脚本生成 diff --git a/src/main/java/com/ly/doc/plugin/constant/MojoConstants.java b/src/main/java/com/ly/doc/plugin/constant/MojoConstants.java index 017a0cf..888845c 100644 --- a/src/main/java/com/ly/doc/plugin/constant/MojoConstants.java +++ b/src/main/java/com/ly/doc/plugin/constant/MojoConstants.java @@ -33,6 +33,8 @@ public interface MojoConstants { String MARKDOWN_MOJO = "markdown"; + String JMETER_MOJO = "jmeter"; + String OPENAPI_MOJO = "openapi"; String SWAGGER_MOJO = "swagger"; diff --git a/src/main/java/com/ly/doc/plugin/mojo/JMeterMojo.java b/src/main/java/com/ly/doc/plugin/mojo/JMeterMojo.java new file mode 100644 index 0000000..3722011 --- /dev/null +++ b/src/main/java/com/ly/doc/plugin/mojo/JMeterMojo.java @@ -0,0 +1,52 @@ +/* + * smart-doc + * + * Copyright (C) 2018-2023 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.ly.doc.plugin.mojo; + +import com.ly.doc.builder.JMeterBuilder; +import com.ly.doc.model.ApiConfig; +import com.ly.doc.plugin.constant.MojoConstants; +import com.thoughtworks.qdox.JavaProjectBuilder; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * @author Lansg + */ +@Execute(phase = LifecyclePhase.COMPILE) +@Mojo(name = MojoConstants.JMETER_MOJO, requiresDependencyResolution = ResolutionScope.COMPILE) +public class JMeterMojo extends BaseDocsGeneratorMojo { + + @Override + public void executeMojo(ApiConfig apiConfig, JavaProjectBuilder javaProjectBuilder) { + try { + JMeterBuilder.buildApiDoc(apiConfig, javaProjectBuilder); + } catch (Throwable e) { + getLog().error(e); + if (apiConfig.isStrict()) { + throw new RuntimeException(e.getMessage()); + } + } + } +}