Skip to content

Commit ad36203

Browse files
committed
feat: javadoc 不存在
1 parent e7c8784 commit ad36203

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ private void extract(ModelAndView modelView,
9494
.addObject("page", page)
9595
.setViewName("doc");
9696

97-
repository.store(groupId, artifactId, version);
98-
97+
int status = repository.store(groupId, artifactId, version);
98+
modelView.addObject("status", status);
9999
}
100100

101101
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.springframework.http.ResponseEntity;
1313
import org.springframework.stereotype.Component;
1414
import org.springframework.util.CollectionUtils;
15+
import org.springframework.web.client.HttpClientErrorException;
16+
import org.springframework.web.client.RestClientException;
1517
import org.springframework.web.client.RestTemplate;
1618

1719
import java.io.File;
@@ -58,7 +60,7 @@ public Repository() {
5860
}
5961

6062
/**
61-
* artifact name list.
63+
* local artifact name list.
6264
*
6365
* @author weibiansanjue
6466
* @param groupId group id
@@ -110,22 +112,32 @@ public Versioning version(String groupId, String artifactId) {
110112
* @param groupId group id
111113
* @param artifactId artifact id
112114
* @param version version
115+
* @return status
113116
* @throws IOException io exception
114117
* @since 1.0.0
115118
*/
116-
public void store(String groupId, String artifactId, String version) throws IOException {
119+
public int store(String groupId, String artifactId, String version) throws IOException {
117120
File docFile = Paths.get(LOCAL_PATH + File.separator + groupId + File.separator + artifactId + File.separator + version).toFile();
118121
if (docFile.exists()) {
119-
return;
122+
return 202;
120123
}
121124

122125
String rep = repositoryUrl(groupId);
123126
String jarName = artifactId + "-" + version + "-javadoc.jar";
124127
String url = String.format("%s/%s/%s/%s/%s", rep, groupId.replace(".", "/"), artifactId, version, jarName);
125128
log.info("download javadoc. url={}", url);
126-
ResponseEntity<byte[]> resp = restTemplate.getForEntity(url, byte[].class);
129+
ResponseEntity<byte[]> resp = null;
130+
try {
131+
resp = restTemplate.getForEntity(url, byte[].class);
132+
} catch (HttpClientErrorException hcee) {
133+
log.error("javadoc 下载失败. hcee={}", hcee.getMessage());
134+
return hcee.getRawStatusCode();
135+
} catch (Exception e) {
136+
log.error("javadoc 下载失败. e={}", e.getMessage());
137+
return 500;
138+
}
127139
if (!resp.getStatusCode().is2xxSuccessful()) {
128-
return;
140+
return 500;
129141
}
130142
Path versionPath = Paths.get(JAR_PATH + File.separator + groupId + File.separator + artifactId + File.separator + version);
131143
Path jarPath = versionPath.resolve(jarName);
@@ -136,6 +148,7 @@ public void store(String groupId, String artifactId, String version) throws IOEx
136148
Extractor extractor = CompressUtil.createExtractor(StandardCharsets.UTF_8, jarPath.toFile());
137149
extractor.extract(docFile);
138150
log.info("discompress javadoc jar. local_path={}", docFile.getAbsolutePath());
151+
return 202;
139152
}
140153

141154
private String repositoryUrl(String groupId) {

src/main/resources/templates/doc.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@
7070
</nav>
7171

7272
<div class="fill">
73-
<iframe name="main" id="docpage" onload="iframeload(this)"
73+
<iframe th:if="${status == 202}" name="main" id="docpage" onload="iframeload(this)"
7474
th:src="|/${groupId}/${artifactId}/${version}/${page}|" >
7575
</iframe>
76+
<h1 th:if="${status == 404}" align="center">😅 javadoc 不存在</h1>
7677
</div>
7778

7879
</div>

0 commit comments

Comments
 (0)