Skip to content

Commit df73a38

Browse files
authored
Merge pull request #26 from kabir/eap-xp-fixes
Fixes to be able to support independent patch streams
2 parents 228261a + 62e2d8f commit df73a38

File tree

12 files changed

+543
-20
lines changed

12 files changed

+543
-20
lines changed

patch-gen-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>patch-gen-parent</artifactId>
88
<groupId>org.jboss.as</groupId>
9-
<version>2.0.2.Alpha1-SNAPSHOT</version>
9+
<version>2.1.0.Alpha1-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>patch-gen-maven-plugin</artifactId>

patch-gen/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.jboss.as</groupId>
99
<artifactId>patch-gen-parent</artifactId>
10-
<version>2.0.2.Alpha1-SNAPSHOT</version>
10+
<version>2.1.0.Alpha1-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>patch-gen</artifactId>

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ abstract class PatchBuilderWrapper extends PatchBuilder {
5050

5151

5252
private FSPathElement optionalPaths = new FSPathElement("root");
53+
private boolean skipNoConfigLayers = false;
5354

5455
protected PatchBuilderWrapper() {
5556
//
@@ -65,6 +66,12 @@ void setOptionalPaths(Collection<OptionalPath> optionalPaths) {
6566
}
6667
}
6768

69+
public void setSkipNonConfiguredLayers(boolean skipNoConfigLayers) {
70+
this.skipNoConfigLayers = skipNoConfigLayers;
71+
}
72+
73+
74+
6875
abstract PatchElementBuilder modifyLayer(final String name, final boolean addOn);
6976

7077
/**
@@ -170,15 +177,19 @@ static void compare(final PatchBuilderWrapper builder, final Distribution origin
170177
updatedLayer = null;
171178
}
172179
//
173-
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
180+
if (!builder.skipNoConfigLayers || elementBuilder != null) {
181+
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
182+
}
174183
}
175184

176185
for (final String layer : updatedLayers) {
177186
final Distribution.ProcessedLayer originalLayer = null;
178187
final Distribution.ProcessedLayer updatedLayer = updated.getLayer(layer);
179188
final PatchElementBuilder elementBuilder = builder.addLayer(layer);
180189
//
181-
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
190+
if (!builder.skipNoConfigLayers || elementBuilder != null) {
191+
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
192+
}
182193
}
183194

184195
// Compare add-ons

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.jboss.as.patching.metadata.ContentItem;
2929
import org.jboss.as.patching.metadata.Patch;
30+
import org.jboss.as.patching.runner.ContentItemFilter;
3031

3132
/**
3233
* Configuration for generating a patch.
@@ -117,6 +118,14 @@ public interface PatchConfig {
117118
*/
118119
Collection<OptionalPath> getOptionalPaths();
119120

121+
/**
122+
* Returns whether we should skip checking the identities of the servers used to
123+
* generate the diff.
124+
*
125+
* @return whether to skip checking the identities
126+
*/
127+
boolean isOverrideIdentity();
128+
120129
/**
121130
* Create a {@link PatchBuilderWrapper} whose basic metadata matches what's configured in this object.
122131
*

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
*/
4949
class PatchConfigBuilder implements ContentItemFilter {
5050

51+
5152
public static enum AffectsType {
5253
UPDATED,
5354
ORIGINAL,
@@ -66,6 +67,10 @@ public static enum AffectsType {
6667
private Set<ContentItem> specifiedContent = new HashSet<ContentItem>();
6768
private Map<String, PatchElementConfigBuilder> elements = new LinkedHashMap<String, PatchElementConfigBuilder>();
6869
private List<OptionalPath> optionalPaths = Collections.emptyList();
70+
private boolean skipNonConfiguredLayers;
71+
private boolean overrideIdentity;
72+
private ContentItemFilter contentItemFilter;
73+
6974

7075
PatchConfigBuilder setPatchId(String patchId) {
7176
this.patchId = patchId;
@@ -153,6 +158,22 @@ PatchConfigBuilder addOptionalPath(String path, String requires) {
153158
return this;
154159
}
155160

161+
public PatchConfigBuilder setSkipNonConfiguredLayers(boolean skipNonConfiguredLayers) {
162+
this.skipNonConfiguredLayers = skipNonConfiguredLayers;
163+
return this;
164+
}
165+
166+
public PatchConfigBuilder setContentItemFilter(ContentItemFilter contentItemFilter) {
167+
this.contentItemFilter = contentItemFilter;
168+
return this;
169+
}
170+
171+
public PatchConfigBuilder setOverrideIdentity(boolean overrideIdentity) {
172+
this.overrideIdentity = overrideIdentity;
173+
return this;
174+
}
175+
176+
156177
PatchConfig build() {
157178
return new PatchConfigImpl(new ArrayList<PatchElementConfig>(elements.values()));
158179
}
@@ -220,6 +241,11 @@ public Collection<OptionalPath> getOptionalPaths() {
220241
return optionalPaths;
221242
}
222243

244+
@Override
245+
public boolean isOverrideIdentity() {
246+
return overrideIdentity;
247+
}
248+
223249
@Override
224250
public PatchBuilderWrapper toPatchBuilder() {
225251
final PatchBuilderWrapper wrapper = new PatchBuilderWrapper() {
@@ -250,6 +276,10 @@ PatchElementBuilder modifyLayer(String name, boolean addOn) {
250276
wrapper.setDescription(description);
251277
wrapper.setPatchId(patchId);
252278
wrapper.setContentItemFilter(PatchConfigBuilder.this);
279+
wrapper.setSkipNonConfiguredLayers(skipNonConfiguredLayers);
280+
if (contentItemFilter != null) {
281+
wrapper.setContentItemFilter(contentItemFilter);
282+
}
253283

254284
return wrapper;
255285
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ public class PatchConfigXml {
4646
static {
4747
MAPPER.registerRootElement(new QName(Namespace.PATCH_1_0.getNamespace(), PatchConfigXml_1_0.Element.PATCH_CONFIG.name), INSTANCE);
4848
MAPPER.registerRootElement(new QName(Namespace.PATCH_1_2.getNamespace(), PatchConfigXml_1_0.Element.PATCH_CONFIG.name), INSTANCE);
49+
MAPPER.registerRootElement(new QName(Namespace.PATCH_1_3.getNamespace(), PatchConfigXml_1_0.Element.PATCH_CONFIG.name), INSTANCE);
4950
}
5051

5152
enum Namespace {
5253

5354
PATCH_1_0("urn:jboss:patch-config:1.0"),
5455
PATCH_1_2("urn:jboss:patch-config:1.2"),
56+
PATCH_1_3("urn:jboss:patch-config:1.3"),
5557
UNKNOWN(null);
5658

5759
private final String namespace;

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131

3232
import javax.xml.stream.XMLStreamConstants;
3333
import javax.xml.stream.XMLStreamException;
34+
35+
import java.util.ArrayList;
3436
import java.util.Arrays;
3537
import java.util.Collections;
3638
import java.util.EnumSet;
3739
import java.util.HashMap;
40+
import java.util.List;
3841
import java.util.Map;
3942
import java.util.Set;
4043

@@ -46,6 +49,7 @@
4649
import org.jboss.as.patching.metadata.Patch;
4750
import org.jboss.staxmapper.XMLElementReader;
4851
import org.jboss.staxmapper.XMLExtendedStreamReader;
52+
import org.projectodd.vdx.core.XMLStreamValidationException;
4953

5054
/**
5155
* Parser for the 1.0 version of the patch-config xsd
@@ -61,6 +65,7 @@ enum Element {
6165
BUNDLES("bundles"),
6266
DESCRIPTION("description"),
6367
ELEMENT("element"),
68+
EXCEPTION("exception"),
6469
GENERATE_BY_DIFF("generate-by-diff"),
6570
IN_RUNTIME_USE("in-runtime-use"),
6671
MISC_FILES("misc-files"),
@@ -71,6 +76,7 @@ enum Element {
7176
PATCH_CONFIG("patch-config"),
7277
PATH("path"),
7378
REMOVED("removed"),
79+
SKIP_MISC_FILES("skip-misc-files"),
7480
SPECIFIED_CONTENT("specified-content"),
7581
UPDATED("updated"),
7682
UPGRADE("cumulative"),
@@ -108,8 +114,10 @@ enum Attribute {
108114
NAME("name"),
109115
PATCH_ID("patch-id"),
110116
PATH("path"),
117+
OVERRIDE_IDENTITY("override-identity"),
111118
REQUIRES("requires"),
112119
RESULTING_VERSION("resulting-version"),
120+
SKIP_NON_CONFIGURED_LAYERS("skip-non-configured-layers"),
113121
SLOT("slot"),
114122
VALUE("value"),
115123

@@ -368,6 +376,8 @@ private void parseCumulativePatchType(final XMLExtendedStreamReader reader, fina
368376
String name = null;
369377
String appliesTo = null;
370378
String resulting = null;
379+
boolean skipNonConfiguredLayers = false;
380+
boolean overrideIdentity = false;
371381

372382
Set<Attribute> required = Collections.emptySet(); // EnumSet.of(Attribute.APPLIES_TO_VERSION, Attribute.RESULTING_VERSION);
373383

@@ -383,22 +393,48 @@ private void parseCumulativePatchType(final XMLExtendedStreamReader reader, fina
383393
case APPLIES_TO_VERSION:
384394
appliesTo = value;
385395
break;
396+
case OVERRIDE_IDENTITY:
397+
overrideIdentity = Boolean.parseBoolean(value);
398+
break;
386399
case RESULTING_VERSION:
387400
resulting = value;
388401
break;
402+
case SKIP_NON_CONFIGURED_LAYERS:
403+
skipNonConfiguredLayers = Boolean.parseBoolean(value);
404+
break;
389405
default:
390406
throw unexpectedAttribute(reader, i);
391407
}
392408
}
393409

394-
requireNoContent(reader);
395-
396410
if (!required.isEmpty()) {
397411
throw missingRequired(reader, required);
398412
}
399413

414+
if (overrideIdentity && (name == null || appliesTo == null || resulting == null)) {
415+
String msg = String.format("When %s=\"true\", all of %s, %s and %s must be set",
416+
Attribute.OVERRIDE_IDENTITY.name,
417+
Attribute.NAME.name,
418+
Attribute.APPLIES_TO_VERSION.name,
419+
Attribute.RESULTING_VERSION.name);
420+
throw new XMLStreamException(msg, reader.getLocation());
421+
}
422+
400423
builder.setAppliesToName(name);
401424
builder.setCumulativeType(appliesTo, resulting);
425+
builder.setSkipNonConfiguredLayers(skipNonConfiguredLayers);
426+
builder.setOverrideIdentity(overrideIdentity);
427+
428+
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
429+
final Element element = Element.forName(reader.getLocalName());
430+
switch (element) {
431+
case SKIP_MISC_FILES:
432+
parseSkipMiscFiles(reader, builder);
433+
break;
434+
default:
435+
throw unexpectedElement(reader);
436+
}
437+
}
402438

403439
patchTypeConfigured = true;
404440
}
@@ -675,4 +711,22 @@ private void parseOptionalPath(final XMLExtendedStreamReader reader, final Patch
675711
builder.addOptionalPath(value, requires);
676712
requireNoContent(reader);
677713
}
714+
715+
private void parseSkipMiscFiles(final XMLExtendedStreamReader reader, final PatchConfigBuilder builder) throws XMLStreamException {
716+
requireNoAttributes(reader);
717+
718+
List<String> exceptions = new ArrayList<>();
719+
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
720+
final Element element = Element.forName(reader.getLocalName());
721+
switch (element) {
722+
case EXCEPTION:
723+
exceptions.add(reader.getElementText());
724+
break;
725+
default:
726+
throw unexpectedElement(reader);
727+
}
728+
}
729+
730+
builder.setContentItemFilter(SkipMiscFilesContentItemFilter.create(exceptions));
731+
}
678732
}

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,19 @@ private void process() throws PatchingException, IOException, XMLStreamException
129129
final Distribution base = Distribution.create(oldRoot, ignored);
130130
final Distribution updated = Distribution.create(newRoot, ignored);
131131

132-
if (!base.getName().equals(updated.getName())) {
133-
throw processingError("distribution names don't match, expected: %s, but was %s ", base.getName(), updated.getName());
134-
}
135-
//
136-
if (patchConfig.getAppliesToProduct() != null && ! patchConfig.getAppliesToProduct().equals(base.getName())) {
137-
throw processingError("patch target does not match, expected: %s, but was %s", patchConfig.getAppliesToProduct(), base.getName());
138-
}
139-
//
140-
if (patchConfig.getAppliesToVersion() != null && ! patchConfig.getAppliesToVersion().equals(base.getVersion())) {
141-
throw processingError("patch target version does not match, expected: %s, but was %s", patchConfig.getAppliesToVersion(), base.getVersion());
132+
if (!patchConfig.isOverrideIdentity()) {
133+
// Only do this checks unless we are overriding the identity
134+
if (!base.getName().equals(updated.getName())) {
135+
throw processingError("distribution names don't match, expected: %s, but was %s ", base.getName(), updated.getName());
136+
}
137+
//
138+
if (patchConfig.getAppliesToProduct() != null && ! patchConfig.getAppliesToProduct().equals(base.getName())) {
139+
throw processingError("patch target does not match, expected: %s, but was %s", patchConfig.getAppliesToProduct(), base.getName());
140+
}
141+
//
142+
if (patchConfig.getAppliesToVersion() != null && ! patchConfig.getAppliesToVersion().equals(base.getVersion())) {
143+
throw processingError("patch target version does not match, expected: %s, but was %s", patchConfig.getAppliesToVersion(), base.getVersion());
144+
}
142145
}
143146

144147
// Build the patch metadata
@@ -151,7 +154,16 @@ private void process() throws PatchingException, IOException, XMLStreamException
151154
if (base.getVersion().equals(updated.getVersion())) {
152155
System.out.println("WARN: cumulative patch does not upgrade version " + base.getVersion());
153156
}
154-
builder.upgradeIdentity(base.getName(), base.getVersion(), updated.getVersion());
157+
String name = base.getName();
158+
String version = base.getVersion();
159+
String toVersion = updated.getVersion();
160+
if (patchConfig.isOverrideIdentity()) {
161+
// The parser checked that all these are set
162+
name = patchConfig.getAppliesToProduct();
163+
version = patchConfig.getAppliesToVersion();
164+
toVersion = patchConfig.getResultingVersion();
165+
}
166+
builder.upgradeIdentity(name, version, toVersion);
155167
} else {
156168
builder.oneOffPatchIdentity(base.getName(), base.getVersion());
157169
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.jboss.as.patching.generator;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.regex.Pattern;
6+
7+
import org.jboss.as.patching.metadata.ContentItem;
8+
import org.jboss.as.patching.metadata.ContentType;
9+
import org.jboss.as.patching.runner.ContentItemFilter;
10+
11+
/**
12+
* @author <a href="mailto:[email protected]">Kabir Khan</a>
13+
*/
14+
public class SkipMiscFilesContentItemFilter implements ContentItemFilter {
15+
private final List<Pattern> includedMiscFiles;
16+
17+
private SkipMiscFilesContentItemFilter(List<Pattern> includedMiscFiles) {
18+
this.includedMiscFiles = includedMiscFiles;
19+
}
20+
21+
static SkipMiscFilesContentItemFilter create(List<String> includedMiscFiles) {
22+
List<Pattern> patterns = new ArrayList<>();
23+
if (includedMiscFiles != null) {
24+
for (String s : includedMiscFiles) {
25+
patterns.add(Pattern.compile(s));
26+
}
27+
}
28+
return new SkipMiscFilesContentItemFilter(patterns);
29+
}
30+
31+
@Override
32+
public boolean accepts(ContentItem item) {
33+
if (item.getContentType() != ContentType.MISC) {
34+
return true;
35+
}
36+
for (Pattern pattern : includedMiscFiles) {
37+
if (pattern.matcher(item.getRelativePath()).matches()) {
38+
return true;
39+
}
40+
}
41+
return false;
42+
}
43+
44+
}

0 commit comments

Comments
 (0)