1 package fr.paris.lutece.plugins.releaser.util.version;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import fr.paris.lutece.portal.service.util.AppLogService;
7
8 public class VersionUtils
9 {
10
11 public static List<String> sortVersionsList( List<String> listVersions, boolean bAscending )
12 {
13 List<String> listSorted = new ArrayList<>( );
14
15 if ( listVersions != null && !listVersions.isEmpty() )
16 {
17 List<Version> listParsedVersions = new ArrayList<>( );
18
19 for ( String strVersion : listVersions )
20 {
21 try
22 {
23 listParsedVersions.add( Version.parse( strVersion ) );
24 }
25 catch ( VersionParsingException e )
26 {
27 AppLogService.error( "Error parsing version, excluded from sorted list : " + strVersion );
28 }
29 }
30
31 listParsedVersions.sort( ( v1, v2 ) -> bAscending ? v1.compareTo( v2 ) : v2.compareTo( v1 ) );
32
33 for ( Version version : listParsedVersions )
34 {
35 listSorted.add( version.toString( ) );
36 }
37 }
38
39 return listSorted;
40 }
41
42 public static String getLastVersion( List<String> listVersions )
43 {
44 String strLastVersion = null;
45
46 if (listVersions != null && !listVersions.isEmpty() )
47 {
48 List<String> listReleaseVersions = VersionUtils.sortVersionsList(listVersions, true );
49 strLastVersion = listReleaseVersions.get(listReleaseVersions.size( ) - 1 );
50 }
51
52 return strLastVersion.toString();
53 }
54 }