You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by io...@apache.org on 2010/11/23 17:04:23 UTC

svn commit: r1038183 - in /karaf/trunk: features/command/src/main/java/org/apache/karaf/features/command/ features/core/src/main/java/org/apache/karaf/features/ features/core/src/main/java/org/apache/karaf/features/internal/ webconsole/features/src/mai...

Author: iocanel
Date: Tue Nov 23 16:04:22 2010
New Revision: 1038183

URL: http://svn.apache.org/viewvc?rev=1038183&view=rev
Log:
[KARAF-257] Added description and details field to features. RepositoryImpl reads description attribute and details element. Features list and info commands have been updated to display description and details

Modified:
    karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
    karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
    karaf/trunk/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/ExtendedFeature.java

Modified: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java?rev=1038183&r1=1038182&r2=1038183&view=diff
==============================================================================
--- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java (original)
+++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java Tue Nov 23 16:04:22 2010
@@ -73,6 +73,10 @@ public class InfoFeatureCommand extends 
 
         System.out.println("Description of " + feature.getName() + " " + feature.getVersion() + " feature");
         System.out.println("----------------------------------------------------------------");
+        if(feature.getDetails() != null && feature.getDetails().length() >0) {
+           System.out.print(feature.getDetails());
+           System.out.println("----------------------------------------------------------------");
+        }
         if (config) {
             displayConfigInformation(feature);
         }

Modified: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java?rev=1038183&r1=1038182&r2=1038183&view=diff
==============================================================================
--- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java (original)
+++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java Tue Nov 23 16:04:22 2010
@@ -16,22 +16,20 @@
  */
 package org.apache.karaf.features.command;
 
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.karaf.features.FeaturesService;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
 import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.Repository;
