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 package fr.paris.lutece.plugins.appstore.service;
35
36 import fr.paris.lutece.plugins.appstore.business.Component;
37 import fr.paris.lutece.portal.service.datastore.DatastoreService;
38 import fr.paris.lutece.portal.service.util.AppLogService;
39 import fr.paris.lutece.portal.service.util.AppPropertiesService;
40 import fr.paris.lutece.util.httpaccess.HttpAccess;
41 import fr.paris.lutece.util.httpaccess.HttpAccessException;
42
43 import org.jsoup.Jsoup;
44
45 import org.jsoup.nodes.Document;
46 import org.jsoup.nodes.Element;
47
48 import org.jsoup.select.Elements;
49
50
51
52
53 public class ComponentInfoService
54 {
55 private static final String PROPERTY_MAVEN_REPO_URL = "appstore.maven.repository.url";
56 private static final String URL_MAVEN_REPO = AppPropertiesService.getProperty( PROPERTY_MAVEN_REPO_URL );
57 private static final String PROPERTY_MAVEN_PATH_PLUGINS = "appstore.maven.repository.path.plugins";
58 private static final String URL_PLUGINS = URL_MAVEN_REPO + AppPropertiesService.getProperty( PROPERTY_MAVEN_PATH_PLUGINS );
59 private static final String PROPERTY_MAVEN_PATH_SITE_POM = "appstore.maven.repository.path.site-pom";
60 private static final String URL_SITE_POM = URL_MAVEN_REPO + AppPropertiesService.getProperty( PROPERTY_MAVEN_PATH_SITE_POM );
61 private static final String KEY_SITE_POM_VERSION = "appstore.pom.site.version";
62 private static final String RELEASE_NOT_FOUND = "Release not found";
63
64
65
66
67
68
69
70 public static void setReleaseVersion( Component component )
71 {
72 component.setVersion( getVersion( URL_PLUGINS + component.getArtifactId( ) ) );
73 }
74
75
76
77
78 public static void setPomSiteVersion( )
79 {
80 String strVersion = getVersion( URL_SITE_POM );
81 DatastoreService.setDataValue( KEY_SITE_POM_VERSION, strVersion );
82 }
83
84
85
86
87
88
89
90
91 private static String getVersion( String strUrl )
92 {
93 String strVersion = RELEASE_NOT_FOUND;
94
95 try
96 {
97 HttpAccess httpAccess = new HttpAccess( );
98 String strHtml = httpAccess.doGet( strUrl );
99 Document jarList = Jsoup.parse( strHtml );
100 Elements trList = jarList.select( "td a" );
101
102 for ( int i = 0; i < trList.size( ); i++ )
103 {
104 Element tr = trList.get( i );
105 String strAnchor = tr.text( );
106 if ( strAnchor.matches( "^[\\d].*" ) )
107 {
108 strVersion = strAnchor.replaceAll( "\\/", "" );
109 }
110 }
111 }
112 catch( HttpAccessException e )
113 {
114 AppLogService.error( "AppStore - ComponentInfoService : Error retrieving release version : " + e.getMessage( ), e );
115 }
116
117 return strVersion;
118 }
119 }