Skip to content

Commit

Permalink
merge to dev
Browse files Browse the repository at this point in the history
  • Loading branch information
shalousun committed Jul 3, 2020
2 parents baeaa87 + 9bc1957 commit b66e288
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 76 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
    {
Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc-maven-plugin</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>maven-plugin</packaging>

<name>smart-doc-maven-plugin</name>
Expand Down Expand Up @@ -71,7 +71,7 @@
<dependency>
<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc</artifactId>
<version>1.8.8</version>
<version>1.8.9</version>
</dependency>
</dependencies>
<build>
Expand Down
130 changes: 64 additions & 66 deletions src/main/java/com/smartdoc/util/ClassLoaderUtil.java
Original file line number Diff line number Diff line change
@@ -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<String> runtimeClasspathElements = project.getRuntimeClasspathElements();
List<String> 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<String> runtimeClasspathElements = project.getRuntimeClasspathElements();
List<String> 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);
}
}
}
20 changes: 13 additions & 7 deletions src/main/java/com/smartdoc/util/MojoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -82,6 +77,7 @@ public static ApiConfig buildConfig(File configFile, String projectName, MavenPr
ApiConfig apiConfig = GSON.fromJson(data, ApiConfig.class);
List<ApiDataDictionary> apiDataDictionaries = apiConfig.getDataDictionaries();
List<ApiErrorCodeDictionary> apiErrorCodes = apiConfig.getErrorCodeDictionaries();
List<ApiConstant> apiConstants = apiConfig.getApiConstants();
if (apiErrorCodes != null) {
apiErrorCodes.forEach(
apiErrorCode -> {
Expand All @@ -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);
}
Expand Down Expand Up @@ -128,6 +132,7 @@ public static Class getClassByClassName(String className, ClassLoader classLoade

/**
* addSourcePath
*
* @param project
* @param apiConfig
* @param sourceCodePaths
Expand All @@ -138,11 +143,11 @@ private static void addSourcePaths(MavenProject project, ApiConfig apiConfig, Ar
List<String> 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);
}

/**
* get project sourceCode
*
Expand All @@ -165,6 +170,7 @@ private static void getSourceCodeFilePath(File file, List<String> path) {

/**
* get RootParentPath
*
* @param project
* @return
*/
Expand Down

0 comments on commit b66e288

Please sign in to comment.