summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java42
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java47
2 files changed, 64 insertions, 25 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
index 7bc17c959d..c1bb1c69ad 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
@@ -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)) {
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
index 5450682136..fdfb0b2028 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/Node2TestCase.java
@@ -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");
}
-
-
+
}