12
12
import org .springframework .http .ResponseEntity ;
13
13
import org .springframework .stereotype .Component ;
14
14
import org .springframework .util .CollectionUtils ;
15
+ import org .springframework .web .client .HttpClientErrorException ;
16
+ import org .springframework .web .client .RestClientException ;
15
17
import org .springframework .web .client .RestTemplate ;
16
18
17
19
import java .io .File ;
@@ -58,7 +60,7 @@ public Repository() {
58
60
}
59
61
60
62
/**
61
- * artifact name list.
63
+ * local artifact name list.
62
64
*
63
65
* @author weibiansanjue
64
66
* @param groupId group id
@@ -110,22 +112,32 @@ public Versioning version(String groupId, String artifactId) {
110
112
* @param groupId group id
111
113
* @param artifactId artifact id
112
114
* @param version version
115
+ * @return status
113
116
* @throws IOException io exception
114
117
* @since 1.0.0
115
118
*/
116
- public void store (String groupId , String artifactId , String version ) throws IOException {
119
+ public int store (String groupId , String artifactId , String version ) throws IOException {
117
120
File docFile = Paths .get (LOCAL_PATH + File .separator + groupId + File .separator + artifactId + File .separator + version ).toFile ();
118
121
if (docFile .exists ()) {
119
- return ;
122
+ return 202 ;
120
123
}
121
124
122
125
String rep = repositoryUrl (groupId );
123
126
String jarName = artifactId + "-" + version + "-javadoc.jar" ;
124
127
String url = String .format ("%s/%s/%s/%s/%s" , rep , groupId .replace ("." , "/" ), artifactId , version , jarName );
125
128
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
+ }
127
139
if (!resp .getStatusCode ().is2xxSuccessful ()) {
128
- return ;
140
+ return 500 ;
129
141
}
130
142
Path versionPath = Paths .get (JAR_PATH + File .separator + groupId + File .separator + artifactId + File .separator + version );
131
143
Path jarPath = versionPath .resolve (jarName );
@@ -136,6 +148,7 @@ public void store(String groupId, String artifactId, String version) throws IOEx
136
148
Extractor extractor = CompressUtil .createExtractor (StandardCharsets .UTF_8 , jarPath .toFile ());
137
149
extractor .extract (docFile );
138
150
log .info ("discompress javadoc jar. local_path={}" , docFile .getAbsolutePath ());
151
+ return 202 ;
139
152
}
140
153
141
154
private String repositoryUrl (String groupId ) {
0 commit comments