3
3
import lombok .extern .slf4j .Slf4j ;
4
4
import org .apache .commons .lang3 .StringUtils ;
5
5
import org .apache .maven .artifact .repository .metadata .Versioning ;
6
- import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .beans .factory .annotation .Qualifier ;
7
7
import org .springframework .beans .factory .annotation .Value ;
8
8
import org .springframework .stereotype .Controller ;
9
9
import org .springframework .util .AntPathMatcher ;
10
10
import org .springframework .web .bind .annotation .GetMapping ;
11
11
import org .springframework .web .bind .annotation .PathVariable ;
12
12
import org .springframework .web .servlet .ModelAndView ;
13
- import world .weibiansanjue .doctools .javadochub .repository .Repository ;
13
+ import world .weibiansanjue .doctools .javadochub .repository .IRepository ;
14
14
15
+ import javax .annotation .Resource ;
15
16
import javax .servlet .http .HttpServletRequest ;
16
17
import java .io .IOException ;
17
18
25
26
@ Controller
26
27
public class JavadocController {
27
28
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}/**" ;
30
31
31
32
private static final String INDEX_PAGE = "overview-summary.html" ;
32
33
33
34
@ Value ("${javadochub.version}" )
34
35
private String JAVADOCHUB_VERSION ;
35
36
36
- @ Autowired
37
- private Repository repository ;
37
+ @ Resource
38
+ @ Qualifier ("repository" )
39
+ private IRepository repositoryRelease ;
38
40
39
- @ GetMapping (value = "/doc" )
41
+ @ Resource
42
+ private IRepository repositorySnapshot ;
43
+
44
+ private IRepository repository ;
45
+
46
+
47
+ @ GetMapping (value = "/{rep:doc|snapshot}" )
40
48
public String redirectHelp () {
41
49
return "redirect:/" ;
42
50
}
@@ -54,11 +62,11 @@ public String redirectHelp() {
54
62
*/
55
63
@ GetMapping (value = URL_GA )
56
64
public ModelAndView getJavadocUrl (ModelAndView modelView ,
65
+ @ PathVariable ("rep" ) String rep ,
57
66
@ PathVariable ("groupId" ) String groupId ,
58
67
@ 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 ));
62
70
return modelView ;
63
71
}
64
72
@@ -77,29 +85,47 @@ public ModelAndView getJavadocUrl(ModelAndView modelView,
77
85
*/
78
86
@ GetMapping (value = URL_PAGE )
79
87
public ModelAndView getJavadocUrl (ModelAndView modelView ,
88
+ @ PathVariable ("rep" ) String rep ,
80
89
@ PathVariable ("groupId" ) String groupId ,
81
90
@ PathVariable ("artifactId" ) String artifactId ,
82
91
@ PathVariable ("version" ) String version ,
83
92
HttpServletRequest request ) throws IOException {
84
93
94
+
95
+ repository = getRepository (groupId , rep );
85
96
String page = new AntPathMatcher ().extractPathWithinPattern (URL_PAGE , request .getServletPath ());
86
97
page = StringUtils .isEmpty (page ) ? INDEX_PAGE : page ;
87
- extract (modelView , groupId , artifactId , version , page );
98
+ extract (modelView , groupId , artifactId , version , page , resetRep ( groupId , rep ) );
88
99
89
100
return modelView ;
90
101
}
91
102
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
+
92
117
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 {
94
119
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 );
96
121
97
122
modelView .addObject ("appversion" , "v" + JAVADOCHUB_VERSION )
98
123
.addObject ("groupId" , groupId )
99
124
.addObject ("artifactId" , artifactId )
100
125
.addObject ("artifactIds" , repository .artifact (groupId ))
101
126
.addObject ("page" , page )
102
- .setViewName ("doc" );
127
+ .addObject ("isInternal" , repository .isInternal (groupId ))
128
+ .setViewName (rep );
103
129
104
130
Versioning versioning = repository .version (groupId , artifactId );
105
131
if (null == versioning ) {
0 commit comments