You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2011/05/13 16:41:30 UTC

svn commit: r1102763 - in /tuscany/sca-java-2.x/trunk/modules/domain-node/src: main/java/org/apache/tuscany/sca/impl/NodeImpl2.java test/java/org/apache/tuscany/sca/impl/Node2TestCase.java

Author: antelder
Date: Fri May 13 14:41:29 2011
New Revision: 1102763

URL: http://svn.apache.org/viewvc?rev=1102763&view=rev
Log:
Add code for handling import/export better, imports now work when the exporting contribution is installed on a distributed remote node, woohoo.

Modified:
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java?rev=1102763&r1=1102762&r2=1102763&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java Fri May 13 14:41:29 2011
@@ -144,9 +144,15 @@ public class NodeImpl2 {
         try {
             deployer.resolve(contribution, dependentContributions, monitor);
         } catch (Exception e) {
+            loadedContributions.remove(ic.getURI());
             throw new RuntimeException(e);
         }
-        monitor.analyzeProblems();
+        try {
+            monitor.analyzeProblems();
+        } catch (ValidationException e) {
+            loadedContributions.remove(ic.getURI());
+            throw e;
+        }
     }
     
     public Map<String, List<QName>> getStartedComposites() {
@@ -206,7 +212,7 @@ public class NodeImpl2 {
     protected List<Contribution> calculateDependentContributions(InstalledContribution ic) throws ContributionReadException, ValidationException {
         List<Contribution> dependentContributions = new ArrayList<Contribution>();
         Contribution c = loadContribution(ic);
-        if (ic.getDependentContributionURIs() != null) {
+        if (ic.getDependentContributionURIs() != null && ic.getDependentContributionURIs().size() > 0) {
             // if the install specified dependent uris use just those contributions
             for (String uri : ic.getDependentContributionURIs()) {
                 InstalledContribution dependee = endpointRegistry.getInstalledContribution(uri);
@@ -215,20 +221,36 @@ public class NodeImpl2 {
                 }
             }
         } else {
-            // TODO: otherwise find from the registry which contributions export the required resources
             for (Import imprt : c.getImports()) {
-                // TODO: Handle Imports in a more extensible way
-                if (imprt instanceof JavaImport) {
-//                    ic.getJavaExports().add(((JavaExport)export).getPackage());
-                } else if (imprt instanceof NamespaceImport) {
-//                    ic.getNamespaceExports().add(((NamespaceExport)export).getNamespace());
-                } 
-//                dependentContributions.add(ics.getContribution());
+                InstalledContribution exportingIC = findExportingContribution(imprt);
+                if (exportingIC != null) {
+                    dependentContributions.add(loadContribution(exportingIC));
+                }
             }
         }
+        // TODO: there is also the location attribute on the import which should be taken into account
         return dependentContributions;
     }
 
+    private InstalledContribution findExportingContribution(Import imprt) {
+        // TODO: Handle Imports in a more extensible way
+        for (String curi : endpointRegistry.getInstalledContributionURIs()) {
+            InstalledContribution ic = endpointRegistry.getInstalledContribution(curi);
+            if (imprt instanceof JavaImport) {
+                for (String s : ic.getJavaExports()) {
+                    if (s.startsWith(((JavaImport)imprt).getPackage())) {
+                        return ic;
+                    }
+                }
+            } else if (imprt instanceof NamespaceImport) {
+                if (ic.getNamespaceExports().contains(((NamespaceImport)imprt).getNamespace())) {
+                        return ic;
+                }
+            } 
+        }
+        return null;
+    }
+
     protected Composite getComposite(Contribution contribution, String compositeURI) {
         for (Artifact a : contribution.getArtifacts()) {
             if (a.getURI().equals(compositeURI)) {

Modified: tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java?rev=1102763&r1=1102762&r2=1102763&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java Fri May 13 14:41:29 2011
@@ -77,7 +77,7 @@ public class Node2TestCase {
 
         InstalledContribution ic = nodeB.getInstalledContribution("export");
         Assert.assertEquals(1, ic.getJavaExports().size());
-        Assert.assertEquals("foo", ic.getJavaExports().get(0));
+        Assert.assertEquals("sample", ic.getJavaExports().get(0));
     }
     
     @Test
@@ -103,7 +103,7 @@ public class Node2TestCase {
         
         InstalledContribution ic = node.getInstalledContribution("export");
         Assert.assertEquals(1, ic.getJavaExports().size());
-        Assert.assertEquals("foo", ic.getJavaExports().get(0));
+        Assert.assertEquals("sample", ic.getJavaExports().get(0));
     }
 
     @Test
@@ -120,20 +120,38 @@ public class Node2TestCase {
         try {
             node.validateContribution("import");
         } catch (ValidationException e) {
-            Assert.assertTrue(e.getMessage().endsWith("Unresolved import: Import = foo"));            
+            Assert.assertTrue(e.getMessage().endsWith("Unresolved import: Import = sample"));            
         }
     }
 
-//    @Test
-//    public void importExportValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
-//        NodeImpl2 node = TuscanyRuntime.newInstance().createNode2("ImportTestCase");
-//        node.installContribution("src/test/resources/import.jar");
-//        try {
-//            node.validateContribution("import");
-//        } catch (ValidationException e) {
-//            Assert.assertTrue(e.getMessage().endsWith("Unresolved import: Import = foo"));            
-//        }
-//    }
+    @Test
+    public void importExportValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+        NodeImpl2 node = TuscanyRuntime.newInstance().createNode2("ImportTestCase");
+        node.installContribution("src/test/resources/import.jar");
+        try {
+            node.validateContribution("import");
+        } catch (ValidationException e) {
+            // expected
+        }
+        node.installContribution("src/test/resources/export.jar");
+        node.validateContribution("import");
+        node.startComposite("import", "helloworld.composite");
+    }
+
+    @Test
+    public void importExportDistributedValidate() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
+        NodeImpl2 nodeA = TuscanyRuntime.newInstance().createNode2("uri:ImportTestCase");
+        nodeA.installContribution("src/test/resources/import.jar");
+        try {
+            nodeA.validateContribution("import");
+        } catch (ValidationException e) {
+            // expected
+        }
+        NodeImpl2 nodeB = TuscanyRuntime.newInstance().createNode2("uri:ImportTestCase");
+        nodeB.installContribution("src/test/resources/export.jar");
+        nodeA.validateContribution("import");
+        nodeA.startComposite("import", "helloworld.composite");
+    }
 
     @Test
     public void startTest() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException {
@@ -152,6 +170,5 @@ public class Node2TestCase {
         Assert.assertEquals("helloworld", node.getStartedComposites().get("sample-helloworld").get(0).getLocalPart());
         node.stopComposite("sample-helloworld", "helloworld.composite");
     }
-    
-    
+
 }