Skip to content

Commit 698f38d

Browse files
committed
[skip ci] add debug to WriteGrailsVersionInfoTask
1 parent c3f2f8a commit 698f38d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

grails-forge/buildSrc/src/main/groovy/org/grails/forge/internal/tasks/WriteGrailsVersionInfoTask.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
import org.xml.sax.SAXException;
3737

3838
import javax.xml.parsers.ParserConfigurationException;
39+
import java.io.File;
3940
import java.io.IOException;
4041
import java.io.OutputStream;
4142
import java.nio.charset.StandardCharsets;
4243
import java.nio.file.Files;
4344
import java.util.Map;
45+
import java.util.Set;
4446
import 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

Comments
 (0)