private void writeServiceFiles ( Map < String , List < String > > serviceImplementations ) throws MojoExecutionException { // TODO give the user an option to write them to the source folder or // any other folder? File parentFolder = new File ( getClassFolder ( ) , "META-INF" + File . separator + "services" ) ; if ( ! parentFolder . exists ( ) ) { parentFolder . mkdirs ( ) ; } for ( Entry < String , List < String > > interfaceClassName : serviceImplementations . entrySet ( ) ) { File serviceFile = new File ( parentFolder , interfaceClassName . getKey ( ) ) ; getLog ( ) . info ( "Generating service file " + serviceFile . getAbsolutePath ( ) ) ; FileWriter writer = null ; try { writer = new FileWriter ( serviceFile ) ; for ( String implementationClassName : interfaceClassName . getValue ( ) ) { getLog ( ) . info ( " + " + implementationClassName ) ; writer . write ( implementationClassName ) ; writer . write ( ' ' ) ; } buildContext . refresh ( serviceFile ) ; } catch ( IOException e ) { throw new MojoExecutionException ( "Error creating file " + serviceFile , e ) ; } finally { if ( writer != null ) { try { writer . close ( ) ; } catch ( IOException e ) { getLog ( ) . error ( e ) ; } } } } }
Writes the output for the service files to disk