diff --git a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/pom/PomUtil.java b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/pom/PomUtil.java index fda4d927ad..7d99264a14 100644 --- a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/pom/PomUtil.java +++ b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/pom/PomUtil.java @@ -48,8 +48,8 @@ public static String expandProperties(String str, List properties) { String unexpandedProperty = m.group(); String propertyName = m.group(1); m.appendReplacement(resolvedVersionBuilder, - properties.stream().filter(p -> p.getName().equals(propertyName)).map(p -> p.getValue()) - .findFirst().orElse(unexpandedProperty)); + Matcher.quoteReplacement(properties.stream().filter(p -> p.getName().equals(propertyName)) + .map(p -> p.getValue()).findFirst().orElse(unexpandedProperty))); } m.appendTail(resolvedVersionBuilder); return resolvedVersionBuilder.toString(); diff --git a/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/pom/tests/PomUtilTest.java b/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/pom/tests/PomUtilTest.java new file mode 100644 index 0000000000..412182d47d --- /dev/null +++ b/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/pom/tests/PomUtilTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2024 SAP SE and others. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * SAP SE - initial API and implementation + *******************************************************************************/ +package org.eclipse.tycho.versions.pom.tests; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; + +import org.eclipse.tycho.versions.pom.PomFile; +import org.eclipse.tycho.versions.pom.PomUtil; +import org.junit.Test; + +public class PomUtilTest { + + @Test + public void expandProperties() throws Exception { + String pom = """ + + + fooValue + barValue + + + """; + PomFile pomFile = PomFile.read(new ByteArrayInputStream(pom.getBytes(StandardCharsets.UTF_8)), true); + + String expanded = PomUtil.expandProperties("${foo}-${bar}-${notFound}", pomFile.getProperties()); + + assertEquals("fooValue-barValue-${notFound}", expanded); + } +}