PageRenderTime 24ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/org/swift/jira/cli/JiraPluginHelper.java

https://bitbucket.org/bob_swift/jira-cli/
Java | 96 lines | 28 code | 11 blank | 57 comment | 7 complexity | ecfe217fda3bb1cbc33ce89644d895db MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. /*
  2. * Copyright (c) 2009 Bob Swift.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * The names of contributors may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. * POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /*
  29. * Created on: Sep 16, 2009
  30. * Author: Bob Swift
  31. */
  32. package org.swift.jira.cli;
  33. import java.io.PrintStream;
  34. import org.swift.common.cli.AbstractPluginHelper;
  35. import org.swift.common.cli.AbstractRestClient;
  36. public class JiraPluginHelper extends AbstractPluginHelper {
  37. protected PrintStream out = System.out;
  38. public JiraPluginHelper(AbstractRestClient client) {
  39. super(client);
  40. }
  41. /**
  42. * Handle change between versions on location of plugins action at version 3
  43. *
  44. * @return request string for plugin actions
  45. */
  46. @Override
  47. public String getPluginRequestString() {
  48. return "/secure/admin/jira/ViewPlugins!default.jspa";
  49. }
  50. /**
  51. * Regex values for finding application specific data for plugin information
  52. *
  53. * <pre>
  54. * Example - plugin
  55. * &lt;a href=&quot;viewplugins.action?pluginKey=com.atlassian.confluence.plugins.attachmentExtractors&quot; &gt;Attachment Extractors&lt;/a&gt;&lt;br&gt;
  56. * Example - plugin version
  57. * &lt;strong&gt;Plugin Version&lt;/strong&gt;: 1.5&lt;br&gt;
  58. * Example - plugin version
  59. * &lt;b&gt;Vendor&lt;/b&gt;: &lt;a href=&quot;http://www.adaptavist.com/&quot;&gt;Adaptavist.com Ltd&lt;/a&gt;&lt;br&gt;
  60. * Example - latest version
  61. * Latest Version: &lt;/dt&gt; &lt;dd&gt;3.1.0&lt;/dd&gt; &lt;th&gt; &lt;a href=&quot;/plugin/details/152?versionId=1044&quot;&gt;3.1.0&lt;/a&gt; &lt;/th&gt;
  62. * Example - download url for version
  63. * &lt;dt&gt;&lt;a href=&quot;/plugin/details/152?versionId=1043&quot;&gt;3.0.2&lt;/a&gt;&lt;/dt&gt;
  64. *
  65. * </pre>
  66. *
  67. * @param key
  68. * @return regex string appropriate for the key specified
  69. */
  70. @Override
  71. public String getPluginRegex(final String key) {
  72. String result = "";
  73. if (key.equals("plugin")) {
  74. result = "ViewPlugins.jspa\\?pluginKey=([^\"]*)\"[^>]*>([^<]*)<"; // <a href="ViewPlugins.jspa?pluginKey=jira.user.format" >User Format</a><br>
  75. } else if (key.equals("plugin-version")) {
  76. result = "Plugin Version[^:]*:[^>]*>\\s*([^<]*)<"; // <b>Plugin Version:</b> 1.0<br>
  77. } else if (key.equals("plugin-vendor")) {
  78. result = "Vendor[^>]*>[^>]*>\\s*([^<]*)<"; // <b>Vendor:</b> <a href="http://www.atlassian.com">Atlassian Pty Ltd<br></a>
  79. } else if (key.equals("plugin-enabled")) { // Doesn't really apply to JIRA
  80. result = ">\\s*This plugin is (disabled).\\s*[^<]*<";
  81. }
  82. // out.println("Regex: " + result);
  83. return result;
  84. }
  85. }