From 2fbadad2c8c2a3024d20d482710282e94bca9322 Mon Sep 17 00:00:00 2001
From: Peter Streef
Date: Fri, 26 Jul 2024 15:06:32 +0200
Subject: [PATCH] fix: CreateXml generate with content
---
.../java/org/openrewrite/properties/CreatePropertiesFile.java | 2 +-
.../src/main/java/org/openrewrite/xml/CreateXmlFile.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/rewrite-properties/src/main/java/org/openrewrite/properties/CreatePropertiesFile.java b/rewrite-properties/src/main/java/org/openrewrite/properties/CreatePropertiesFile.java
index 0c8f899d1fb..1dbc298b93b 100644
--- a/rewrite-properties/src/main/java/org/openrewrite/properties/CreatePropertiesFile.java
+++ b/rewrite-properties/src/main/java/org/openrewrite/properties/CreatePropertiesFile.java
@@ -78,7 +78,7 @@ public TreeVisitor, ExecutionContext> getScanner(AtomicBoolean shouldCreate) {
@Override
public Collection generate(AtomicBoolean shouldCreate, ExecutionContext ctx) {
if (shouldCreate.get()) {
- return PropertiesParser.builder().build().parse(!StringUtils.isBlank(fileContents) ? fileContents : "")
+ return PropertiesParser.builder().build().parse(fileContents == null ? "" : fileContents)
.map(brandNewFile -> (SourceFile) brandNewFile.withSourcePath(Paths.get(relativeFileName)))
.collect(Collectors.toList());
}
diff --git a/rewrite-xml/src/main/java/org/openrewrite/xml/CreateXmlFile.java b/rewrite-xml/src/main/java/org/openrewrite/xml/CreateXmlFile.java
index 0870e8f01dc..04a35bfa548 100644
--- a/rewrite-xml/src/main/java/org/openrewrite/xml/CreateXmlFile.java
+++ b/rewrite-xml/src/main/java/org/openrewrite/xml/CreateXmlFile.java
@@ -81,7 +81,7 @@ public TreeVisitor, ExecutionContext> getScanner(AtomicBoolean shouldCreate) {
@Override
public Collection generate(AtomicBoolean shouldCreate, ExecutionContext ctx) {
if (shouldCreate.get()) {
- return XmlParser.builder().build().parse("")
+ return XmlParser.builder().build().parse(fileContents == null ? "" : fileContents)
.map(brandNewFile -> (SourceFile) brandNewFile.withSourcePath(Paths.get(relativeFileName)))
.collect(Collectors.toList());
}
@@ -94,7 +94,7 @@ public TreeVisitor, ExecutionContext> getVisitor(AtomicBoolean created) {
return new XmlVisitor() {
@Override
public Xml visitDocument(Xml.Document document, ExecutionContext ctx) {
- if ((created.get() || Boolean.TRUE.equals(overwriteExisting)) && path.equals(document.getSourcePath())) {
+ if (Boolean.TRUE.equals(overwriteExisting) && path.equals(document.getSourcePath())) {
if (StringUtils.isBlank(fileContents)) {
return document.withProlog(null).withRoot(null);
}