Skip to content

Commit 16e4f77

Browse files
authored
Merge pull request #19 from aloubyansky/optional-paths-template
Optional paths template
2 parents 344aea7 + 495e1dc commit 16e4f77

File tree

6 files changed

+190
-622
lines changed

6 files changed

+190
-622
lines changed

patch-gen-maven-plugin/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,19 @@
2020
<artifactId>patch-gen</artifactId>
2121
<version>${project.version}</version>
2222
</dependency>
23-
2423
<dependency>
2524
<groupId>org.apache.maven</groupId>
2625
<artifactId>maven-plugin-api</artifactId>
27-
<version>2.0</version>
2826
<scope>provided</scope>
2927
</dependency>
3028
<dependency>
3129
<groupId>org.apache.maven.plugin-tools</groupId>
3230
<artifactId>maven-plugin-annotations</artifactId>
33-
<version>3.2</version>
3431
<scope>provided</scope>
3532
</dependency>
3633
<dependency>
3734
<groupId>org.apache.maven.shared</groupId>
3835
<artifactId>maven-shared-utils</artifactId>
39-
<version>3.1.0</version>
4036
</dependency>
4137
</dependencies>
4238

patch-gen/src/main/java/org/jboss/as/patching/generator/PatchBuilderWrapper.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

patch-gen/src/main/java/org/jboss/as/patching/generator/PatchGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.jboss.as.patching.ZipUtils;
4242
import org.jboss.as.patching.logging.PatchLogger;
4343
import org.jboss.as.patching.metadata.Patch;
44+
import org.jboss.as.patching.metadata.PatchMerger;
4445
import org.jboss.as.version.ProductConfig;
4546
import org.jboss.modules.Module;
4647

0 commit comments

Comments
 (0)