FELIX-498: add 'obr javadoc' command to bundlerepository

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@629378 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ObrCommandImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ObrCommandImpl.java
index 5bef561..84f02cd 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ObrCommandImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ObrCommandImpl.java
@@ -38,6 +38,7 @@
     private static final String DEPLOY_CMD = "deploy";
     private static final String START_CMD = "start";
     private static final String SOURCE_CMD = "source";
+    private static final String JAVADOC_CMD = "javadoc";
 
     private static final String EXTRACT_SWITCH = "-x";
 
@@ -113,6 +114,10 @@
                 {
                     source(commandLine, command, out, err);
                 }
+                else if (command.equals(JAVADOC_CMD))
+                {
+                    javadoc(commandLine, command, out, err);
+                }
                 else
                 {
                     err.println("Unknown command: " + command);
@@ -419,6 +424,37 @@
         }
     }
 
+    private void javadoc(
+        String commandLine, String command, PrintStream out, PrintStream err)
+        throws IOException, InvalidSyntaxException
+    {
+        // Parse the command line to get all local targets to update.
+        ParsedCommand pc = parseSource(commandLine);
+        for (int i = 0; i < pc.getTargetCount(); i++)
+        {
+            Resource resource = selectNewestVersion(
+                searchRepository(pc.getTargetId(i), pc.getTargetVersion(i)));
+            if (resource == null)
+            {
+                err.println("Unknown bundle and/or version: "
+                    + pc.getTargetId(i));
+            }
+            else
+            {
+                URL docURL = (URL) resource.getProperties().get("javadoc");
+                if (docURL != null)
+                {
+                    FileUtil.downloadSource(
+                        out, err, docURL, pc.getDirectory(), pc.isExtract());
+                }
+                else
+                {
+                    err.println("Missing javadoc URL: " + pc.getTargetId(i));
+                }
+            }
+        }
+    }
+
     private Resource[] searchRepository(String targetId, String targetVersion)
     {
         // Try to see if the targetId is a bundle ID.
@@ -978,6 +1014,27 @@
                 "specified local directory.");
             out.println("");
         }
+        else if (command.equals(JAVADOC_CMD))
+        {
+            out.println("");
+            out.println("obr " + JAVADOC_CMD
+                + " [" + EXTRACT_SWITCH
+                + "] <local-dir> <bundle-name>[;<version>] ...");
+            out.println("");
+            out.println(
+                "This command retrieves the javadoc archives of the specified\n" +
+                "bundles and saves them to the specified local directory; use\n" +
+                "the \"" + EXTRACT_SWITCH + "\" switch to automatically extract the javadoc archives.\n" +
+                "If a bundle name contains spaces, then it must be surrounded\n" +
+                "by quotes. It is also possible to specify a precise version if\n" +                "more than one version exists, such as:\n" +
+                "\n" +
+                "    obr javadoc /home/rickhall/tmp \"Bundle Repository\";1.0.0\n" +
+                "\n" +
+                "The above example retrieves the javadoc archive of version \"1.0.0\"\n" +
+                "of the bundle named \"Bundle Repository\" and saves it to the\n" +
+                "specified local directory.");
+            out.println("");
+        }
         else
         {
             out.println("obr " + HELP_CMD
@@ -987,7 +1044,7 @@
                 + " | " + LIST_CMD
                 + " | " + INFO_CMD
                 + " | " + DEPLOY_CMD + " | " + START_CMD
-                + " | " + SOURCE_CMD + "]");
+                + " | " + SOURCE_CMD + " | " + JAVADOC_CMD + "]");
             out.println("obr " + ADDURL_CMD + " [<repository-file-url> ...]");
             out.println("obr " + REMOVEURL_CMD + " [<repository-file-url> ...]");
             out.println("obr " + LISTURL_CMD);
@@ -1001,6 +1058,9 @@
             out.println("obr " + SOURCE_CMD
                 + " [" + EXTRACT_SWITCH
                 + "] <local-dir> <bundle-name>[;<version>] ...");
+            out.println("obr " + JAVADOC_CMD
+                + " [" + EXTRACT_SWITCH
+                + "] <local-dir> <bundle-name>[;<version>] ...");
         }
     }
 
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
index fb57b28..70040c2 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
@@ -39,6 +39,7 @@
     private String m_docURI = null;
     private String m_licenseURI = null;
     private String m_sourceURI = null;
+    private String m_javadocURI = null;
     private boolean m_converted = false;
 
     public ResourceImpl()
@@ -178,6 +179,10 @@
         {
             m_sourceURI = (String) value;
         }
+        else if (key.equals("javadoc"))
+        {
+            m_javadocURI = (String) value;
+        }
         else if (key.equals(URI))
         {
             m_resourceURI = (String) value;
@@ -222,6 +227,10 @@
                 {
                     m_map.put(SOURCE_URL, new URL(base, m_sourceURI));
                 }
+                if (m_javadocURI != null)
+                {
+                    m_map.put("javadoc", new URL(base, m_javadocURI));
+                }
                 m_converted = true;
             }
             catch (MalformedURLException ex)