Skip to content

Commit 2ee3e4c

Browse files
committed
feat: 支持私有仓库快照版本 Javadoc 浏览
1 parent 9055971 commit 2ee3e4c

File tree

10 files changed

+570
-17
lines changed

10 files changed

+570
-17
lines changed

antora-playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ content:
1313
sources:
1414
# 本项目文档
1515
- url: https://github.com/DocsAggregationTools/javadochub.git
16-
branches: develop
16+
branches: main
1717
start_path: docs
1818

1919

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
= Changelog
22

3-
== xx
3+
== v0.3.0-20240810
4+
5+
* 支持私有仓库快照版本 Javadoc 浏览

src/main/java/world/weibiansanjue/doctools/javadochub/controller/JavadocController.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
import lombok.extern.slf4j.Slf4j;
44
import org.apache.commons.lang3.StringUtils;
55
import org.apache.maven.artifact.repository.metadata.Versioning;
6-
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Qualifier;
77
import org.springframework.beans.factory.annotation.Value;
88
import org.springframework.stereotype.Controller;
99
import org.springframework.util.AntPathMatcher;
1010
import org.springframework.web.bind.annotation.GetMapping;
1111
import org.springframework.web.bind.annotation.PathVariable;
1212
import org.springframework.web.servlet.ModelAndView;
13-
import world.weibiansanjue.doctools.javadochub.repository.Repository;
13+
import world.weibiansanjue.doctools.javadochub.repository.IRepository;
1414

15+
import javax.annotation.Resource;
1516
import javax.servlet.http.HttpServletRequest;
1617
import java.io.IOException;
1718

