@@ -353,7 +353,7 @@ static ModificationCondition getCondition(FSPathElement optionalPaths, Distribut
353353
354354 static List <String > matchOptionalPath (FSPathElement root , DistributionContentItem item ) {
355355 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 ());
357357 if (dir != null ) {
358358 root .linkTo (dir );
359359 return Collections .emptyList ();
@@ -367,7 +367,7 @@ static List<String> matchOptionalPath(FSPathElement root, DistributionContentIte
367367 if (root .children .isEmpty ()) {
368368 return path ;
369369 }
370- final FSPathElement dir = root .children . get (item .getName ());
370+ final FSPathElement dir = root .getMatchingElement (item .getName ());
371371 if (dir != null ) {
372372 switch (path .size ()) {
373373 case 0 :
@@ -386,6 +386,7 @@ static List<String> matchOptionalPath(FSPathElement root, DistributionContentIte
386386
387387 private static final class FSPathElement {
388388 private String name ;
389+ private boolean containsWildcard ;
389390 private Map <String , FSPathElement > children = Collections .emptyMap ();
390391 private String [] requires ;
391392
@@ -395,17 +396,35 @@ private static final class FSPathElement {
395396
396397 FSPathElement (FSPathElement parent , String name ) {
397398 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 ;
399401 if (parent != null ) {
400402 parent .addChild (this );
401403 }
402404 }
403405
404406 FSPathElement (FSPathElement linkTo ) {
407+ containsWildcard = linkTo .containsWildcard ;
405408 name = linkTo .name ;
406409 children = linkTo .children ;
407410 }
408411
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+
409428 FSPathElement addChild (String ... names ) {
410429 FSPathElement parent = this ;
411430 FSPathElement child = null ;
@@ -453,6 +472,7 @@ private void toString(StringBuilder buf, int depth) {
453472 }
454473
455474 void linkTo (FSPathElement dir ) {
475+ this .containsWildcard = dir .containsWildcard ;
456476 this .name = dir .name ;
457477 this .children = dir .children ;
458478 this .requires = dir .requires ;
0 commit comments