summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-06-14 07:00:09 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-06-14 07:00:09 +0000
commit86341a0d865276fac10d6d595cfa6361380559fe (patch)
tree0bf27a14d184b416fc61cb8667ee2ce76aa789f0 /sca-java-2.x/trunk
parent745f458002e384d4de784449685e9fc21e667a99 (diff)
Have a look at creating a domain node from a file system dirctory to see if its possible to do it in a way thats simpler than requiring a node.xml config file
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1135391 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java70
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java72
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite29
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jarbin0 -> 4788 bytes
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml23
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jarbin0 -> 4808 bytes
6 files changed, 193 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java
index 4dbccfbe28..3c34a24ca3 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java
@@ -19,13 +19,21 @@
package org.apache.tuscany.sca;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.Properties;
+import javax.xml.stream.XMLStreamException;
+
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.common.java.io.IOHelper;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
@@ -136,7 +144,7 @@ public class TuscanyRuntime {
* @return a Node
*/
public Node createNode() {
- return createNode(null);
+ return createNode((String)null);
}
/**
@@ -152,6 +160,66 @@ public class TuscanyRuntime {
DomainRegistry domainRegistry = domainRegistryFactory.getEndpointRegistry(domainURI, domainName);
return new NodeImpl(deployer, compositeActivator, domainRegistry, extensionPointRegistry, null);
}
+
+ /*
+ * Create a node from a file system directory.
+ * The directory can contain:
+ * domain.properties
+ * contributions - jar, zip, or exploded directories
+ * sca-contribution.xml metaData files to override whats in a contribution
+ * .composite files to add to contributions as additional deployables
+ *
+ * TODO: Review if this is useful?
+ */
+ public Node createNode(File directory) throws ContributionReadException, ValidationException, ActivationException, XMLStreamException, IOException {
+
+ Properties domainProps = new Properties();
+ File propsFile = new File(directory, "domain.properties");
+ if (propsFile.exists()) {
+ domainProps.load(new FileInputStream(propsFile));
+ }
+ String domainName = domainProps.getProperty("domainName", directory.getName());
+ String domainURI = domainProps.getProperty("domainURI", domainName);
+
+ DomainRegistry domainRegistry = domainRegistryFactory.getEndpointRegistry(domainURI, domainName);
+ Node node = new NodeImpl(deployer, compositeActivator, domainRegistry, extensionPointRegistry, null);
+
+
+ List<String> installed = new ArrayList<String>();
+ for (File f : directory.listFiles()) {
+ if (!f.getName().endsWith(".xml") && !f.getName().endsWith(".composite")) {
+ String fn = f.getName().lastIndexOf('.') == -1 ? f.getName() : f.getName().substring(0, f.getName().lastIndexOf('.'));
+ String metaData = null;
+ for (File f2 : directory.listFiles()) {
+ if (f2.getName().startsWith(fn) && f2.getName().endsWith(".xml")) {
+ metaData = f2.getPath();
+ break;
+ }
+ }
+
+ List<String> dependencyURIs = new ArrayList();
+ String dependencyURIprop = domainProps.getProperty(fn + ".dependencies");
+ if (dependencyURIprop != null && dependencyURIprop.length() > 0) {
+ dependencyURIs = Arrays.asList(dependencyURIprop.split(","));
+ }
+
+ String curi = node.installContribution(null, f.getPath(), metaData, dependencyURIs);
+ installed.add(curi);
+
+ for (File f2 : directory.listFiles()) {
+ if (f2.getName().startsWith(fn) && f2.getName().endsWith(".composite")) {
+ node.addDeploymentComposite(curi, new FileReader(f2));
+ }
+ }
+ }
+ }
+
+ for (String curi : installed) {
+ node.startDeployables(curi);
+ }
+
+ return node;
+ }
/**
* Creates a Node from an XML configuration file
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
new file mode 100644
index 0000000000..0a6d148957
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.ContributionDescription;
+import org.junit.Test;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public class DirectoryDomainTestCase {
+
+ @Test
+ public void testDefaultDomain() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/default"));
+
+ Assert.assertEquals("default", node.getDomainName());
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("sample-helloworld", node.getInstalledContributionURIs().get(0));
+ Assert.assertEquals("helloworld.composite", node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+ }
+
+ @Test
+ public void testMyDomain() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException {
+ Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/MyDomain"));
+
+ Assert.assertEquals("MyDomain", node.getDomainName());
+ Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+ Assert.assertEquals("helloworld-contribution", node.getInstalledContributionURIs().get(0));
+
+ // validate additional deployable composite
+ Map<String, List<String>> scs = node.getStartedCompositeURIs();
+ Assert.assertEquals(2, scs.get("helloworld-contribution").size());
+ Assert.assertTrue(scs.get("helloworld-contribution").contains("helloworld.composite"));
+ Assert.assertTrue(scs.get("helloworld-contribution").contains("helloworld2.composite"));
+
+ // validate metadata side file
+ ContributionDescription ic = node.getInstalledContribution("helloworld-contribution");
+ Assert.assertEquals(1, ic.getJavaExports().size());
+ Assert.assertEquals("sample", ic.getJavaExports().get(0));
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite
new file mode 100644
index 0000000000..8c7a789380
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://sample"
+ name="helloworld2">
+
+ <component name="Helloworld2Component">
+ <implementation.java class="sample.HelloworldImpl"/>
+ </component>
+
+</composite>
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jar b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jar
new file mode 100644
index 0000000000..5198370d85
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jar
Binary files differ
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml
new file mode 100644
index 0000000000..2788e14022
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:sample="http://sample">
+ <export.java package="sample" />
+</contribution>
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jar b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jar
new file mode 100644
index 0000000000..1ea85c8e63
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jar
Binary files differ