Update the context extension to the latest Launcher extension API
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 8c2cd40..1111a32 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
@@ -39,8 +39,8 @@
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionType;
import org.apache.sling.feature.launcher.spi.LauncherPrepareContext;
+import org.apache.sling.feature.launcher.spi.extensions.ExtensionContext;
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";
@@ -97,9 +97,8 @@
}
@Override
- public boolean handle(Extension extension, LauncherPrepareContext prepareContext,
- ExtensionInstallationContext installationContext) throws Exception {
- File registryHome = getRegistryHomeDir(installationContext);
+ public boolean handle(ExtensionContext context, Extension extension) throws Exception {
+ File registryHome = getRegistryHomeDir(context);
if (extension.getType() == ExtensionType.ARTIFACTS
&& extension.getName().equals(Extension.EXTENSION_NAME_CONTENT_PACKAGES)) {
MultiValueMap orderedArtifacts = MultiValueMap.decorate(new TreeMap<Integer, Collection<Artifact>>());
@@ -118,7 +117,7 @@
for (Object key : orderedArtifacts.keySet()) {
@SuppressWarnings("unchecked")
Collection<Artifact> artifacts = orderedArtifacts.getCollection(key);
- ExecutionPlanBuilder builder = buildExecutionPlan(artifacts, satisfiedPackages, prepareContext, registryHome);
+ ExecutionPlanBuilder builder = buildExecutionPlan(artifacts, satisfiedPackages, context, registryHome);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
builder.save(baos);
executionPlans.add(baos.toString("UTF-8"));
@@ -127,11 +126,11 @@
final Configuration initcfg = new Configuration("org.UNSHADE.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer");
initcfg.getProperties().put("executionplans", executionPlans.toArray(new String[executionPlans.size()]));
initcfg.getProperties().put("statusfilepath", registryHome.getAbsolutePath() + "/executedplans.file");
- installationContext.addConfiguration(initcfg.getPid(), null, initcfg.getProperties());
+ context.addConfiguration(initcfg.getPid(), null, 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(), null, registrycfg.getProperties());
+ context.addConfiguration(registrycfg.getPid(), null, registrycfg.getProperties());
return true;
}
@@ -140,7 +139,7 @@
}
}
- private File getRegistryHomeDir(ExtensionInstallationContext installationContext) {
+ private File getRegistryHomeDir(ExtensionContext context) {
//read repository- home from framework properties (throw exception if repo.home not set)
String registryPath = System.getProperty(PACKAGEREGISTRY_HOME);
File registryHome;
@@ -148,7 +147,7 @@
registryHome = Paths.get(registryPath).toFile();
} else {
- String repoHome = installationContext.getFrameworkProperties().get(REPOSITORY_HOME);
+ String repoHome = context.getFrameworkProperties().get(REPOSITORY_HOME);
if (repoHome == null) {
throw new IllegalStateException("Neither registry.home set nor repository.home configured.");
}
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 5721457..adbcbd9 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,8 +18,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -32,8 +32,7 @@
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionType;
-import org.apache.sling.feature.launcher.spi.LauncherPrepareContext;
-import org.apache.sling.feature.launcher.spi.extensions.ExtensionInstallationContext;
+import org.apache.sling.feature.launcher.spi.extensions.ExtensionContext;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -51,10 +50,7 @@
public TemporaryFolder testFolder = new TemporaryFolder();
@Mock
- LauncherPrepareContext prepareContext;
-
- @Mock
- ExtensionInstallationContext installationContext;
+ ExtensionContext extensionContext;
/**
* Test package A-1.0. Depends on B and C-1.X
@@ -80,11 +76,11 @@
@Before
public void setUp() throws Exception {
URL test_a = this.getClass().getResource(TEST_PACKAGE_A_10);
- when(prepareContext.getArtifactFile(TEST_PACKAGE_AID_A_10)).thenReturn(new File(test_a.getFile()));
+ when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_A_10)).thenReturn(new File(test_a.getFile()));
URL test_b = this.getClass().getResource(TEST_PACKAGE_B_10);
- when(prepareContext.getArtifactFile(TEST_PACKAGE_AID_B_10)).thenReturn(new File(test_b.getFile()));
+ when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_B_10)).thenReturn(new File(test_b.getFile()));
URL test_c = this.getClass().getResource(TEST_PACKAGE_C_10);
- when(prepareContext.getArtifactFile(TEST_PACKAGE_AID_C_10)).thenReturn(new File(test_c.getFile()));
+ when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_C_10)).thenReturn(new File(test_c.getFile()));
}
@Test
@@ -104,9 +100,9 @@
@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());
+ ch.handle(extensionContext, ext);
+ verify(extensionContext).addConfiguration(eq("org.UNSHADE.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer"), any(), executionPlanCaptor.capture());
+ verify(extensionContext).addConfiguration(eq("org.UNSHADE.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry"), any(), any());
Iterator<Dictionary<String, Object>> dictIt = executionPlanCaptor.getAllValues().iterator();
Dictionary<String, Object> dict = dictIt.next();
final String[] executionplans = (String[]) dict.get("executionplans");