Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion patch-gen-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>patch-gen-parent</artifactId>
<groupId>org.jboss.as</groupId>
<version>2.0.2.Alpha1-SNAPSHOT</version>
<version>2.1.0.Alpha1-SNAPSHOT</version>
</parent>

<artifactId>patch-gen-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion patch-gen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jboss.as</groupId>
<artifactId>patch-gen-parent</artifactId>
<version>2.0.2.Alpha1-SNAPSHOT</version>
<version>2.1.0.Alpha1-SNAPSHOT</version>
</parent>

<artifactId>patch-gen</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ abstract class PatchBuilderWrapper extends PatchBuilder {


private FSPathElement optionalPaths = new FSPathElement("root");
private boolean skipNoConfigLayers = false;

protected PatchBuilderWrapper() {
//
Expand All @@ -65,6 +66,12 @@ void setOptionalPaths(Collection<OptionalPath> optionalPaths) {
}
}

public void setSkipNonConfiguredLayers(boolean skipNoConfigLayers) {
this.skipNoConfigLayers = skipNoConfigLayers;
}



abstract PatchElementBuilder modifyLayer(final String name, final boolean addOn);

/**
Expand Down Expand Up @@ -170,15 +177,19 @@ static void compare(final PatchBuilderWrapper builder, final Distribution origin
updatedLayer = null;
}
//
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
if (!builder.skipNoConfigLayers || elementBuilder != null) {
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
}
}

for (final String layer : updatedLayers) {
final Distribution.ProcessedLayer originalLayer = null;
final Distribution.ProcessedLayer updatedLayer = updated.getLayer(layer);
final PatchElementBuilder elementBuilder = builder.addLayer(layer);
//
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
if (!builder.skipNoConfigLayers || elementBuilder != null) {
compareLayer(layer, elementBuilder, originalLayer, updatedLayer, includeVersion);
}
}

// Compare add-ons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.jboss.as.patching.metadata.ContentItem;
import org.jboss.as.patching.metadata.Patch;
import org.jboss.as.patching.runner.ContentItemFilter;

/**
* Configuration for generating a patch.
Expand Down Expand Up @@ -117,6 +118,14 @@ public interface PatchConfig {
*/
Collection<OptionalPath> getOptionalPaths();

/**
* Returns whether we should skip checking the identities of the servers used to
* generate the diff.
*
* @return whether to skip checking the identities
*/
boolean isOverrideIdentity();

/**
* Create a {@link PatchBuilderWrapper} whose basic metadata matches what's configured in this object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/
class PatchConfigBuilder implements ContentItemFilter {


public static enum AffectsType {
UPDATED,
ORIGINAL,
Expand All @@ -66,6 +67,10 @@ public static enum AffectsType {
private Set<ContentItem> specifiedContent = new HashSet<ContentItem>();
private Map<String, PatchElementConfigBuilder> elements = new LinkedHashMap<String, PatchElementConfigBuilder>();
private List<OptionalPath> optionalPaths = Collections.emptyList();
private boolean skipNonConfiguredLayers;
private boolean overrideIdentity;
private ContentItemFilter contentItemFilter;


PatchConfigBuilder setPatchId(String patchId) {
this.patchId = patchId;
Expand Down Expand Up @@ -153,6 +158,22 @@ PatchConfigBuilder addOptionalPath(String path, String requires) {
return this;
}

public PatchConfigBuilder setSkipNonConfiguredLayers(boolean skipNonConfiguredLayers) {
this.skipNonConfiguredLayers = skipNonConfiguredLayers;
return this;
}

public PatchConfigBuilder setContentItemFilter(ContentItemFilter contentItemFilter) {
this.contentItemFilter = contentItemFilter;
return this;
}

public PatchConfigBuilder setOverrideIdentity(boolean overrideIdentity) {
this.overrideIdentity = overrideIdentity;
return this;
}


PatchConfig build() {
return new PatchConfigImpl(new ArrayList<PatchElementConfig>(elements.values()));
}
Expand Down Expand Up @@ -220,6 +241,11 @@ public Collection<OptionalPath> getOptionalPaths() {
return optionalPaths;
}

@Override
public boolean isOverrideIdentity() {
return overrideIdentity;
}

@Override
public PatchBuilderWrapper toPatchBuilder() {
final PatchBuilderWrapper wrapper = new PatchBuilderWrapper() {
Expand Down Expand Up @@ -250,6 +276,10 @@ PatchElementBuilder modifyLayer(String name, boolean addOn) {
wrapper.setDescription(description);
wrapper.setPatchId(patchId);
wrapper.setContentItemFilter(PatchConfigBuilder.this);
wrapper.setSkipNonConfiguredLayers(skipNonConfiguredLayers);
if (contentItemFilter != null) {
wrapper.setContentItemFilter(contentItemFilter);
}

return wrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public class PatchConfigXml {
static {
MAPPER.registerRootElement(new QName(Namespace.PATCH_1_0.getNamespace(), PatchConfigXml_1_0.Element.PATCH_CONFIG.name), INSTANCE);
MAPPER.registerRootElement(new QName(Namespace.PATCH_1_2.getNamespace(), PatchConfigXml_1_0.Element.PATCH_CONFIG.name), INSTANCE);
MAPPER.registerRootElement(new QName(Namespace.PATCH_1_3.getNamespace(), PatchConfigXml_1_0.Element.PATCH_CONFIG.name), INSTANCE);
}

enum Namespace {

PATCH_1_0("urn:jboss:patch-config:1.0"),
PATCH_1_2("urn:jboss:patch-config:1.2"),
PATCH_1_3("urn:jboss:patch-config:1.3"),
UNKNOWN(null);

private final String namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -46,6 +49,7 @@
import org.jboss.as.patching.metadata.Patch;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import org.projectodd.vdx.core.XMLStreamValidationException;

/**
* Parser for the 1.0 version of the patch-config xsd
Expand All @@ -61,6 +65,7 @@ enum Element {
BUNDLES("bundles"),
DESCRIPTION("description"),
ELEMENT("element"),
EXCEPTION("exception"),
GENERATE_BY_DIFF("generate-by-diff"),
IN_RUNTIME_USE("in-runtime-use"),
MISC_FILES("misc-files"),
Expand All @@ -71,6 +76,7 @@ enum Element {
PATCH_CONFIG("patch-config"),
PATH("path"),
REMOVED("removed"),
SKIP_MISC_FILES("skip-misc-files"),
SPECIFIED_CONTENT("specified-content"),
UPDATED("updated"),
UPGRADE("cumulative"),
Expand Down Expand Up @@ -108,8 +114,10 @@ enum Attribute {
NAME("name"),
PATCH_ID("patch-id"),
PATH("path"),
OVERRIDE_IDENTITY("override-identity"),
REQUIRES("requires"),
RESULTING_VERSION("resulting-version"),
SKIP_NON_CONFIGURED_LAYERS("skip-non-configured-layers"),
SLOT("slot"),
VALUE("value"),

Expand Down Expand Up @@ -368,6 +376,8 @@ private void parseCumulativePatchType(final XMLExtendedStreamReader reader, fina
String name = null;
String appliesTo = null;
String resulting = null;
boolean skipNonConfiguredLayers = false;
boolean overrideIdentity = false;

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

Expand All @@ -383,22 +393,48 @@ private void parseCumulativePatchType(final XMLExtendedStreamReader reader, fina
case APPLIES_TO_VERSION:
appliesTo = value;
break;
case OVERRIDE_IDENTITY:
overrideIdentity = Boolean.parseBoolean(value);
break;
case RESULTING_VERSION:
resulting = value;
break;
case SKIP_NON_CONFIGURED_LAYERS:
skipNonConfiguredLayers = Boolean.parseBoolean(value);
break;
default:
throw unexpectedAttribute(reader, i);
}
}

requireNoContent(reader);

if (!required.isEmpty()) {
throw missingRequired(reader, required);
}

if (overrideIdentity && (name == null || appliesTo == null || resulting == null)) {
String msg = String.format("When %s=\"true\", all of %s, %s and %s must be set",
Attribute.OVERRIDE_IDENTITY.name,
Attribute.NAME.name,
Attribute.APPLIES_TO_VERSION.name,
Attribute.RESULTING_VERSION.name);
throw new XMLStreamException(msg, reader.getLocation());
}

builder.setAppliesToName(name);
builder.setCumulativeType(appliesTo, resulting);
builder.setSkipNonConfiguredLayers(skipNonConfiguredLayers);
builder.setOverrideIdentity(overrideIdentity);

while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case SKIP_MISC_FILES:
parseSkipMiscFiles(reader, builder);
break;
default:
throw unexpectedElement(reader);
}
}

patchTypeConfigured = true;
}
Expand Down Expand Up @@ -675,4 +711,22 @@ private void parseOptionalPath(final XMLExtendedStreamReader reader, final Patch
builder.addOptionalPath(value, requires);
requireNoContent(reader);
}

private void parseSkipMiscFiles(final XMLExtendedStreamReader reader, final PatchConfigBuilder builder) throws XMLStreamException {
requireNoAttributes(reader);

List<String> exceptions = new ArrayList<>();
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case EXCEPTION:
exceptions.add(reader.getElementText());
break;
default:
throw unexpectedElement(reader);
}
}

builder.setContentItemFilter(SkipMiscFilesContentItemFilter.create(exceptions));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,19 @@ private void process() throws PatchingException, IOException, XMLStreamException
final Distribution base = Distribution.create(oldRoot, ignored);
final Distribution updated = Distribution.create(newRoot, ignored);

if (!base.getName().equals(updated.getName())) {
throw processingError("distribution names don't match, expected: %s, but was %s ", base.getName(), updated.getName());
}
//
if (patchConfig.getAppliesToProduct() != null && ! patchConfig.getAppliesToProduct().equals(base.getName())) {
throw processingError("patch target does not match, expected: %s, but was %s", patchConfig.getAppliesToProduct(), base.getName());
}
//
if (patchConfig.getAppliesToVersion() != null && ! patchConfig.getAppliesToVersion().equals(base.getVersion())) {
throw processingError("patch target version does not match, expected: %s, but was %s", patchConfig.getAppliesToVersion(), base.getVersion());
if (!patchConfig.isOverrideIdentity()) {
// Only do this checks unless we are overriding the identity
if (!base.getName().equals(updated.getName())) {
throw processingError("distribution names don't match, expected: %s, but was %s ", base.getName(), updated.getName());
}
//
if (patchConfig.getAppliesToProduct() != null && ! patchConfig.getAppliesToProduct().equals(base.getName())) {
throw processingError("patch target does not match, expected: %s, but was %s", patchConfig.getAppliesToProduct(), base.getName());
}
//
if (patchConfig.getAppliesToVersion() != null && ! patchConfig.getAppliesToVersion().equals(base.getVersion())) {
throw processingError("patch target version does not match, expected: %s, but was %s", patchConfig.getAppliesToVersion(), base.getVersion());
}
}

// Build the patch metadata
Expand All @@ -151,7 +154,16 @@ private void process() throws PatchingException, IOException, XMLStreamException
if (base.getVersion().equals(updated.getVersion())) {
System.out.println("WARN: cumulative patch does not upgrade version " + base.getVersion());
}
builder.upgradeIdentity(base.getName(), base.getVersion(), updated.getVersion());
String name = base.getName();
String version = base.getVersion();
String toVersion = updated.getVersion();
if (patchConfig.isOverrideIdentity()) {
// The parser checked that all these are set
name = patchConfig.getAppliesToProduct();
version = patchConfig.getAppliesToVersion();
toVersion = patchConfig.getResultingVersion();
}
builder.upgradeIdentity(name, version, toVersion);
} else {
builder.oneOffPatchIdentity(base.getName(), base.getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jboss.as.patching.generator;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.jboss.as.patching.metadata.ContentItem;
import org.jboss.as.patching.metadata.ContentType;
import org.jboss.as.patching.runner.ContentItemFilter;

/**
* @author <a href="mailto:kabir.khan@jboss.com">Kabir Khan</a>
*/
public class SkipMiscFilesContentItemFilter implements ContentItemFilter {
private final List<Pattern> includedMiscFiles;

private SkipMiscFilesContentItemFilter(List<Pattern> includedMiscFiles) {
this.includedMiscFiles = includedMiscFiles;
}

static SkipMiscFilesContentItemFilter create(List<String> includedMiscFiles) {
List<Pattern> patterns = new ArrayList<>();
if (includedMiscFiles != null) {
for (String s : includedMiscFiles) {
patterns.add(Pattern.compile(s));
}
}
return new SkipMiscFilesContentItemFilter(patterns);
}

@Override
public boolean accepts(ContentItem item) {
if (item.getContentType() != ContentType.MISC) {
return true;
}
for (Pattern pattern : includedMiscFiles) {
if (pattern.matcher(item.getRelativePath()).matches()) {
return true;
}
}
return false;
}

}
Loading