Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tycho-versions-plugin: PomUtil.expandProperties(): Quote replacements #4453

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static String expandProperties(String str, List<Property> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = """
<project>
<properties>
<foo> fooValue </foo>
<bar>barValue</bar>
</properties>
</project>
""";
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);
}
}
Loading