From 96f0fe2a8ac2908a632ed40e87c7c5af31f1b95e Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Thu, 6 Apr 2023 10:15:37 +0200 Subject: [PATCH 1/2] fix: Support back-to-back properties and file.separator in SpoonPom This fixes property extraction for poms with `${first}${second}`. --- src/main/java/spoon/support/compiler/SpoonPom.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/spoon/support/compiler/SpoonPom.java b/src/main/java/spoon/support/compiler/SpoonPom.java index 4d8d7c4a9a6..23eb72d5975 100644 --- a/src/main/java/spoon/support/compiler/SpoonPom.java +++ b/src/main/java/spoon/support/compiler/SpoonPom.java @@ -310,7 +310,7 @@ public List getClasspathTmpFiles(String fileName) { } // Pattern corresponding to maven properties ${propertyName} - private static Pattern mavenProperty = Pattern.compile("\\$\\{.*\\}"); + private static Pattern mavenProperty = Pattern.compile("\\$\\{.*?\\}"); /** * Extract the variable from a string @@ -353,6 +353,8 @@ private String getProperty(String key) { } } else if ("project.basedir".equals(key) || "pom.basedir".equals(key) || "basedir".equals(key)) { return pomFile.getParent(); + } else if ("file.separator".equals(key)) { + return File.separator; } String value = extractVariable(model.getProperties().getProperty(key)); if (value == null) { From 614dafae77d00f5a245b3e837799f647636224dc Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Thu, 6 Apr 2023 10:29:50 +0200 Subject: [PATCH 2/2] Clean up qodana warnings... --- src/main/java/spoon/support/compiler/SpoonPom.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/spoon/support/compiler/SpoonPom.java b/src/main/java/spoon/support/compiler/SpoonPom.java index 23eb72d5975..9cb7885bb73 100644 --- a/src/main/java/spoon/support/compiler/SpoonPom.java +++ b/src/main/java/spoon/support/compiler/SpoonPom.java @@ -310,7 +310,7 @@ public List getClasspathTmpFiles(String fileName) { } // Pattern corresponding to maven properties ${propertyName} - private static Pattern mavenProperty = Pattern.compile("\\$\\{.*?\\}"); + private static final Pattern MAVEN_PROPERTY = Pattern.compile("\\$\\{.*?}"); /** * Extract the variable from a string @@ -318,7 +318,7 @@ public List getClasspathTmpFiles(String fileName) { private String extractVariable(String value) { String val = value; if (value != null && value.contains("$")) { - Matcher matcher = mavenProperty.matcher(value); + Matcher matcher = MAVEN_PROPERTY.matcher(value); while (matcher.find()) { String var = matcher.group(); val = val.replace(var, getProperty(var.substring(2, var.length() - 1)));