3636import org .xml .sax .SAXException ;
3737
3838import javax .xml .parsers .ParserConfigurationException ;
39+ import java .io .File ;
3940import java .io .IOException ;
4041import java .io .OutputStream ;
4142import java .nio .charset .StandardCharsets ;
4243import java .nio .file .Files ;
4344import java .util .Map ;
45+ import java .util .Set ;
4446import java .util .TreeMap ;
4547
4648@ CacheableTask
@@ -58,8 +60,13 @@ public WriteGrailsVersionInfoTask() {
5860 @ TaskAction
5961 public void writeVersionInfo () throws IOException {
6062 Map <String , String > props = generateProperties ();
61- try (OutputStream out = Files .newOutputStream (getOutputDirectory ().file ("grails-versions.properties" ).get ().getAsFile ().toPath ())) {
63+ File outputFile = getOutputDirectory ().file ("grails-versions.properties" ).get ().getAsFile ();
64+ if (outputFile .exists ()) {
65+ outputFile .delete ();
66+ }
67+ try (OutputStream out = Files .newOutputStream (outputFile .toPath ())) {
6268 for (Map .Entry <String , String > entry : props .entrySet ()) {
69+ getLogger ().info ("Writing version property: {} => {}" , entry .getKey (), entry .getValue ());
6370 String line = entry .getKey () + "=" + entry .getValue () + "\n " ;
6471 out .write (line .getBytes (StandardCharsets .ISO_8859_1 ));
6572 }
@@ -73,21 +80,26 @@ private Map<String, String> generateProperties() {
7380 .execute ();
7481 Map <String , String > props = new TreeMap <>();
7582 props .put ("grails.version" , getVersion ().get ());
76- for (ComponentArtifactsResult component : result .getResolvedComponents ()) {
83+ Set <ComponentArtifactsResult > resolvedComponents = result .getResolvedComponents ();
84+ getLogger ().info ("Resolved {} components" , resolvedComponents .size ());
85+ for (ComponentArtifactsResult component : resolvedComponents ) {
7786 component .getArtifacts (MavenPomArtifact .class ).forEach (artifact -> {
7887 if (artifact instanceof ResolvedArtifactResult ) {
7988 ResolvedArtifactResult resolved = (ResolvedArtifactResult ) artifact ;
8089 GPathResult pom = null ;
8190 try {
8291 pom = new XmlSlurper ().parse (resolved .getFile ());
8392 } catch (IOException | SAXException | ParserConfigurationException e ) {
84- // ignore
93+ getLogger (). warn ( "Failed to parse POM file: {} due to {}" , resolved . getFile (), e . getMessage ());
8594 }
8695 ((GPathResult ) pom .getProperty ("properties" )).children ().forEach (child -> {
8796 NodeChild node = (NodeChild ) child ;
8897 props .put (node .name (), node .text ());
8998 });
9099 }
100+ else {
101+ getLogger ().warn ("Expected ResolvedArtifactResult but got: {}" , artifact .getClass ().getName ());
102+ }
91103 });
92104 }
93105 return props ;
0 commit comments