-import org.apache.felix.gogo.commands.Option;
-import org.apache.felix.gogo.commands.Command;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 @Command(scope = "features", name = "list", description = "Lists all existing features available from the defined repositories.")
 public class ListFeaturesCommand extends FeaturesCommandSupport {
 
-    @Option(name = "-i", aliases={"--installed"}, description="Display a list of all installed features only", required = false, multiValued = false)
+    @Option(name = "-i", aliases = {"--installed"}, description = "Display a list of all installed features only", required = false, multiValued = false)
     boolean installed;
 
     private static final String STATE = "State";
@@ -41,6 +39,7 @@ public class ListFeaturesCommand extends
     private static final String VERSION = "Version";
     private static final String NAME = "Name";
     private static final String REPOSITORY = "Repository";
+    private static final String DESCRIPTION = "Description";
 
     protected void doExecute(FeaturesService admin) throws Exception {
 
@@ -59,8 +58,7 @@ public class ListFeaturesCommand extends
         if (features.size() == 0) {
             if (installed) {
                 System.out.println("No features installed.");
-            }
-            else {
+            } else {
                 System.out.println("No features available.");
             }
             return;
@@ -75,6 +73,11 @@ public class ListFeaturesCommand extends
         for (Feature f : features) {
             maxNameSize = Math.max(maxNameSize, f.getName().length());
         }
+        int maxRepositorySize = REPOSITORY.length();
+        for (Repository repository:repositories) {
+                maxRepositorySize = Math.max(maxRepositorySize,  repository.getName().length());
+        }
+
         StringBuilder sb = new StringBuilder();
         sb.append(STATE).append("         ").append(VERSION).append("   ");
         for (int i = VERSION.length(); i < maxVersionSize; i++) {
@@ -84,7 +87,12 @@ public class ListFeaturesCommand extends
         for (int i = NAME.length(); i < maxNameSize; i++) {
             sb.append(" ");
         }
-        sb.append(REPOSITORY);
+        sb.append(REPOSITORY).append(" ");
+
+        for (int i = REPOSITORY.length(); i < maxRepositorySize; i++) {
+            sb.append(" ");
+        }
+        sb.append(DESCRIPTION);
         System.out.println(sb.toString());
 
         // Print the feature data.
@@ -117,11 +125,22 @@ public class ListFeaturesCommand extends
             String name = repositories.get(0).getName();
             sb.append(name);
             repositories.remove(0);
-            System.out.println(sb.toString());
+            
             if (name.charAt(name.length() - 1) == '*') {
                 needsLegend = true;
             }
 
+            for (int i = name.length(); i < maxRepositorySize; i++) {
+                sb.append(" ");
+            }
+
+            String description = "";
+            if(f.getDescription() != null) {
+            description = f.getDescription();
+            }
+            sb.append(description);
+
+            System.out.println(sb.toString());            
         }
 
         if (needsLegend) {

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java?rev=1038183&r1=1038182&r2=1038183&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java Tue Nov 23 16:04:22 2010
@@ -28,6 +28,10 @@ public interface Feature {
 
     String getName();
 
+    String getDescription();
+
+    String getDetails();
+
     String getVersion();
 
     String getResolver();

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java?rev=1038183&r1=1038182&r2=1038183&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java Tue Nov 23 16:04:22 2010
@@ -31,6 +31,8 @@ public class FeatureImpl implements Feat
 
     private String id;
     private String name;
+    private String description;
+    private String details;
     private String version;
     private String resolver;
     private List<Feature> dependencies = new ArrayList<Feature>();
@@ -60,6 +62,22 @@ public class FeatureImpl implements Feat
         return name;
     }
 
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getDetails() {
+        return details;
+    }
+
+    public void setDetails(String details) {
+        this.details = details;
+    }
+
     public String getVersion() {
 		return version;
 	}

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java?rev=1038183&r1=1038182&r2=1038183&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java Tue Nov 23 16:04:22 2010
@@ -16,34 +16,27 @@
  */
 package org.apache.karaf.features.internal;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.Repository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-
-import org.apache.karaf.features.Repository;
-import org.apache.karaf.features.Feature;
 import org.xml.sax.SAXException;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLConnection;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * The repository implementation.
  */
@@ -85,24 +78,23 @@ public class RepositoryImpl implements R
 
     public void load() throws IOException {
         try {
-        	valid = true;
+            valid = true;
             repositories = new ArrayList<URI>();
             features = new ArrayList<Feature>();
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             URLConnection conn = uri.toURL().openConnection();
             conn.setDefaultUseCaches(false);
             Document doc = factory.newDocumentBuilder().parse(conn.getInputStream());
-            String temp = doc.getDocumentElement().getAttribute( "name" );
+            String temp = doc.getDocumentElement().getAttribute("name");
             if ("".equals(temp)) {
                 name = "repo-" + String.valueOf(unnamedRepoId++);
-            }
-            else {
+            } else {
                 name = temp;
             }
-            if ( uri.toString().startsWith( "bundle" ) ) {
+            if (uri.toString().startsWith("bundle")) {
                 name += "*";
             }
-            
+
             NodeList nodes = doc.getDocumentElement().getChildNodes();
             for (int i = 0; i < nodes.getLength(); i++) {
                 Node node = nodes.item(i);
@@ -133,14 +125,30 @@ public class RepositoryImpl implements R
                         f.setResolver(resolver);
                     }
 
+                    String description = e.getAttribute("description");
+                    if (description != null && description.length() > 0) {
+                        f.setDescription(description);
+                    }
+
+                    NodeList detailsNodes = e.getElementsByTagName("details");
+                    StringBuffer detailsBuffer = new StringBuffer();
+                    for (int j = 0; j < detailsNodes.getLength(); j++) {
+                        Element b = (Element) detailsNodes.item(j);
+                        String detail = b.getTextContent().trim();
+                        detailsBuffer.append(detail).append("\n");
+                    }
+                    String details = detailsBuffer.toString();
+                    if (details != null && details.length() > 0)
+                        f.setDetails(details);
+
                     NodeList featureNodes = e.getElementsByTagName("feature");
                     for (int j = 0; j < featureNodes.getLength(); j++) {
                         Element b = (Element) featureNodes.item(j);
                         String dependencyFeatureVersion = b.getAttribute("version");
                         if (dependencyFeatureVersion != null && dependencyFeatureVersion.length() > 0) {
-                        	f.addDependency(new FeatureImpl(b.getTextContent(), dependencyFeatureVersion));
+                            f.addDependency(new FeatureImpl(b.getTextContent(), dependencyFeatureVersion));
                         } else {
-                        	f.addDependency(new FeatureImpl(b.getTextContent()));
+                            f.addDependency(new FeatureImpl(b.getTextContent()));
                         }
                     }
                     NodeList configNodes = e.getElementsByTagName("config");
@@ -167,7 +175,7 @@ public class RepositoryImpl implements R
                         boolean bs = true;
                         boolean bd = false;
                         int bsl = 0;
-                        
+
                         // Check the value of the "start" attribute
                         if (bStart != null && bStart.length() > 0) {
                             bs = Boolean.parseBoolean(bStart);
@@ -178,10 +186,10 @@ public class RepositoryImpl implements R
                         }
                         // Check start level
                         if (bStartLevel != null && bStartLevel.length() > 0) {
-                        	try {
+                            try {
                                 bsl = Integer.parseInt(bStartLevel);
-                        	} catch (Exception ex) {
-                        		LOGGER.error("The start-level is not an int value for the bundle : " + b.getTextContent());
+                            } catch (Exception ex) {
+                                LOGGER.error("The start-level is not an int value for the bundle : " + b.getTextContent());
                             }
                         }
                         f.addBundle(new BundleInfoImpl(b.getTextContent().trim(), bsl, bs, bd));
@@ -190,23 +198,23 @@ public class RepositoryImpl implements R
                 }
             }
         } catch (SAXException e) {
-        	valid = false;
+            valid = false;
             throw (IOException) new IOException().initCause(e);
         } catch (ParserConfigurationException e) {
-        	valid = false;
-        	throw (IOException) new IOException().initCause(e);
+            valid = false;
+            throw (IOException) new IOException().initCause(e);
         } catch (IllegalArgumentException e) {
-        	valid = false;
-        	throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
+            valid = false;
+            throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
         } catch (Exception e) {
-        	valid = false;
-        	throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
+            valid = false;
+            throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
         }
     }
 
     protected void interpolation(Properties properties) {
         for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
-            String key = (String)e.nextElement();
+            String key = (String) e.nextElement();
             String val = properties.getProperty(key);
             Matcher matcher = Pattern.compile("\\$\\{([^}]+)\\}").matcher(val);
             while (matcher.find()) {
@@ -220,8 +228,8 @@ public class RepositoryImpl implements R
         }
     }
 
-	public boolean isValid() {
-		return this.valid;
-	}
+    public boolean isValid() {
+        return this.valid;
+    }
 
 }

Modified: karaf/trunk/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/ExtendedFeature.java
URL: http://svn.apache.org/viewvc/karaf/trunk/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/ExtendedFeature.java?rev=1038183&r1=1038182&r2=1038183&view=diff
==============================================================================
--- karaf/trunk/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/ExtendedFeature.java (original)
+++ karaf/trunk/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/ExtendedFeature.java Tue Nov 23 16:04:22 2010
@@ -105,6 +105,15 @@ public class ExtendedFeature implements 
         return this.feature.getResolver();
     }
 
+    public String getDescription() {
+        return this.feature.getDescription();
+    }
+
+    public String getDetails() {
+        return this.feature.getDetails();
+    }
+
+
     //
     // Additional methods
     //