1、API升级

Former-commit-id: 64d50a337d2ef4013525999e3dcd49bdcada4484
master
wangbing 5 years ago
parent fe4729845f
commit 28d7d1b50a

@ -2,8 +2,6 @@ package xyz.wbsite.dbtool.javafx.manger.callable;
import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
import xyz.wbsite.dbtool.javafx.po.Api;
import xyz.wbsite.dbtool.javafx.tool.EntityReader;
import xyz.wbsite.dbtool.javafx.tool.RequestReader;
@ -15,6 +13,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -26,9 +25,10 @@ public class ApiCallable implements Callable {
private List<Api> apiList;
private List<String> domainList;
private Tool tool = new Tool();
File domain;
File frame;
File testdomain;
File apiDomain;
File apiModule;
File apiFrame;
File testApiDomain;
private FreeMarkerManager freeMarkerManager;
public ApiCallable(File module, File apiFile, List<String> domainList, List<Api> apiList) {
@ -46,9 +46,6 @@ public class ApiCallable implements Callable {
Tool.clear(apiFile);
}
AbstractDBmapper dBmapper = ProjectManager.dBmapper;
StringBuffer sbmain = new StringBuffer("");
sbmain.append(this.apiFile.getPath() + File.separator);
sbmain.append("src" + File.separator);
@ -66,22 +63,13 @@ public class ApiCallable implements Callable {
sbtest.append(s1 + File.separator);
}
domain = Tool.createPath(sbmain.toString(),"module");
frame = Tool.createPath(sbmain.toString(),"frame");
testdomain = new File(sbtest.toString());
testdomain.mkdirs();
apiDomain = Tool.createPath(sbmain.toString());
apiModule = Tool.createPath(sbmain.toString(), "module");
apiFrame = Tool.createPath(sbmain.toString(), "frame");
testApiDomain = Tool.createPath(sbtest.toString());
for (Api api : apiList) {
if (api.isCheck()) {
File apiModule = new File(domain, api.getModule());
apiModule.mkdirs();
File apiRequest = new File(apiModule, "req");
apiRequest.mkdirs();
File apiResponse = new File(apiModule, "rsp");
apiResponse.mkdirs();
File entity = new File(apiModule, "ent");
entity.mkdirs();
RequestReader requestReader = new RequestReader(api.getRequestFile());
generateRequest(requestReader);
@ -93,99 +81,124 @@ public class ApiCallable implements Callable {
{
System.out.println("生成模块:Pom");
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("module", apiFile.getName());
ctx.put("domain", String.join(".", domainList));
ctx.put("projectName", apiFile.getName());
File file = new File(apiFile, "pom.xml");
freeMarkerManager.outputTemp(file, "Java_api/pom.xml", ctx);
}
{
System.out.println("生成基础类");
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("domain", String.join(".", domainList));
{
File file = new File(frame, "ApiEntity.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiEntity.java", ctx);
File file = new File(apiDomain, "ApiClient.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiClient.java", ctx);
}
{
File file = new File(frame, "AESUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/AESUtil.java", ctx);
System.out.println("生成基础类");
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("domain", String.join(".", domainList));
{
File file = new File(apiFrame, "ApiEntity.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiEntity.java", ctx);
}
{
File file = new File(frame, "ApiClient.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiClient.java", ctx);
File file = new File(apiFrame, "AESUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/AESUtil.java", ctx);
}
{
File file = new File(frame, "ApiRequest.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiRequest.java", ctx);
File file = new File(apiFrame, "ApiRequest.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiRequest.java", ctx);
}
{
File file = new File(frame, "ApiFindRequest.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiFindRequest.java", ctx);
File file = new File(apiFrame, "ApiFindRequest.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiFindRequest.java", ctx);
}
{
File file = new File(frame, "ApiSearchRequest.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiSearchRequest.java", ctx);
File file = new File(apiFrame, "ApiSearchRequest.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiSearchRequest.java", ctx);
}
{
File file = new File(frame, "ApiResponse.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiResponse.java", ctx);
File file = new File(apiFrame, "ApiResponse.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiResponse.java", ctx);
}
{
File file = new File(frame, "ApiFindResponse.java");
freeMarkerManager.outputTemp(file, "/Java_api/ApiFindResponse.java", ctx);
File file = new File(apiFrame, "ApiFindResponse.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiFindResponse.java", ctx);
}
{
File file = new File(frame, "Base64Util.java");
freeMarkerManager.outputTemp(file, "/Java_api/Base64Util.java", ctx);
File file = new File(apiFrame, "Base64Util.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/Base64Util.java", ctx);
}
{
File file = new File(frame, "DownloadUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/DownloadUtil.java", ctx);
File file = new File(apiFrame, "DownloadUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/DownloadUtil.java", ctx);
}
{
File file = new File(frame, "Error.java");
freeMarkerManager.outputTemp(file, "/Java_api/Error.java", ctx);
File file = new File(apiFrame, "Error.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/Error.java", ctx);
}
{
File file = new File(frame, "ErrorType.java");
freeMarkerManager.outputTemp(file, "/Java_api/ErrorType.java", ctx);
File file = new File(apiFrame, "ErrorType.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ErrorType.java", ctx);
}
{
File file = new File(frame, "MapperUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/MapperUtil.java", ctx);
File file = new File(apiFrame, "MapperUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/MapperUtil.java", ctx);
}
{
File file = new File(frame, "MD5Util.java");
freeMarkerManager.outputTemp(file, "/Java_api/MD5Util.java", ctx);
File file = new File(apiFrame, "MD5Util.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/MD5Util.java", ctx);
}
{
File file = new File(frame, "RSAUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/RSAUtil.java", ctx);
File file = new File(apiFrame, "RSAUtil.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/RSAUtil.java", ctx);
}
{
File file = new File(frame, "ProgressRequestBody.java");
freeMarkerManager.outputTemp(file, "/Java_api/ProgressRequestBody.java", ctx);
File file = new File(apiFrame, "ProgressRequestBody.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/ProgressRequestBody.java", ctx);
}
{
File file = new File(frame, "SortType.java");
freeMarkerManager.outputTemp(file, "/Java_api/SortType.java", ctx);
File file = new File(apiFrame, "SortType.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/SortType.java", ctx);
}
{
File file = new File(frame, "StringUtils.java");
freeMarkerManager.outputTemp(file, "/Java_api/StringUtils.java", ctx);
File file = new File(apiFrame, "StringUtils.java");
freeMarkerManager.outputTemp(file, "/Java_api/frame/StringUtils.java", ctx);
}
//4.0.1 去掉验证 减少体积
// {
// File file = new File(frameWork , "ValidationUtil.java");
// freeMarkerManager.outputTemp(file, "/Java_api/ValidationUtil.java", ctx);
// freeMarkerManager.outputTemp(file, "/Java_api/frame/ValidationUtil.java", ctx);
// }
}
{//生成Test
generateTest();
System.out.println("finish");
return true;
}
private void generateTest() {
Set<String> modules = new HashSet<>();
for (Api api : apiList) {
modules.add(api.getModule());
}
for (String m : modules) {
ArrayList<Api> apis = new ArrayList<>();
for (Api api : apiList) {
if (m.equals(api.getModule())){
apis.add(api);
}
}
//生成Test
System.out.println("生成模块:Test");
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("tool", tool);
@ -195,13 +208,12 @@ public class ApiCallable implements Callable {
for (Api api : apiList) {
hashSet.add(api.getModule());
}
ctx.put("modules", hashSet);
ctx.put("apiList", apiList);
freeMarkerManager.outputTemp(new File(testdomain.getAbsolutePath(), "ApiTest.java"), "Java_api/ApiTest.java", ctx);
ctx.put("module", m);
ctx.put("apiList", apis);
ctx.put("className", Tool.abb2Abb(m) + "ApiTest");
File api = Tool.createFile(testApiDomain.getAbsolutePath(), Tool.abb2Abb(m) + "ApiTest.java");
freeMarkerManager.outputTemp(api, "Java_api/ApiTest.java", ctx);
}
System.out.println("finish");
return true;
}
private void generateRequest(RequestReader reader) {
@ -285,7 +297,7 @@ public class ApiCallable implements Callable {
ctx.put("hasList", reader.isHasList());
ctx.put("findOrSearchflag", reader.getFindOrSearchflag());
File req = Tool.createPath(domain.getAbsolutePath(), reader.getModuleName(), "req");
File req = Tool.createPath(apiModule.getAbsolutePath(), reader.getModuleName(), "req");
File file = new File(req, reader.getClassName() + ".java");
freeMarkerManager.outputTemp(file, "Java_api/module/req/request.java", ctx);
@ -326,7 +338,7 @@ public class ApiCallable implements Callable {
ctx.put("hasList", reader.isHasList());
ctx.put("Tclass", reader.getTclass());
File rsp = Tool.createPath(domain.getAbsolutePath(), reader.getModuleName(), "rsp");
File rsp = Tool.createPath(apiModule.getAbsolutePath(), reader.getModuleName(), "rsp");
File file = new File(rsp, reader.getClassName() + ".java");
freeMarkerManager.outputTemp(file, "Java_api/module/rsp/response.java", ctx);
@ -343,7 +355,7 @@ public class ApiCallable implements Callable {
ctx.put("className", reader.getClassName());
ctx.put("body", reader.getBody());
ctx.put("tool", tool);
File ent = Tool.createPath(domain.getAbsolutePath(), reader.getModuleName(), "ent");
File ent = Tool.createPath(apiModule.getAbsolutePath(), reader.getModuleName(), "ent");
File EntFile = new File(ent, reader.getClassName() + ".java");
freeMarkerManager.outputTemp(EntFile, "Java_api/module/ent/entity.java", ctx);
System.out.println("生成文件" + reader.getClassName() + "成功");

@ -1,8 +1,18 @@
package xyz.wbsite.dbtool.javafx.tool;
import java.io.*;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -460,6 +470,19 @@ public class Tool {
return file;
}
public static File createFile(String path, String fileName) {
File path1 = createPath(path);
File f = new File(path1, fileName);
if (!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return f;
}
public static boolean hasChild(File file, String child) {
if (file == null || child == null || "".equals(child) || file.listFiles() == null) {
return false;

@ -1,6 +1,17 @@
package ${domain}.frame;
import okhttp3.*;
package ${domain};
import ${domain}.frame.AESUtil;
import ${domain}.frame.ApiRequest;
import ${domain}.frame.ApiResponse;
import ${domain}.frame.ErrorType;
import ${domain}.frame.MD5Util;
import ${domain}.frame.MapperUtil;
import ${domain}.frame.ProgressRequestBody;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import java.io.IOException;
import java.net.ConnectException;

@ -1,8 +1,13 @@
package ${domain};
<#list modules as module>
import ${domain}.module.${module}.req.*;
import ${domain}.module.${module}.rsp.*;
import ${domain}.frame.ApiRequest;
import ${domain}.frame.ApiResponse;
import ${domain}.frame.MapperUtil;
<#list apiList as item>
import ${domain}.module.${module}.req.${item.request};
</#list>
<#list apiList as item>
import ${domain}.module.${module}.rsp.${item.response};
</#list>
import org.junit.Assert;
import org.junit.Before;
@ -18,7 +23,7 @@ import java.util.Date;
* @version 0.0.1
* @since 2019-06-11
*/
public class ApiTest {
public class ${className} {
private ApiClient apiClient;

@ -1,100 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wb</groupId>
<artifactId>${api}</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<#--<!-- 属性注解验证依赖包 &ndash;&gt;-->
<#--<dependency>-->
<#--<groupId>org.hibernate.validator</groupId>-->
<#--<artifactId>hibernate-validator</artifactId>-->
<#--<version>6.0.10.Final</version>-->
<#--</dependency>-->
<#--<dependency>-->
<#--<groupId>org.glassfish</groupId>-->
<#--<artifactId>javax.el</artifactId>-->
<#--<version>3.0.0</version>-->
<#--</dependency>-->
</dependencies>
<build>
<!-- 项目名称 -->
<finalName>${r"${artifactId}"}-${r"${version}"}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- ${r"${project.build.directory}"}为Maven内置变量缺省为target -->
<outputDirectory>${r"${project.build.directory}"}/lib</outputDirectory>
<!-- 表示是否不包含间接依赖的包 -->
<excludeTransitive>false</excludeTransitive>
<!-- 表示复制的jar文件去掉版本信息 -->
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.example.ApiClient</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wb</groupId>
<artifactId>${module}</artifactId>
<groupId>${domain}</groupId>
<artifactId>${projectName}</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@ -31,17 +31,17 @@
<version>4.12</version>
</dependency>
<#--<!-- 属性注解验证依赖包 &ndash;&gt;-->
<#--<dependency>-->
<#--<groupId>org.hibernate.validator</groupId>-->
<#--<artifactId>hibernate-validator</artifactId>-->
<#--<version>6.0.10.Final</version>-->
<#--</dependency>-->
<#--<dependency>-->
<#--<groupId>org.glassfish</groupId>-->
<#--<artifactId>javax.el</artifactId>-->
<#--<version>3.0.0</version>-->
<#--</dependency>-->
<!--属性注解验证依赖包-->
<!--<dependency>-->
<!--<groupId>org.hibernate.validator</groupId>-->
<!--<artifactId>hibernate-validator</artifactId>-->
<!--<version>6.0.10.Final</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.glassfish</groupId>-->
<!--<artifactId>javax.el</artifactId>-->
<!--<version>3.0.0</version>-->
<!--</dependency>-->
</dependencies>
<build>

Loading…
Cancel
Save

Powered by TurnKey Linux.