felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1700092 - in /felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command: Basic.java Inspect42.java Util.java
Date Sun, 30 Aug 2015 06:38:59 GMT
Author: djencks
Date: Sun Aug 30 06:38:58 2015
New Revision: 1700092

URL: http://svn.apache.org/r1700092
Log:
FELIX-5008: suppress CommandSession from help messages.
Supply generics in source of Basic.java to reduce warnings.
Fill in missing bits of format string.

Thanks to Benson Margulies.  Additional generics/cleanup by David Jencks

Modified:
    felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java
    felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Inspect42.java
    felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java

Modified: felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java?rev=1700092&r1=1700091&r2=1700092&view=diff
==============================================================================
--- felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java (original)
+++ felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java Sun Aug
30 06:38:58 2015
@@ -37,6 +37,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.TreeMap;
+
+import org.apache.felix.service.command.CommandSession;
 import org.apache.felix.service.command.Descriptor;
 import org.apache.felix.service.command.Parameter;
 import org.osgi.framework.Bundle;
@@ -52,6 +54,7 @@ import org.osgi.service.log.LogService;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
 
+@SuppressWarnings("deprecation")
 public class Basic
 {
     private final BundleContext m_bc;
@@ -65,7 +68,7 @@ public class Basic
     public void bundlelevel(@Descriptor("bundle to query") Bundle bundle)
     {
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get start level service.
         StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
@@ -95,7 +98,7 @@ public class Basic
         @Descriptor("target identifiers") Bundle[] bundles)
     {
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get start level service.
         StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
@@ -150,7 +153,7 @@ public class Basic
     public void frameworklevel()
     {
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get start level service.
         StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
@@ -166,7 +169,7 @@ public class Basic
     public void frameworklevel(@Descriptor("target start level") int level)
     {
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get start level service.
         StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
@@ -188,13 +191,13 @@ public class Basic
             String title = Util.getBundleName(bundle);
             System.out.println("\n" + title);
             System.out.println(Util.getUnderlineString(title.length()));
-            Dictionary dict = bundle.getHeaders();
-            Enumeration keys = dict.keys();
+            Dictionary<String, String> dict = bundle.getHeaders();
+            Enumeration<String> keys = dict.keys();
             while (keys.hasMoreElements())
             {
-                Object k = (String) keys.nextElement();
-                Object v = dict.get(k);
-                System.out.println(k + " = " + Util.getValueString(v));
+                String k = keys.nextElement();
+                String v = dict.get(k);
+                System.out.println(k + " = " + v);
             }
         }
     }
@@ -255,15 +258,20 @@ public class Basic
                 System.out.println("   scope: " + name.substring(0, name.indexOf(':')));
 
                 // Get flags and options.
-                Class[] paramTypes = m.getParameterTypes();
-                Map<String, Parameter> flags = new TreeMap();
-                Map<String, String> flagDescs = new TreeMap();
-                Map<String, Parameter> options = new TreeMap();
-                Map<String, String> optionDescs = new TreeMap();
-                List<String> params = new ArrayList();
+                Class<?>[] paramTypes = m.getParameterTypes();
+                Map<String, Parameter> flags = new TreeMap<String, Parameter>();
+                Map<String, String> flagDescs = new TreeMap<String, String>();
+                Map<String, Parameter> options = new TreeMap<String, Parameter>();
+                Map<String, String> optionDescs = new TreeMap<String, String>();
+                List<String> params = new ArrayList<String>();
                 Annotation[][] anns = m.getParameterAnnotations();
                 for (int paramIdx = 0; paramIdx < anns.length; paramIdx++)
                 {
+                    Class<?> paramType = m.getParameterTypes()[paramIdx];
+                    if (paramType == CommandSession.class) {
+                        /* Do not bother the user with a CommandSession. */
+                        continue;
+                    }
                     Parameter p = findAnnotation(anns[paramIdx], Parameter.class);
                     d = findAnnotation(anns[paramIdx], Descriptor.class);
                     if (p != null)
@@ -358,7 +366,7 @@ public class Basic
 
     private Map<String, List<Method>> getCommands()
     {
-        ServiceReference[] refs = null;
+        ServiceReference<?>[] refs = null;
         try
         {
             refs = m_bc.getAllServiceReferences(null, "(osgi.command.scope=*)");
@@ -368,9 +376,9 @@ public class Basic
             // This should never happen.
         }
 
-        Map<String, List<Method>> commands = new TreeMap();
+        Map<String, List<Method>> commands = new TreeMap<String, List<Method>>();
 
-        for (ServiceReference ref : refs)
+        for (ServiceReference<?> ref : refs)
         {
             Object svc = m_bc.getService(ref);
             if (svc != null)
@@ -382,7 +390,7 @@ public class Basic
 
                 for (String func : funcs)
                 {
-                    commands.put(scope + ":" + func, new ArrayList());
+                    commands.put(scope + ":" + func, new ArrayList<Method>());
                 }
 
                 if (!commands.isEmpty())
@@ -482,7 +490,7 @@ public class Basic
         @Descriptor("subtring matched against name or symbolic name") String pattern)
     {
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get start level service.
         StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
@@ -491,7 +499,7 @@ public class Basic
             System.out.println("Start Level service is unavailable.");
         }
 
-        List<Bundle> found = new ArrayList();
+        List<Bundle> found = new ArrayList<Bundle>();
 
         if (pattern == null)
         {
@@ -543,7 +551,7 @@ public class Basic
         @Descriptor("minimum log level [ debug | info | warn | error ]") String logLevel)
     {
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get start level service.
         LogReaderService lrs = Util.getService(m_bc, LogReaderService.class, refs);
@@ -553,7 +561,8 @@ public class Basic
         }
         else
         {
-            Enumeration entries = lrs.getLog();
+            @SuppressWarnings("unchecked")
+            Enumeration<LogEntry> entries = lrs.getLog();
 
             int minLevel = logLevelAsInt(logLevel);
 
@@ -640,7 +649,7 @@ public class Basic
         }
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get package admin service.
         PackageAdmin pa = Util.getService(m_bc, PackageAdmin.class, refs);
@@ -664,7 +673,7 @@ public class Basic
         }
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get package admin service.
         PackageAdmin pa = Util.getService(m_bc, PackageAdmin.class, refs);
@@ -925,7 +934,7 @@ public class Basic
         }
         else
         {
-            Class clazz = null;
+            Class<?> clazz = null;
             try
             {
                 clazz = bundle.loadClass(className);
@@ -1020,12 +1029,12 @@ public class Basic
 
             if (level < 0)
             {
-                System.out.println(String.format("%5d|%-11s|%s", bundle.getBundleId(),
+                System.out.println(String.format("%5d|%-11s|%s|%s", bundle.getBundleId(),
                     getStateString(bundle), name, bundle.getVersion()));
             }
             else
             {
-                System.out.println(String.format("%5d|%-11s|%5d|%s",
+                System.out.println(String.format("%5d|%-11s|%5d|%s|%s",
                     bundle.getBundleId(), getStateString(bundle), level, name,
                     bundle.getVersion()));
             }
@@ -1060,4 +1069,4 @@ public class Basic
             return "Unknown    ";
         }
     }
-}
\ No newline at end of file
+}

Modified: felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Inspect42.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Inspect42.java?rev=1700092&r1=1700091&r2=1700092&view=diff
==============================================================================
--- felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Inspect42.java (original)
+++ felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Inspect42.java Sun
Aug 30 06:38:58 2015
@@ -30,6 +30,7 @@ import org.osgi.service.packageadmin.Exp
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.packageadmin.RequiredBundle;
 
+@SuppressWarnings("deprecation")
 public class Inspect42
 {
     public static final String LEGACY_PACKAGE_NAMESPACE = "package";
@@ -175,7 +176,7 @@ public class Inspect42
         boolean matches = false;
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Fragments cannot export packages.
         if (!isFragment(b))
@@ -242,7 +243,7 @@ public class Inspect42
         boolean matches = false;
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Fragments cannot import packages.
         if (!isFragment(b))
@@ -298,7 +299,7 @@ public class Inspect42
         boolean matches = false;
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Fragments cannot be required.
         if (!isFragment(b))
@@ -371,7 +372,7 @@ public class Inspect42
         boolean matches = false;
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Fragments cannot require bundles.
         if (!isFragment(b))
@@ -421,7 +422,7 @@ public class Inspect42
         boolean matches = false;
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get package admin service.
         PackageAdmin pa = Util.getService(bc, PackageAdmin.class, refs);
@@ -480,7 +481,7 @@ public class Inspect42
         boolean matches = false;
 
         // Keep track of service references.
-        List<ServiceReference> refs = new ArrayList();
+        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
 
         // Get package admin service.
         PackageAdmin pa = Util.getService(bc, PackageAdmin.class, refs);

Modified: felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java?rev=1700092&r1=1700091&r2=1700092&view=diff
==============================================================================
--- felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java (original)
+++ felix/trunk/gogo/command/src/main/java/org/apache/felix/gogo/command/Util.java Sun Aug
30 06:38:58 2015
@@ -123,9 +123,10 @@ public class Util
     }
 
     public static <T> T getService(
-        BundleContext bc, Class<T> clazz, List<ServiceReference> refs)
+        BundleContext bc, Class<T> clazz, List<ServiceReference<?>> refs)
     {
-        ServiceReference ref = bc.getServiceReference(clazz.getName());
+        @SuppressWarnings("unchecked")
+        ServiceReference<T> ref = (ServiceReference<T>) bc.getServiceReference(clazz.getName());
         if (ref == null)
         {
             return null;
@@ -138,7 +139,7 @@ public class Util
         return t;
     }
 
-    public static void ungetServices(BundleContext bc, List<ServiceReference> refs)
+    public static void ungetServices(BundleContext bc, List<ServiceReference<?>>
refs)
     {
         while (refs.size() > 0)
         {
@@ -181,10 +182,8 @@ public class Util
                 out.println("Downloading " + fileName + ".");
             }
             byte[] buffer = new byte[4096];
-            int count = 0;
             for (int len = is.read(buffer); len > 0; len = is.read(buffer))
             {
-                count += len;
                 os.write(buffer, 0, len);
             }
 
@@ -320,7 +319,7 @@ public class Util
 
     public static List<String> parseSubstring(String value)
     {
-        List<String> pieces = new ArrayList();
+        List<String> pieces = new ArrayList<String>();
         StringBuffer ss = new StringBuffer();
         // int kind = SIMPLE; // assume until proven otherwise
         boolean wasStar = false; // indicates last piece was a star



Mime
View raw message