tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1103280 - /tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java
Date Sun, 15 May 2011 06:54:08 GMT
Author: antelder
Date: Sun May 15 06:54:08 2011
New Revision: 1103280

URL: http://svn.apache.org/viewvc?rev=1103280&view=rev
Log:
Update InstalledContribution to derive a default uri when no uri is specify

Modified:
    tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java

Modified: tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java?rev=1103280&r1=1103279&r2=1103280&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/InstalledContribution.java
Sun May 15 06:54:08 2011
@@ -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 imple
     // 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 imple
     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;
+    }
 }



Mime
View raw message