Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Sklyut2011-03-16 20:05:34 +0000
committerDmitry Sklyut2011-03-16 20:05:34 +0000
commit5393f1dfb5944f806e0a7e01d44e8cf780f10e99 (patch)
tree41bed2fb1e87187b653ee3ce3c6b12b2808a0c90
parent8da8146451901f479931c4989760fb92ac84786d (diff)
downloadorg.eclipse.virgo.kernel-5393f1dfb5944f806e0a7e01d44e8cf780f10e99.tar.gz
org.eclipse.virgo.kernel-5393f1dfb5944f806e0a7e01d44e8cf780f10e99.tar.xz
org.eclipse.virgo.kernel-5393f1dfb5944f806e0a7e01d44e8cf780f10e99.zip
introduce factory-configuration artifact type and support it in plan deployment
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationTestUtils.java11
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/FactoryConfigurationDeploymentTests.java57
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanFactoryConfigurationDeploymentTests.java213
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/resources/configuration.deployment/factory.config.plan11
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/ArtifactSpecificationBridge.java (renamed from org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/ArtifactSpecificationBridge.java)2
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/InstallArtifactTreeFactory.java14
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridge.java20
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifact.java49
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifactTreeFactory.java2
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosure.java10
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardRepositoryArtifactSpecificationBridge.java1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml2
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridgeTests.java62
13 files changed, 407 insertions, 47 deletions
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationTestUtils.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationTestUtils.java
index 935a70d1..a78fb7f6 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationTestUtils.java
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationTestUtils.java
@@ -120,4 +120,15 @@ final class ConfigurationTestUtils {
Thread.sleep(100);
}
}
+
+ static int countFactoryConfigurations(ConfigurationAdmin configAdmin, String factoryPid) throws Exception {
+ Configuration[] configurations = configAdmin.listConfigurations(null);
+ int counter = 0;
+ for (Configuration c : configurations) {
+ if (factoryPid.equals(c.getFactoryPid())) {
+ counter++;
+ }
+ }
+ return counter;
+ }
}
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/FactoryConfigurationDeploymentTests.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/FactoryConfigurationDeploymentTests.java
index 59379102..aad619bd 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/FactoryConfigurationDeploymentTests.java
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/FactoryConfigurationDeploymentTests.java
@@ -13,6 +13,9 @@
package org.eclipse.virgo.kernel.deployer.test;
+import static org.eclipse.virgo.kernel.deployer.test.ConfigurationTestUtils.countFactoryConfigurations;
+import static org.eclipse.virgo.kernel.deployer.test.ConfigurationTestUtils.pollUntilFactoryInConfigurationAdmin;
+import static org.eclipse.virgo.kernel.deployer.test.ConfigurationTestUtils.pollUntilFactoryNotInConfigurationAdmin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -31,7 +34,6 @@ import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
@@ -116,7 +118,7 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
this.context.registerService(ManagedServiceFactory.class, service, properties);
// make sure that we are starting off with a clean slate
- assertEquals(0, countFactoryConfigurations("test.factory.pid.a"));
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, "test.factory.pid.a"));
File configurationFile = new File("src/test/resources/configuration.deployment/factory-config-a.properties");
@@ -126,7 +128,7 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
// let it deploy
Thread.sleep(1000);
- assertEquals(1, countFactoryConfigurations("test.factory.pid.a"));
+ assertEquals(1, countFactoryConfigurations(this.configAdmin, "test.factory.pid.a"));
assertEquals(1, service.updateCount());
assertEquals(0, service.deleteCount());
Dictionary propertiesFromService = service.getProperties();
@@ -139,14 +141,14 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
// give time for events to percolate
Thread.sleep(1000);
- assertEquals(0, countFactoryConfigurations("test.factory.pid.a"));
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, "test.factory.pid.a"));
assertEquals(1, service.updateCount());
assertEquals(1, service.deleteCount());
// now lets make sure that we can deploy it again
deploymentIdentity = this.appDeployer.deploy(configurationFile.toURI());
Thread.sleep(1000);
- assertEquals(1, countFactoryConfigurations("test.factory.pid.a"));
+ assertEquals(1, countFactoryConfigurations(this.configAdmin, "test.factory.pid.a"));
assertEquals(2, service.updateCount());
assertEquals(1, service.deleteCount());
@@ -176,13 +178,13 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
this.context.registerService(ManagedServiceFactory.class, service, properties);
// make sure that we are starting off with a clean slate
- assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, factoryPid));
// copy file to hot deploy location
hotDeployConfiguration.store(new FileOutputStream(target), "no comment");
- ConfigurationTestUtils.pollUntilFactoryInConfigurationAdmin(this.configAdmin, factoryPid);
- assertEquals(1, countFactoryConfigurations(factoryPid));
+ pollUntilFactoryInConfigurationAdmin(this.configAdmin, factoryPid);
+ assertEquals(1, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(1, service.updateCount());
assertEquals(0, service.deleteCount());
@@ -193,9 +195,9 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
// remove the file and let it be removed
target.delete();
- ConfigurationTestUtils.pollUntilFactoryNotInConfigurationAdmin(this.configAdmin, factoryPid);
+ pollUntilFactoryNotInConfigurationAdmin(this.configAdmin, factoryPid);
- assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(1, service.updateCount());
assertEquals(1, service.deleteCount());
} finally {
@@ -230,15 +232,15 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
this.context.registerService(ManagedServiceFactory.class, service, properties);
// make sure that we are starting off with a clean slate
- assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, factoryPid));
// copy file to hot deploy location
hotDeployConfiguration.store(new FileOutputStream(target), "initial");
- ConfigurationTestUtils.pollUntilFactoryInConfigurationAdmin(this.configAdmin, factoryPid);
+ pollUntilFactoryInConfigurationAdmin(this.configAdmin, factoryPid);
// let events propagate
Thread.sleep(100);
- assertEquals(1, countFactoryConfigurations(factoryPid));
+ assertEquals(1, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(1, service.updateCount());
assertEquals(0, service.deleteCount());
@@ -254,7 +256,7 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
// let events propagate and update happen
Thread.sleep(3000);
- assertEquals(1, countFactoryConfigurations(factoryPid));
+ assertEquals(1, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(2, service.updateCount());
assertEquals(0, service.deleteCount());
@@ -265,9 +267,9 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
// remove the file and let it be removed
target.delete();
- ConfigurationTestUtils.pollUntilFactoryNotInConfigurationAdmin(this.configAdmin, factoryPid);
+ pollUntilFactoryNotInConfigurationAdmin(this.configAdmin, factoryPid);
- assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(2, service.updateCount());
assertEquals(1, service.deleteCount());
} finally {
@@ -311,15 +313,15 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
this.context.registerService(ManagedServiceFactory.class, service, properties);
// make sure that we are starting off with a clean slate
- assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, factoryPid));
// copy file to hot deploy location
configOne.store(new FileOutputStream(targetOne), "initial");
- ConfigurationTestUtils.pollUntilFactoryInConfigurationAdmin(this.configAdmin, factoryPid);
+ pollUntilFactoryInConfigurationAdmin(this.configAdmin, factoryPid);
// let events propagate
Thread.sleep(100);
- assertEquals(1, countFactoryConfigurations(factoryPid));
+ assertEquals(1, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(1, service.updateCount());
assertEquals(0, service.deleteCount());
@@ -331,7 +333,7 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
configTwo.store(new FileOutputStream(targetTwo), "initial");
Thread.sleep(3000);
- assertEquals(2, countFactoryConfigurations(factoryPid));
+ assertEquals(2, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(2, service.updateCount());
assertEquals(0, service.deleteCount());
@@ -344,8 +346,8 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
assertTrue(targetTwo.delete());
// let events propagate and update happen
- ConfigurationTestUtils.pollUntilFactoryNotInConfigurationAdmin(this.configAdmin, factoryPid);
- assertEquals(0, countFactoryConfigurations(factoryPid));
+ pollUntilFactoryNotInConfigurationAdmin(this.configAdmin, factoryPid);
+ assertEquals(0, countFactoryConfigurations(this.configAdmin, factoryPid));
assertEquals(2, service.updateCount());
assertEquals(2, service.deleteCount());
@@ -358,15 +360,4 @@ public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegra
}
}
}
-
- private int countFactoryConfigurations(String factoryPid) throws Exception {
- Configuration[] configurations = this.configAdmin.listConfigurations(null);
- int counter = 0;
- for (Configuration c : configurations) {
- if (factoryPid.equals(c.getFactoryPid())) {
- counter++;
- }
- }
- return counter;
- }
}
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanFactoryConfigurationDeploymentTests.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanFactoryConfigurationDeploymentTests.java
new file mode 100644
index 00000000..5cfeafaa
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanFactoryConfigurationDeploymentTests.java
@@ -0,0 +1,213 @@
+/*
+ * This file is part of the Eclipse Virgo project.
+ *
+ * Copyright (c) 2011 Chariot Solutions, LLC
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * dsklyut - initial contribution
+ */
+
+package org.eclipse.virgo.kernel.deployer.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.eclipse.virgo.kernel.deployer.test.ConfigurationTestUtils.*;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.eclipse.virgo.util.io.IOUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+/**
+ * Test to validate deployment of plans with "factory-configuration" artifact type.
+ * <p />
+ *
+ */
+public class PlanFactoryConfigurationDeploymentTests extends AbstractDeployerIntegrationTest {
+
+ private ServiceReference<ApplicationDeployer> appDeployerServiceReference;
+
+ private ApplicationDeployer appDeployer;
+
+ private ServiceReference<ConfigurationAdmin> configAdminServiceReference;
+
+ private ConfigurationAdmin configAdmin;
+
+ private static final String factoryPid = "org.eclipse.virgo.kernel.deployer.test.factory.config";
+
+ private static final File watchedRepository = new File("target/watched");
+
+ private static final String fileNameTemplate = factoryPid + "-%s.properties";
+
+ private static final FileFilter fileFilter = new FileFilter() {
+
+ @Override
+ public boolean accept(File pathname) {
+ final String name = pathname.getName();
+ return name.startsWith(factoryPid) && name.endsWith(".properties");
+ }
+ };
+
+ @BeforeClass
+ public static void setupConfigurationInWatchedRepository() throws Exception {
+ int count = 2;
+ for (int index = 0; index < count; index++) {
+ setupConfiguration(index);
+ }
+ }
+
+ private static void setupConfiguration(int index) throws FileNotFoundException, IOException {
+ File config = new File(watchedRepository, String.format(fileNameTemplate, index));
+ if (!config.exists()) {
+ config.createNewFile();
+ }
+ Properties props = new Properties();
+ props.setProperty(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
+ props.setProperty("index", String.valueOf(index));
+
+ OutputStream stream = new FileOutputStream(config);
+ try {
+ props.store(new FileOutputStream(config), "Config " + index);
+ } finally {
+ IOUtils.closeQuietly(stream);
+ }
+ }
+
+ @AfterClass
+ public static void cleanupConfigurationFromWatchedDirectory() {
+ try {
+ File[] files = watchedRepository.listFiles(fileFilter);
+ for (File f : files) {
+ f.delete();
+ }
+ } catch (Exception ex) {
+ // do anything?
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ this.appDeployerServiceReference = this.context.getServiceReference(ApplicationDeployer.class);
+ this.appDeployer = this.context.getService(this.appDeployerServiceReference);
+ this.configAdminServiceReference = this.context.getServiceReference(ConfigurationAdmin.class);
+ this.configAdmin = this.context.getService(this.configAdminServiceReference);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (this.appDeployerServiceReference != null) {
+ this.context.ungetService(this.appDeployerServiceReference);
+ }
+ if (this.configAdminServiceReference != null) {
+ this.context.ungetService(this.configAdminServiceReference);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static class TestManagedServiceFactory implements ManagedServiceFactory {
+
+ private final Map<String, Dictionary> properties = new HashMap<String, Dictionary>();
+
+ private final AtomicInteger updateCallCount = new AtomicInteger(0);
+
+ private final AtomicInteger deleteCallCount = new AtomicInteger(0);
+
+ @Override
+ public String getName() {
+ return "Test Managed Service Factory";
+ }
+
+ @Override
+ public void updated(String pid, Dictionary properties) throws ConfigurationException {
+ this.updateCallCount.incrementAndGet();
+ this.properties.put(pid, properties);
+ }
+
+ @Override
+ public void deleted(String pid) {
+ this.deleteCallCount.incrementAndGet();
+ this.properties.remove(pid);
+ }
+
+ Map<String, Dictionary> getProperties() {
+ return this.properties;
+ }
+
+ int updateCount() {
+ return this.updateCallCount.get();
+ }
+
+ int deleteCount() {
+ return this.deleteCallCount.get();
+ }
+ }
+
+ @Test
+ public void validateThatPlanWithFactoryConfigDeploys() throws Exception {
+
+ TestManagedServiceFactory service = new TestManagedServiceFactory();
+ Hashtable<String, String> properties = new Hashtable<String, String>();
+ properties.put(Constants.SERVICE_PID, factoryPid);
+ ServiceRegistration<ManagedServiceFactory> registration = this.context.registerService(ManagedServiceFactory.class, service, properties);
+
+ // let repository indexing complete
+ Thread.sleep(2000);
+
+ // deploy the plan
+ DeploymentIdentity deploymentIdentity = this.appDeployer.deploy(new File("src/test/resources/configuration.deployment/factory.config.plan").toURI());
+ assertNotNull(deploymentIdentity);
+
+ int factoryConfigCount = countFactoryConfigurations(this.configAdmin, factoryPid);
+ assertEquals(2, factoryConfigCount);
+
+ // let config admin events propagate
+ Thread.sleep(300);
+
+ // check managed service factory for update events
+ assertEquals(2, service.updateCount());
+ assertEquals(2, service.getProperties().size());
+
+ this.appDeployer.undeploy(deploymentIdentity);
+
+ // let config admin events propagate
+ Thread.sleep(300);
+
+ factoryConfigCount = countFactoryConfigurations(this.configAdmin, factoryPid);
+ assertEquals(0, factoryConfigCount);
+
+ // check managed service factory on delete count
+ assertEquals(2, service.deleteCount());
+ assertEquals(2, service.updateCount());
+ assertEquals(0, service.getProperties().size());
+
+ registration.unregister();
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/resources/configuration.deployment/factory.config.plan b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/configuration.deployment/factory.config.plan
new file mode 100644
index 00000000..0bc11f1a
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/configuration.deployment/factory.config.plan
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plan name="factory.config.plan" version="1.0.0" scoped="false" atomic="true"
+ xmlns="http://www.eclipse.org/virgo/schema/plan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.eclipse.org/virgo/schema/plan
+ http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd">
+
+ <artifact type="factory-configuration" name="org.eclipse.virgo.kernel.deployer.test.factory.config"/>
+
+</plan> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/ArtifactSpecificationBridge.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/ArtifactSpecificationBridge.java
index 2e906605..7a196c39 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/ArtifactSpecificationBridge.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/ArtifactSpecificationBridge.java
@@ -11,7 +11,7 @@
* dsklyut - initial contribution
*/
-package org.eclipse.virgo.kernel.install.artifact.internal;
+package org.eclipse.virgo.kernel.install.artifact;
import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
import org.eclipse.virgo.repository.RepositoryAwareArtifactDescriptor;
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/InstallArtifactTreeFactory.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/InstallArtifactTreeFactory.java
index 474c7822..13130947 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/InstallArtifactTreeFactory.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/InstallArtifactTreeFactory.java
@@ -13,7 +13,6 @@ package org.eclipse.virgo.kernel.install.artifact;
import java.util.Map;
-
import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
import org.eclipse.virgo.util.common.Tree;
@@ -27,6 +26,19 @@ import org.eclipse.virgo.util.common.Tree;
*
*/
public interface InstallArtifactTreeFactory {
+//
+// /**
+// * Constructs an install tree from the {@link ArtifactStorage}. If this factory cannot handle the given artifact type, it
+// * returns <code>null</code>.
+// * @param artifactIdentity
+// * @param deploymentProperties the deployment properties for the artifact. Can be <code>null</code>.
+// * @param repositoryName The name of the repository from which that artifact originates, or <code>null</code> if the artifact is not from a repository.
+// * @return an install tree or <code>null</code> if the factory cannot handle the given artifact type
+// * @throws DeploymentException if the tree cannot be constructed
+// */
+// Tree<InstallArtifact> constructInstallArtifactTree(ArtifactIdentity artifactIdentity, Map<String, String> deploymentProperties, RepositoryAwareArtifactDescriptor artifactDescriptor) throws DeploymentException;
+//
+//
/**
* Constructs an install tree from the {@link ArtifactStorage}. If this factory cannot handle the given artifact type, it
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridge.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridge.java
index a148badf..76b130c6 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridge.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridge.java
@@ -13,10 +13,12 @@
package org.eclipse.virgo.kernel.install.artifact.internal;
+import java.net.URI;
import java.util.Set;
import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentityDeterminer;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactSpecificationBridge;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.eclipse.virgo.repository.ArtifactDescriptor;
import org.eclipse.virgo.repository.Attribute;
@@ -75,11 +77,7 @@ final class FactoryConfigArtifactSpecificationBridge implements ArtifactSpecific
}
public java.net.URI getUri() {
- if (this.delegate.getUri() == null) {
- PathReference pr = PathReference.concat(this.delegate.getType(), this.delegate.getName(), this.delegate.getVersion().toString());
- return pr.toFile().toURI();
- }
- return this.delegate.getUri();
+ return null;
}
public Version getVersion() {
@@ -109,6 +107,7 @@ final class FactoryConfigArtifactSpecificationBridge implements ArtifactSpecific
return this.delegate.toString();
}
}
+
/**
* {@inheritDoc}
*/
@@ -122,8 +121,19 @@ final class FactoryConfigArtifactSpecificationBridge implements ArtifactSpecific
.setName(artifactSpecification.getName())//
.setType(ArtifactIdentityDeterminer.FACTORY_CONFIGURATION_TYPE)//
.setVersion(artifactSpecification.getVersionRange().toParseString())//
+ .setUri(buildUri(artifactSpecification))//
.addAttribute(new AttributeBuilder().setName(ConfigurationAdmin.SERVICE_FACTORYPID).setValue(artifactSpecification.getName()).build());
return new DelegatingRepositoryAwareArtifactDescriptor(builder.build(), null);
}
+
+ /**
+ * @param artifactSpecification
+ * @return
+ */
+ private URI buildUri(ArtifactSpecification artifactSpecification) {
+ PathReference pr = PathReference.concat(artifactSpecification.getType(), artifactSpecification.getName(),
+ artifactSpecification.getVersionRange().toParseString());
+ return pr.toFile().toURI();
+ }
}
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifact.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifact.java
index 5842aad6..c29cb847 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifact.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifact.java
@@ -13,12 +13,14 @@
package org.eclipse.virgo.kernel.install.artifact.internal;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.eclipse.virgo.kernel.artifact.fs.ArtifactFS;
import org.eclipse.virgo.kernel.core.AbortableSignal;
import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
import org.eclipse.virgo.kernel.deployer.core.internal.AbortableSignalJunction;
@@ -38,7 +40,47 @@ import org.eclipse.virgo.util.common.Tree;
* TODO Document concurrent semantics of FactoryConfigInstallArtifact
*/
public final class FactoryConfigInstallArtifact extends AbstractInstallArtifact {
+
+ private static final class NoOpArtifactStorage implements ArtifactStorage {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void synchronize() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void synchronize(URI sourceUri) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void rollBack() {
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void delete() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ArtifactFS getArtifactFS() {
+ return null;
+ }
+
+ }
+
private final Object monitor = new Object();
private Set<RepositoryAwareArtifactDescriptor> artifacts;
@@ -46,11 +88,10 @@ public final class FactoryConfigInstallArtifact extends AbstractInstallArtifact
/**
* @throws DeploymentException
*/
- FactoryConfigInstallArtifact(@NonNull ArtifactIdentity identity, @NonNull ArtifactStorage artifactStorage,
- @NonNull ArtifactStateMonitor artifactStateMonitor, EventLogger eventLogger, @NonNull Set<RepositoryAwareArtifactDescriptor> artifacts)
- throws DeploymentException {
+ FactoryConfigInstallArtifact(@NonNull ArtifactIdentity identity, @NonNull ArtifactStateMonitor artifactStateMonitor, EventLogger eventLogger,
+ @NonNull Set<RepositoryAwareArtifactDescriptor> artifacts) throws DeploymentException {
- super(identity, artifactStorage, artifactStateMonitor, null, eventLogger);
+ super(identity, new NoOpArtifactStorage() , artifactStateMonitor, null, eventLogger);
// make a copy of input list
this.artifacts = new HashSet<RepositoryAwareArtifactDescriptor>(artifacts);
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifactTreeFactory.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifactTreeFactory.java
index b0e848ca..b6190914 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifactTreeFactory.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigInstallArtifactTreeFactory.java
@@ -82,7 +82,7 @@ class FactoryConfigInstallArtifactTreeFactory implements InstallArtifactTreeFact
+ "' not found");
}
ArtifactStateMonitor artifactStateMonitor = new StandardArtifactStateMonitor(this.bundleContext);
- FactoryConfigInstallArtifact result = new FactoryConfigInstallArtifact(artifactIdentity, artifactStorage, artifactStateMonitor, eventLogger,
+ FactoryConfigInstallArtifact result = new FactoryConfigInstallArtifact(artifactIdentity, artifactStateMonitor, eventLogger,
factoryConfigurationArtifacts);
return constructInstallTree(result);
}
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosure.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosure.java
index 8d14e5b0..8a4eee29 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosure.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosure.java
@@ -23,6 +23,7 @@ import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
import org.eclipse.virgo.kernel.deployer.core.DeploymentOptions;
import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentity;
import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentityDeterminer;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactSpecificationBridge;
import org.eclipse.virgo.kernel.install.artifact.ArtifactStorage;
import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
import org.eclipse.virgo.kernel.install.artifact.InstallArtifactTreeFactory;
@@ -114,7 +115,14 @@ public final class StandardInstallArtifactTreeInclosure implements InstallArtifa
ArtifactIdentity identity = new ArtifactIdentity(type, name, artifactDescriptor.getVersion(), scopeName);
identity = ArtifactIdentityScoper.scopeArtifactIdentity(identity);
- ArtifactStorage artifactStorage = this.artifactStorageFactory.create(new File(artifactURI), identity);
+ // TODO: Need a better way to skip creating of ArtifactStorage or have ArtifactStorage deal with a URI
+ // XXX: Not sure how to deal with situations where ArtifactDescriptor is a "virtual", i.e. does not have a
+ // source file/uri (example: factory-configuration that is just a key to look up actual configurations in
+ // repositories)
+ ArtifactStorage artifactStorage = null;
+ if (artifactURI != null) {
+ artifactStorage = this.artifactStorageFactory.create(new File(artifactURI), identity);
+ }
Tree<InstallArtifact> installArtifactTree = constructInstallArtifactTree(identity, specification.getProperties(), artifactStorage,
artifactDescriptor.getRepositoryName());
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardRepositoryArtifactSpecificationBridge.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardRepositoryArtifactSpecificationBridge.java
index ba230d6f..effdd3bd 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardRepositoryArtifactSpecificationBridge.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardRepositoryArtifactSpecificationBridge.java
@@ -14,6 +14,7 @@
package org.eclipse.virgo.kernel.install.artifact.internal;
import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactSpecificationBridge;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.eclipse.virgo.repository.Repository;
import org.eclipse.virgo.repository.RepositoryAwareArtifactDescriptor;
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml b/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml
index 6a6990a8..6e4b3fd2 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml
+++ b/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml
@@ -74,7 +74,7 @@
interface="org.eclipse.virgo.kernel.install.pipeline.stage.transform.Transformer"
ref="planResolver" ranking="1000" />
<service interface="org.eclipse.virgo.kernel.install.pipeline.stage.transform.Transformer"
- ref="planResolver" ranking="1050" />
+ ref="factoryConfigurationResolver" ranking="1050" />
<service
interface="org.eclipse.virgo.kernel.install.pipeline.stage.transform.Transformer"
ref="bundleManifestVersionUpgrader" ranking="2000" />
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridgeTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridgeTests.java
new file mode 100644
index 00000000..b09926bb
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/FactoryConfigArtifactSpecificationBridgeTests.java
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the Eclipse Virgo project.
+ *
+ * Copyright (c) 2011 Chariot Solutions, LLC
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * dsklyut - initial contribution
+ */
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentityDeterminer;
+import org.eclipse.virgo.repository.RepositoryAwareArtifactDescriptor;
+import org.eclipse.virgo.util.osgi.VersionRange;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for FactoryConfigArtifactSpecificationBridge
+ * <p />
+ */
+public class FactoryConfigArtifactSpecificationBridgeTests {
+
+ private FactoryConfigArtifactSpecificationBridge bridge;
+
+ @Before
+ public void onSetUp() {
+ bridge = new FactoryConfigArtifactSpecificationBridge();
+ }
+
+ @Test
+ public void validateArtifactType() {
+
+ final String artifactType = ArtifactIdentityDeterminer.CONFIGURATION_TYPE;
+ ArtifactSpecification spec = new ArtifactSpecification(artifactType, "spec-1", VersionRange.naturalNumberRange());
+
+ assertNull(bridge.generateArtifactDescriptor(spec));
+ }
+
+ @Test
+ public void validateGenerationOfFactryContainer() {
+ final String artifactType = ArtifactIdentityDeterminer.FACTORY_CONFIGURATION_TYPE;
+ ArtifactSpecification spec = new ArtifactSpecification(artifactType, "spec-1", VersionRange.naturalNumberRange());
+
+ RepositoryAwareArtifactDescriptor descriptor = bridge.generateArtifactDescriptor(spec);
+
+ assertNotNull(descriptor);
+ assertEquals(artifactType, descriptor.getType());
+ assertEquals("spec-1", descriptor.getName());
+ assertEquals(VersionRange.naturalNumberRange().toParseString(), descriptor.getVersion().toString());
+ assertNull(descriptor.getUri());
+ }
+}

Back to the top