tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r981496 - /tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java
Date Mon, 02 Aug 2010 13:00:13 GMT
Author: antelder
Date: Mon Aug  2 13:00:13 2010
New Revision: 981496

URL: http://svn.apache.org/viewvc?rev=981496&view=rev
Log:
Update for using a default contribution uri if none is specified

Modified:
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java

Modified: tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java?rev=981496&r1=981495&r2=981496&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java
Mon Aug  2 13:00:13 2010
@@ -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;
+    }
+    
 }



Mime
View raw message