Skip to content

Commit 7ee64d5

Browse files
committed
好像出了大问题。。一个是编译时寻找一个是运行时寻找
1 parent 6ed1a5b commit 7ee64d5

File tree

6 files changed

+158
-56
lines changed

6 files changed

+158
-56
lines changed

apidoc-maven-plugin/pom.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>apidoc</artifactId>
7+
<groupId>com.ztianzeng.apidoc</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<packaging>maven-plugin</packaging>
13+
<artifactId>apidoc-maven-plugin</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.apache.maven.plugin-tools</groupId>
18+
<artifactId>maven-plugin-annotations</artifactId>
19+
<version>3.4</version>
20+
<scope>provided</scope>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.apache.maven</groupId>
24+
<artifactId>maven-plugin-api</artifactId>
25+
<version>3.3.9</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.ztianzeng.apidoc</groupId>
29+
<artifactId>apidoc-core</artifactId>
30+
<version>1.0-SNAPSHOT</version>
31+
<scope>compile</scope>
32+
</dependency>
33+
</dependencies>
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-plugin-plugin</artifactId>
39+
<version>3.6.0</version>
40+
<configuration>
41+
<goalPrefix>apidoc</goalPrefix>
42+
</configuration>
43+
<executions>
44+
<execution>
45+
<id>default-descriptor</id>
46+
<goals>
47+
<goal>descriptor</goal>
48+
</goals>
49+
<phase>process-classes</phase>
50+
</execution>
51+
<execution>
52+
<id>help-descriptor</id>
53+
<goals>
54+
<goal>helpmojo</goal>
55+
</goals>
56+
<phase>process-classes</phase>
57+
</execution>
58+
</executions>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright © 2017 - 2020 Cnabc. All Rights Reserved.
3+
*/
4+
5+
package com.ztianzeng.apidoc.maven;
6+
7+
import com.ztianzeng.apidoc.Reader;
8+
import com.ztianzeng.apidoc.SourceBuilder;
9+
import com.ztianzeng.apidoc.models.OpenAPI;
10+
import com.ztianzeng.apidoc.models.info.Info;
11+
import com.ztianzeng.apidoc.utils.Json;
12+
import org.apache.maven.plugin.AbstractMojo;
13+
import org.apache.maven.plugin.MojoExecutionException;
14+
import org.apache.maven.plugin.MojoFailureException;
15+
import org.apache.maven.plugins.annotations.LifecyclePhase;
16+
import org.apache.maven.plugins.annotations.Mojo;
17+
import org.apache.maven.plugins.annotations.Parameter;
18+
19+
import java.util.Set;
20+
21+
/**
22+
* @goal apidoc
23+
*/
24+
@Mojo(name = "openapi")
25+
public class DocMojo extends AbstractMojo {
26+
27+
/**
28+
* @parameter expression="${src}" default-value="src"
29+
*/
30+
@Parameter(property = "src")
31+
private String src;
32+
33+
@Parameter(property = "title", defaultValue = "doc")
34+
private String title;
35+
36+
@Parameter(property = "version", defaultValue = "1.0")
37+
private String version;
38+
39+
40+
@Override
41+
public void execute() throws MojoExecutionException, MojoFailureException {
42+
getLog().info("扫描地址 " + src);
43+
execute(src);
44+
}
45+
46+
public void execute(String url) {
47+
SourceBuilder sourceBuilder = new SourceBuilder(url);
48+
49+
Reader reader = new Reader(new OpenAPI(), sourceBuilder);
50+
51+
Set<Class<?>> controllerData = null;
52+
try {
53+
controllerData = sourceBuilder.getControllerData();
54+
} catch (ClassNotFoundException e) {
55+
e.printStackTrace();
56+
}
57+
58+
OpenAPI openAPI = reader.read(controllerData);
59+
Info info = new Info();
60+
info.title(title);
61+
info.setVersion(version);
62+
63+
openAPI.setInfo(info);
64+
65+
Json.prettyPrint(openAPI);
66+
}
67+
68+
69+
}

apidoc-swagger/pom.xml

Lines changed: 0 additions & 53 deletions
This file was deleted.

pom.xml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,45 @@
88
<artifactId>apidoc</artifactId>
99
<packaging>pom</packaging>
1010
<version>1.0-SNAPSHOT</version>
11+
<properties>
12+
<java.version>1.8</java.version>
13+
<file.encoding>UTF-8</file.encoding>
14+
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
15+
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
16+
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
17+
<eclipse.jetty>9.4.12.v20180830</eclipse.jetty>
18+
</properties>
1119
<build>
20+
<finalName>apidoc</finalName>
1221
<plugins>
1322
<plugin>
1423
<groupId>org.apache.maven.plugins</groupId>
1524
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>${maven-compiler-plugin.version}</version>
1626
<configuration>
17-
<source>8</source>
18-
<target>8</target>
27+
<source>${java.version}</source>
28+
<target>${java.version}</target>
29+
<encoding>${file.encoding}</encoding>
1930
</configuration>
2031
</plugin>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-source-plugin</artifactId>
35+
<version>${maven-source-plugin.version}</version>
36+
<executions>
37+
<execution>
38+
<id>attach-sources</id>
39+
<goals>
40+
<goal>jar</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
</plugin>
2145
</plugins>
2246
</build>
2347
<modules>
2448
<module>apidoc-core</module>
25-
<module>apidoc-swagger</module>
49+
<module>apidoc-maven-plugin</module>
2650
</modules>
2751

2852

0 commit comments

Comments
 (0)