public static void ensureOrGenerateSecret ( MavenProject project , Log log ) throws IOException { File conf = new File ( project . getBasedir ( ) , "src/main/configuration/application.conf" ) ; if ( conf . isFile ( ) ) { List < String > lines = FileUtils . readLines ( conf ) ; boolean changed = false ; for ( int i = 0 ; i < lines . size ( ) ; i ++ ) { String line = lines . get ( i ) ; Matcher matcher = OLD_SECRET_LINE_PATTERN . matcher ( line ) ; if ( matcher . matches ( ) ) { if ( matcher . group ( 1 ) . length ( ) == 0 ) { lines . set ( i , "application.secret=\"" + generate ( ) + "\"" ) ; changed = true ; } } else { matcher = SECRET_LINE_PATTERN . matcher ( line ) ; if ( matcher . matches ( ) ) { if ( matcher . group ( 2 ) . trim ( ) . length ( ) == 0 ) { lines . set ( i , " secret = \"" + generate ( ) + "\"" ) ; changed = true ; } } } } if ( changed ) { FileUtils . writeLines ( conf , lines ) ; log . info ( "Application Secret generated - the configuration file was updated." ) ; } } }
Checks whether the application configuration file as the application secret . If not generates one .