Skip to content

Commit 3437e93

Browse files
committed
Merge branch 'master' of
https://github.com/codehaus-plexus/plexus-interpolation.git into Fix16 Conflicts: src/main/java/org/codehaus/plexus/interpolation/StringSearchInterpolator.java
2 parents 7b97695 + c8058ba commit 3437e93

File tree

2 files changed

+98
-90
lines changed

2 files changed

+98
-90
lines changed

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
</parent>
99

1010
<artifactId>plexus-interpolation</artifactId>
11-
<version>1.26-SNAPSHOT</version>
11+
<version>1.27-SNAPSHOT</version>
1212
<packaging>bundle</packaging>
1313

1414
<name>Plexus Interpolation API</name>
1515

1616
<scm>
17-
<connection>scm:git:git@github.com:codehaus-plexus/plexus-interpolation.git</connection>
18-
<developerConnection>scm:git:git@github.com:codehaus-plexus/plexus-interpolation.git</developerConnection>
17+
<connection>scm:git:https://github.com/codehaus-plexus/plexus-interpolation.git</connection>
18+
<developerConnection>scm:git:https://github.com/codehaus-plexus/plexus-interpolation.git</developerConnection>
1919
<url>http://github.com/codehaus-plexus/plexus-interpolation/tree/${project.scm.tag}/</url>
2020
<tag>master</tag>
2121
</scm>

src/main/java/org/codehaus/plexus/interpolation/StringSearchInterpolator.java

+95-87
Original file line numberDiff line numberDiff line change
@@ -138,141 +138,149 @@ private String interpolate( String input, RecursionInterceptor recursionIntercep
138138
// return empty String to prevent NPE too
139139
return "";
140140
}
141-
StringBuilder result = new StringBuilder( input.length() * 2 );
142141

