This is an automated email from the ASF dual-hosted git repository. davidb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-content.git
commit eef39be1c2b7c67695b2fac990893aa388701497 Author: Dominik Suess <[email protected]> AuthorDate: Tue Oct 9 21:41:54 2018 +0200 SLING-7991 - adding extension to also bake a default start order during feature merging via feature property --- .../feature/extension/content/ContentHandler.java | 2 +- .../content/ContentOrderMergeProcessor.java | 67 ++++++++++++++++++++++ ...e.sling.feature.builder.FeatureExtensionHandler | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java index 8a84ddb..1a57118 100644 --- a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java +++ b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java @@ -98,7 +98,7 @@ public class ContentHandler implements ExtensionHandler { int order; // content-packages without explicit start-order to be installed last if (a.getMetadata().get(Artifact.KEY_START_ORDER) != null) { - order = Integer.valueOf(a.getStartOrder()); + order = a.getStartOrder(); } else { order = Integer.MAX_VALUE; } diff --git a/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java b/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java new file mode 100644 index 0000000..3cc9e97 --- /dev/null +++ b/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.feature.extension.content; + +import org.apache.sling.feature.Artifact; +import org.apache.sling.feature.Extension; +import org.apache.sling.feature.ExtensionType; +import org.apache.sling.feature.Feature; +import org.apache.sling.feature.FeatureConstants; +import org.apache.sling.feature.KeyValueMap; +import org.apache.sling.feature.builder.FeatureExtensionHandler; + +public class ContentOrderMergeProcessor implements FeatureExtensionHandler { + + private static final String DEFAULT_CONTENT_START_ORDER = "default.content.startorder"; + + /** + * Only postprocessing - relying on default merge strategy + * (non-Javadoc) + * @see org.apache.sling.feature.builder.FeatureExtensionHandler#canMerge(org.apache.sling.feature.Extension) + */ + @Override + public boolean canMerge(Extension extension) { + return false; + } + + /* + * Only postprocessing - relying on default merge strategy + * (non-Javadoc) + * @see org.apache.sling.feature.builder.FeatureExtensionHandler#merge(org.apache.sling.feature.Feature, org.apache.sling.feature.Feature, org.apache.sling.feature.Extension) + */ + @Override + public void merge(Feature target, Feature source, Extension extension) { + // not merging + } + + @Override + public void postProcess(Feature feature, Extension extension) { + if (extension.getType() == ExtensionType.ARTIFACTS + && extension.getName().equals(FeatureConstants.EXTENSION_NAME_CONTENT_PACKAGES)) { + String defaultOrder = feature.getVariables().get(DEFAULT_CONTENT_START_ORDER); + if (defaultOrder != null) { + for (Artifact a : extension.getArtifacts()) { + KeyValueMap kvm = a.getMetadata(); + if(kvm.get(Artifact.KEY_START_ORDER) == null) { + kvm.put(Artifact.KEY_START_ORDER, defaultOrder); + } + } + feature.getVariables().remove(DEFAULT_CONTENT_START_ORDER); + } + } + } +} diff --git a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.FeatureExtensionHandler b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.FeatureExtensionHandler new file mode 100644 index 0000000..91b597c --- /dev/null +++ b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.FeatureExtensionHandler @@ -0,0 +1 @@ +org.apache.sling.feature.extension.content.ContentOrderMergeProcessor \ No newline at end of file