@@ -25,18 +26,25 @@
2526
@Controller
2627
public class JavadocController {
2728

28-
private static final String URL_GA = "/doc/{groupId}/{artifactId}";
29-
private static final String URL_PAGE = "/doc/{groupId}/{artifactId}/{version}/**";
29+
private static final String URL_GA = "/{rep:doc|snapshot}/{groupId}/{artifactId}";
30+
private static final String URL_PAGE = "/{rep:doc|snapshot}/{groupId}/{artifactId}/{version}/**";
3031

3132
private static final String INDEX_PAGE = "overview-summary.html";
3233

3334
@Value("${javadochub.version}")
3435
private String JAVADOCHUB_VERSION;
3536

36-
@Autowired
37-
private Repository repository;
37+
@Resource
38+
@Qualifier("repository")
39+
private IRepository repositoryRelease;
3840

39-
@GetMapping(value = "/doc")
41+
@Resource
42+
private IRepository repositorySnapshot;
43+
44+
private IRepository repository;
45+
46+
47+
@GetMapping(value = "/{rep:doc|snapshot}")
4048
public String redirectHelp() {
4149
return "redirect:/";
4250
}
@@ -54,11 +62,11 @@ public String redirectHelp() {
5462
*/
5563
@GetMapping(value = URL_GA)
5664
public ModelAndView getJavadocUrl(ModelAndView modelView,
65+
@PathVariable("rep") String rep,
5766
@PathVariable("groupId") String groupId,
5867
@PathVariable("artifactId") String artifactId) throws IOException {
59-
60-
extract(modelView, groupId, artifactId, null, INDEX_PAGE);
61-
68+
repository = getRepository(groupId, rep);
69+
extract(modelView, groupId, artifactId, null, INDEX_PAGE, resetRep(groupId, rep));
6270
return modelView;
6371
}
6472

@@ -77,29 +85,47 @@ public ModelAndView getJavadocUrl(ModelAndView modelView,
7785
*/
7886
@GetMapping(value = URL_PAGE)
7987
public ModelAndView getJavadocUrl(ModelAndView modelView,
88+
@PathVariable("rep") String rep,
8089
@PathVariable("groupId") String groupId,
8190
@PathVariable("artifactId") String artifactId,
8291
@PathVariable("version") String version,
8392
HttpServletRequest request) throws IOException {
8493

94+
95+
repository = getRepository(groupId, rep);
8596
String page = new AntPathMatcher().extractPathWithinPattern(URL_PAGE, request.getServletPath());
8697
page = StringUtils.isEmpty(page) ? INDEX_PAGE : page;
87-
extract(modelView, groupId, artifactId, version, page);
98+
extract(modelView, groupId, artifactId, version, page, resetRep(groupId, rep));
8899

89100
return modelView;
90101
}
91102

103+
private IRepository getRepository(String groupId, String rep) {
104+
if ("snapshot".equals(rep) && repositorySnapshot.isInternal(groupId)) {
105+
return repositorySnapshot;
106+
}
107+
return repositoryRelease;
108+
}
109+
110+
private String resetRep(String groupId, String rep) {
111+
if ("snapshot".equals(rep) && repositorySnapshot.isInternal(groupId)){
112+
return rep;
113+
}
114+
return "doc";
115+
}
116+
92117
private void extract(ModelAndView modelView,
93-
String groupId, String artifactId, String version, String page) throws IOException {
118+
String groupId, String artifactId, String version, String page, String rep) throws IOException {
94119

95-
log.info("extract javadoc. g={} a={} v={} p={}", groupId, artifactId, version, page);
120+
log.info("extract javadoc. g={} a={} v={} p={} rep={}", groupId, artifactId, version, page, rep);
96121

97122
modelView.addObject("appversion", "v" + JAVADOCHUB_VERSION)
98123
.addObject("groupId", groupId)
99124
.addObject("artifactId", artifactId)
100125
.addObject("artifactIds", repository.artifact(groupId))
101126
.addObject("page", page)
102-
.setViewName("doc");
127+
.addObject("isInternal", repository.isInternal(groupId))
128+
.setViewName(rep);
103129

104130
Versioning versioning = repository.version(groupId, artifactId);
105131
if (null == versioning) {
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package world.weibiansanjue.doctools.javadochub.repository;
2+
3+
import org.apache.maven.artifact.repository.metadata.Versioning;
4+
5+
import java.io.IOException;
6+
import java.util.List;
7+
8+
/**
9+
* 仓库操作.
10+
*
11+
* @author weibiansanjue
12+
* @since 0.3.0
13+
*/
14+
public interface IRepository {
15+
16+
17+
/**
18+
* 获取本地 artifact 名词集合.
19+
*
20+
* @author weibiansanjue
21+
* @param groupId group id
22+
* @return artifact name list
23+
* @since 0.1.0
24+
*/
25+
List<String> artifact(String groupId);
26+
27+
/**
28+
* 获取 maven 仓库中 javadoc 版本.
29+
*
30+
* @author weibiansanjue
31+
* @param groupId group id
32+
* @param artifactId artifact id
33+
* @return remote metadata
34+
* @since 0.1.0
35+
*/
36+
Versioning version(String groupId, String artifactId);
37+
38+
/**
39+
* 获取 maven 仓库中 javadoc 快照版本.
40+
*
41+
* @author weibiansanjue
42+
* @param groupId group id
43+
* @param artifactId artifact id
44+
* @param version version
45+
* @return remote metadata
46+
* @since 0.3.0
47+
*/
48+
Versioning version(String groupId, String artifactId, String version);
49+
50+
/**
51+
* metadata url.
52+
*
53+
* @author weibiansanjue
54+
* @param groupId group id
55+
* @param artifactId artifact id
56+
* @return remote metadata url
57+
* @since 0.2.0
58+
*/
59+
String metadataUrl(String groupId, String artifactId);
60+
61+
/**
62+
* 删除 javadoc page
63+
*
64+
* @author weibiansanjue
65+
* @param groupId group id
66+
* @param artifactId artifact id
67+
* @param version version
68+
* @return 删除成功
69+
* @throws IOException io e
70+
* @since 0.2.0
71+
*/
72+
boolean delete(String groupId, String artifactId, String version) throws IOException;
73+
74+
/**
75+
* 下载、解压 javadoc.jar.
76+
*
77+
* @author weibiansanjue
78+
* @param groupId group id
79+
* @param artifactId artifact id
80+
* @param version version
81+
* @return status
82+
* @throws IOException io exception
83+
* @since 0.1.0
84+
*/
85+
int store(String groupId, String artifactId, String version) throws IOException;
86+
87+
/**
88+
* javadoc jar download url.
89+
*
90+
* @author weibiansanjue
91+
* @param groupId group id
92+
* @param artifactId artifact id
93+
* @param version version
94+
* @return url
95+
* @since 0.2.0
96+
*/
97+
String javadocDownloadUrl(String groupId, String artifactId, String version);
98+
99+
/**
100+
* is internal package
101+
*
102+
* @author weibiansanjue
103+
* @param groupId group Id
104+
* @return is internal package
105+
* @since 0.3.0
106+
*/
107+
Boolean isInternal(String groupId);
108+
109+
}

src/main/java/world/weibiansanjue/doctools/javadochub/repository/Repository.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
@Slf4j
3838
@Component("repository")
39-
public class Repository implements CommandLineRunner {
39+
public class Repository implements IRepository, CommandLineRunner {
4040

4141
@Value("${javadochub.storage}/storage")
4242
private String LOCAL_PATH;
@@ -110,6 +110,11 @@ public Versioning version(String groupId, String artifactId) {
110110
return versioning;
111111
}
112112

113+
@Override
114+
public Versioning version(String groupId, String artifactId, String version) {
115+
return null;
116+
}
117+
113118
/**
114119
* metadata url.
115120
*
@@ -214,6 +219,16 @@ public String javadocDownloadUrl(String groupId, String artifactId, String versi
214219
javadocJarName(artifactId, version));
215220
}
216221

222+
@Override
223+
public Boolean isInternal(String groupId) {
224+
for (String prefix : INTERNAL_GROUP_PREFIX) {
225+
if (groupId.startsWith(prefix)) {
226+
return true;
227+
}
228+
}
229+
return false;
230+
}
231+
217232
private String javadocJarName(String artifactId, String version) {
218233
return artifactId + "-" + version + "-javadoc.jar";
219234
}

0 commit comments

Comments
 (0)