This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-content.git
The following commit(s) were added to refs/heads/master by this push:
new 791d50c SLING-9908: remove the ContentOrderMergeProcessor
791d50c is described below
commit 791d50c452bd82733db99b1be6bb29ad99d0c5c5
Author: Karl Pauls <[email protected]>
AuthorDate: Fri Nov 13 14:20:50 2020 +0100
SLING-9908: remove the ContentOrderMergeProcessor
---
.../content/ContentOrderMergeProcessor.java | 77 -------------
.../org.apache.sling.feature.builder.MergeHandler | 1 -
.../content/ContentOrderMergeProcessorTest.java | 124 ---------------------
3 files changed, 202 deletions(-)
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
deleted file mode 100644
index 2d18a82..0000000
---
a/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.builder.HandlerContext;
-import org.apache.sling.feature.builder.MergeHandler;
-
-import java.util.Map;
-
-public class ContentOrderMergeProcessor implements MergeHandler {
-
- public static final String DEFAULT_CONTENT_START_ORDER =
"default.content.startorder";
-
- private void processFeature(Feature feature, Extension extension) {
- if (feature == null || extension == null) {
- return;
- }
- String defaultOrder =
feature.getVariables().get(DEFAULT_CONTENT_START_ORDER);
- if (defaultOrder != null) {
- for (Artifact a : extension.getArtifacts()) {
- Map<String,String> 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);
- }
- }
-
- @Override
- public boolean canMerge(Extension extension) {
- return extension.getType() == ExtensionType.ARTIFACTS
- &&
extension.getName().equals(Extension.EXTENSION_NAME_CONTENT_PACKAGES);
- }
-
- @Override
- public void merge(HandlerContext context, Feature target, Feature source,
Extension targetEx, Extension sourceEx) {
-
- processFeature(target, targetEx);
- processFeature(source, sourceEx);
-
- if (targetEx == null) {
- target.getExtensions().add(sourceEx.copy());
- return;
- }
- for (final Artifact a : sourceEx.getArtifacts()) {
- boolean replace = true;
- final Artifact existing =
targetEx.getArtifacts().getSame(a.getId());
- if (existing != null &&
existing.getId().getOSGiVersion().compareTo(a.getId().getOSGiVersion()) > 0) {
- replace = false;
- }
-
- if (replace) {
- targetEx.getArtifacts().removeSame(a.getId());
- targetEx.getArtifacts().add(a.copy(a.getId()));
- }
- }
- }
-}
diff --git
a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
deleted file mode 100644
index 91b597c..0000000
---
a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.sling.feature.extension.content.ContentOrderMergeProcessor
\ No newline at end of file
diff --git
a/src/test/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessorTest.java
b/src/test/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessorTest.java
deleted file mode 100644
index 15c5b8f..0000000
---
a/src/test/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessorTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.sling.feature.Artifact;
-import org.apache.sling.feature.ArtifactId;
-import org.apache.sling.feature.Artifacts;
-import org.apache.sling.feature.Extension;
-import org.apache.sling.feature.ExtensionType;
-import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.builder.HandlerContext;
-import org.junit.Test;
-import org.mockito.Mock;
-
-public class ContentOrderMergeProcessorTest {
-
- @Mock
- HandlerContext handlerContext;
-
- @Test
- public void testMergeDifferentStartOrders() {
- final Artifacts targetArtifacts = new Artifacts();
-
- final ArtifactId tid1 = ArtifactId.fromMvnId("sling:targetpack1:1");
- Artifact targetpack1 = new Artifact(tid1);
- assertNull(targetpack1.getMetadata().get("start-order"));
- targetArtifacts.add(targetpack1);
-
- final ArtifactId tid2 = ArtifactId.fromMvnId("sling:targetpack2:1");
- Artifact targetpack2 = new Artifact(tid2);
- assertNull(targetpack2.getMetadata().get("start-order"));
- targetArtifacts.add(targetpack2);
-
- final Artifacts sourceArtifacts = new Artifacts();
-
- final ArtifactId sid1 = ArtifactId.fromMvnId("sling:sourcepack1:1");
- final Artifact sourcepack1 = new Artifact(sid1);
- assertNull(sourcepack1.getMetadata().get("start-order"));
- sourceArtifacts.add(sourcepack1);
-
- final ArtifactId sid2 = ArtifactId.fromMvnId("sling:sourcepack2:1");
- Artifact sourcepack2 = new Artifact(sid2);
- assertNull(sourcepack2.getMetadata().get("start-order"));
- sourceArtifacts.add(sourcepack2);
-
- final Extension targetEx = new Extension(ExtensionType.ARTIFACTS,
"content-package", false);
- targetEx.getArtifacts().addAll(targetArtifacts);
- final Feature target = new
Feature(ArtifactId.fromMvnId("sling:targettest:1"));
- target.getExtensions().add(targetEx);
-
target.getVariables().put(ContentOrderMergeProcessor.DEFAULT_CONTENT_START_ORDER,
"1");
-
- final Extension sourceEx = new Extension(ExtensionType.ARTIFACTS,
"content-package", false);
- sourceEx.getArtifacts().addAll(sourceArtifacts);
- final Feature source = new
Feature(ArtifactId.fromMvnId("sling:sourcetest:1"));
- source.getExtensions().add(sourceEx);
-
source.getVariables().put(ContentOrderMergeProcessor.DEFAULT_CONTENT_START_ORDER,
"2");
-
- final Set<Artifact> testArtifacts = new
HashSet<>(Arrays.asList(targetpack1, targetpack2, sourcepack1, sourcepack2));
-
- ContentOrderMergeProcessor comp = new ContentOrderMergeProcessor();
- comp.merge(handlerContext, target, source, targetEx, sourceEx);
-
-
- Artifacts mergedArtifacts = targetEx.getArtifacts();
- assertTrue(mergedArtifacts.containsAll(testArtifacts));
-
- assertEquals("1",
mergedArtifacts.getSame(tid1).getMetadata().get("start-order"));
- assertEquals("1",
mergedArtifacts.getSame(tid2).getMetadata().get("start-order"));
- assertEquals("2",
mergedArtifacts.getSame(sid1).getMetadata().get("start-order"));
- assertEquals("2",
mergedArtifacts.getSame(sid2).getMetadata().get("start-order"));
-
- }
-
-
- @Test
- public void testEmptyTargetExtension() {
- final Artifacts sourceArtifacts = new Artifacts();
-
- final ArtifactId sid1 = ArtifactId.fromMvnId("sling:sourcepack1:1");
- final Artifact sourcepack1 = new Artifact(sid1);
- assertNull(sourcepack1.getMetadata().get("start-order"));
- sourceArtifacts.add(sourcepack1);
-
- final Feature target = new
Feature(ArtifactId.fromMvnId("sling:targettest:1"));
-
- final Extension sourceEx = new Extension(ExtensionType.ARTIFACTS,
"content-package", false);
- sourceEx.getArtifacts().addAll(sourceArtifacts);
-
- final Feature source = new
Feature(ArtifactId.fromMvnId("sling:sourcetest:1"));
- source.getExtensions().add(sourceEx);
-
source.getVariables().put(ContentOrderMergeProcessor.DEFAULT_CONTENT_START_ORDER,
"2");
-
- ContentOrderMergeProcessor comp = new ContentOrderMergeProcessor();
- comp.merge(handlerContext, target, source, null, sourceEx);
-
-
- Artifacts mergedArtifacts =
target.getExtensions().getByName("content-package").getArtifacts();
- assertTrue(mergedArtifacts.contains(sourcepack1));
- assertEquals("2",
mergedArtifacts.getSame(sid1).getMetadata().get("start-order"));
- }
-
-}