[Git][java-team/plexus-interpolation][upstream] 3 commits: New upstream version 1.28
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Fri Oct 30 11:31:05 GMT 2026
Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / plexus-interpolation
Commits:
750dc0ae by Emmanuel Bourg at 2026-10-30T11:27:16+01:00
New upstream version 1.28
- - - - -
5ec9b53f by Emmanuel Bourg at 2026-10-30T11:27:16+01:00
New upstream version 1.29
- - - - -
89d7a785 by Emmanuel Bourg at 2026-10-30T11:27:17+01:00
New upstream version 1.30.0
- - - - -
28 changed files:
- − .github/release-drafter.yml
- README.md
- pom.xml
- src/main/java/org/codehaus/plexus/interpolation/AbstractDelegatingValueSource.java
- + src/main/java/org/codehaus/plexus/interpolation/FeedbackingValueSource.java
- src/main/java/org/codehaus/plexus/interpolation/RegexBasedInterpolator.java
- src/main/java/org/codehaus/plexus/interpolation/StringSearchInterpolator.java
- src/main/java/org/codehaus/plexus/interpolation/ValueSource.java
- src/main/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java
- src/main/java/org/codehaus/plexus/interpolation/os/OperatingSystemUtils.java
- + src/main/java9/module-info.java
- src/site/apt/index.apt → src/site/markdown/index.md
- src/site/site.xml
- src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java
- + src/test/java/org/codehaus/plexus/interpolation/FeedbackingValueSourceTest.java
- src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java
- src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java
- src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java
- src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java
- src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java
- src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java
- src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java
- src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java
- src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java
- src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java
- src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java
- src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java
- src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java
Changes:
=====================================
.github/release-drafter.yml deleted
=====================================
@@ -1,2 +0,0 @@
-_extends: .github
-tag-template: plexus-interpolation-$NEXT_MINOR_VERSION
=====================================
README.md
=====================================
@@ -1,15 +1,49 @@
-Plexus-Interpolation
-===============
+# Plexus Interpolation
-[](http://search.maven.org/artifact/org.codehaus.plexus/plexus-interpolation)
+[](https://central.sonatype.com/artifact/org.codehaus.plexus/plexus-interpolation)
+[](https://github.com/codehaus-plexus/plexus-interpolation/actions)
+[](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/codehaus/plexus/plexus-interpolation/README.md)
-The current master is now at https://github.com/codehaus-plexus/plexus-interpolation
+Resolves `${...}` expressions in strings. This is the engine behind POM interpolation — when Maven turns
+`${project.version}` in your POM into an actual version, this is what does it.
-Components for interpolating `${}` strings and the like.
+Expression sources are stackable, so you can resolve against a model object, then system properties, then
+the environment, in a defined order; cycle detection and synonym prefixes (`${pom.x}` and `${project.x}`)
+are built in.
-For publishing [the site](https://codehaus-plexus.github.io/plexus-interpolation/) do the following:
+It began as a package inside `plexus-utils` and was split out so the two could version independently.
+## Status
+
+Maintained, conservatively. The API is stable and very widely depended on transitively — changes are
+mostly bug fixes.
+
+## Using it
+
+```xml
+<dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.29</version>
+</dependency>
```
-mvn -Preporting verify site-deploy
-```
+Check the badge above for the current version.
+
+## Requirements
+
+Java 8 or later.
+
+## Documentation
+
+- [Project site](https://codehaus-plexus.github.io/plexus-interpolation/) — includes a worked example of the configuration Maven uses
+- [Javadoc](https://javadoc.io/doc/org.codehaus.plexus/plexus-interpolation)
+- [Release notes](https://github.com/codehaus-plexus/plexus-interpolation/releases)
+
+## Contributing
+
+See [CONTRIBUTING.md](https://github.com/codehaus-plexus/.github/blob/master/CONTRIBUTING.md). In short:
+`mvn verify` builds, and run `mvn spotless:apply` before pushing or CI will fail on formatting.
+
+Please report security vulnerabilities privately — see
+[SECURITY.md](https://github.com/codehaus-plexus/.github/blob/master/SECURITY.md), not a public issue.
=====================================
pom.xml
=====================================
@@ -5,24 +5,26 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus</artifactId>
- <version>16</version>
+ <version>27</version>
</parent>
<artifactId>plexus-interpolation</artifactId>
- <version>1.27</version>
+ <version>1.30.0</version>
<packaging>bundle</packaging>
<name>Plexus Interpolation API</name>
+ <description>A component that resolves expressions in strings against stackable value sources, as used for
+ POM interpolation.</description>
<scm>
<connection>scm:git:https://github.com/codehaus-plexus/plexus-interpolation.git</connection>
<developerConnection>scm:git:https://github.com/codehaus-plexus/plexus-interpolation.git</developerConnection>
- <tag>plexus-interpolation-1.27</tag>
+ <tag>plexus-interpolation-1.30.0</tag>
<url>http://github.com/codehaus-plexus/plexus-interpolation/tree/${project.scm.tag}/</url>
</scm>
<issueManagement>
- <system>JIRA</system>
+ <system>Github</system>
<url>https://github.com/codehaus-plexus/plexus-interpolation/issues</url>
</issueManagement>
<distributionManagement>
@@ -33,13 +35,13 @@
</distributionManagement>
<properties>
- <project.build.outputTimestamp>2023-12-24T00:37:41Z</project.build.outputTimestamp>
+ <project.build.outputTimestamp>2026-08-19T08:09:55Z</project.build.outputTimestamp>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter</artifactId>
+ <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
@@ -88,4 +90,48 @@
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>java9+</id>
+ <activation>
+ <jdk>[9,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>compile-java9</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <phase>compile</phase>
+ <configuration>
+ <release>9</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Multi-Release>true</Multi-Release>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
=====================================
src/main/java/org/codehaus/plexus/interpolation/AbstractDelegatingValueSource.java
=====================================
@@ -34,14 +34,22 @@ public abstract class AbstractDelegatingValueSource implements ValueSource {
return delegate;
}
+ @Override
+ public Object getValue(String expression, String delimiterStart, String delimiterEnd) {
+ return getDelegate().getValue(expression, delimiterStart, delimiterEnd);
+ }
+
+ @Override
public Object getValue(String expression) {
return getDelegate().getValue(expression);
}
+ @Override
public void clearFeedback() {
delegate.clearFeedback();
}
+ @Override
public List getFeedback() {
return delegate.getFeedback();
}
=====================================
src/main/java/org/codehaus/plexus/interpolation/FeedbackingValueSource.java
=====================================
@@ -0,0 +1,44 @@
+package org.codehaus.plexus.interpolation;
+
+/*
+ * Copyright 2001-2008 Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Adds feedback on any {@link #getValue(String) getValue(String)} call.
+ * <p>One of the obvious usages is to add FeedbackingValueSource as last value source to {@link Interpolator}
+ * to add feedback messages indicating not resolved expressions.</p>
+ */
+public class FeedbackingValueSource extends AbstractValueSource {
+ private final String messagePattern;
+
+ public FeedbackingValueSource() {
+ this("'${expression}' not resolved");
+ }
+
+ /**
+ * @param messagePattern could contain <code>${expression}</code> placeholder
+ */
+ public FeedbackingValueSource(String messagePattern) {
+ super(true);
+ this.messagePattern = messagePattern;
+ }
+
+ @Override
+ public Object getValue(String expression) {
+ addFeedback(messagePattern.replace("${expression}", expression));
+ return null;
+ }
+}
=====================================
src/main/java/org/codehaus/plexus/interpolation/RegexBasedInterpolator.java
=====================================
@@ -177,6 +177,8 @@ public class RegexBasedInterpolator implements Interpolator {
int realExprGroup = 2;
Pattern expressionPattern;
+ final String expressionDelimiterStart;
+ final String expressionDelimiterEnd;
if (startRegex != null || endRegex != null) {
if (thisPrefixPattern == null) {
expressionPattern = getPattern(startRegex + endRegex);
@@ -184,16 +186,27 @@ public class RegexBasedInterpolator implements Interpolator {
} else {
expressionPattern = getPattern(startRegex + thisPrefixPattern + endRegex);
}
+ expressionDelimiterStart = startRegex;
+ expressionDelimiterEnd = endRegex;
- } else if (thisPrefixPattern != null) {
- expressionPattern = getPattern("\\$\\{(" + thisPrefixPattern + ")?(.+?)\\}");
} else {
- expressionPattern = getPattern(DEFAULT_REGEXP);
- realExprGroup = 1;
+ expressionDelimiterStart = "${";
+ expressionDelimiterEnd = "}";
+ if (thisPrefixPattern != null) {
+ expressionPattern = getPattern("\\$\\{(" + thisPrefixPattern + ")?(.+?)\\}");
+ } else {
+ expressionPattern = getPattern(DEFAULT_REGEXP);
+ realExprGroup = 1;
+ }
}
-
try {
- return interpolate(input, recursionInterceptor, expressionPattern, realExprGroup);
+ return interpolate(
+ input,
+ recursionInterceptor,
+ expressionPattern,
+ expressionDelimiterStart,
+ expressionDelimiterEnd,
+ realExprGroup);
} finally {
if (!cacheAnswers) {
clearAnswers();
@@ -228,7 +241,12 @@ public class RegexBasedInterpolator implements Interpolator {
* @todo Ensure unresolvable expressions don't trigger infinite recursion.
*/
private String interpolate(
- String input, RecursionInterceptor recursionInterceptor, Pattern expressionPattern, int realExprGroup)
+ String input,
+ RecursionInterceptor recursionInterceptor,
+ Pattern expressionPattern,
+ String expressionDelimiterStart,
+ String expressionDelimiterEnd,
+ int realExprGroup)
throws InterpolationException {
if (input == null) {
// return empty String to prevent NPE too
@@ -256,11 +274,17 @@ public class RegexBasedInterpolator implements Interpolator {
for (ValueSource vs : valueSources) {
if (value != null) break;
- value = vs.getValue(realExpr);
+ value = vs.getValue(realExpr, expressionDelimiterStart, expressionDelimiterEnd);
}
if (value != null) {
- value = interpolate(String.valueOf(value), recursionInterceptor, expressionPattern, realExprGroup);
+ value = interpolate(
+ String.valueOf(value),
+ recursionInterceptor,
+ expressionPattern,
+ expressionDelimiterStart,
+ expressionDelimiterEnd,
+ realExprGroup);
if (postProcessors != null && !postProcessors.isEmpty()) {
for (InterpolationPostProcessor postProcessor : postProcessors) {
@@ -277,6 +301,10 @@ public class RegexBasedInterpolator implements Interpolator {
// but this could result in multiple lookups of stringValue, and replaceAll is not correct behaviour
result = StringUtils.replace(result, wholeExpr, String.valueOf(value));
+ if (cacheAnswers) {
+ existingAnswers.put(realExpr, value);
+ }
+
matcher.reset(result);
}
} finally {
=====================================
src/main/java/org/codehaus/plexus/interpolation/StringSearchInterpolator.java
=====================================
@@ -156,14 +156,14 @@ public class StringSearchInterpolator implements Interpolator {
recursionInterceptor.expressionResolutionStarted(realExpr);
try {
- Object value = existingAnswers.get(realExpr);
+ Object value = getExistingAnswer(realExpr);
Object bestAnswer = null;
for (ValueSource valueSource : valueSources) {
if (value != null) {
break;
}
- value = valueSource.getValue(realExpr);
+ value = valueSource.getValue(realExpr, startExpr, endExpr);
if (value != null && value.toString().contains(wholeExpr)) {
bestAnswer = value;
@@ -197,6 +197,10 @@ public class StringSearchInterpolator implements Interpolator {
// behaviour
result.append(String.valueOf(value));
resolved = true;
+
+ if (cacheAnswers) {
+ existingAnswers.put(realExpr, value);
+ }
} else {
unresolvable.add(wholeExpr);
}
@@ -275,4 +279,13 @@ public class StringSearchInterpolator implements Interpolator {
public void setEscapeString(String escapeString) {
this.escapeString = escapeString;
}
+
+ /**
+ * For testing purposes only. Not part of the public API.
+ * @param key the key of a possible existing answer.
+ * @return the associated interpolated object, or null if there is none.
+ */
+ protected Object getExistingAnswer(String key) {
+ return existingAnswers.get(key);
+ }
}
=====================================
src/main/java/org/codehaus/plexus/interpolation/ValueSource.java
=====================================
@@ -25,8 +25,21 @@ import java.util.List;
public interface ValueSource {
/**
+ * Returns a value resolved from an expression. The return value is recursively resolved via {@link Interpolator#interpolate(String)}, i.e. might contain expressions as well.
* @param expression The string expression.
- * @return the value related to the expression, or null if not found.
+ * @param expressionStartDelimiter A valid start delimiter of the expression to be used with the calling {@link Interpolator} (by default <code>${</code>).
+ * @param expressionEndDelimiter A valid end delimiter of the expression to be used with the calling {@link Interpolator} (by default <code>}</code>).
+ * @return the value related to the expression, or {@code null} if not found. This value might contain other expressions separated by {@code expressionStartDelimiter} and {@code expressionEndDelimiter}
+ * @since 1.28
+ */
+ default Object getValue(String expression, String expressionStartDelimiter, String expressionEndDelimiter) {
+ return getValue(expression);
+ }
+
+ /**
+ * @param expression The string expression.
+ * @return the value related to the expression, or {@code null} if not found.
+ * @see #getValue(String, String, String)
*/
public Object getValue(String expression);
=====================================
src/main/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java
=====================================
@@ -201,7 +201,7 @@ public class MultiDelimiterStringSearchInterpolator implements Interpolator {
for (ValueSource vs : valueSources) {
if (value != null) break;
- value = vs.getValue(realExpr);
+ value = vs.getValue(realExpr, startExpr, endExpr);
if (value != null && value.toString().contains(wholeExpr)) {
bestAnswer = value;
@@ -236,6 +236,10 @@ public class MultiDelimiterStringSearchInterpolator implements Interpolator {
// behaviour
result.append(String.valueOf(value));
resolved = true;
+
+ if (cacheAnswers) {
+ existingAnswers.put(realExpr, value);
+ }
} else {
unresolvable.add(wholeExpr);
}
=====================================
src/main/java/org/codehaus/plexus/interpolation/os/OperatingSystemUtils.java
=====================================
@@ -1,27 +1,19 @@
package org.codehaus.plexus.interpolation.os;
/*
- * The MIT License
+ * Copyright 2001-2008 Codehaus Foundation.
*
- * Copyright (c) 2004, The Codehaus
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
import java.io.IOException;
=====================================
src/main/java9/module-info.java
=====================================
@@ -0,0 +1,3 @@
+module org.codehaus.plexus.interpolation {
+ exports org.codehaus.plexus.interpolation;
+}
=====================================
src/site/apt/index.apt → src/site/markdown/index.md
=====================================
@@ -1,75 +1,56 @@
- -----
- Plexus Interpolator
- -----
- John Casey
- Hervé Boutemy
- -----
- 2012-10-31
- -----
-
-Introduction
-
- Plexus interpolator is the outgrowth of multiple iterations of development focused on providing a more modular,
- flexible interpolation framework for the expression language style commonly seen in Maven, Plexus, and other related projects.
-
- It has its foundation in the <<<org.codehaus.plexus.utils.interpolation>>> package within
- {{{/plexus-utils/}<<<plexus-utils>>>}}, but has been separated in order to allow these two libraries to vary independently
- of one another.
-
-Features
-
- * Stackable Expression-Resolution Strategies
-
- Expression-resolution strategies can be 'stacked' to provide an order of operations, containing multiple approaches that could
- potentially resolve a given expression.
-
- These strategies are called {{{./apidocs/org/codehaus/plexus/interpolation/ValueSource.html}<<<ValueSource>>>s}},
- and each implements a very simple piece of resolution logic.
+---
+title: Plexus Interpolator
+author:
+ - John Casey
+ - Hervé Boutemy
+date: 2012-10-31
+---
+
+# Introduction
+
+Plexus interpolator is the outgrowth of multiple iterations of development focused on providing a more modular, flexible interpolation framework for the expression language style commonly seen in Maven, Plexus, and other related projects.
+
+It has its foundation in the `org.codehaus.plexus.utils.interpolation` package within [`plexus-utils`](/plexus-utils/), but has been separated in order to allow these two libraries to vary independently of one another.
+
+# Features
+
+- Stackable Expression-Resolution Strategies
+
+ Expression-resolution strategies can be 'stacked' to provide an order of operations, containing multiple approaches that could potentially resolve a given expression.
+
+ These strategies are called [`ValueSource`s](./apidocs/org/codehaus/plexus/interpolation/ValueSource.html), and each implements a very simple piece of resolution logic.
It's also possible to define your own, domain-specific value source.
-
- * Flexible Expression-Cycle Detection
- Expression cycles are detected using various strategies, ranging from simplistic consultation of a stack of explicit in-process
- expressions, to tracking of in-process expressions that takes multiple synonym expression variants into account.
+- Flexible Expression-Cycle Detection
- It's even possible to define your own
- {{{./apidocs/org/codehaus/plexus/interpolation/RecursionInterceptor.html}<<<RecursionInterceptor>>>}} to implement
- an alternative strategy.
+ Expression cycles are detected using various strategies, ranging from simplistic consultation of a stack of explicit in-process expressions, to tracking of in-process expressions that takes multiple synonym expression variants into account.
- * Configurable Regular Expression-Based Default Interpolator
+ It's even possible to define your own [`RecursionInterceptor`](./apidocs/org/codehaus/plexus/interpolation/RecursionInterceptor.html) to implement an alternative strategy.
- The default interpolator implementation uses regular expressions to search for interpolation candidate expressions within
- an input string.
+- Configurable Regular Expression-Based Default Interpolator
- This interpolator can use a custom prefix/suffix pair that will effectively redefine the regular expression used to extract
- candidate expressions.
-
- * Built-In Synonym Support for Expressions
+ The default interpolator implementation uses regular expressions to search for interpolation candidate expressions within an input string.
- Any <<<ValueSource>>> implementation can be wrapped to allow multiple synonym expressions using different expression prefixes.
-
- * Resolution Feedback
+ This interpolator can use a custom prefix/suffix pair that will effectively redefine the regular expression used to extract candidate expressions.
- <<<ValueSource>>> implementations have the option of implementing <<<FeedbackEnabledValueSource>>>, which provides the ability to
- give feedback to the calling code about what failed during expression resolution. For instance, the <<<ObjectBasedValueSource>>>
- traverses the object graph below a given root object; if an object in that graph doesn't contain a property corresponding to
- the expression-part currently being navigated, the value source can store a feedback message to that effect.
- Once interpolation of the larger input string has completed, the calling code can use the <<<Interpolator.getFeedback()>>> method
- to retrieve this feedback message (among others).
-
-Getting Started
+- Built-In Synonym Support for Expressions
- The simplest way to explain how to use the plexus-interpolation API is with a few examples.
+ Any `ValueSource` implementation can be wrapped to allow multiple synonym expressions using different expression prefixes.
- First, let's look at a simplified version of the interpolation configuration used in Maven.
- Remember that Maven uses several source for interpolation of its POM files: the POM itself, system properties,
- user-defined properties, and environment variables from the shell that spawned the current Java process.
- Also, Maven allows POM references to be defined as $\{pom.groupId}, $\{project.groupId}, or even the discouraged $\{groupId}.
+- Resolution Feedback
- The following is a simplified version of the plexus-interpolation configuration Maven might use to resolve POM expressions:
-
-+---+
+ `ValueSource` implementations have the option of implementing `FeedbackEnabledValueSource`, which provides the ability to give feedback to the calling code about what failed during expression resolution. For instance, the `ObjectBasedValueSource` traverses the object graph below a given root object; if an object in that graph doesn't contain a property corresponding to the expression-part currently being navigated, the value source can store a feedback message to that effect. Once interpolation of the larger input string has completed, the calling code can use the `Interpolator.getFeedback()` method to retrieve this feedback message (among others).
+
+# Getting Started
+
+The simplest way to explain how to use the plexus-interpolation API is with a few examples.
+
+First, let's look at a simplified version of the interpolation configuration used in Maven. Remember that Maven uses several source for interpolation of its POM files: the POM itself, system properties, user-defined properties, and environment variables from the shell that spawned the current Java process. Also, Maven allows POM references to be defined as ${pom.groupId}, ${project.groupId}, or even the discouraged ${groupId}.
+
+The following is a simplified version of the plexus-interpolation configuration Maven might use to resolve POM expressions:
+
+```unknown
// serialize current POM object graph into a string called serializedPOM.
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
@@ -97,4 +78,5 @@ RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor(
serializedPOM = interpolator.interpolate( serializedPOM, recursionInterceptor );
// parse POM back into an object graph, and pass it back.
-+---+
\ No newline at end of file
+```
+
=====================================
src/site/site.xml
=====================================
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project name="Plexus Interpolation" xmlns="http://maven.apache.org/DECORATION/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
+<site xmlns="http://maven.apache.org/SITE/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
@@ -13,4 +12,4 @@
<menu ref="parent"/>
<menu ref="reports"/>
</body>
-</project>
+</site>
=====================================
src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java
=====================================
@@ -1,24 +1,6 @@
package org.codehaus.plexus.interpolation;
-/*
- * Copyright 2007 The Codehaus Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Map;
import org.codehaus.plexus.interpolation.os.OperatingSystemUtils;
import org.junit.jupiter.api.BeforeEach;
@@ -28,21 +10,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
-public class EnvarBasedValueSourceTest {
+class EnvarBasedValueSourceTest {
@BeforeEach
- public void setUp() {
+ void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- void testNoArgConstructorIsCaseSensitive() throws IOException {
- OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
- public Map<String, String> getEnvMap() {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("aVariable", "variable");
- return map;
- }
+ void noArgConstructorIsCaseSensitive() throws Exception {
+ OperatingSystemUtils.setEnvVarSource(() -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("aVariable", "variable");
+ return map;
});
EnvarBasedValueSource source = new EnvarBasedValueSource();
@@ -54,13 +34,11 @@ public class EnvarBasedValueSourceTest {
}
@Test
- void testCaseInsensitive() throws IOException {
- OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
- public Map<String, String> getEnvMap() {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("aVariable", "variable");
- return map;
- }
+ void caseInsensitive() throws Exception {
+ OperatingSystemUtils.setEnvVarSource(() -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("aVariable", "variable");
+ return map;
});
EnvarBasedValueSource source = new EnvarBasedValueSource(false);
@@ -72,7 +50,7 @@ public class EnvarBasedValueSourceTest {
}
@Test
- void testGetRealEnvironmentVariable() throws IOException {
+ void getRealEnvironmentVariable() throws Exception {
OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.DefaultEnvVarSource());
EnvarBasedValueSource source = new EnvarBasedValueSource();
=====================================
src/test/java/org/codehaus/plexus/interpolation/FeedbackingValueSourceTest.java
=====================================
@@ -0,0 +1,63 @@
+package org.codehaus.plexus.interpolation;
+
+/*
+ * Copyright 2001-2008 Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.junit.jupiter.api.Test;
+
+import static java.util.Collections.singletonMap;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class FeedbackingValueSourceTest {
+
+ @Test
+ void standalone() {
+ ValueSource valueSource = new FeedbackingValueSource();
+ assertNull(valueSource.getValue("test"));
+ assertEquals(1, valueSource.getFeedback().size());
+ assertEquals("'test' not resolved", valueSource.getFeedback().iterator().next());
+ }
+
+ @Test
+ void afterResolvedExpression() throws Exception {
+ StringSearchInterpolator interpolator = new StringSearchInterpolator();
+ interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val")));
+ interpolator.addValueSource(new FeedbackingValueSource());
+ assertEquals("val", interpolator.interpolate("${key}"));
+ assertTrue(interpolator.getFeedback().isEmpty());
+ }
+
+ @Test
+ void beforeResolvedExpression() throws Exception {
+ StringSearchInterpolator interpolator = new StringSearchInterpolator();
+ interpolator.addValueSource(new FeedbackingValueSource("Resolving ${expression}"));
+ interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val")));
+ assertEquals("val", interpolator.interpolate("${key}"));
+ assertEquals(1, interpolator.getFeedback().size());
+ assertEquals("Resolving key", interpolator.getFeedback().iterator().next());
+ }
+
+ @Test
+ void afterNotResolvedExpression() throws Exception {
+ StringSearchInterpolator interpolator = new StringSearchInterpolator();
+ interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val")));
+ interpolator.addValueSource(new FeedbackingValueSource());
+ assertEquals("${other-key}", interpolator.interpolate("${other-key}"));
+ assertEquals(1, interpolator.getFeedback().size());
+ }
+}
=====================================
src/test/java/org/codehaus/plexus/interpolation/InterpolatorFilterReaderTest.java
=====================================
@@ -1,27 +1,19 @@
package org.codehaus.plexus.interpolation;
/*
- * The MIT License
+ * Copyright 2001-2008 Codehaus Foundation.
*
- * Copyright (c) 2004, The Codehaus
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
import java.io.StringReader;
@@ -41,14 +33,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* @author cstamas
*
*/
-public class InterpolatorFilterReaderTest {
+class InterpolatorFilterReaderTest {
/*
* Added and commented by jdcasey at 03-Feb-2005 because it is a bug in the InterpolationFilterReader.
* kenneyw at 15-04-2005 fixed the bug.
*/
@Test
- public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "TestValue");
String testStr = "This is a ${test";
@@ -60,8 +52,8 @@ public class InterpolatorFilterReaderTest {
* kenneyw at 14-04-2005 Added test to check above fix.
*/
@Test
- public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "TestValue");
String testStr = "This is a ${test, really";
@@ -70,8 +62,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testShouldNotInterpolateWithMalformedStartToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateWithMalformedStartToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "testValue");
String foo = "This is a $!test} again";
@@ -80,8 +72,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testShouldNotInterpolateWithMalformedEndToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateWithMalformedEndToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "testValue");
String foo = "This is a ${test!} again";
@@ -90,8 +82,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
- Map m = new HashMap();
+ void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -101,8 +93,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
- Map m = new HashMap();
+ void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -112,8 +104,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
- Map m = new HashMap();
+ void interpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -123,8 +115,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
- Map m = new HashMap();
+ void interpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -134,8 +126,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testEscape() throws Exception {
- Map m = new HashMap();
+ void escape() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -145,8 +137,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testEscapeAtStart() throws Exception {
- Map m = new HashMap();
+ void escapeAtStart() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -156,8 +148,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testEscapeOnlyAtStart() throws Exception {
- Map m = new HashMap();
+ void escapeOnlyAtStart() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -168,8 +160,8 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testEscapeOnlyAtStartDefaultToken() throws Exception {
- Map m = new HashMap();
+ void escapeOnlyAtStartDefaultToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -180,15 +172,15 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
- List prefixes = new ArrayList();
+ void shouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
+ List<String> prefixes = new ArrayList<>();
prefixes.add("prefix1");
prefixes.add("prefix2");
RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("name", "${prefix2.name}");
String input = "${prefix1.name}";
@@ -211,14 +203,14 @@ public class InterpolatorFilterReaderTest {
}
@Test
- public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
- List prefixes = new ArrayList();
+ void shouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
+ List<String> prefixes = new ArrayList<>();
prefixes.add("prefix1");
RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("name", "${prefix1.name}");
String input = "${name}";
@@ -244,11 +236,11 @@ public class InterpolatorFilterReaderTest {
//
// ----------------------------------------------------------------------
- private String interpolate(String input, Map context) throws Exception {
+ private String interpolate(String input, Map<String, String> context) throws Exception {
return interpolate(input, context, null);
}
- private String interpolate(String input, Map context, String escapeStr) throws Exception {
+ private String interpolate(String input, Map<String, String> context, String escapeStr) throws Exception {
Interpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource(new MapBasedValueSource(context));
@@ -268,7 +260,8 @@ public class InterpolatorFilterReaderTest {
return buf.toString();
}
- private String interpolate(String input, Map context, String beginToken, String endToken) throws Exception {
+ private String interpolate(String input, Map<String, String> context, String beginToken, String endToken)
+ throws Exception {
StringSearchInterpolator interpolator = new StringSearchInterpolator(beginToken, endToken);
interpolator.addValueSource(new MapBasedValueSource(context));
=====================================
src/test/java/org/codehaus/plexus/interpolation/PrefixAwareRecursionInterceptorTest.java
=====================================
@@ -25,10 +25,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class PrefixAwareRecursionInterceptorTest {
+class PrefixAwareRecursionInterceptorTest {
@Test
- public void testFindExpression() {
+ void findExpression() {
PrefixAwareRecursionInterceptor receptor =
new PrefixAwareRecursionInterceptor(Collections.singleton("prefix."));
@@ -45,9 +45,9 @@ public class PrefixAwareRecursionInterceptorTest {
}
@Test
- public void testFindExpressionWithDifferentPrefix() {
+ void findExpressionWithDifferentPrefix() {
PrefixAwareRecursionInterceptor receptor =
- new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."}));
+ new PrefixAwareRecursionInterceptor(Arrays.asList("prefix.", "other."));
String expr = "prefix.first";
@@ -61,9 +61,9 @@ public class PrefixAwareRecursionInterceptorTest {
}
@Test
- public void testFindExpressionWithoutPrefix() {
+ void findExpressionWithoutPrefix() {
PrefixAwareRecursionInterceptor receptor =
- new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."}));
+ new PrefixAwareRecursionInterceptor(Arrays.asList("prefix.", "other."));
String prefixedExpr = "prefix.first";
String expr = "first";
=====================================
src/test/java/org/codehaus/plexus/interpolation/PrefixedObjectValueSourceTest.java
=====================================
@@ -23,13 +23,13 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNull;
-public class PrefixedObjectValueSourceTest {
+class PrefixedObjectValueSourceTest {
@Test
- public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed() {
+ void emptyExpressionResultsInNullReturnNoPrefixUsed() {
String target = "Target object";
- List prefixes = new ArrayList();
+ List<String> prefixes = new ArrayList<>();
prefixes.add("target");
prefixes.add("object");
@@ -40,10 +40,10 @@ public class PrefixedObjectValueSourceTest {
}
@Test
- public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot() {
+ void emptyExpressionResultsInNullReturnPrefixUsedWithDot() {
String target = "Target object";
- List prefixes = new ArrayList();
+ List<String> prefixes = new ArrayList<>();
prefixes.add("target");
prefixes.add("object");
@@ -54,10 +54,10 @@ public class PrefixedObjectValueSourceTest {
}
@Test
- public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithoutDot() {
+ void emptyExpressionResultsInNullReturnPrefixUsedWithoutDot() {
String target = "Target object";
- List prefixes = new ArrayList();
+ List<String> prefixes = new ArrayList<>();
prefixes.add("target");
prefixes.add("object");
=====================================
src/test/java/org/codehaus/plexus/interpolation/PrefixedValueSourceWrapperTest.java
=====================================
@@ -23,10 +23,10 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
-public class PrefixedValueSourceWrapperTest {
+class PrefixedValueSourceWrapperTest {
@Test
- public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix() {
+ void shouldReturnValueForPropertyVSWRappedWithSinglePrefix() {
String prefix = "prefix.";
String key = "key";
String value = "value";
@@ -41,7 +41,7 @@ public class PrefixedValueSourceWrapperTest {
}
@Test
- public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix() {
+ void shouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix() {
String prefix = "prefix.";
String otherPrefix = "other.";
String key = "key";
@@ -57,7 +57,7 @@ public class PrefixedValueSourceWrapperTest {
}
@Test
- public void testShouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix() {
+ void shouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix() {
String prefix = "prefix.";
String key = "key";
=====================================
src/test/java/org/codehaus/plexus/interpolation/PropertiesBasedValueSourceTest.java
=====================================
@@ -23,10 +23,10 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
-public class PropertiesBasedValueSourceTest {
+class PropertiesBasedValueSourceTest {
@Test
- public void testPropertyShouldReturnValueFromProperties() {
+ void propertyShouldReturnValueFromProperties() {
Properties props = new Properties();
String key = "key";
@@ -40,7 +40,7 @@ public class PropertiesBasedValueSourceTest {
}
@Test
- public void testPropertyShouldReturnNullWhenPropertyMissing() {
+ void propertyShouldReturnNullWhenPropertyMissing() {
Properties props = new Properties();
String key = "key";
=====================================
src/test/java/org/codehaus/plexus/interpolation/RegexBasedInterpolatorTest.java
=====================================
@@ -1,22 +1,5 @@
package org.codehaus.plexus.interpolation;
-/*
- * Copyright 2001-2008 Codehaus Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -31,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.fail;
public class RegexBasedInterpolatorTest {
@BeforeEach
- public void setUp() {
+ void setUp() {
EnvarBasedValueSource.resetStatics();
}
@@ -40,7 +23,7 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testShouldFailOnExpressionCycle() {
+ void shouldFailOnExpressionCycle() {
Properties props = new Properties();
props.setProperty("key1", "${key2}");
props.setProperty("key2", "${key1}");
@@ -58,7 +41,7 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testShouldResolveByMy_getVar_Method() throws InterpolationException {
+ void shouldResolveByMyGetVarMethod() throws Exception {
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
rbi.addValueSource(new ObjectBasedValueSource(this));
String result = rbi.interpolate("this is a ${this.var}", "this");
@@ -67,10 +50,10 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testShouldResolveByContextValue() throws InterpolationException {
+ void shouldResolveByContextValue() throws Exception {
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
- Map context = new HashMap();
+ Map<String, String> context = new HashMap();
context.put("var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
@@ -81,13 +64,33 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testShouldResolveByEnvar() throws IOException, InterpolationException {
- OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
- public Map<String, String> getEnvMap() {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("SOME_ENV", "variable");
- return map;
+ void delimitersPassedToValueSource() throws Exception {
+ RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
+ interpolator.addValueSource(new AbstractValueSource(false) {
+
+ @Override
+ public Object getValue(String expression, String expressionStartDelimiter, String expressionEndDelimiter) {
+ assertEquals("${", expressionStartDelimiter);
+ assertEquals("}", expressionEndDelimiter);
+ return expression;
}
+
+ @Override
+ public Object getValue(String expression) {
+ fail("This method is not supposed to be called");
+ return null;
+ }
+ });
+
+ assertEquals("test", interpolator.interpolate("${test}"));
+ }
+
+ @Test
+ void shouldResolveByEnvar() throws Exception {
+ OperatingSystemUtils.setEnvVarSource(() -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("SOME_ENV", "variable");
+ return map;
});
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
@@ -100,10 +103,10 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testUseAlternateRegex() throws Exception {
+ void useAlternateRegex() throws Exception {
RegexBasedInterpolator rbi = new RegexBasedInterpolator("\\@\\{(", ")?([^}]+)\\}@");
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
@@ -114,10 +117,10 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testNPEFree() throws Exception {
+ void npeFree() throws Exception {
RegexBasedInterpolator rbi = new RegexBasedInterpolator("\\@\\{(", ")?([^}]+)\\}@");
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
@@ -128,19 +131,15 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException {
+ void usePostProcessorDoesNotChangeValue() throws Exception {
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("test.var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor(new InterpolationPostProcessor() {
- public Object execute(String expression, Object value) {
- return null;
- }
- });
+ rbi.addPostProcessor((expression, value) -> null);
String result = rbi.interpolate("this is a ${test.var}", "");
@@ -148,7 +147,7 @@ public class RegexBasedInterpolatorTest {
}
@Test
- public void testUsePostProcessor_ChangesValue() throws InterpolationException {
+ void usePostProcessorChangesValue() throws Exception {
int loopNumber = 200000;
@@ -156,16 +155,12 @@ public class RegexBasedInterpolatorTest {
RegexBasedInterpolator rbi = new RegexBasedInterpolator();
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("test.var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor(new InterpolationPostProcessor() {
- public Object execute(String expression, Object value) {
- return value + "2";
- }
- });
+ rbi.addPostProcessor((expression, value) -> value + "2");
for (int i = 0, number = loopNumber; i < number; i++) {
@@ -183,11 +178,7 @@ public class RegexBasedInterpolatorTest {
rbi = new RegexBasedInterpolator(true);
- rbi.addPostProcessor(new InterpolationPostProcessor() {
- public Object execute(String expression, Object value) {
- return value + "2";
- }
- });
+ rbi.addPostProcessor((expression, value) -> value + "2");
rbi.addValueSource(new MapBasedValueSource(context));
@@ -201,4 +192,73 @@ public class RegexBasedInterpolatorTest {
System.out.println("time with pattern reuse and RegexBasedInterpolator instance reuse " + (end - start));
}
+
+ @Test
+ void cacheAnswersTrue() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
+ ctx.put("key", "value");
+
+ final int[] valueSourceCallCount = {0};
+
+ ValueSource vs = new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ valueSourceCallCount[0]++;
+ return ctx.get(expression);
+ }
+ };
+
+ RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
+ interpolator.setCacheAnswers(true);
+ interpolator.addValueSource(vs);
+
+ // First interpolation
+ String result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+ assertEquals("value-value-value-value", result);
+ assertEquals(1, valueSourceCallCount[0]);
+
+ // Second interpolation - cache should be used, no new ValueSource calls
+ result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+ assertEquals("value-value-value-value", result);
+ assertEquals(1, valueSourceCallCount[0]); // still 1, cache was used
+
+ // Third interpolation with different expression that also uses cached value
+ result = interpolator.interpolate("The value is ${key}");
+ assertEquals("The value is value", result);
+ assertEquals(1, valueSourceCallCount[0]); // still 1, cache was used
+ }
+
+ @Test
+ void cacheAnswersFalse() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
+ ctx.put("key", "value");
+
+ final int[] valueSourceCallCount = {0};
+
+ ValueSource vs = new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ valueSourceCallCount[0]++;
+ return ctx.get(expression);
+ }
+ };
+
+ RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
+ interpolator.addValueSource(vs);
+
+ // First interpolation
+ String result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+ assertEquals("value-value-value-value", result);
+ assertEquals(1, valueSourceCallCount[0]);
+
+ // Second interpolation - without caching, ValueSource is called again
+ result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+ assertEquals("value-value-value-value", result);
+ assertEquals(2, valueSourceCallCount[0]); // incremented to 2
+
+ // Third interpolation
+ result = interpolator.interpolate("The value is ${key}");
+ assertEquals("The value is value", result);
+ assertEquals(3, valueSourceCallCount[0]); // incremented to 3
+ }
}
=====================================
src/test/java/org/codehaus/plexus/interpolation/StringSearchInterpolatorTest.java
=====================================
@@ -1,22 +1,5 @@
package org.codehaus.plexus.interpolation;
-/*
- * Copyright 2001-2008 Codehaus Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -34,12 +17,12 @@ import static org.junit.jupiter.api.Assertions.fail;
public class StringSearchInterpolatorTest {
@BeforeEach
- public void setUp() {
+ void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- public void testLongDelimitersInContext() throws InterpolationException {
+ void longDelimitersInContext() throws Exception {
String src = "This is a <expression>test.label</expression> for long delimiters in context.";
String result = "This is a test for long delimiters in context.";
@@ -53,7 +36,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testLongDelimitersWithNoStartContext() throws InterpolationException {
+ void longDelimitersWithNoStartContext() throws Exception {
String src = "<expression>test.label</expression> for long delimiters in context.";
String result = "test for long delimiters in context.";
@@ -67,7 +50,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testLongDelimitersWithNoEndContext() throws InterpolationException {
+ void longDelimitersWithNoEndContext() throws Exception {
String src = "This is a <expression>test.label</expression>";
String result = "This is a test";
@@ -81,7 +64,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testLongDelimitersWithNoContext() throws InterpolationException {
+ void longDelimitersWithNoContext() throws Exception {
String src = "<expression>test.label</expression>";
String result = "test";
@@ -95,7 +78,31 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testSimpleSubstitution() throws InterpolationException {
+ void longDelimitersPassedToValueSource() throws Exception {
+ String src = "<expression>test</expression>";
+
+ StringSearchInterpolator interpolator = new StringSearchInterpolator("<expression>", "</expression>");
+ interpolator.addValueSource(new AbstractValueSource(false) {
+
+ @Override
+ public Object getValue(String expression, String expressionStartDelimiter, String expressionEndDelimiter) {
+ assertEquals("<expression>", expressionStartDelimiter);
+ assertEquals("</expression>", expressionEndDelimiter);
+ return expression;
+ }
+
+ @Override
+ public Object getValue(String expression) {
+ fail("This method is not supposed to be called");
+ return null;
+ }
+ });
+
+ assertEquals("test", interpolator.interpolate(src));
+ }
+
+ @Test
+ void simpleSubstitution() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -106,7 +113,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testSimpleSubstitution_TwoExpressions() throws InterpolationException {
+ void simpleSubstitutionTwoExpressions() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
@@ -118,7 +125,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testBrokenExpression_LeaveItAlone() throws InterpolationException {
+ void brokenExpressionLeaveItAlone() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -129,7 +136,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testShouldFailOnExpressionCycle() {
+ void shouldFailOnExpressionCycle() {
Properties props = new Properties();
props.setProperty("key1", "${key2}");
props.setProperty("key2", "${key1}");
@@ -147,7 +154,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testShouldResolveByUsingObject_List_Map() throws InterpolationException {
+ void shouldResolveByUsingObjectListMap() throws Exception {
StringSearchInterpolator rbi = new StringSearchInterpolator();
rbi.addValueSource(new ObjectBasedValueSource(this));
String result =
@@ -157,10 +164,10 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testShouldResolveByContextValue() throws InterpolationException {
+ void shouldResolveByContextValue() throws Exception {
StringSearchInterpolator rbi = new StringSearchInterpolator();
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
@@ -171,14 +178,12 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testShouldResolveByEnvar() throws IOException, InterpolationException {
- OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
- public Map<String, String> getEnvMap() {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("SOME_ENV", "variable");
- map.put("OTHER_ENV", "other variable");
- return map;
- }
+ void shouldResolveByEnvar() throws Exception {
+ OperatingSystemUtils.setEnvVarSource(() -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("SOME_ENV", "variable");
+ map.put("OTHER_ENV", "other variable");
+ return map;
});
StringSearchInterpolator rbi = new StringSearchInterpolator();
@@ -191,19 +196,15 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException {
+ void usePostProcessorDoesNotChangeValue() throws Exception {
StringSearchInterpolator rbi = new StringSearchInterpolator();
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("test.var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor(new InterpolationPostProcessor() {
- public Object execute(String expression, Object value) {
- return null;
- }
- });
+ rbi.addPostProcessor((expression, value) -> null);
String result = rbi.interpolate("this is a ${test.var}");
@@ -211,20 +212,16 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testUsePostProcessor_ChangesValue() throws InterpolationException {
+ void usePostProcessorChangesValue() throws Exception {
StringSearchInterpolator rbi = new StringSearchInterpolator();
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("test.var", "testVar");
rbi.addValueSource(new MapBasedValueSource(context));
- rbi.addPostProcessor(new InterpolationPostProcessor() {
- public Object execute(String expression, Object value) {
- return value + "2";
- }
- });
+ rbi.addPostProcessor((expression, value) -> value + "2");
String result = rbi.interpolate("this is a ${test.var}");
@@ -232,7 +229,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException {
+ void simpleSubstitutionWithDefinedExpr() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -243,7 +240,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testEscape() throws InterpolationException {
+ void escape() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -257,7 +254,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testEscapeWithLongEscapeStr() throws InterpolationException {
+ void escapeWithLongEscapeStr() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -271,7 +268,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testEscapeWithLongEscapeStrAtStart() throws InterpolationException {
+ void escapeWithLongEscapeStrAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -285,7 +282,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException {
+ void notEscapeWithLongEscapeStrAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -299,7 +296,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testEscapeNotFailWithNullEscapeStr() throws InterpolationException {
+ void escapeNotFailWithNullEscapeStr() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -313,7 +310,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testOnlyEscapeExprAtStart() throws InterpolationException {
+ void onlyEscapeExprAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -327,7 +324,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testNotEscapeExprAtStart() throws InterpolationException {
+ void notEscapeExprAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -341,7 +338,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testEscapeExprAtStart() throws InterpolationException {
+ void escapeExprAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -355,7 +352,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testNPEFree() throws InterpolationException {
+ void npeFree() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -369,7 +366,7 @@ public class StringSearchInterpolatorTest {
}
@Test
- public void testInterruptedInterpolate() throws InterpolationException {
+ void interruptedInterpolate() throws Exception {
Interpolator interpolator = new StringSearchInterpolator();
RecursionInterceptor recursionInterceptor = new SimpleRecursionInterceptor();
final boolean[] error = new boolean[] {false};
@@ -406,6 +403,77 @@ public class StringSearchInterpolatorTest {
"should not believe there is a cycle here");
}
+ @Test
+ void cacheAnswersTrue() throws Exception {
+ Properties p = new Properties();
+ p.setProperty("key", "value");
+
+ class CountingStringSearchInterpolator extends StringSearchInterpolator {
+ private int existingCallCount;
+
+ @Override
+ protected Object getExistingAnswer(String key) {
+ Object value = super.getExistingAnswer(key);
+ if (value != null) {
+ ++existingCallCount;
+ }
+ return value;
+ }
+
+ public int getExistingCallCount() {
+ return existingCallCount;
+ }
+ }
+
+ CountingStringSearchInterpolator interpolator = new CountingStringSearchInterpolator();
+ interpolator.setCacheAnswers(true);
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
+
+ String result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+
+ assertEquals("value-value-value-value", result);
+ // first value is interpolated and saved, then the 3 next answers came from existing answer Map
+ assertEquals(3, interpolator.getExistingCallCount());
+
+ // answers are preserved between calls:
+ result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+ assertEquals("value-value-value-value", result);
+ // 3 from the first call to interpolate(), plus 4 from second call
+ assertEquals(3 + 4, interpolator.getExistingCallCount());
+ }
+
+ @Test
+ void cacheAnswersFalse() throws Exception {
+ Properties p = new Properties();
+ p.setProperty("key", "value");
+
+ class CountingStringSearchInterpolator extends StringSearchInterpolator {
+ private int existingCallCount;
+
+ @Override
+ protected Object getExistingAnswer(String key) {
+ Object value = super.getExistingAnswer(key);
+ if (value != null) {
+ ++existingCallCount;
+ }
+ return value;
+ }
+
+ public int getExistingCallCount() {
+ return existingCallCount;
+ }
+ }
+
+ CountingStringSearchInterpolator interpolator = new CountingStringSearchInterpolator();
+ interpolator.addValueSource(new PropertiesBasedValueSource(p));
+
+ String result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+
+ assertEquals("value-value-value-value", result);
+ // all values are interpolated each time
+ assertEquals(0, interpolator.getExistingCallCount());
+ }
+
public String getVar() {
return "testVar";
}
@@ -419,7 +487,7 @@ public class StringSearchInterpolatorTest {
}
public List<Person> getList() {
- List<Person> list = new ArrayList<Person>();
+ List<Person> list = new ArrayList<>();
list.add(new Person("Gabriel"));
list.add(new Person("testIndexedWithList"));
list.add(new Person("Daniela"));
@@ -427,13 +495,13 @@ public class StringSearchInterpolatorTest {
}
public Map<String, Person> getMap() {
- Map<String, Person> map = new HashMap<String, StringSearchInterpolatorTest.Person>();
+ Map<String, Person> map = new HashMap<>();
map.put("Key with spaces", new Person("testMap"));
return map;
}
public static class Person {
- private String name;
+ private final String name;
public Person(String name) {
this.name = name;
=====================================
src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java
=====================================
@@ -16,9 +16,7 @@ package org.codehaus.plexus.interpolation.fixed;
* limitations under the License.
*/
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Map;
import org.codehaus.plexus.interpolation.os.OperatingSystemUtils;
import org.junit.jupiter.api.BeforeEach;
@@ -28,21 +26,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
-public class EnvarBasedValueSourceTest {
+class EnvarBasedValueSourceTest {
@BeforeEach
- public void setUp() {
+ void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- void testNoArgConstructorIsCaseSensitive() throws IOException {
- OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
- public Map<String, String> getEnvMap() {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("aVariable", "variable");
- return map;
- }
+ void noArgConstructorIsCaseSensitive() throws Exception {
+ OperatingSystemUtils.setEnvVarSource(() -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("aVariable", "variable");
+ return map;
});
EnvarBasedValueSource source = new EnvarBasedValueSource();
@@ -54,13 +50,11 @@ public class EnvarBasedValueSourceTest {
}
@Test
- void testCaseInsensitive() throws IOException {
- OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
- public Map<String, String> getEnvMap() {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("aVariable", "variable");
- return map;
- }
+ void caseInsensitive() throws Exception {
+ OperatingSystemUtils.setEnvVarSource(() -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("aVariable", "variable");
+ return map;
});
EnvarBasedValueSource source = new EnvarBasedValueSource(false);
@@ -72,7 +66,7 @@ public class EnvarBasedValueSourceTest {
}
@Test
- void testGetRealEnvironmentVariable() throws IOException {
+ void getRealEnvironmentVariable() throws Exception {
OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.DefaultEnvVarSource());
EnvarBasedValueSource source = new EnvarBasedValueSource();
=====================================
src/test/java/org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolatorTest.java
=====================================
@@ -15,7 +15,6 @@ package org.codehaus.plexus.interpolation.fixed;
* limitations under the License.
*/
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -23,7 +22,6 @@ import java.util.Map;
import java.util.Properties;
import org.codehaus.plexus.interpolation.FixedInterpolatorValueSource;
-import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.codehaus.plexus.interpolation.os.OperatingSystemUtils;
@@ -37,12 +35,12 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
public class FixedStringSearchInterpolatorTest {
@BeforeEach
- public void setUp() {
+ void setUp() {
EnvarBasedValueSource.resetStatics();
}
@Test
- void testLongDelimitersInContext() {
+ void longDelimitersInContext() {
String src = "This is a <expression>test.label</expression> for long delimiters in context.";
String result = "This is a test for long delimiters in context.";
@@ -56,7 +54,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testLongDelimitersWithNoStartContext() {
+ void longDelimitersWithNoStartContext() {
String src = "<expression>test.label</expression> for long delimiters in context.";
String result = "test for long delimiters in context.";
@@ -70,7 +68,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testLongDelimitersWithNoEndContext() {
+ void longDelimitersWithNoEndContext() {
String src = "This is a <expression>test.label</expression>";
String result = "This is a test";
@@ -84,7 +82,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testLongDelimitersWithNoContext() {
+ void longDelimitersWithNoContext() {
String src = "<expression>test.label</expression>";
String result = "test";
@@ -98,7 +96,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testSimpleSubstitution() {
+ void simpleSubstitution() {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -108,7 +106,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testSimpleSubstitution_TwoExpressions() {
+ void simpleSubstitutionTwoExpressions() {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
@@ -119,7 +117,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testBrokenExpression_LeaveItAlone() {
+ void brokenExpressionLeaveItAlone() {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -129,7 +127,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testShouldFailOnExpressionCycle() {
+ void shouldFailOnExpressionCycle() {
Properties props = new Properties();
props.setProperty("key1", "${key2}");
props.setProperty("key2", "${key1}");
@@ -143,7 +141,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testShouldResolveByUsingObject_List_Map() throws InterpolationException {
+ void shouldResolveByUsingObjectListMap() throws Exception {
FixedStringSearchInterpolator rbi = create(new ObjectBasedValueSource(this));
String result =
rbi.interpolate("this is a ${var} ${list[1].name} ${anArray[2].name} ${map(Key with spaces).name}");
@@ -152,9 +150,9 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testShouldResolveByContextValue() throws InterpolationException {
+ void shouldResolveByContextValue() throws Exception {
- Map<String, String> context = new HashMap<String, String>();
+ Map<String, String> context = new HashMap<>();
context.put("var", "testVar");
FixedStringSearchInterpolator rbi = create(new MapBasedValueSource(context));
@@ -165,14 +163,12 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testShouldResolveByEnvar() throws IOException, InterpolationException {
- OperatingSystemUtils.setEnvVarSource(new OperatingSystemUtils.EnvVarSource() {
- public Map<String, String> getEnvMap() {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("SOME_ENV", "variable");
- map.put("OTHER_ENV", "other variable");
- return map;
- }
+ void shouldResolveByEnvar() throws Exception {
+ OperatingSystemUtils.setEnvVarSource(() -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("SOME_ENV", "variable");
+ map.put("OTHER_ENV", "other variable");
+ return map;
});
FixedStringSearchInterpolator rbi = create(new EnvarBasedValueSource(false));
@@ -183,16 +179,12 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testUsePostProcessor_DoesNotChangeValue() throws InterpolationException {
+ void usePostProcessorDoesNotChangeValue() throws Exception {
- Map<String, String> context = new HashMap<String, String>();
+ Map<String, String> context = new HashMap<>();
context.put("test.var", "testVar");
- final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor() {
- public Object execute(String expression, Object value) {
- return null;
- }
- };
+ InterpolationPostProcessor postProcessor = (expression, value) -> null;
FixedStringSearchInterpolator rbi =
create(new MapBasedValueSource(context)).withPostProcessor(postProcessor);
@@ -202,16 +194,12 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testUsePostProcessor_ChangesValue() throws InterpolationException {
+ void usePostProcessorChangesValue() throws Exception {
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("test.var", "testVar");
- final InterpolationPostProcessor postProcessor = new InterpolationPostProcessor() {
- public Object execute(String expression, Object value) {
- return value + "2";
- }
- };
+ InterpolationPostProcessor postProcessor = (expression, value) -> value + "2";
FixedStringSearchInterpolator rbi =
create(new MapBasedValueSource(context)).withPostProcessor(postProcessor);
@@ -222,7 +210,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testSimpleSubstitutionWithDefinedExpr() throws InterpolationException {
+ void simpleSubstitutionWithDefinedExpr() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -232,7 +220,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testEscape() throws InterpolationException {
+ void escape() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -246,7 +234,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testEscapeWithLongEscapeStr() throws InterpolationException {
+ void escapeWithLongEscapeStr() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -260,7 +248,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testEscapeWithLongEscapeStrAtStart() throws InterpolationException {
+ void escapeWithLongEscapeStrAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -274,7 +262,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testNotEscapeWithLongEscapeStrAtStart() throws InterpolationException {
+ void notEscapeWithLongEscapeStrAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -288,7 +276,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testEscapeNotFailWithNullEscapeStr() throws InterpolationException {
+ void escapeNotFailWithNullEscapeStr() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -302,7 +290,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testOnlyEscapeExprAtStart() throws InterpolationException {
+ void onlyEscapeExprAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -316,7 +304,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testNotEscapeExprAtStart() throws InterpolationException {
+ void notEscapeExprAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -330,7 +318,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testEscapeExprAtStart() throws InterpolationException {
+ void escapeExprAtStart() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -344,7 +332,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testNPEFree() throws InterpolationException {
+ void npeFree() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
@@ -358,18 +346,16 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testInterruptedInterpolate() throws InterpolationException {
+ void interruptedInterpolate() throws Exception {
final boolean[] error = new boolean[] {false};
- FixedValueSource valueSource = new FixedValueSource() {
- public Object getValue(String expression, InterpolationState errorCollector) {
- if (expression.equals("key")) {
- if (error[0]) {
- throw new IllegalStateException("broken");
- }
- return "val";
- } else {
- return null;
+ FixedValueSource valueSource = (expression, errorCollector) -> {
+ if (expression.equals("key")) {
+ if (error[0]) {
+ throw new IllegalStateException("broken");
}
+ return "val";
+ } else {
+ return null;
}
};
@@ -400,7 +386,7 @@ public class FixedStringSearchInterpolatorTest {
}
public List<Person> getList() {
- List<Person> list = new ArrayList<Person>();
+ List<Person> list = new ArrayList<>();
list.add(new Person("Gabriel"));
list.add(new Person("testIndexedWithList"));
list.add(new Person("Daniela"));
@@ -408,13 +394,13 @@ public class FixedStringSearchInterpolatorTest {
}
public Map<String, Person> getMap() {
- Map<String, Person> map = new HashMap<String, Person>();
+ Map<String, Person> map = new HashMap<>();
map.put("Key with spaces", new Person("testMap"));
return map;
}
public static class Person {
- private String name;
+ private final String name;
public Person(String name) {
this.name = name;
@@ -426,7 +412,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testLinkedInterpolators() {
+ void linkedInterpolators() {
final String EXPR = "${test.label}AND${test2}";
final String EXPR2 = "${test.label}${test2.label}AND${test2}";
@@ -439,7 +425,7 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testDominance() {
+ void dominance() {
final String EXPR = "${test.label}AND${test2}";
final String EXPR2 = "${test.label}${test2.label}AND${test2}";
@@ -463,25 +449,21 @@ public class FixedStringSearchInterpolatorTest {
}
@Test
- void testCyclesWithLinked() {
- assertThrows(InterpolationCycleException.class, () -> {
- FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}"));
- FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}"));
- second.interpolate("${key2}");
- });
+ void cyclesWithLinked() {
+ FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}"));
+ FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}"));
+ assertThrows(InterpolationCycleException.class, () -> second.interpolate("${key2}"));
}
@Test
- void testCyclesWithLinked_betweenRootAndOther() {
- assertThrows(InterpolationCycleException.class, () -> {
- FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}"));
- FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}"));
- second.interpolate("${key1}");
- });
+ void cyclesWithLinkedBetweenRootAndOther() {
+ FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "${key2}"));
+ FixedStringSearchInterpolator second = create(first, properttyBasedValueSource("key2", "${key1}"));
+ assertThrows(InterpolationCycleException.class, () -> second.interpolate("${key1}"));
}
@Test
- void fixedInjectedIntoRegular() throws InterpolationException {
+ void fixedInjectedIntoRegular() throws Exception {
FixedStringSearchInterpolator first = create(properttyBasedValueSource("key1", "v1"));
Properties p = new Properties();
=====================================
src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReaderTest.java
=====================================
@@ -1,27 +1,19 @@
package org.codehaus.plexus.interpolation.multi;
/*
- * The MIT License
+ * Copyright 2001-2009 Codehaus Foundation.
*
- * Copyright (c) 2004, The Codehaus
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
import java.io.StringReader;
@@ -46,14 +38,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* @author cstamas
*
*/
-public class MultiDelimiterInterpolatorFilterReaderTest {
+class MultiDelimiterInterpolatorFilterReaderTest {
/*
* Added and commented by jdcasey at 03-Feb-2005 because it is a bug in the InterpolationFilterReader.
* kenneyw at 15-04-2005 fixed the bug.
*/
@Test
- public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "TestValue");
String testStr = "This is a ${test";
@@ -65,8 +57,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
* kenneyw at 14-04-2005 Added test to check above fix.
*/
@Test
- public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateExpressionWithMissingEndToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "TestValue");
String testStr = "This is a ${test, really";
@@ -75,8 +67,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testShouldNotInterpolateWithMalformedStartToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateWithMalformedStartToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "testValue");
String foo = "This is a $!test} again";
@@ -85,8 +77,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testShouldNotInterpolateWithMalformedEndToken() throws Exception {
- Map m = new HashMap();
+ void shouldNotInterpolateWithMalformedEndToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("test", "testValue");
String foo = "This is a ${test!} again";
@@ -95,8 +87,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
- Map m = new HashMap();
+ void defaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -106,8 +98,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
- Map m = new HashMap();
+ void defaultInterpolationWithInterpolatedValueAtEnd() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -117,8 +109,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
- Map m = new HashMap();
+ void interpolationWithInterpolatedValueAtEndWithCustomToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -128,8 +120,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
- Map m = new HashMap();
+ void interpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -139,8 +131,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testEscape() throws Exception {
- Map m = new HashMap();
+ void escape() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -150,8 +142,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testEscapeAtStart() throws Exception {
- Map m = new HashMap();
+ void escapeAtStart() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -161,8 +153,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testEscapeOnlyAtStart() throws Exception {
- Map m = new HashMap();
+ void escapeOnlyAtStart() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -173,8 +165,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testEscapeOnlyAtStartDefaultToken() throws Exception {
- Map m = new HashMap();
+ void escapeOnlyAtStartDefaultToken() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("noun", "asshole");
@@ -185,15 +177,15 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
- List prefixes = new ArrayList();
+ void shouldDetectRecursiveExpressionPassingThroughTwoPrefixes() throws Exception {
+ List<String> prefixes = new ArrayList<>();
prefixes.add("prefix1");
prefixes.add("prefix2");
RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("name", "${prefix2.name}");
String input = "${prefix1.name}";
@@ -217,14 +209,14 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testShouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
- List prefixes = new ArrayList();
+ void shouldDetectRecursiveExpressionWithPrefixAndWithout() throws Exception {
+ List<String> prefixes = new ArrayList<>();
prefixes.add("prefix1");
RecursionInterceptor ri = new PrefixAwareRecursionInterceptor(prefixes, false);
- Map context = new HashMap();
+ Map<String, String> context = new HashMap<>();
context.put("name", "${prefix1.name}");
String input = "${name}";
@@ -248,8 +240,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testInterpolationWithMultipleTokenTypes() throws Exception {
- Map m = new HashMap();
+ void interpolationWithMultipleTokenTypes() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("otherName", "@name@");
@@ -259,8 +251,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
}
@Test
- public void testInterpolationWithMultipleTokenTypes_ReversedOrdering() throws Exception {
- Map m = new HashMap();
+ void interpolationWithMultipleTokenTypesReversedOrdering() throws Exception {
+ Map<String, String> m = new HashMap<>();
m.put("name", "jason");
m.put("otherName", "${name}");
@@ -273,11 +265,11 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
//
// ----------------------------------------------------------------------
- private String interpolate(String input, Map context) throws Exception {
+ private String interpolate(String input, Map<String, String> context) throws Exception {
return interpolate(input, context, null);
}
- private String interpolate(String input, Map context, String escapeStr) throws Exception {
+ private String interpolate(String input, Map<String, String> context, String escapeStr) throws Exception {
Interpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource(new MapBasedValueSource(context));
@@ -298,7 +290,8 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
return buf.toString();
}
- private String interpolate(String input, Map context, String beginToken, String endToken) throws Exception {
+ private String interpolate(String input, Map<String, String> context, String beginToken, String endToken)
+ throws Exception {
StringSearchInterpolator interpolator = new StringSearchInterpolator(beginToken, endToken);
interpolator.addValueSource(new MapBasedValueSource(context));
@@ -319,7 +312,7 @@ public class MultiDelimiterInterpolatorFilterReaderTest {
return buf.toString();
}
- private String interpolateMulti(String input, Map context, String[] specs) throws Exception {
+ private String interpolateMulti(String input, Map<String, String> context, String[] specs) throws Exception {
MultiDelimiterStringSearchInterpolator interp = new MultiDelimiterStringSearchInterpolator();
interp.addValueSource(new MapBasedValueSource(context));
=====================================
src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java
=====================================
@@ -19,18 +19,19 @@ package org.codehaus.plexus.interpolation.multi;
import java.util.HashMap;
import java.util.Map;
-import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.AbstractValueSource;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.ValueSource;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
-public class MultiDelimiterStringSearchInterpolatorTest {
+class MultiDelimiterStringSearchInterpolatorTest {
@Test
- public void testInterpolationWithDifferentDelimiters() throws InterpolationException {
- Map ctx = new HashMap();
+ void interpolationWithDifferentDelimiters() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
ctx.put("name", "User");
ctx.put("otherName", "@name@");
@@ -47,9 +48,8 @@ public class MultiDelimiterStringSearchInterpolatorTest {
}
@Test
- public void testSuccessiveInterpolationWithDifferentDelimiters_ReversedDelimiterSequence()
- throws InterpolationException {
- Map ctx = new HashMap();
+ void successiveInterpolationWithDifferentDelimitersReversedDelimiterSequence() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
ctx.put("name", "User");
ctx.put("otherName", "${name}");
@@ -66,8 +66,8 @@ public class MultiDelimiterStringSearchInterpolatorTest {
}
@Test
- public void testInterpolationWithMultipleEscapes() throws InterpolationException {
- Map ctx = new HashMap();
+ void interpolationWithMultipleEscapes() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
ctx.put("name", "User");
ctx.put("otherName", "##${first} and #${last}");
@@ -84,8 +84,8 @@ public class MultiDelimiterStringSearchInterpolatorTest {
}
@Test
- public void testInterpolationWithMultipleEscapes2() throws InterpolationException {
- Map ctx = new HashMap();
+ void interpolationWithMultipleEscapes2() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
ctx.put("name", "User");
ctx.put("otherName", "#${first} and ##${last}");
@@ -102,8 +102,8 @@ public class MultiDelimiterStringSearchInterpolatorTest {
}
@Test
- public void testInterpolationWithMultipleEscapes3() throws InterpolationException {
- Map ctx = new HashMap();
+ void interpolationWithMultipleEscapes3() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
ctx.put("name", "User");
ctx.put("last", "beer");
ctx.put("otherName", "###${first} and ##${second} and ${last}");
@@ -119,4 +119,87 @@ public class MultiDelimiterStringSearchInterpolatorTest {
assertEquals("##${first} and #${second} and beer", result);
}
+
+ @Test
+ void delimitersPassedToValueSource() throws Exception {
+ ValueSource vs = new AbstractValueSource(false) {
+
+ @Override
+ public Object getValue(String expression, String expressionStartDelimiter, String expressionEndDelimiter) {
+ assertEquals("#(", expressionStartDelimiter);
+ assertEquals(")", expressionEndDelimiter);
+ return expression;
+ }
+
+ @Override
+ public Object getValue(String expression) {
+ fail("This method is not supposed to be called");
+ return null;
+ }
+ };
+ MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator() //
+ .withValueSource(vs) //
+ .escapeString("#");
+ interpolator.addDelimiterSpec("#(*)");
+
+ assertEquals("test", interpolator.interpolate("#(test)"));
+ }
+
+ @Test
+ void cacheAnswersTrue() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
+ ctx.put("key", "value");
+
+ final int[] valueSourceCallCount = {0};
+
+ ValueSource vs = new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ valueSourceCallCount[0]++;
+ return ctx.get(expression);
+ }
+ };
+
+ MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator();
+ interpolator.setCacheAnswers(true);
+ interpolator.addValueSource(vs);
+
+ String result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+
+ assertEquals("value-value-value-value", result);
+ // first value is interpolated and saved, then the 3 next answers came from existing answer Map
+ assertEquals(1, valueSourceCallCount[0]);
+
+ // answers are preserved between calls:
+ result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+ assertEquals("value-value-value-value", result);
+ // still 1 from first call as cache is preserved
+ assertEquals(1, valueSourceCallCount[0]);
+ }
+
+ @Test
+ void cacheAnswersFalse() throws Exception {
+ Map<String, String> ctx = new HashMap<>();
+ ctx.put("key", "value");
+
+ final int[] valueSourceCallCount = {0};
+
+ ValueSource vs = new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ valueSourceCallCount[0]++;
+ return ctx.get(expression);
+ }
+ };
+
+ MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator();
+ interpolator.addValueSource(vs);
+
+ String result = interpolator.interpolate("${key}-${key}-${key}-${key}");
+
+ assertEquals("value-value-value-value", result);
+ // Without caching, expressions are evaluated multiple times due to multi-pass resolution
+ // In this case: 4 expressions evaluated in 2 passes = 8 calls
+ assertEquals(8, valueSourceCallCount[0]);
+ }
}
=====================================
src/test/java/org/codehaus/plexus/interpolation/object/FieldBasedObjectInterpolatorTest.java
=====================================
@@ -29,10 +29,10 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class FieldBasedObjectInterpolatorTest {
+class FieldBasedObjectInterpolatorTest {
@Test
- public void testInterpolateStringArray() throws Exception {
+ void interpolateStringArray() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
@@ -49,7 +49,7 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithStringArrayField() throws Exception {
+ void interpolateObjectWithStringArrayField() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
@@ -68,12 +68,12 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithStringListField() throws Exception {
+ void interpolateObjectWithStringListField() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
- List<String> values = new ArrayList<String>();
+ List<String> values = new ArrayList<>();
values.add("${key}");
values.add("${key2}");
@@ -89,12 +89,12 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithStringListFieldAndOneLiteralValue() throws Exception {
+ void interpolateObjectWithStringListFieldAndOneLiteralValue() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
- List<String> values = new ArrayList<String>();
+ List<String> values = new ArrayList<>();
values.add("key");
values.add("${key2}");
@@ -110,12 +110,12 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithUnmodifiableStringListField() throws Exception {
+ void interpolateObjectWithUnmodifiableStringListField() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
- List values = Collections.unmodifiableList(Collections.singletonList("${key}"));
+ List<String> values = Collections.singletonList("${key}");
ObjectWithListField obj = new ObjectWithListField(values);
@@ -128,14 +128,14 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithStringArrayListField() throws Exception {
+ void interpolateObjectWithStringArrayListField() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
p.setProperty("key3", "value3");
p.setProperty("key4", "value4");
- List<String[]> values = new ArrayList<String[]>();
+ List<String[]> values = new ArrayList<>();
values.add(new String[] {"${key}", "${key2}"});
values.add(new String[] {"${key3}", "${key4}"});
@@ -153,12 +153,12 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithStringToStringMapField() throws Exception {
+ void interpolateObjectWithStringToStringMapField() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
- Map<String, String> values = new HashMap<String, String>();
+ Map<String, String> values = new HashMap<>();
values.put("key", "${key}");
values.put("key2", "${key2}");
@@ -174,12 +174,12 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue() throws Exception {
+ void interpolateObjectWithStringToStringMapFieldAndOneLiteralValue() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
- Map<String, String> values = new HashMap<String, String>();
+ Map<String, String> values = new HashMap<>();
values.put("key", "val");
values.put("key2", "${key2}");
@@ -195,12 +195,12 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithUnmodifiableStringToStringMapField() throws Exception {
+ void interpolateObjectWithUnmodifiableStringToStringMapField() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
- Map values = Collections.unmodifiableMap(Collections.singletonMap("key", "${key}"));
+ Map<String, String> values = Collections.singletonMap("key", "${key}");
ObjectWithMapField obj = new ObjectWithMapField(values);
@@ -213,14 +213,14 @@ public class FieldBasedObjectInterpolatorTest {
}
@Test
- public void testInterpolateObjectWithStringToStringArrayMapField() throws Exception {
+ void interpolateObjectWithStringToStringArrayMapField() throws Exception {
Properties p = new Properties();
p.setProperty("key", "value");
p.setProperty("key2", "value2");
p.setProperty("key3", "value3");
p.setProperty("key4", "value4");
- Map<String, String[]> values = new HashMap<String, String[]>();
+ Map<String, String[]> values = new HashMap<>();
values.put("key", new String[] {"${key}", "${key2}"});
values.put("key2", new String[] {"${key3}", "${key4}"});
=====================================
src/test/java/org/codehaus/plexus/interpolation/util/StringUtilsTest.java
=====================================
@@ -19,9 +19,9 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class StringUtilsTest {
+class StringUtilsTest {
@Test
- public void testCapitalizeFirstLetter() throws Exception {
+ void capitalizeFirstLetter() throws Exception {
assertEquals("Abc", StringUtils.capitalizeFirstLetter("abc"));
assertEquals("\u00cdce", StringUtils.capitalizeFirstLetter("\u00edce"));
assertEquals("X", StringUtils.capitalizeFirstLetter("x"));
View it on GitLab: https://salsa.debian.org/java-team/plexus-interpolation/-/compare/af32534b1b20919b81675041a9429121818ded09...89d7a785e4d1fa215f7873313d0b24c76950e2af
--
View it on GitLab: https://salsa.debian.org/java-team/plexus-interpolation/-/compare/af32534b1b20919b81675041a9429121818ded09...89d7a785e4d1fa215f7873313d0b24c76950e2af
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20261030/734d6b41/attachment.htm>
More information about the pkg-java-commits
mailing list