From 2824e4671c63ade1931704feed956f3a7b0e3d63 Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Fri, 3 Jul 2020 01:33:52 +0800 Subject: [PATCH 1/3] add constant handle --- .../java/com/smartdoc/util/MojoUtils.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/smartdoc/util/MojoUtils.java b/src/main/java/com/smartdoc/util/MojoUtils.java index 9fa0c2e..b06f0cc 100644 --- a/src/main/java/com/smartdoc/util/MojoUtils.java +++ b/src/main/java/com/smartdoc/util/MojoUtils.java @@ -27,10 +27,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.power.common.util.FileUtil; -import com.power.doc.model.ApiConfig; -import com.power.doc.model.ApiDataDictionary; -import com.power.doc.model.ApiErrorCodeDictionary; -import com.power.doc.model.SourceCodePath; +import com.power.doc.model.*; import com.smartdoc.constant.GlobalConstants; import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugin.MojoExecutionException; @@ -41,9 +38,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; -import java.util.Objects; /** * @author xingzi 2019/12/07 21:19 @@ -82,6 +77,7 @@ public static ApiConfig buildConfig(File configFile, String projectName, MavenPr ApiConfig apiConfig = GSON.fromJson(data, ApiConfig.class); List apiDataDictionaries = apiConfig.getDataDictionaries(); List apiErrorCodes = apiConfig.getErrorCodeDictionaries(); + List apiConstants = apiConfig.getApiConstants(); if (apiErrorCodes != null) { apiErrorCodes.forEach( apiErrorCode -> { @@ -98,6 +94,14 @@ public static ApiConfig buildConfig(File configFile, String projectName, MavenPr } ); } + if (apiConstants != null) { + apiConstants.forEach( + apiConstant -> { + String className = apiConstant.getConstantsClassName(); + apiConstant.setConstantsClass(getClassByClassName(className, classLoader)); + } + ); + } if (StringUtils.isBlank(apiConfig.getProjectName())) { apiConfig.setProjectName(projectName); } @@ -128,6 +132,7 @@ public static Class getClassByClassName(String className, ClassLoader classLoade /** * addSourcePath + * * @param project * @param apiConfig * @param sourceCodePaths @@ -143,6 +148,7 @@ private static void addSourcePaths(MavenProject project, ApiConfig apiConfig, Ar sourceCodePaths.toArray(codePaths); apiConfig.setSourceCodePaths(codePaths); } + /** * get project sourceCode * @@ -165,6 +171,7 @@ private static void getSourceCodeFilePath(File file, List path) { /** * get RootParentPath + * * @param project * @return */ From 4ac55d3523a79e119a7752c48515e11d95b4dda4 Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Fri, 3 Jul 2020 17:58:56 +0800 Subject: [PATCH 2/3] upgrade version to 1.1.1 --- pom.xml | 4 +- .../com/smartdoc/util/ClassLoaderUtil.java | 130 +++++++++--------- .../java/com/smartdoc/util/MojoUtils.java | 1 - 3 files changed, 66 insertions(+), 69 deletions(-) diff --git a/pom.xml b/pom.xml index e668f00..1486d8c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.shalousun smart-doc-maven-plugin - 1.1.0 + 1.1.1 maven-plugin smart-doc-maven-plugin @@ -71,7 +71,7 @@ com.github.shalousun smart-doc - 1.8.8 + 1.8.9 diff --git a/src/main/java/com/smartdoc/util/ClassLoaderUtil.java b/src/main/java/com/smartdoc/util/ClassLoaderUtil.java index 8865bbd..0a9088c 100644 --- a/src/main/java/com/smartdoc/util/ClassLoaderUtil.java +++ b/src/main/java/com/smartdoc/util/ClassLoaderUtil.java @@ -1,66 +1,64 @@ -/* - * Living Documentation - * - * Copyright (C) 2017 Focus IT - * - * 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.smartdoc.util; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; - -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; - -/** - * @author Julien Boz - */ -public class ClassLoaderUtil { - - /** - * Get classloader - * - * @param project MavenProject - * @return ClassLoader - * @throws MojoExecutionException dd - */ - public static ClassLoader getRuntimeClassLoader(MavenProject project) throws MojoExecutionException { - try { - List runtimeClasspathElements = project.getRuntimeClasspathElements(); - List compileClasspathElements = project.getCompileClasspathElements(); - URL[] runtimeUrls = new URL[runtimeClasspathElements.size() + compileClasspathElements.size()]; - for (int i = 0; i < runtimeClasspathElements.size(); i++) { - String element = runtimeClasspathElements.get(i); - runtimeUrls[i] = new File(element).toURI().toURL(); - } - - int j = runtimeClasspathElements.size(); - - for (int i = 0; i < compileClasspathElements.size(); i++) { - String element = compileClasspathElements.get(i); - runtimeUrls[i + j] = new File(element).toURI().toURL(); - } - return new URLClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); - } catch (Exception e) { - throw new MojoExecutionException("Unable to load project runtime !", e); - } - } -} +/* + * Living Documentation + * + * Copyright (C) 2017 Focus IT + * + * 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.smartdoc.util; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.List; + +/** + * @author Julien Boz + */ +public class ClassLoaderUtil { + + /** + * Get classloader + * + * @param project MavenProject + * @return ClassLoader + * @throws MojoExecutionException dd + */ + public static ClassLoader getRuntimeClassLoader(MavenProject project) throws MojoExecutionException { + try { + List runtimeClasspathElements = project.getRuntimeClasspathElements(); + List compileClasspathElements = project.getCompileClasspathElements(); + URL[] runtimeUrls = new URL[runtimeClasspathElements.size() + compileClasspathElements.size()]; + for (int i = 0; i < runtimeClasspathElements.size(); i++) { + String element = runtimeClasspathElements.get(i); + runtimeUrls[i] = new File(element).toURI().toURL(); + } + int j = runtimeClasspathElements.size(); + for (int i = 0; i < compileClasspathElements.size(); i++) { + String element = compileClasspathElements.get(i); + runtimeUrls[i + j] = new File(element).toURI().toURL(); + } + return new URLClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader()); + } catch (Exception e) { + throw new MojoExecutionException("Unable to load project runtime !", e); + } + } +} diff --git a/src/main/java/com/smartdoc/util/MojoUtils.java b/src/main/java/com/smartdoc/util/MojoUtils.java index b06f0cc..22c6ac0 100644 --- a/src/main/java/com/smartdoc/util/MojoUtils.java +++ b/src/main/java/com/smartdoc/util/MojoUtils.java @@ -143,7 +143,6 @@ private static void addSourcePaths(MavenProject project, ApiConfig apiConfig, Ar List path = new ArrayList<>(); getSourceCodeFilePath(file, path); path.forEach(s -> sourceCodePaths.add(SourceCodePath.path().setPath(s))); - SourceCodePath[] codePaths = new SourceCodePath[sourceCodePaths.size()]; sourceCodePaths.toArray(codePaths); apiConfig.setSourceCodePaths(codePaths); From 9bc1957b91d482d14f4291fde2d31b9d12df40e1 Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Fri, 3 Jul 2020 18:00:57 +0800 Subject: [PATCH 3/3] update readme --- README.md | 3 +++ README_CN.md | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a084d88..8b7e679 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,9 @@ When you need to use smart-doc to generate more API document information, you ca "groupId":"com.demo", "version":"1.0.0" }], + "apiConstants": [{//Configure your own constant class, smart-doc automatically replaces with a specific value when parsing to a constant + "constantsClassName": "com.power.doc.constants.RequestParamConstant" + }], "rpcConsumerConfig": "src/main/resources/consumer-example.conf",//dubbo consumer config example   "requestHeaders": [// Set global request headers, no need to set     { diff --git a/README_CN.md b/README_CN.md index 7308b5d..932880a 100644 --- a/README_CN.md +++ b/README_CN.md @@ -120,7 +120,9 @@ smart-doc-maven-plugin是smart-doc官方团队开发的`maven`插件,该插件 "since": "-" } ], - + "apiConstants": [{//从1.8.9开始配置自己的常量类,smart-doc在解析到常量时自动替换为具体的值 + "constantsClassName": "com.power.doc.constants.RequestParamConstant" + }], "sourceCodePaths": [ //设置代码路径,默认加载src/main/java, 没有需求可以不设置 { "path": "src/main/java",