├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
└── java
└── com
└── apigcc
└── maven
└── ApigccMojo.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Log file
4 | *.log
5 |
6 | # BlueJ files
7 | *.ctxt
8 |
9 | # Mobile Tools for Java (J2ME)
10 | .mtj.tmp/
11 |
12 | # Package Files #
13 | *.jar
14 | *.war
15 | *.nar
16 | *.ear
17 | *.zip
18 | *.tar.gz
19 | *.rar
20 |
21 | hs_err_pid*
22 |
23 | .idea
24 | *.iml
25 | target
26 | .gradle
27 | out
28 | build
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Apigcc-maven-plugin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # apiggs-maven-plugin
2 | [  ](https://bintray.com/apiggs/maven/apiggs-maven-plugin/_latestVersion)
3 |
4 | easy use apigcc with maven
5 |
6 | ### install
7 | ```xml
8 |
9 | com.github.apiggs
10 | apiggs-maven-plugin
11 |
12 |
13 |
14 | compile
15 |
16 | apiggs
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | ```
25 |
26 | when you compile source code, apiggs will build rest doc.
27 |
28 | ### options
29 |
30 | 1. id 项目id,生成id.html文件
31 | 1. title 文档标题
32 | 1. description 文档描述
33 | 1. production 输出文件夹,默认为 apiggs
34 | 1. out 输出目录,默认为 target
35 | 1. source 源码目录
36 | 1. dependency 源码依赖的代码目录,以逗号隔开
37 | 1. jar 源码依赖的jar包目录,以逗号隔开
38 | 1. ignore 忽略某些类型
39 | 1. version 文档版本号
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.apigcc
8 | apigcc-maven-plugin
9 | 1.7.0
10 |
11 | apigcc-maven-plugin
12 | easy use apigcc with maven.
13 | https://github.com/apigcc/apigcc-maven-plugin
14 |
15 |
16 | MIT License
17 |
18 |
19 |
20 |
21 | ayz6uem
22 | ayz6uem
23 | 360188606@qq.com
24 |
25 |
26 |
27 | https://github.com/apigcc/apigcc-maven-plugin.git
28 | https://github.com/apigcc/apigcc-maven-plugin.git
29 | https://github.com/apigcc/apigcc-maven-plugin.git
30 |
31 |
32 |
33 | 1.8
34 |
35 |
36 | maven-plugin
37 |
38 |
39 |
40 | org.apache.maven
41 | maven-core
42 | 3.5.4
43 |
44 |
45 | org.apache.maven
46 | maven-plugin-api
47 | 3.5.4
48 |
49 |
50 | org.apache.maven.plugin-tools
51 | maven-plugin-annotations
52 | 3.5.2
53 |
54 |
55 | com.apigcc
56 | apigcc-springmvc
57 | ${version}
58 |
59 |
60 |
61 |
62 |
63 |
64 | org.apache.maven.plugins
65 | maven-compiler-plugin
66 |
67 | ${java.version}
68 | ${java.version}
69 |
70 |
71 |
72 | org.apache.maven.plugins
73 | maven-plugin-plugin
74 | 3.5.2
75 |
76 |
77 | org.apache.maven.plugins
78 | maven-source-plugin
79 |
80 |
81 | attach-sources
82 |
83 | jar
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | org.apache.maven.plugins
93 | maven-jar-plugin
94 | 2.3.2
95 |
96 |
97 | org.apache.maven.plugins
98 | maven-source-plugin
99 | 2.1.2
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | bintray-apigcc-maven
108 | https://api.bintray.com/maven/apigcc/maven/apigcc-maven-plugin/;publish=1
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/src/main/java/com/apigcc/maven/ApigccMojo.java:
--------------------------------------------------------------------------------
1 | package com.apigcc.maven;
2 |
3 | import com.apigcc.core.Apigcc;
4 | import com.apigcc.core.Context;
5 | import org.apache.maven.plugin.AbstractMojo;
6 | import org.apache.maven.plugins.annotations.Mojo;
7 | import org.apache.maven.plugins.annotations.Parameter;
8 | import org.apache.maven.project.MavenProject;
9 |
10 | import java.nio.file.Path;
11 | import java.nio.file.Paths;
12 |
13 | /**
14 | * generate rest doc with apigcc
15 | */
16 | @Mojo(name = "build")
17 | public class ApigccMojo extends AbstractMojo {
18 |
19 | MavenProject project;
20 |
21 | @Parameter
22 | String id;
23 | @Parameter
24 | String name;
25 | @Parameter
26 | String description;
27 | @Parameter
28 | String build;
29 | //传字符串,使用逗号分隔
30 | @Parameter
31 | String source;
32 | @Parameter
33 | String dependency;
34 | @Parameter
35 | String jar;
36 | @Parameter
37 | String version;
38 | @Parameter
39 | String css;
40 |
41 | @Override
42 | public void execute() {
43 | if(getPluginContext().containsKey("project") && getPluginContext().get("project") instanceof MavenProject){
44 | project = (MavenProject) getPluginContext().get("project");
45 | build();
46 | }
47 | }
48 |
49 | private void build(){
50 | Context context = new Context();
51 | if (source != null) {
52 | for (String dir : source.split(",")) {
53 | context.addSource(abs(dir));
54 | }
55 | } else {
56 | context.addSource(project.getBasedir().toPath());
57 | }
58 | if (dependency != null) {
59 | for (String dir : dependency.split(",")) {
60 | context.addDependency(abs(dir));
61 | }
62 | }else{
63 | MavenProject parent = findParent(project);
64 | context.addDependency(parent.getBasedir().toPath());
65 | }
66 | if (jar != null) {
67 | for (String dir : jar.split(",")) {
68 | context.addJar(abs(dir));
69 | }
70 | }
71 | context.setId(id != null?id:project.getName());
72 | if (build != null) {
73 | context.setBuildPath(abs(build));
74 | } else {
75 | context.setBuildPath(Paths.get(project.getBuild().getDirectory()));
76 | }
77 | if (name != null) {
78 | context.setName(name);
79 | } else {
80 | context.setName(project.getName());
81 | }
82 | if (description != null) {
83 | context.setDescription(description);
84 | } else if (project.getDescription()!=null) {
85 | context.setDescription(project.getDescription());
86 | }
87 | if (version != null){
88 | context.setVersion(version);
89 | } else if (project.getVersion()!=null){
90 | context.setVersion(project.getVersion());
91 | }
92 | if (css != null) {
93 | context.setCss(css);
94 | }
95 |
96 | Apigcc apigcc = new Apigcc(context);
97 | apigcc.parse();
98 | apigcc.render();
99 |
100 | }
101 |
102 | private MavenProject findParent(MavenProject mp){
103 | if(mp.getParentFile()!=null && mp.getParentFile().exists()){
104 | return findParent(mp.getParent());
105 | }
106 | return mp;
107 | }
108 |
109 | private Path abs(String dir){
110 | Path path = Paths.get(dir);
111 | if(path.isAbsolute()){
112 | return path;
113 | }else{
114 | return project.getBasedir().toPath().resolve(path);
115 | }
116 | }
117 |
118 | public MavenProject getProject() {
119 | return project;
120 | }
121 |
122 | public void setProject(MavenProject project) {
123 | this.project = project;
124 | }
125 |
126 | public String getId() {
127 | return id;
128 | }
129 |
130 | public void setId(String id) {
131 | this.id = id;
132 | }
133 |
134 | public String getName() {
135 | return name;
136 | }
137 |
138 | public void setName(String name) {
139 | this.name = name;
140 | }
141 |
142 | public String getDescription() {
143 | return description;
144 | }
145 |
146 | public void setDescription(String description) {
147 | this.description = description;
148 | }
149 |
150 | public String getBuild() {
151 | return build;
152 | }
153 |
154 | public void setBuild(String build) {
155 | this.build = build;
156 | }
157 |
158 | public String getSource() {
159 | return source;
160 | }
161 |
162 | public void setSource(String source) {
163 | this.source = source;
164 | }
165 |
166 | public String getDependency() {
167 | return dependency;
168 | }
169 |
170 | public void setDependency(String dependency) {
171 | this.dependency = dependency;
172 | }
173 |
174 | public String getJar() {
175 | return jar;
176 | }
177 |
178 | public void setJar(String jar) {
179 | this.jar = jar;
180 | }
181 |
182 | public String getVersion() {
183 | return version;
184 | }
185 |
186 | public void setVersion(String version) {
187 | this.version = version;
188 | }
189 |
190 | public String getCss() {
191 | return css;
192 | }
193 |
194 | public void setCss(String css) {
195 | this.css = css;
196 | }
197 | }
198 |
--------------------------------------------------------------------------------