1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
package fr.paris.lutece.plugins.releaser.util.svn; |
37 | |
|
38 | |
import fr.paris.lutece.plugins.releaser.business.ReleaserUser; |
39 | |
import fr.paris.lutece.plugins.releaser.util.ReleaserUtils; |
40 | |
import fr.paris.lutece.portal.service.util.AppLogService; |
41 | |
import fr.paris.lutece.portal.service.util.AppPropertiesService; |
42 | |
import fr.paris.lutece.util.httpaccess.HttpAccess; |
43 | |
import fr.paris.lutece.util.httpaccess.HttpAccessException; |
44 | |
import fr.paris.lutece.util.signrequest.BasicAuthorizationAuthenticator; |
45 | |
import fr.paris.lutece.util.signrequest.RequestAuthenticator; |
46 | |
import java.util.ArrayList; |
47 | |
import java.util.List; |
48 | |
import java.util.Locale; |
49 | |
|
50 | |
import javax.servlet.http.HttpServletRequest; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class SvnSiteService |
56 | |
{ |
57 | |
private static final String PROPERTY_SITE_REPOSITORY_LOGIN = "releaser.site.repository.login"; |
58 | |
private static final String PROPERTY_SITE_REPOSITORY_PASSWORD = "releaser.site.repository.password"; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public static String fetchPom( String strPomUrl,HttpServletRequest request,Locale locale ) |
68 | |
{ |
69 | |
try |
70 | |
{ |
71 | 0 | RequestAuthenticator authenticator = getSiteAuthenticator( request,locale); |
72 | 0 | HttpAccess httpAccess = new HttpAccess( ); |
73 | 0 | return httpAccess.doGet( strPomUrl, authenticator, null ); |
74 | |
} |
75 | 0 | catch( HttpAccessException ex ) |
76 | |
{ |
77 | 0 | AppLogService.error( "Error fecthing pom.xml content : " + ex.getMessage( ), ex ); |
78 | |
} |
79 | 0 | return null; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public static String getLastRelease( String strSiteArtifactId , String strTrunkUrl,HttpServletRequest request,Locale locale ) |
89 | |
{ |
90 | 1 | String strTagsUrl = strTrunkUrl.replace( "trunk", "tags" ); |
91 | |
|
92 | 1 | List<String> list = new ArrayList<>( ); |
93 | |
|
94 | |
try |
95 | |
{ |
96 | 1 | RequestAuthenticator authenticator = getSiteAuthenticator(request,locale ); |
97 | 1 | HttpAccess httpAccess = new HttpAccess( ); |
98 | 1 | String strHtml = httpAccess.doGet( strTagsUrl , authenticator , null ); |
99 | 0 | list = getAnchorsList( strHtml , strSiteArtifactId ); |
100 | |
} |
101 | 1 | catch( HttpAccessException e ) |
102 | |
{ |
103 | 1 | AppLogService.error( "SvnSiteService : Error retrieving release version : " + e.getMessage( ), e ); |
104 | 0 | } |
105 | |
|
106 | 1 | return ( !list.isEmpty() ) ? list.get( list.size() - 1 ) : null; |
107 | |
|
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
private static List<String> getAnchorsList( String strHtml , String strPrefix ) |
118 | |
{ |
119 | 0 | List<String> list = new ArrayList<String>( ); |
120 | 0 | String strCurrent = strHtml; |
121 | |
|
122 | 0 | int nPos = strCurrent.indexOf( "<a " ); |
123 | |
|
124 | 0 | while ( nPos > 0 ) |
125 | |
{ |
126 | 0 | strCurrent = strCurrent.substring( nPos ); |
127 | |
|
128 | 0 | int nEndTag = strCurrent.indexOf( '>' ); |
129 | 0 | int nTagEnd = strCurrent.indexOf( "</a>" ); |
130 | 0 | String strTag = strCurrent.substring( nEndTag + 1, nTagEnd ).replaceAll( "\\/", "" ); |
131 | 0 | if( strTag.startsWith( strPrefix )) |
132 | |
{ |
133 | 0 | list.add( strTag ); |
134 | |
} |
135 | 0 | strCurrent = strCurrent.substring( nTagEnd + 4 ); |
136 | 0 | nPos = strCurrent.indexOf( "<a " ); |
137 | 0 | } |
138 | |
|
139 | 0 | return list; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
private static RequestAuthenticator getSiteAuthenticator( HttpServletRequest request,Locale locale) |
148 | |
{ |
149 | 1 | ReleaserUser user=ReleaserUtils.getReleaserUser( request, locale ); |
150 | 1 | String strLogin=null; |
151 | 1 | String strPassword=null; |
152 | |
|
153 | 1 | if(user!=null) |
154 | |
{ |
155 | 1 | strLogin=user.getSvnSiteAccountLogin( ); |
156 | 1 | strPassword=user.getSvnSiteAccountPassword( ); |
157 | |
} |
158 | 1 | return new BasicAuthorizationAuthenticator( strLogin, strPassword ); |
159 | |
} |
160 | |
|
161 | |
} |