tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r662898 - in /incubator/tuscany/java/sca/modules/domain-manager/src/main: java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java resources/workspace.html
Date Tue, 03 Jun 2008 21:31:38 GMT
Author: jsdelfino
Date: Tue Jun  3 14:31:37 2008
New Revision: 662898

URL: http://svn.apache.org/viewvc?rev=662898&view=rev
Log:
List available contribution directories in the Add Contribution field.

Modified:
    incubator/tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java
    incubator/tuscany/java/sca/modules/domain-manager/src/main/resources/workspace.html

Modified: incubator/tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java?rev=662898&r1=662897&r2=662898&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java
(original)
+++ incubator/tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java
Tue Jun  3 14:31:37 2008
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.sca.domain.manager.impl;
 
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
 import static org.apache.tuscany.sca.domain.manager.impl.DomainManagerUtil.DEPLOYMENT_CONTRIBUTION_URI;
 import static org.apache.tuscany.sca.domain.manager.impl.DomainManagerUtil.compositeSimpleTitle;
 import static org.apache.tuscany.sca.domain.manager.impl.DomainManagerUtil.compositeSourceLink;
@@ -29,6 +30,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
@@ -45,6 +47,7 @@
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -292,6 +295,61 @@
 
             return entries.toArray(new Entry[entries.size()]);
             
+        } if (queryString.startsWith("suggestions=true")) {
+            
+            // Returns a list of contribution suggestions, by scanning the parent of the
workspace
+            // directory for potential contribution directories, for example project directories
+            Workspace suggestionWorkspace = workspaceFactory.createWorkspace();
+            List<Entry> entries = new ArrayList<Entry>();
+            String rootDirectory = domainManagerConfiguration.getRootDirectory();
+            File rootLocation = new File(new File(rootDirectory).toURI().normalize());
+            for (File project: rootLocation.getParentFile().listFiles()) {
+                File dotProject = new File(project, ".project");
+                if (!dotProject.exists()) {
+                    continue;
+                }
+                
+                // We have a potential contribution
+                String uri = project.getName();
+                File location = project;
+                
+                // If this is a Java project, find it's output location
+                File dotClasspath = new File(project, ".classpath");
+                if (dotClasspath.exists()) {
+                    try {
+                        XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(dotClasspath));
+                        reader.nextTag();
+                        while (reader.hasNext()) {
+                            int event = reader.getEventType();
+                            if (event == START_ELEMENT) {
+                                if ("classpathentry".equals(reader.getName().getLocalPart()))
{
+                                    if ("output".equals(reader.getAttributeValue("", "kind")))
{
+                                        location = new File(project, reader.getAttributeValue("",
"path"));
+                                        break;
+                                    }
+                                }
+                            }
+                            if (reader.hasNext()) {
+                                reader.next();
+                            }
+                        }
+                    } catch (FileNotFoundException e) {
+                    } catch (XMLStreamException e) {
+                    }
+                    
+                }
+                
+                // Create a contribution entry
+                if (!location.getPath().startsWith(rootLocation.getPath())) {
+                    Contribution contribution = contributionFactory.createContribution();
+                    contribution.setURI(uri);
+                    contribution.setLocation(location.getPath());
+                    entries.add(entry(suggestionWorkspace, contribution));
+                }
+            }
+            
+            return entries.toArray(new Entry[entries.size()]);
+            
         } else {
             throw new UnsupportedOperationException();
         }

Modified: incubator/tuscany/java/sca/modules/domain-manager/src/main/resources/workspace.html
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/domain-manager/src/main/resources/workspace.html?rev=662898&r1=662897&r2=662898&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/domain-manager/src/main/resources/workspace.html (original)
+++ incubator/tuscany/java/sca/modules/domain-manager/src/main/resources/workspace.html Tue
Jun  3 14:31:37 2008
@@ -83,6 +83,24 @@
 		}
 	}				
 
+	var suggestedContributions = new Array();
+	
+	function getSuggestedContributions() {
+		workspace.get("?suggestions=true", getSuggestedContributionsResponse);
+	}
+	
+	function getSuggestedContributionsResponse(feed) {
+		suggestedContributions = new Array();
+		if (feed != null) {
+			var entries = feed.getElementsByTagName("entry");              
+			for (var i=0; i<entries.length; i++) {
+				var id = entries[i].getElementsByTagName("id")[0].firstChild.nodeValue;
+				var location = entries[i].getElementsByTagName("link")[1].getAttribute("href");
+				suggestedContributions[i] = id + ':' + location;	
+			}
+		}
+	}				
+
 	function deleteContribution() {
 		var contributions  = array(document.workspaceForm.contributions);
 		for (var i=0; i < contributions.length; i++) {
@@ -113,10 +131,36 @@
 		document.newContributionForm.contributionLocation.value = "";
 	    getContributions();
 	}
-	
+
+	function suggestContributionIDs() {
+		var ids = new Array();
+		for (var i=0; i<suggestedContributions.length; i++) {
+			var uri = suggestedContributions[i];
+			var id = uri.substring(0, uri.indexOf(':'));
+			ids[id] = id;
+		}
+		return array(ids);
+	}
+
+	function suggestContributionLocations() {
+		var locations = new Array();
+		for (var i=0; i<suggestedContributions.length; i++) {
+			var uri = suggestedContributions[i];
+			var id = uri.substring(0, uri.indexOf(':'));
+			if (id == document.newContributionForm.contributionID.value) {
+				var location = uri.substring(uri.indexOf(':') +1);
+				locations[location] = location;
+			}
+		}
+		return array(locations);
+	}
+
 	function init() {
 		toolbar();
 		getContributions();
+		getSuggestedContributions();
+		suggest(document.newContributionForm.contributionID, suggestContributionIDs);
+		suggest(document.newContributionForm.contributionLocation, suggestContributionLocations);
 	}
 	
 </script>



Mime
View raw message