summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-08-02 13:00:13 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-08-02 13:00:13 +0000
commit96934d78d97077accdc392e858a3824d40e27cc1 (patch)
tree90820061ae35972aab639b56d0b5d9b8f5b9a501 /sca-java-2.x
parent3e0e09e6e2cfd96f814c307ce5757f5c86c70993 (diff)
Update for using a default contribution uri if none is specified
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@981496 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java48
1 files changed, 35 insertions, 13 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java
index 40ea587684..e0c7db3286 100644
--- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.node2.impl;
+import java.io.File;
import java.io.Reader;
import java.net.URI;
import java.util.ArrayList;
@@ -70,19 +71,13 @@ public class NodeImpl implements Node {
}
public String installContribution(String contributionURL) throws ContributionReadException, ActivationException, ValidationException {
- int lastDot = contributionURL.lastIndexOf('.');
- int lastSep = contributionURL.lastIndexOf("/");
- String uri;
- if (lastDot > -1 && lastSep > -1 && lastDot > lastSep) {
- uri = contributionURL.substring(lastSep+1, lastDot);
- } else {
- uri = contributionURL;
- }
- installContribution(uri, contributionURL, null, null, true);
- return uri;
+ return installContribution(null, contributionURL, null, null, true);
}
-
- public void installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs, boolean runDeployables) throws ContributionReadException, ActivationException, ValidationException {
+
+ public String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs, boolean runDeployables) throws ContributionReadException, ActivationException, ValidationException {
+ if (uri == null) {
+ uri = getDefaultContributionURI(contributionURL);
+ }
Monitor monitor = deployer.createMonitor();
Contribution contribution = deployer.loadContribution(IOHelper.createURI(uri), IOHelper.getLocationAsURL(contributionURL), monitor);
monitor.analyzeProblems();
@@ -90,6 +85,7 @@ public class NodeImpl implements Node {
mergeContributionMetaData(metaDataURL, contribution);
}
installContribution(contribution, dependentContributionURIs, runDeployables);
+ return uri;
}
private void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException {
@@ -106,7 +102,7 @@ public class NodeImpl implements Node {
contribution.getExports().addAll(metaData.getExports());
}
- public void installContribution(Contribution contribution, List<String> dependentContributionURIs, boolean runDeployables) throws ContributionReadException, ActivationException, ValidationException {
+ public String installContribution(Contribution contribution, List<String> dependentContributionURIs, boolean runDeployables) throws ContributionReadException, ActivationException, ValidationException {
InstalledContribution ic = new InstalledContribution(contribution.getURI(), contribution.getLocation(), contribution, dependentContributionURIs);
installedContributions.put(contribution.getURI(), ic);
if (runDeployables) {
@@ -126,6 +122,7 @@ public class NodeImpl implements Node {
}
monitor.analyzeProblems();
}
+ return ic.getURI();
}
protected List<Contribution> calculateDependentContributions(InstalledContribution ic) {
@@ -332,4 +329,29 @@ public class NodeImpl implements Node {
}
return dependentContributionURIs;
}
+
+ /**
+ * Returns a default URI for a contribution based on the contribution URL
+ */
+ protected String getDefaultContributionURI(String contributionURL) {
+ String uri = null;
+ try {
+ File f = new File(contributionURL);
+ if ("classes".equals(f.getName()) && "target".equals(f.getParentFile().getName())) {
+ uri = f.getParentFile().getParentFile().getName();
+ } else {
+ uri = f.getName();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ if (uri == null) {
+ uri = contributionURL;
+ }
+ if (uri.endsWith(".zip") || uri.endsWith(".jar")) {
+ uri = uri.substring(0, uri.length()-4);
+ }
+ return uri;
+ }
+
}