143142
int startIdx;
144143
int endIdx = -1;
145-
while ( ( startIdx = input.indexOf( startExpr, endIdx + 1 ) ) > -1 )
144+
if ( ( startIdx = input.indexOf( startExpr, endIdx + 1 ) ) > -1 )
146145
{
147-
result.append( input, endIdx + 1, startIdx );
148-
149-
endIdx = input.indexOf( endExpr, startIdx + 1 );
150-
if ( endIdx < 0 )
151-
{
152-
break;
153-
}
154-
155-
final String wholeExpr = input.substring( startIdx, endIdx + endExpr.length() );
156-
String realExpr = wholeExpr.substring( startExpr.length(), wholeExpr.length() - endExpr.length() );
157-
158-
if ( startIdx >= 0 && escapeString != null && escapeString.length() > 0 )
159-
{
160-
int startEscapeIdx = startIdx == 0 ? 0 : startIdx - escapeString.length();
161-
if ( startEscapeIdx >= 0 )
146+
StringBuilder result = new StringBuilder( input.length() * 2 );
147+
do
162148
{
163-
String escape = input.substring( startEscapeIdx, startIdx );
164-
if ( escapeString.equals( escape ) )
165-
{
166-
result.append( wholeExpr );
167-
result.replace( startEscapeIdx, startEscapeIdx + escapeString.length(), "" );
168-
continue;
169-
}
170-
}
171-
}
149+
result.append( input, endIdx + 1, startIdx );
172150

173-
boolean resolved = false;
174-
if ( !unresolvable.contains( wholeExpr ) )
175-
{
176-
if ( realExpr.startsWith( "." ) )
151+
endIdx = input.indexOf( endExpr, startIdx + 1 );
152+
if ( endIdx < 0 )
177153
{
178-
realExpr = realExpr.substring( 1 );
154+
break;
179155
}
180156

181-
if ( recursionInterceptor.hasRecursiveExpression( realExpr ) )
182-
{
183-
throw new InterpolationCycleException( recursionInterceptor, realExpr, wholeExpr );
184-
}
157+
final String wholeExpr = input.substring( startIdx, endIdx + endExpr.length() );
158+
String realExpr = wholeExpr.substring( startExpr.length(), wholeExpr.length() - endExpr.length() );
185159

186-
recursionInterceptor.expressionResolutionStarted( realExpr );
187-
try
160+
if ( startIdx >= 0 && escapeString != null && escapeString.length() > 0 )
188161
{
189-
Object value = getExistingAnswer( realExpr );
190-
Object bestAnswer = null;
191-
192-
for ( ValueSource valueSource : valueSources )
162+
int startEscapeIdx = startIdx == 0 ? 0 : startIdx - escapeString.length();
163+
if ( startEscapeIdx >= 0 )
193164
{
194-
if ( value != null )
165+
String escape = input.substring( startEscapeIdx, startIdx );
166+
if ( escapeString.equals( escape ) )
195167
{
196-
break;
168+
result.append(wholeExpr);
169+
result.replace(startEscapeIdx, startEscapeIdx + escapeString.length(), "");
170+
continue;
197171
}
198-
value = valueSource.getValue( realExpr );
172+
}
173+
}
199174

200-
if ( value != null && value.toString().contains( wholeExpr ) )
201-
{
202-
bestAnswer = value;
203-
value = null;
204-
}
175+
boolean resolved = false;
176+
if ( !unresolvable.contains( wholeExpr ) )
177+
{
178+
if ( realExpr.startsWith( "." ) )
179+
{
180+
realExpr = realExpr.substring(1);
205181
}
206182

207-
// this is the simplest recursion check to catch exact recursion
208-
// (non synonym), and avoid the extra effort of more string
209-
// searching.
210-
if ( value == null && bestAnswer != null )
183+
if ( recursionInterceptor.hasRecursiveExpression( realExpr ) )
211184
{
212185
throw new InterpolationCycleException( recursionInterceptor, realExpr, wholeExpr );
213186
}
214187

215-
if ( value != null )
188+
recursionInterceptor.expressionResolutionStarted( realExpr );
189+
try
216190
{
217-
value = interpolate( String.valueOf( value ), recursionInterceptor, unresolvable );
191+
Object value = getExistingAnswer( realExpr );
192+
Object bestAnswer = null;
193+
194+
for ( ValueSource valueSource : valueSources )
195+
{
196+
if ( value != null )
197+
{
198+
break;
199+
}
200+
value = valueSource.getValue( realExpr );
201+
202+
if ( value != null && value.toString().contains( wholeExpr ) )
203+
{
204+
bestAnswer = value;
205+
value = null;
206+
}
207+
}
218208

219-
if ( postProcessors != null && !postProcessors.isEmpty() )
209+
// this is the simplest recursion check to catch exact recursion
210+
// (non synonym), and avoid the extra effort of more string
211+
// searching.
212+
if ( value == null && bestAnswer != null )
220213
{
221-
for ( InterpolationPostProcessor postProcessor : postProcessors )
214+
throw new InterpolationCycleException( recursionInterceptor, realExpr, wholeExpr );
215+
}
216+
217+
if ( value != null )
218+
{
219+
value = interpolate( String.valueOf(value), recursionInterceptor, unresolvable );
220+
221+
if ( postProcessors != null && !postProcessors.isEmpty() )
222222
{
223-
Object newVal = postProcessor.execute( realExpr, value );
224-
if ( newVal != null )
223+
for ( InterpolationPostProcessor postProcessor : postProcessors )
225224
{
226-
value = newVal;
227-
break;
225+
Object newVal = postProcessor.execute( realExpr, value );
226+
if ( newVal != null )
227+
{
228+
value = newVal;
229+
break;
230+
}
228231
}
229232
}
230-
}
231233

232-
// could use:
233-
// result = matcher.replaceFirst( stringValue );
234-
// but this could result in multiple lookups of stringValue, and replaceAll is not correct
235-
// behaviour
236-
result.append( String.valueOf( value ) );
237-
resolved = true;
234+
// could use:
235+
// result = matcher.replaceFirst( stringValue );
236+
// but this could result in multiple lookups of stringValue, and replaceAll is not correct
237+
// behaviour
238+
result.append( String.valueOf( value ) );
239+
resolved = true;
238240

239-
if (cacheAnswers)
241+
if (cacheAnswers)
242+
{
243+
existingAnswers.put( realExpr, value );
244+
}
245+
}
246+
else
240247
{
241-
existingAnswers.put( realExpr, value );
248+
unresolvable.add( wholeExpr );
242249
}
243250
}
244-
else
251+
finally
245252
{
246-
unresolvable.add( wholeExpr );
253+
recursionInterceptor.expressionResolutionFinished( realExpr );
247254
}
248255
}
249-
finally
256+
257+
if (!resolved)
250258
{
251-
recursionInterceptor.expressionResolutionFinished( realExpr );
259+
result.append( wholeExpr );
260+
}
261+
262+
if ( endIdx > -1 )
263+
{
264+
endIdx += endExpr.length() - 1;
252265
}
253266
}
267+
while ( ( startIdx = input.indexOf( startExpr, endIdx + 1 ) ) > -1);
254268

255-
if ( !resolved )
269+
if ( endIdx == -1 && startIdx > -1 )
256270
{
257-
result.append( wholeExpr );
271+
result.append( input, startIdx, input.length());
258272
}
259-
260-
if ( endIdx > -1 )
273+
else if ( endIdx < input.length() )
261274
{
262-
endIdx += endExpr.length() - 1;
275+
result.append( input, endIdx + 1, input.length() );
263276
}
264-
}
265277

266-
if ( endIdx == -1 && startIdx > -1 )
267-
{
268-
result.append( input, startIdx, input.length());
278+
return result.toString();
269279
}
270-
else if ( endIdx < input.length() )
280+
else
271281
{
272-
result.append( input, endIdx + 1, input.length() );
282+
return input;
273283
}
274-
275-
return result.toString();
276284
}
277285

278286
/**

0 commit comments

Comments
 (0)