-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tycho-versions-plugin: Support ci-friendly versions
In PomFile#getVersion(), resolve properties used in the raw version of the project. This is necessary so that downstream manipulators (MANIFEST.MF, feature.xml, category.xml, ...) can see the actual version and act on it. Fixes #3744. (cherry picked from commit f4e7ede)
- Loading branch information
1 parent
5ccc6bc
commit 75df1d6
Showing
6 changed files
with
150 additions
and
24 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
tycho-its/projects/tycho-version-plugin/set-version/ci_friendly/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: Test Artifact | ||
Bundle-SymbolicName: test.artifact | ||
Bundle-Version: 1.0.0.qualifier | ||
Bundle-RequiredExecutionEnvironment: JavaSE-17 |
23 changes: 23 additions & 0 deletions
23
tycho-its/projects/tycho-version-plugin/set-version/ci_friendly/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>test.artifact</artifactId> | ||
<groupId>org.tycho.its</groupId> | ||
<packaging>eclipse-plugin</packaging> | ||
<properties> | ||
<revision>1.0.0-SNAPSHOT</revision> | ||
</properties> | ||
<version>${revision}</version> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-maven-plugin</artifactId> | ||
<version>${tycho-version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/pom/PomUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class PomUtil { | ||
|
||
private static final Pattern PROPERTY_PATTERN = Pattern.compile("\\$\\{(.+?)\\}"); | ||
|
||
/** | ||
* Returns whether the string contains properties <code>${properties}</code>. | ||
*/ | ||
public static boolean containsProperties(String str) { | ||
return str != null && str.contains("${"); | ||
} | ||
|
||
/** | ||
* Expands properties in the given string. | ||
* <p> | ||
* If a property is not found it is left unexpanded. | ||
* | ||
* @param str | ||
* the input string | ||
* @param properties | ||
* possible replacement properties | ||
* @return the expanded string | ||
*/ | ||
public static String expandProperties(String str, List<Property> properties) { | ||
if (containsProperties(str)) { | ||
StringBuilder resolvedVersionBuilder = new StringBuilder(); | ||
Matcher m = PROPERTY_PATTERN.matcher(str.trim()); | ||
while (m.find()) { | ||
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)); | ||
} | ||
m.appendTail(resolvedVersionBuilder); | ||
return resolvedVersionBuilder.toString(); | ||
} else { | ||
return str; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the list of property names that make up the given string. | ||
*/ | ||
public static List<String> getContainedPropertyNames(String str) { | ||
if (containsProperties(str)) { | ||
Matcher m = PROPERTY_PATTERN.matcher(str.trim()); | ||
List<String> propertyNames = new ArrayList<>(); | ||
while (m.find()) { | ||
propertyNames.add(m.group(1)); | ||
} | ||
return Collections.unmodifiableList(propertyNames); | ||
} | ||
return List.of(); | ||
} | ||
} |