private static void addMavenCoordinates ( File modifiedJsonFile , JsonArray jsonArray , Map < String , LibertyFeature > features ) throws IOException { JsonArrayBuilder jsonArrayBuilder = Json . createArrayBuilder ( ) ; for ( int i = 0 ; i < jsonArray . size ( ) ; i ++ ) { JsonObject jsonObject = jsonArray . getJsonObject ( i ) ; JsonObjectBuilder jsonObjectBuilder = Json . createObjectBuilder ( jsonObject ) ; JsonObject wlpInfo = jsonObject . getJsonObject ( Constants . WLP_INFORMATION_KEY ) ; JsonObjectBuilder wlpInfoBuilder = Json . createObjectBuilder ( wlpInfo ) ; JsonArray provideFeatureArray = wlpInfo . getJsonArray ( Constants . PROVIDE_FEATURE_KEY ) ; String symbolicName = provideFeatureArray . getString ( 0 ) ; wlpInfoBuilder . add ( Constants . MAVEN_COORDINATES_KEY , features . get ( symbolicName ) . getMavenCoordinates ( ) . toString ( ) ) ; jsonObjectBuilder . add ( Constants . WLP_INFORMATION_KEY , wlpInfoBuilder ) ; jsonArrayBuilder . add ( jsonObjectBuilder ) ; } // Write JSON to the modified file FileOutputStream out = null ; try { Map < String , Object > config = new HashMap < String , Object > ( ) ; config . put ( JsonGenerator . PRETTY_PRINTING , true ) ; JsonWriterFactory writerFactory = Json . createWriterFactory ( config ) ; out = new FileOutputStream ( modifiedJsonFile ) ; JsonWriter streamWriter = writerFactory . createWriter ( out ) ; streamWriter . write ( jsonArrayBuilder . build ( ) ) ; } finally { if ( out != null ) { out . close ( ) ; } } }
Add Maven coordinates into the modified JSON file .