diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-15 06:54:08 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-15 06:54:08 +0000 |
commit | 5bbd095ce19fd97cfddd476dff166ad61d91fd39 (patch) | |
tree | 9bb77884c8fe3efa8269738aabda564aec10261e /sca-java-2.x/trunk/modules/core-spi/src | |
parent | 2dea3f21e44db4a7a7cba487a83149a10ec63811 (diff) |
Update InstalledContribution to derive a default uri when no uri is specify
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1103280 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/core-spi/src')
-rw-r--r-- | sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java index fe058de53f..b3d5863891 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.runtime;
+import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -46,18 +47,23 @@ public class InstalledContribution implements Serializable { // the URI and XML content of composites to include in the contribution
private Map<String, String> additionalDeployables = new HashMap<String, String>();
- public String getURI() {
- return uri;
+ public InstalledContribution(String url) {
+ this(null, url);
}
- public void setURI(String uri) {
+ public InstalledContribution(String uri, String url) {
+ this.url = url;
this.uri = uri;
+ if (uri == null || uri.length() < 1) {
+ this.uri = deriveContributionURI(url);
+ }
+ }
+
+ public String getURI() {
+ return uri;
}
public String getURL() {
return url;
}
- public void setURL(String url) {
- this.url = url;
- }
public List<String> getDeployables() {
return deployables;
}
@@ -91,4 +97,32 @@ public class InstalledContribution implements Serializable { public List<String> getNamespaceExports() {
return namespaceExports;
}
+
+ /**
+ * Derives a URI for the contribution based on its URL
+ */
+ protected String deriveContributionURI(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);
+ }
+ if (uri.endsWith("SNAPSHOT")) {
+ uri = uri.substring(0, uri.lastIndexOf('-'));
+ uri = uri.substring(0, uri.lastIndexOf('-'));
+ }
+ return uri;
+ }
}
|