@@ -353,7 +353,7 @@ static ModificationCondition getCondition(FSPathElement optionalPaths, Distribut
353
353
354
354
static List <String > matchOptionalPath (FSPathElement root , DistributionContentItem item ) {
355
355
if (item .getParent () == null || item .getParent ().name == null ) {
356
- final FSPathElement dir = root .children . get (item .getName ());
356
+ final FSPathElement dir = root .getMatchingElement (item .getName ());
357
357
if (dir != null ) {
358
358
root .linkTo (dir );
359
359
return Collections .emptyList ();
@@ -367,7 +367,7 @@ static List<String> matchOptionalPath(FSPathElement root, DistributionContentIte
367
367
if (root .children .isEmpty ()) {
368
368
return path ;
369
369
}
370
- final FSPathElement dir = root .children . get (item .getName ());
370
+ final FSPathElement dir = root .getMatchingElement (item .getName ());
371
371
if (dir != null ) {
372
372
switch (path .size ()) {
373
373
case 0 :
@@ -386,6 +386,7 @@ static List<String> matchOptionalPath(FSPathElement root, DistributionContentIte
386
386
387
387
private static final class FSPathElement {
388
388
private String name ;
389
+ private boolean containsWildcard ;
389
390
private Map <String , FSPathElement > children = Collections .emptyMap ();
390
391
private String [] requires ;
391
392
@@ -395,17 +396,35 @@ private static final class FSPathElement {
395
396
396
397
FSPathElement (FSPathElement parent , String name ) {
397
398
assert name != null : "name is null" ;
398
- this .name = name ;
399
+ containsWildcard = name .charAt (name .length () - 1 ) == '*' ;
400
+ this .name = containsWildcard ? name .substring (0 , name .length () - 1 ) : name ;
399
401
if (parent != null ) {
400
402
parent .addChild (this );
401
403
}
402
404
}
403
405
404
406
FSPathElement (FSPathElement linkTo ) {
407
+ containsWildcard = linkTo .containsWildcard ;
405
408
name = linkTo .name ;
406
409
children = linkTo .children ;
407
410
}
408
411
412
+ FSPathElement getMatchingElement (String targetName ) {
413
+ for (FSPathElement child : children .values ()) {
414
+ if (child .matches (targetName )) {
415
+ return child ;
416
+ }
417
+ }
418
+ return null ;
419
+ }
420
+
421
+ boolean matches (String targetName ) {
422
+ if (containsWildcard ) {
423
+ return targetName .startsWith (name );
424
+ }
425
+ return name .equals (targetName );
426
+ }
427
+
409
428
FSPathElement addChild (String ... names ) {
410
429
FSPathElement parent = this ;
411
430
FSPathElement child = null ;
@@ -453,6 +472,7 @@ private void toString(StringBuilder buf, int depth) {
453
472
}
454
473
455
474
void linkTo (FSPathElement dir ) {
475
+ this .containsWildcard = dir .containsWildcard ;
456
476
this .name = dir .name ;
457
477
this .children = dir .children ;
458
478
this .requires = dir .requires ;
0 commit comments