Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Implements ${key:defaultValue} syntax where defaultValue is used when key is not found in value sources.

Changes

Core interpolation logic (StringSearchInterpolator, FixedStringSearchInterpolator, MultiDelimiterStringSearchInterpolator):

  • Parse expressions for : separator to extract key and default value
  • First attempt resolution of full expression (preserves backward compatibility for keys containing colons)
  • If unresolved and colon present, split and resolve key portion only
  • Use default value when key lookup fails
  • Added findMatchingEndExpr() to correctly handle nested expressions like ${missing:${fallback}}

Backward compatibility:

  • Keys containing colons (e.g., url:key) continue to work if they exist in value sources
  • Empty key syntax (e.g., ${:default}) remains unresolved

Usage

Properties p = new Properties();
p.setProperty("version", "1.0.0");
p.setProperty("fallback.url", "http://example.com");

StringSearchInterpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource(new PropertiesBasedValueSource(p));

// Uses existing value
interpolator.interpolate("${version:SNAPSHOT}");  // → "1.0.0"

// Uses default when missing
interpolator.interpolate("${missing:default}");  // → "default"

// Nested expressions in defaults
interpolator.interpolate("${url:${fallback.url}}");  // → "http://example.com"

// Colons in defaults (URLs, paths)
interpolator.interpolate("${repo:https://github.com/example/repo}");  // → "https://github.com/example/repo"
Original prompt

This section details on the original issue you should resolve

<issue_title>Default Values in Interpolation</issue_title>
<issue_description>The current interpolation logic does not seem to support default values, i.e. ${primary.value:fallback}, instead treating the entire primary.value:fallback as the property key. This may be conflating resource filtering with actual maven property expressions, but I do still think the ability to have default values would be of value. Is there another way to achieve this currently?</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Default Values in Interpolation Add default value support for interpolation expressions Nov 3, 2025
Copilot AI requested a review from slachiewicz November 3, 2025 15:51
Copilot finished work on behalf of slachiewicz November 3, 2025 15:51
@slachiewicz slachiewicz marked this pull request as ready for review November 3, 2025 16:00
@slachiewicz slachiewicz requested review from cstamas and gnodet November 3, 2025 16:10
@cstamas
Copy link
Member

cstamas commented Nov 3, 2025

I am unsure... Maven 4 does not use this anymore, as it has own interpolation service. Basically this component is actively used in Maven 3 realm only, and as such, unsure do we want to add new features to it?

@slachiewicz
Copy link
Member

Good point, let's reject this feature then.

@slachiewicz slachiewicz closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default Values in Interpolation

3 participants