karlpauls closed pull request #19: SLING-7991 - setting order to Integer.MAX_VALUE for processing last i… URL: https://github.com/apache/sling-whiteboard/pull/19
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/.gitignore b/.gitignore index b018844..f7422e7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ bin *.iml .idea .DS_Store +dependency-reduced-pom.xml diff --git a/featuremodel/feature-content-extension/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java b/featuremodel/feature-content-extension/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java index e19ba12..1a57118 100644 --- a/featuremodel/feature-content-extension/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java +++ b/featuremodel/feature-content-extension/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java @@ -95,7 +95,14 @@ public boolean handle(Extension extension, LauncherPrepareContext prepareContext && extension.getName().equals(FeatureConstants.EXTENSION_NAME_CONTENT_PACKAGES)) { MultiValueMap orderedArtifacts = MultiValueMap.decorate(new LinkedHashMap<Integer, Collection<Artifact>>()); for (final Artifact a : extension.getArtifacts()) { - orderedArtifacts.put(Integer.valueOf(a.getStartOrder()), a); + int order; + // content-packages without explicit start-order to be installed last + if (a.getMetadata().get(Artifact.KEY_START_ORDER) != null) { + order = a.getStartOrder(); + } else { + order = Integer.MAX_VALUE; + } + orderedArtifacts.put(order, a); } List<String> executionPlans = new ArrayList<String>(); for (Object key : orderedArtifacts.keySet()) { diff --git a/featuremodel/feature-content-extension/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java b/featuremodel/feature-content-extension/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java new file mode 100644 index 0000000..3cc9e97 --- /dev/null +++ b/featuremodel/feature-content-extension/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/featuremodel/feature-content-extension/src/main/resources/META-INF/services/org.apache.sling.feature.builder.FeatureExtensionHandler b/featuremodel/feature-content-extension/src/main/resources/META-INF/services/org.apache.sling.feature.builder.FeatureExtensionHandler new file mode 100644 index 0000000..91b597c --- /dev/null +++ b/featuremodel/feature-content-extension/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 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services