You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/11/26 14:09:28 UTC
[sling-org-apache-sling-feature-extension-content] branch master
updated: Update to Feature Model 0.8.0
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
The following commit(s) were added to refs/heads/master by this push:
new 0e202d2 Update to Feature Model 0.8.0
0e202d2 is described below
commit 0e202d20287e7c3d3cedc08955c2a011b655a8ca
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 26 14:09:11 2018 +0000
Update to Feature Model 0.8.0
---
pom.xml | 6 ++--
.../feature/extension/content/ContentHandler.java | 36 ++++++++++++++++------
.../content/ContentOrderMergeProcessor.java | 3 +-
.../extension/content/ContentHandlerTest.java | 36 +++++++++++++++++++---
4 files changed, 61 insertions(+), 20 deletions(-)
diff --git a/pom.xml b/pom.xml
index 7ffd003..d96cd2a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,19 +122,19 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.feature.launcher</artifactId>
- <version>0.2.1-SNAPSHOT</version>
+ <version>0.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.feature.io</artifactId>
- <version>0.2.1-SNAPSHOT</version>
+ <version>0.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.feature</artifactId>
- <version>0.2.1-SNAPSHOT</version>
+ <version>0.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
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 dd94747..ab4d5a6 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
@@ -22,7 +22,6 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
-
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -38,15 +37,15 @@ import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.Configuration;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionType;
-import org.apache.sling.feature.FeatureConstants;
import org.apache.sling.feature.launcher.spi.LauncherPrepareContext;
import org.apache.sling.feature.launcher.spi.extensions.ExtensionHandler;
import org.apache.sling.feature.launcher.spi.extensions.ExtensionInstallationContext;
public class ContentHandler implements ExtensionHandler {
-
public static final String PACKAGEREGISTRY_HOME = "packageregistry.home";
+ private static final char FACTORY_CONFIG_SEPARATOR = '~';
+
private static final String REPOSITORY_HOME = "repository.home";
private static final String REGISTRY_FOLDER = "packageregistry";
@@ -62,7 +61,7 @@ public class ContentHandler implements ExtensionHandler {
}
}
-
+
if(!registryHome.exists()) {
registryHome.mkdirs();
}
@@ -97,7 +96,7 @@ public class ContentHandler implements ExtensionHandler {
ExtensionInstallationContext installationContext) throws Exception {
File registryHome = getRegistryHomeDir(installationContext);
if (extension.getType() == ExtensionType.ARTIFACTS
- && extension.getName().equals(FeatureConstants.EXTENSION_NAME_CONTENT_PACKAGES)) {
+ && extension.getName().equals(Extension.EXTENSION_NAME_CONTENT_PACKAGES)) {
MultiValueMap orderedArtifacts = MultiValueMap.decorate(new TreeMap<Integer, Collection<Artifact>>());
for (final Artifact a : extension.getArtifacts()) {
int order;
@@ -119,14 +118,14 @@ public class ContentHandler implements ExtensionHandler {
builder.save(baos);
executionPlans.add(baos.toString("UTF-8"));
}
- // Workaround for too bold relocation mechanism - corresponding details at https://issues.apache.org/jira/browse/MSHADE-156
+ // Workaround for too bold relocation mechanism - corresponding details at https://issues.apache.org/jira/browse/MSHADE-156
final Configuration initcfg = new Configuration("org.UNSHADE.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer");
initcfg.getProperties().put("executionplans", executionPlans.toArray(new String[executionPlans.size()]));
- installationContext.addConfiguration(initcfg.getPid(), initcfg.getFactoryPid(), initcfg.getProperties());
- // Workaround for too bold relocation mechanism - corresponding details at https://issues.apache.org/jira/browse/MSHADE-156
+ installationContext.addConfiguration(getPid(initcfg), getFactoryPid(initcfg), initcfg.getProperties());
+ // Workaround for too bold relocation mechanism - corresponding details at https://issues.apache.org/jira/browse/MSHADE-156
final Configuration registrycfg = new Configuration("org.UNSHADE.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry");
registrycfg.getProperties().put("homePath", registryHome.getPath());
- installationContext.addConfiguration(registrycfg.getPid(), registrycfg.getFactoryPid(), registrycfg.getProperties());;
+ installationContext.addConfiguration(getPid(registrycfg), getFactoryPid(registrycfg), registrycfg.getProperties());
return true;
}
@@ -146,7 +145,7 @@ public class ContentHandler implements ExtensionHandler {
String repoHome = installationContext.getFrameworkProperties().get(REPOSITORY_HOME);
if (repoHome == null) {
throw new IllegalStateException("Neither registry.home set nor repository.home configured.");
- }
+ }
registryHome = Paths.get(repoHome, REGISTRY_FOLDER).toFile();
}
if (!registryHome.exists()) {
@@ -157,4 +156,21 @@ public class ContentHandler implements ExtensionHandler {
}
return registryHome;
}
+
+ static String getPid(Configuration cfg) {
+ String pid = cfg.getPid();
+ int idx = pid.indexOf(FACTORY_CONFIG_SEPARATOR);
+ if (idx > 0)
+ return pid.substring(0, idx);
+ else
+ return pid;
+ }
+
+ static String getFactoryPid(Configuration cfg) {
+ String pid = cfg.getPid();
+ if (pid.indexOf(FACTORY_CONFIG_SEPARATOR) > 0)
+ return pid;
+ else
+ return null;
+ }
}
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
index 3d5d51e..4de97b5 100644
--- a/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java
+++ b/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java
@@ -20,7 +20,6 @@ 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.builder.HandlerContext;
import org.apache.sling.feature.builder.MergeHandler;
@@ -49,7 +48,7 @@ public class ContentOrderMergeProcessor implements MergeHandler {
@Override
public boolean canMerge(Extension extension) {
return extension.getType() == ExtensionType.ARTIFACTS
- && extension.getName().equals(FeatureConstants.EXTENSION_NAME_CONTENT_PACKAGES);
+ && extension.getName().equals(Extension.EXTENSION_NAME_CONTENT_PACKAGES);
}
@Override
diff --git a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
index 06b7cff..49347a6 100644
--- a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
@@ -18,6 +18,7 @@ package org.apache.sling.feature.extension.content;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.verify;
@@ -30,6 +31,7 @@ import java.util.Iterator;
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Configuration;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionType;
import org.apache.sling.feature.launcher.spi.LauncherPrepareContext;
@@ -45,17 +47,17 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ContentHandlerTest {
-
+
@Rule
public TemporaryFolder testFolder = new TemporaryFolder();
-
+
@Mock
LauncherPrepareContext prepareContext;
-
+
@Mock
ExtensionInstallationContext installationContext;
-
+
/**
* Test package A-1.0. Depends on B and C-1.X
*/
@@ -103,7 +105,7 @@ public class ContentHandlerTest {
ext.getArtifacts().add(artifact_c);
@SuppressWarnings("unchecked")
ArgumentCaptor<Dictionary<String, Object>> executionPlanCaptor = ArgumentCaptor.forClass(Dictionary.class);
-
+
ch.handle(ext, prepareContext, installationContext);
verify(installationContext).addConfiguration(eq("org.UNSHADE.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer"), any(), executionPlanCaptor.capture());
verify(installationContext).addConfiguration(eq("org.UNSHADE.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry"), any(), any());
@@ -126,4 +128,28 @@ public class ContentHandlerTest {
assertEquals(expected_1, executionplans[1]);
assertFalse(dictIt.hasNext());
}
+
+ @Test
+ public void testGetConfigPidNormal() {
+ Configuration cfg = new Configuration("a.b.c");
+ assertEquals("a.b.c", ContentHandler.getPid(cfg));
+ }
+
+ @Test
+ public void testGetConfigPidFactory() {
+ Configuration cfg = new Configuration("a.b.c~d");
+ assertEquals("a.b.c", ContentHandler.getPid(cfg));
+ }
+
+ @Test
+ public void testGetFactoryPidNormal() {
+ Configuration cfg = new Configuration("a.b.c");
+ assertNull(ContentHandler.getFactoryPid(cfg));
+ }
+
+ @Test
+ public void testGetFactoryPidFactory() {
+ Configuration cfg = new Configuration("a.b.c~d");
+ assertEquals("a.b.c~d", ContentHandler.getFactoryPid(cfg));
+ }
}