Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.virgo.kernel.artifact/.classpath2
-rw-r--r--org.eclipse.virgo.kernel.artifact/ivy.xml3
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java2
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridge.java62
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java77
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/properties/factoryPid.properties6
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/properties/with-service-pid.properties6
-rw-r--r--org.eclipse.virgo.kernel.artifact/template.mf1
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/.project5
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationDeploymentTests.java58
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationTestUtils.java123
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/FactoryConfigurationDeploymentTests.java356
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/resources/configuration.deployment/factory-config-a.properties6
-rw-r--r--org.eclipse.virgo.kernel.services/src/main/resources/META-INF/spring/repository-context.xml3
-rw-r--r--org.eclipse.virgo.kernel.services/template.mf1
-rw-r--r--org.eclipse.virgo.kernel.test/.project5
16 files changed, 639 insertions, 77 deletions
diff --git a/org.eclipse.virgo.kernel.artifact/.classpath b/org.eclipse.virgo.kernel.artifact/.classpath
index a75419e7..19629731 100644
--- a/org.eclipse.virgo.kernel.artifact/.classpath
+++ b/org.eclipse.virgo.kernel.artifact/.classpath
@@ -33,5 +33,7 @@
<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.aspectj/com.springsource.org.aspectj.runtime/1.6.6.RELEASE/com.springsource.org.aspectj.runtime-1.6.6.RELEASE.jar" sourcepath="/KERNEL_IVY_CACHE/org.aspectj/com.springsource.org.aspectj.runtime/1.6.6.RELEASE/com.springsource.org.aspectj.runtime-1.6.6.RELEASE.jar"/>
<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.virgo.medic/org.eclipse.virgo.medic/3.0.0.M02/org.eclipse.virgo.medic-3.0.0.M02.jar" sourcepath="/KERNEL_IVY_CACHE/org.eclipse.virgo.medic/org.eclipse.virgo.medic/1.0.0.CI-B20/org.eclipse.virgo.medic-sources-1.0.0.CI-B20.jar"/>
<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.virgo.medic/org.eclipse.virgo.medic.core/3.0.0.M02/org.eclipse.virgo.medic.core-3.0.0.M02.jar" sourcepath="/KERNEL_IVY_CACHE/org.eclipse.virgo.medic/org.eclipse.virgo.medic.core/3.0.0.M02/org.eclipse.virgo.medic.core-sources-3.0.0.M02.jar"/>
+ <classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-3.3.0.v20110110.jar" sourcepath="/KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-sources-3.3.0.v20110110.jar"/>
+ <classpathentry kind="var" path="KERNEL_IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar" sourcepath="/KERNEL_IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/org.eclipse.virgo.kernel.artifact/ivy.xml b/org.eclipse.virgo.kernel.artifact/ivy.xml
index 4b96c7e7..a28bb2dc 100644
--- a/org.eclipse.virgo.kernel.artifact/ivy.xml
+++ b/org.eclipse.virgo.kernel.artifact/ivy.xml
@@ -17,11 +17,14 @@
<dependency org="org.eclipse.virgo.repository" name="org.eclipse.virgo.repository" rev="${org.eclipse.virgo.repository}" conf="compile->compile" />
<dependency org="org.junit" name="com.springsource.org.junit" rev="${org.junit}" conf="test->runtime"/>
+ <dependency org="org.easymock" name="com.springsource.org.easymock" rev="${org.easymock}" conf="test->runtime"/>
<dependency org="org.slf4j" name="com.springsource.slf4j.nop" rev="${org.slf4j}" conf="test->runtime"/>
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="${javax.servlet}" conf="test->runtime"/>
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.dbcp" rev="${commons.dbcp}" conf="test->runtime" />
<dependency org="org.aopalliance" name="com.springsource.org.aopalliance" rev="${org.aopalliance}" conf="test->runtime" />
+
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.cm" rev="${org.eclipse.equinox.cm}" conf="compile->runtime"/>
<override org="org.eclipse.virgo.util" rev="${org.eclipse.virgo.util}"/>
</dependencies>
diff --git a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java
index 35791e57..d3f145a0 100644
--- a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java
+++ b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java
@@ -14,8 +14,6 @@ package org.eclipse.virgo.kernel.artifact.par;
import java.io.File;
import java.io.IOException;
-import org.osgi.framework.Version;
-
import org.eclipse.virgo.kernel.artifact.internal.BundleManifestUtils;
import org.eclipse.virgo.repository.ArtifactBridge;
import org.eclipse.virgo.repository.ArtifactDescriptor;
diff --git a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridge.java b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridge.java
index a1963ff6..cd62c9ba 100644
--- a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridge.java
+++ b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridge.java
@@ -16,14 +16,17 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
-import org.osgi.framework.Version;
-
import org.eclipse.virgo.repository.ArtifactBridge;
import org.eclipse.virgo.repository.ArtifactDescriptor;
import org.eclipse.virgo.repository.ArtifactGenerationException;
import org.eclipse.virgo.repository.HashGenerator;
import org.eclipse.virgo.repository.builder.ArtifactDescriptorBuilder;
+import org.eclipse.virgo.repository.builder.AttributeBuilder;
+import org.eclipse.virgo.util.common.StringUtils;
import org.eclipse.virgo.util.io.IOUtils;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.service.cm.ConfigurationAdmin;
/**
* An {@link ArtifactBridge} that creates {@link ArtifactDescriptor ArtifactDescriptors} for .properties files.
@@ -42,8 +45,11 @@ public final class PropertiesBridge implements ArtifactBridge {
private final HashGenerator hashGenerator;
- public PropertiesBridge(HashGenerator hashGenerator) {
+ private final ConfigurationAdmin configAdmin;
+
+ public PropertiesBridge(HashGenerator hashGenerator, ConfigurationAdmin configAdmin) {
this.hashGenerator = hashGenerator;
+ this.configAdmin = configAdmin;
}
public ArtifactDescriptor generateArtifactDescriptor(File artifactFile) throws ArtifactGenerationException {
@@ -51,10 +57,11 @@ public final class PropertiesBridge implements ArtifactBridge {
FileReader reader = null;
try {
reader = new FileReader(artifactFile);
- new Properties().load(reader);
- return createArtifactDescriptor(artifactFile);
+ Properties properties = new Properties();
+ properties.load(reader);
+ return createArtifactDescriptor(artifactFile, properties);
} catch (IOException e) {
- throw new ArtifactGenerationException("Failed to read properties file", ARTIFACT_TYPE, e);
+ throw new ArtifactGenerationException("Failed processing properties file", ARTIFACT_TYPE, e);
} finally {
IOUtils.closeQuietly(reader);
}
@@ -62,10 +69,43 @@ public final class PropertiesBridge implements ArtifactBridge {
return null;
}
- private ArtifactDescriptor createArtifactDescriptor(File propertiesFile) {
- String fileName = propertiesFile.getName();
- String name = fileName.substring(0, fileName.length() - PROPERTIES_SUFFIX.length());
+ private ArtifactDescriptor createArtifactDescriptor(File propertiesFile, Properties properties) throws IOException {
+
+ String name = properties.getProperty(ConfigurationAdmin.SERVICE_FACTORYPID);
+ if (StringUtils.hasText(name)) {
+ // this is a factory configuration - need to generate actual PID for a new configuration
+ return buildForManagedServiceFactoryConfiguration(propertiesFile, name, properties);
+ }
+
+ name = properties.getProperty(Constants.SERVICE_PID);
+ if (!StringUtils.hasText(name)) {
+ String fileName = propertiesFile.getName();
+ name = fileName.substring(0, fileName.length() - PROPERTIES_SUFFIX.length());
+ }
+
+ return buildAtrifactDescriptor(propertiesFile, name).build();
+ }
+
+ /**
+ * @param propertiesFile
+ * @param name
+ * @param properties
+ * @return
+ * @throws IOException
+ */
+ private ArtifactDescriptor buildForManagedServiceFactoryConfiguration(File propertiesFile, String factoryPid, Properties properties)
+ throws IOException {
+
+ // generated service.pid - will use as a name for artifactId
+ String pid = configAdmin.createFactoryConfiguration(factoryPid, null).getPid();
+ ArtifactDescriptorBuilder builder = buildAtrifactDescriptor(propertiesFile, pid);
+ builder.addAttribute(new AttributeBuilder().setName(ConfigurationAdmin.SERVICE_FACTORYPID).setValue(factoryPid).build());
+
+ return builder.build();
+ }
+
+ private ArtifactDescriptorBuilder buildAtrifactDescriptor(File propertiesFile, String name) {
ArtifactDescriptorBuilder artifactDescriptorBuilder = new ArtifactDescriptorBuilder();
artifactDescriptorBuilder //
@@ -73,9 +113,9 @@ public final class PropertiesBridge implements ArtifactBridge {
.setType(ARTIFACT_TYPE) //
.setName(name) //
.setVersion(Version.emptyVersion);
-
+
this.hashGenerator.generateHash(artifactDescriptorBuilder, propertiesFile);
- return artifactDescriptorBuilder.build();
+ return artifactDescriptorBuilder;
}
}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java
index 4f046b2b..d0aa49f4 100644
--- a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java
@@ -11,18 +11,23 @@
package org.eclipse.virgo.kernel.artifact.properties;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
import java.io.File;
+import java.io.IOException;
+import java.util.Set;
import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
-
+import org.easymock.EasyMock;
import org.eclipse.virgo.kernel.artifact.StubHashGenerator;
import org.eclipse.virgo.kernel.artifact.properties.PropertiesBridge;
import org.eclipse.virgo.repository.ArtifactDescriptor;
import org.eclipse.virgo.repository.ArtifactGenerationException;
+import org.eclipse.virgo.repository.Attribute;
/**
*/
@@ -30,14 +35,14 @@ public class PropertiesBridgeTests {
@Test
public void testGeneratePropertiesFile() throws ArtifactGenerationException {
- PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator());
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator(), EasyMock.createMock(ConfigurationAdmin.class));
ArtifactDescriptor result = bridge.generateArtifactDescriptor(new File("src/test/resources/properties/foo.properties"));
assertNotNull(result);
}
@Test(expected = ArtifactGenerationException.class)
public void testFileDoesNotExist() throws ArtifactGenerationException {
- PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator());
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator(), EasyMock.createMock(ConfigurationAdmin.class));
File file = new File("src/test/resources/properties/not.exist.properties");
bridge.generateArtifactDescriptor(file);
@@ -45,8 +50,68 @@ public class PropertiesBridgeTests {
@Test
public void testGenerateNotPropertiesFile() throws ArtifactGenerationException {
- PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator());
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator(), createMock(ConfigurationAdmin.class));
ArtifactDescriptor descriptor = bridge.generateArtifactDescriptor(new File("src/test/resources/bar.noterties"));
assertNull(descriptor);
}
+
+ @Test
+ public void testGenerateWithFactoryPid() throws ArtifactGenerationException {
+ final String factoryPid = "test.factory.pid";
+ final String propertiesFile = "src/test/resources/properties/factoryPid.properties";
+
+ ConfigurationAdmin mockConfigAdmin = createMock(ConfigurationAdmin.class);
+ Configuration mockConfiguration = createMock(Configuration.class);
+
+ try {
+ expect(mockConfigAdmin.createFactoryConfiguration(factoryPid, null)).andReturn(mockConfiguration);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ expect(mockConfiguration.getPid()).andReturn("1");
+
+ replay(mockConfigAdmin, mockConfiguration);
+
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator(), mockConfigAdmin);
+ ArtifactDescriptor descriptor = bridge.generateArtifactDescriptor(new File(propertiesFile));
+
+ verify(mockConfigAdmin, mockConfiguration);
+
+ // asserts
+ assertNotNull(descriptor);
+ assertEquals("1", descriptor.getName());
+ // only expect one attribute
+ Set<Attribute> attrSet = descriptor.getAttribute(ConfigurationAdmin.SERVICE_FACTORYPID);
+ assertEquals(1, attrSet.size());
+ Attribute attr = attrSet.iterator().next();
+ assertNotNull(factoryPid, attr.getValue());
+ }
+
+ @Test(expected = ArtifactGenerationException.class)
+ public void testGenerateWithFactoryPidAndIoExceptionFromConfigAdmin() throws ArtifactGenerationException {
+ final String factoryPid = "test.factory.pid";
+ final String propertiesFile = "src/test/resources/properties/factoryPid.properties";
+
+ ConfigurationAdmin mockConfigAdmin = createMock(ConfigurationAdmin.class);
+
+ try {
+ expect(mockConfigAdmin.createFactoryConfiguration(factoryPid, null)).andThrow(new IOException("exception from configadmin"));
+ } catch (IOException e) {
+ // I really hate checked exceptions.
+ }
+
+ replay(mockConfigAdmin);
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator(), mockConfigAdmin);
+ bridge.generateArtifactDescriptor(new File(propertiesFile));
+ verify(mockConfigAdmin);
+ }
+
+ @Test
+ public void makeSureThatServicePidIsTakenFromTheFileProvidedProperties() throws ArtifactGenerationException {
+ final String name = "service.pid.in.the.file";
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator(), EasyMock.createMock(ConfigurationAdmin.class));
+ ArtifactDescriptor result = bridge.generateArtifactDescriptor(new File("src/test/resources/properties/with-service-pid.properties"));
+ assertNotNull(result);
+ assertEquals(name, result.getName());
+ }
}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/factoryPid.properties b/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/factoryPid.properties
new file mode 100644
index 00000000..f8d8d915
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/factoryPid.properties
@@ -0,0 +1,6 @@
+# factory pid for config admin service
+service.factoryPid = test.factory.pid
+
+# properties for the managed service
+prop1 = prop1
+prop2 = 2 \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/with-service-pid.properties b/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/with-service-pid.properties
new file mode 100644
index 00000000..e008c6c3
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/with-service-pid.properties
@@ -0,0 +1,6 @@
+#config admin properties config with service.pid specified in the file vs. filename
+service.pid = service.pid.in.the.file
+
+# properties
+prop1 = prop1
+prop2 = 2 \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/template.mf b/org.eclipse.virgo.kernel.artifact/template.mf
index bba83828..14c55078 100644
--- a/org.eclipse.virgo.kernel.artifact/template.mf
+++ b/org.eclipse.virgo.kernel.artifact/template.mf
@@ -9,6 +9,7 @@ Import-Template:
org.slf4j.*;version="${org.slf4j:[=.=.=, +1)}",
org.eclipse.virgo.medic.*;version="${org.eclipse.virgo.medic:[=.=.=, =.+1)}",
org.osgi.framework.*;version="0",
+ org.osgi.service.cm.*;version="0",
org.springframework.*;version="${org.springframework:[2.5.6, =.+1)}",
javax.xml.*;version="0",
org.xml.*;version="0",
diff --git a/org.eclipse.virgo.kernel.deployer.test/.project b/org.eclipse.virgo.kernel.deployer.test/.project
index f79f9158..11a008c8 100644
--- a/org.eclipse.virgo.kernel.deployer.test/.project
+++ b/org.eclipse.virgo.kernel.deployer.test/.project
@@ -20,11 +20,6 @@
<arguments>
</arguments>
</buildCommand>
- <buildCommand>
- <name>com.springsource.server.ide.bundlor.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
</buildSpec>
<natures>
<nature>com.springsource.server.ide.facet.core.bundlenature</nature>
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationDeploymentTests.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationDeploymentTests.java
index effd2b9b..3f49789e 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationDeploymentTests.java
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationDeploymentTests.java
@@ -160,27 +160,11 @@ public class ConfigurationDeploymentTests extends AbstractDeployerIntegrationTes
}
private void pollUntilInDeploymentIdentities(String type, String name, String version) throws InterruptedException {
- long start = System.currentTimeMillis();
-
- while (!isInDeploymentIdentities(type, name, version)) {
- long delta = System.currentTimeMillis() - start;
- if (delta > 60000) {
- fail("Deployment identity was not available within 60 seconds");
- }
- Thread.sleep(100);
- }
+ ConfigurationTestUtils.pollUntilInDeploymentIdentities(appDeployer, type, name, version);
}
private void pollUntilNotInDeploymentIdentities(String type, String name, String version) throws InterruptedException {
- long start = System.currentTimeMillis();
-
- while (isInDeploymentIdentities(type, name, version)) {
- long delta = System.currentTimeMillis() - start;
- if (delta > 60000) {
- fail("Deployment identity was still available after 60 seconds");
- }
- Thread.sleep(100);
- }
+ ConfigurationTestUtils.pollUntilNotInDeploymentIdentities(appDeployer, type, name, version);
}
@SuppressWarnings("unchecked")
@@ -206,40 +190,18 @@ public class ConfigurationDeploymentTests extends AbstractDeployerIntegrationTes
}
private boolean isInDeploymentIdentities(DeploymentIdentity deploymentIdentity) {
- boolean found = false;
- for (DeploymentIdentity id : this.appDeployer.getDeploymentIdentities()) {
- if (deploymentIdentity.equals(id)) {
- found = true;
- }
- }
- return found;
- }
-
- private boolean isInDeploymentIdentities(String type, String name, String version) {
- for (DeploymentIdentity id : this.appDeployer.getDeploymentIdentities()) {
- if (id.getType().equals(type) && id.getSymbolicName().equals(name) && id.getVersion().equals(version)) {
- return true;
- }
- }
- return false;
+ return ConfigurationTestUtils.isInDeploymentIdentities(appDeployer, deploymentIdentity);
}
private boolean isInConfigurationAdmin() throws IOException, InvalidSyntaxException {
- Configuration[] configurations = this.configAdmin.listConfigurations(null);
- for (Configuration configuration : configurations) {
- if ("t".equals(configuration.getPid())) {
- return true;
- }
- }
-
- return false;
+ return ConfigurationTestUtils.isInConfigurationAdmin(configAdmin, "t");
}
@SuppressWarnings("unchecked")
private void checkConfigAvailable() throws IOException, InvalidSyntaxException, InterruptedException {
- // Allow asynchronous delivery of configuration events to complete
- Thread.sleep(100);
-
+ // Allow asynchronous delivery of configuration events to complete
+ Thread.sleep(100);
+
long start = System.currentTimeMillis();
while (!isInConfigurationAdmin()) {
@@ -257,9 +219,9 @@ public class ConfigurationDeploymentTests extends AbstractDeployerIntegrationTes
}
private void checkConfigUnavailable() throws IOException, InvalidSyntaxException, InterruptedException {
- // Allow asynchronous delivery of configuration events to complete
- Thread.sleep(100);
-
+ // Allow asynchronous delivery of configuration events to complete
+ Thread.sleep(100);
+
assertFalse(isInConfigurationAdmin());
}
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
new file mode 100644
index 00000000..7daef1d7
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ConfigurationTestUtils.java
@@ -0,0 +1,123 @@
+/*
+ * This file is part of the Eclipse Virgo project.
+ *
+ * Copyright (c) 2011 copyright_holder
+ * 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.fail;
+
+import java.io.IOException;
+
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Utilities to share between configuration and factory configuration tests.
+ * <p />
+ *
+ */
+final class ConfigurationTestUtils {
+
+ static void pollUntilInDeploymentIdentities(ApplicationDeployer appDeployer, String type, String name, String version)
+ throws InterruptedException {
+ long start = System.currentTimeMillis();
+
+ while (!isInDeploymentIdentities(appDeployer, type, name, version)) {
+ long delta = System.currentTimeMillis() - start;
+ if (delta > 60000) {
+ fail("Deployment identity was not available within 60 seconds");
+ }
+ Thread.sleep(100);
+ }
+ }
+
+ static void pollUntilNotInDeploymentIdentities(ApplicationDeployer appDeployer, String type, String name, String version)
+ throws InterruptedException {
+ long start = System.currentTimeMillis();
+
+ while (isInDeploymentIdentities(appDeployer, type, name, version)) {
+ long delta = System.currentTimeMillis() - start;
+ if (delta > 60000) {
+ fail("Deployment identity was still available after 60 seconds");
+ }
+ Thread.sleep(100);
+ }
+ }
+
+ static boolean isInDeploymentIdentities(ApplicationDeployer appDeployer, DeploymentIdentity deploymentIdentity) {
+ for (DeploymentIdentity id : appDeployer.getDeploymentIdentities()) {
+ if (deploymentIdentity.equals(id)) {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
+ static boolean isInDeploymentIdentities(ApplicationDeployer appDeployer, String type, String name, String version) {
+ for (DeploymentIdentity id : appDeployer.getDeploymentIdentities()) {
+ if (id.getType().equals(type) && id.getSymbolicName().equals(name) && id.getVersion().equals(version)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ static boolean isInConfigurationAdmin(ConfigurationAdmin configAdmin, String pid) throws IOException, InvalidSyntaxException {
+ Configuration[] configurations = configAdmin.listConfigurations(null);
+ for (Configuration configuration : configurations) {
+ if (pid.equals(configuration.getPid())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ static boolean isFactoryInConfigurationAdmin(ConfigurationAdmin configAdmin, String factoryPid) throws IOException, InvalidSyntaxException {
+ Configuration[] configurations = configAdmin.listConfigurations(null);
+ for (Configuration configuration : configurations) {
+ if (factoryPid.equals(configuration.getFactoryPid())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ static void pollUntilFactoryInConfigurationAdmin(ConfigurationAdmin configAdmin, String factoryPid) throws Exception {
+ long start = System.currentTimeMillis();
+
+ while (!isFactoryInConfigurationAdmin(configAdmin, factoryPid)) {
+ long delta = System.currentTimeMillis() - start;
+ if (delta > 60000) {
+ fail("Deployment identity was not available within 60 seconds");
+ }
+ Thread.sleep(100);
+ }
+ }
+
+ static void pollUntilFactoryNotInConfigurationAdmin(ConfigurationAdmin configAdmin, String factoryPid) throws Exception {
+ long start = System.currentTimeMillis();
+
+ while (isFactoryInConfigurationAdmin(configAdmin, factoryPid)) {
+ long delta = System.currentTimeMillis() - start;
+ if (delta > 60000) {
+ fail("Deployment identity was still available after 60 seconds");
+ }
+ Thread.sleep(100);
+ }
+ }
+}
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
new file mode 100644
index 00000000..9da2048c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/FactoryConfigurationDeploymentTests.java
@@ -0,0 +1,356 @@
+
+package org.eclipse.virgo.kernel.deployer.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+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.junit.After;
+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;
+
+public class FactoryConfigurationDeploymentTests extends AbstractDeployerIntegrationTest {
+
+ private ServiceReference<ApplicationDeployer> appDeployerServiceReference;
+
+ private ApplicationDeployer appDeployer;
+
+ private ServiceReference<ConfigurationAdmin> configAdminServiceReference;
+
+ private ConfigurationAdmin configAdmin;
+
+ @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 volatile Dictionary properties;
+
+ 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 = properties;
+ }
+
+ @Override
+ public void deleted(String pid) {
+ this.deleteCallCount.incrementAndGet();
+ }
+
+ Dictionary getProperties() {
+ return this.properties;
+ }
+
+ int updateCount() {
+ return this.updateCallCount.get();
+ }
+
+ int deleteCount() {
+ return this.deleteCallCount.get();
+ }
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void testSimpleDeployUndeployOfFactoryConfig() throws Exception {
+
+ Hashtable<String, String> properties = new Hashtable<String, String>();
+ properties.put(Constants.SERVICE_PID, "test.factory.pid.a");
+ TestManagedServiceFactory service = new TestManagedServiceFactory();
+ 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"));
+
+ File configurationFile = new File("src/test/resources/configuration.deployment/factory-config-a.properties");
+
+ DeploymentIdentity deploymentIdentity = this.appDeployer.deploy(configurationFile.toURI());
+ assertNotNull(deploymentIdentity);
+
+ // let it deploy
+ Thread.sleep(1000);
+
+ assertEquals(1, countFactoryConfigurations("test.factory.pid.a"));
+ assertEquals(1, service.updateCount());
+ assertEquals(0, service.deleteCount());
+ Dictionary propertiesFromService = service.getProperties();
+ assertNotNull(propertiesFromService);
+ assertEquals("prop1", propertiesFromService.get("prop1"));
+ assertEquals("2", propertiesFromService.get("prop2"));
+
+ this.appDeployer.undeploy(deploymentIdentity);
+
+ // give time for events to percolate
+ Thread.sleep(1000);
+
+ assertEquals(0, countFactoryConfigurations("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(2, service.updateCount());
+ assertEquals(1, service.deleteCount());
+
+ this.appDeployer.undeploy(deploymentIdentity);
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void testHotDeployFactoryConfiguration() throws Exception {
+
+ final String factoryPid = "test.factory.pid.hot";
+ final Properties hotDeployConfiguration = new Properties();
+ hotDeployConfiguration.setProperty(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
+ hotDeployConfiguration.setProperty("prop1", "prop1");
+ hotDeployConfiguration.setProperty("prop2", "2");
+
+ File target = new File("target/pickup/factory-config-a-hot.properties");
+
+ if (target.exists()) {
+ assertTrue(target.delete());
+ }
+
+ try {
+ Hashtable<String, String> properties = new Hashtable<String, String>();
+ properties.put(Constants.SERVICE_PID, factoryPid);
+ TestManagedServiceFactory service = new TestManagedServiceFactory();
+ this.context.registerService(ManagedServiceFactory.class, service, properties);
+
+ // make sure that we are starting off with a clean slate
+ assertEquals(0, countFactoryConfigurations(factoryPid));
+
+ // copy file to hot deploy location
+ hotDeployConfiguration.store(new FileOutputStream(target), "no comment");
+
+ ConfigurationTestUtils.pollUntilFactoryInConfigurationAdmin(configAdmin, factoryPid);
+ assertEquals(1, countFactoryConfigurations(factoryPid));
+ assertEquals(1, service.updateCount());
+ assertEquals(0, service.deleteCount());
+
+ Dictionary propertiesFromService = service.getProperties();
+ assertNotNull(propertiesFromService);
+ assertEquals("prop1", propertiesFromService.get("prop1"));
+ assertEquals("2", propertiesFromService.get("prop2"));
+
+ // remove the file and let it be removed
+ target.delete();
+ ConfigurationTestUtils.pollUntilFactoryNotInConfigurationAdmin(configAdmin, factoryPid);
+
+ assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(1, service.updateCount());
+ assertEquals(1, service.deleteCount());
+ } finally {
+ if (target.exists()) {
+ target.delete();
+ }
+ }
+
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void testHotDeployWithUpdateFactoryConfiguration() throws Exception {
+
+ final String factoryPid = "test.factory.pid.hot.update";
+ final Properties hotDeployConfiguration = new Properties();
+ hotDeployConfiguration.setProperty(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
+ hotDeployConfiguration.setProperty("prop1", "prop1");
+ hotDeployConfiguration.setProperty("prop2", "2");
+
+ File target = new File("target/pickup/factory-config-a-hot-update.properties");
+
+ if (target.exists()) {
+ assertTrue(target.delete());
+ }
+
+ try {
+
+ Hashtable<String, String> properties = new Hashtable<String, String>();
+ properties.put(Constants.SERVICE_PID, factoryPid);
+ TestManagedServiceFactory service = new TestManagedServiceFactory();
+ this.context.registerService(ManagedServiceFactory.class, service, properties);
+
+ // make sure that we are starting off with a clean slate
+ assertEquals(0, countFactoryConfigurations(factoryPid));
+
+ // copy file to hot deploy location
+ hotDeployConfiguration.store(new FileOutputStream(target), "initial");
+
+ ConfigurationTestUtils.pollUntilFactoryInConfigurationAdmin(configAdmin, factoryPid);
+ // let events propagate
+ Thread.sleep(100);
+ assertEquals(1, countFactoryConfigurations(factoryPid));
+ assertEquals(1, service.updateCount());
+ assertEquals(0, service.deleteCount());
+
+ Dictionary propertiesFromService = service.getProperties();
+ assertNotNull(propertiesFromService);
+ assertEquals("prop1", propertiesFromService.get("prop1"));
+ assertEquals("2", propertiesFromService.get("prop2"));
+
+ // update configuration
+ hotDeployConfiguration.setProperty("prop2", "22");
+ // save updated configuration
+ hotDeployConfiguration.store(new FileOutputStream(target), "updated");
+
+ // let events propagate and update happen
+ Thread.sleep(3000);
+ assertEquals(1, countFactoryConfigurations(factoryPid));
+ assertEquals(2, service.updateCount());
+ assertEquals(0, service.deleteCount());
+
+ propertiesFromService = service.getProperties();
+ assertNotNull(propertiesFromService);
+ assertEquals("prop1", propertiesFromService.get("prop1"));
+ assertEquals("22", propertiesFromService.get("prop2"));
+
+ // remove the file and let it be removed
+ target.delete();
+ ConfigurationTestUtils.pollUntilFactoryNotInConfigurationAdmin(configAdmin, factoryPid);
+
+ assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(2, service.updateCount());
+ assertEquals(1, service.deleteCount());
+ } finally {
+ if (target.exists()) {
+ target.delete();
+ }
+ }
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void testHotDeployMultipleFactoryConfiguration() throws Exception {
+
+ final String factoryPid = "test.factory.pid.hot.multiple";
+
+ final Properties configOne = new Properties();
+ configOne.setProperty(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
+ configOne.setProperty("prop1", "prop1");
+ configOne.setProperty("prop2", "1");
+
+ final Properties configTwo = new Properties();
+ configTwo.setProperty(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
+ configTwo.setProperty("prop1", "prop2");
+ configTwo.setProperty("prop2", "2");
+
+ final File targetOne = new File("target/pickup/factory-config-a-hot-update-1.properties");
+ final File targetTwo = new File("target/pickup/factory-config-a-hot-update-2.properties");
+
+ if (targetOne.exists()) {
+ assertTrue(targetOne.delete());
+ }
+ if (targetTwo.exists()) {
+ assertTrue(targetTwo.delete());
+ }
+
+ try {
+
+ Hashtable<String, String> properties = new Hashtable<String, String>();
+ properties.put(Constants.SERVICE_PID, factoryPid);
+ TestManagedServiceFactory service = new TestManagedServiceFactory();
+ this.context.registerService(ManagedServiceFactory.class, service, properties);
+
+ // make sure that we are starting off with a clean slate
+ assertEquals(0, countFactoryConfigurations(factoryPid));
+
+ // copy file to hot deploy location
+ configOne.store(new FileOutputStream(targetOne), "initial");
+
+ ConfigurationTestUtils.pollUntilFactoryInConfigurationAdmin(configAdmin, factoryPid);
+ // let events propagate
+ Thread.sleep(100);
+ assertEquals(1, countFactoryConfigurations(factoryPid));
+ assertEquals(1, service.updateCount());
+ assertEquals(0, service.deleteCount());
+
+ // validate first configuration
+ Dictionary propertiesFromService = service.getProperties();
+ assertNotNull(propertiesFromService);
+ assertEquals("prop1", propertiesFromService.get("prop1"));
+ assertEquals("1", propertiesFromService.get("prop2"));
+
+ configTwo.store(new FileOutputStream(targetTwo), "initial");
+ Thread.sleep(3000);
+ assertEquals(2, countFactoryConfigurations(factoryPid));
+ assertEquals(2, service.updateCount());
+ assertEquals(0, service.deleteCount());
+
+ propertiesFromService = service.getProperties();
+ assertNotNull(propertiesFromService);
+ assertEquals("prop2", propertiesFromService.get("prop1"));
+ assertEquals("2", propertiesFromService.get("prop2"));
+
+ assertTrue(targetOne.delete());
+ assertTrue(targetTwo.delete());
+
+ // let events propagate and update happen
+ ConfigurationTestUtils.pollUntilFactoryNotInConfigurationAdmin(configAdmin, factoryPid);
+ assertEquals(0, countFactoryConfigurations(factoryPid));
+ assertEquals(2, service.updateCount());
+ assertEquals(2, service.deleteCount());
+
+ } finally {
+ if (targetOne.exists()) {
+ targetOne.delete();
+ }
+ if (targetTwo.exists()) {
+ targetTwo.delete();
+ }
+ }
+ }
+
+ 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/resources/configuration.deployment/factory-config-a.properties b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/configuration.deployment/factory-config-a.properties
new file mode 100644
index 00000000..6313f1a1
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/configuration.deployment/factory-config-a.properties
@@ -0,0 +1,6 @@
+# factory pid for config admin service
+service.factoryPid = test.factory.pid.a
+
+# properties for the managed service
+prop1 = prop1
+prop2 = 2 \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.services/src/main/resources/META-INF/spring/repository-context.xml b/org.eclipse.virgo.kernel.services/src/main/resources/META-INF/spring/repository-context.xml
index c8a3de66..2335409b 100644
--- a/org.eclipse.virgo.kernel.services/src/main/resources/META-INF/spring/repository-context.xml
+++ b/org.eclipse.virgo.kernel.services/src/main/resources/META-INF/spring/repository-context.xml
@@ -48,6 +48,9 @@
<bean id="propertiesBridge" class="org.eclipse.virgo.kernel.artifact.properties.PropertiesBridge">
<constructor-arg ref="hashGenerator"/>
+ <constructor-arg>
+ <osgi:reference interface="org.osgi.service.cm.ConfigurationAdmin"/>
+ </constructor-arg>
</bean>
<osgi:service ref="propertiesBridge" interface="org.eclipse.virgo.repository.ArtifactBridge"/>
diff --git a/org.eclipse.virgo.kernel.services/template.mf b/org.eclipse.virgo.kernel.services/template.mf
index 97f8e042..6e06cb1d 100644
--- a/org.eclipse.virgo.kernel.services/template.mf
+++ b/org.eclipse.virgo.kernel.services/template.mf
@@ -13,6 +13,7 @@ Import-Template:
org.aspectj.*;version="${org.aspectj:[=.=.=.=, +1)}",
org.slf4j.*;version="${org.slf4j:[=.=.=, +1)}",
org.osgi.framework.*;version="0",
+ org.osgi.service.cm.*;version="0",
org.springframework.*;version="${org.springframework:[2.5.6, =.+1)}",
javax.management.*;version="0",
javax.xml.*;version="0",
diff --git a/org.eclipse.virgo.kernel.test/.project b/org.eclipse.virgo.kernel.test/.project
index 5781bd1d..ac8c0052 100644
--- a/org.eclipse.virgo.kernel.test/.project
+++ b/org.eclipse.virgo.kernel.test/.project
@@ -20,11 +20,6 @@
<arguments>
</arguments>
</buildCommand>
- <buildCommand>
- <name>com.springsource.server.ide.bundlor.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
</buildSpec>
<natures>
<nature>com.springsource.server.ide.facet.core.bundlenature</nature>

Back to the top