[
  {
    "path": ".gitignore",
    "content": "# IntelliJ\nout/\n.idea/\ntarget/\n*.iml\nlocal.properties\n\n### Java ###\n*.class\nclasses/\n\n# Package Files #\n*.jar\n\n### Gradle ###\n.gradle\nbuild/\n\n### Specific ###\n*.zip\n\n# Ignore Gradle GUI config\ngradle-app.setting\n\n# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)\n!gradle-wrapper.jar\n\n# Avoid ignoring AndroidWiFiADB.iml file to be able to import the project into any IntelliJ IDE and run/debug the pulgin without problems\n!AndroidWiFiADB.iml\n\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: java\njdk: oraclejdk7\nenv:\n  matrix:\n  - TERM=dumb\nafter_success:\n  - ./gradlew test jacocoTestReport coveralls\n\nscript:\n  ./gradlew checkstyle build\n"
  },
  {
    "path": "AndroidWiFiADB.iml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<module external.linked.project.id=\"AndroidWiFiADB\" external.linked.project.path=\"$MODULE_DIR$\" external.root.project.path=\"$MODULE_DIR$\" external.system.id=\"GRADLE\" external.system.module.group=\"com.github.pedrovgs\" external.system.module.version=\"1.3-SNAPSHOT\" type=\"PLUGIN_MODULE\" version=\"4\">\n  <component name=\"DevKit.ModuleBuildProperties\" url=\"file://$MODULE_DIR$/src/main/resources/META-INF/plugin.xml\" />\n  <component name=\"NewModuleRootManager\" inherit-compiler-output=\"false\">\n    <output url=\"file://$MODULE_DIR$/build/classes/main\" />\n    <output-test url=\"file://$MODULE_DIR$/build/classes/test\" />\n    <exclude-output />\n    <content url=\"file://$MODULE_DIR$\">\n      <sourceFolder url=\"file://$MODULE_DIR$/src/main/java\" isTestSource=\"false\" />\n      <sourceFolder url=\"file://$MODULE_DIR$/src/test/java\" isTestSource=\"true\" />\n      <sourceFolder url=\"file://$MODULE_DIR$/src/main/resources\" type=\"java-resource\" />\n      <sourceFolder url=\"file://$MODULE_DIR$/src/test/resources\" type=\"java-test-resource\" />\n      <excludeFolder url=\"file://$MODULE_DIR$/.gradle\" />\n      <excludeFolder url=\"file://$MODULE_DIR$/build\" />\n    </content>\n    <orderEntry type=\"jdk\" jdkName=\"IntelliJ IDEA Community Edition IC-143.1184.17\" jdkType=\"IDEA JDK\" />\n    <orderEntry type=\"sourceFolder\" forTests=\"false\" />\n    <orderEntry type=\"library\" exported=\"\" name=\"Gradle: com.jetbrains:android:14.1.5\" level=\"project\" />\n    <orderEntry type=\"library\" name=\"Gradle: junit:junit:4.12\" level=\"project\" />\n    <orderEntry type=\"library\" name=\"Gradle: org.mockito:mockito-all:1.10.19\" level=\"project\" />\n    <orderEntry type=\"library\" name=\"Gradle: com.jetbrains:android-common:14.1.5\" level=\"project\" />\n    <orderEntry type=\"library\" name=\"Gradle: com.jetbrains:android-rt:14.1.5\" level=\"project\" />\n    <orderEntry type=\"library\" name=\"Gradle: com.jetbrains:androidAnnotations:14.1.5\" level=\"project\" />\n  </component>\n</module>"
  },
  {
    "path": "LICENSE.txt",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License."
  },
  {
    "path": "README.md",
    "content": "Android WiFi ADB - IntelliJ/Android Studio Plugin [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20WiFi%20ADB-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2654)\n=================================================\n![Android WiFi ADB][1]\n\n**IntelliJ and Android Studio plugin** created to **quickly connect your Android device over WiFi** to install, run and debug your applications without a USB connected. Press one button and forget about your USB cable.\n\n**Android WiFI ADB plugin adds a button ![Android WiFi ADB Button][5] to your IntelliJ/Android Studio Toolbar** to connect your device to your computer over WiFi.  \n\n*To use this plugin the project opened in your IntelliJ/Android Studio has to be an Android project configured with the Android SDK.*\n\n**Archived repository:** Maintaining this project up to date for all the different Android devices without having access to the physical devices is not possible at all right now. Most of the bugs reported ar related to the adb installation and not to the plugin code so this repository will keep archived for now.\n\nScreenshots\n-----------\nConnect all devices button:\n\n![Android WiFi ADB Usage][2]\n\nDevices dashboard:\n\n![Android Devices Window][7]\n\nUsage\n-----\n\nConnect your device to your computer using a USB cable. Then press the button, and a notification will pop up saying that the phone has been connected. Disconnect your USB once the plugin shows your device is connected. Open the Android WiFi ADB tab at the right side to see all the devices and manage your connections. Your device will be connected over WiFi now. You can now deploy, run and debug your device using your WiFi connection. Remember that your device and your computer have to be in the same WiFi connection. Also, you have to first connect your device with a USB every time you open Android Studio, for setting up the connection over WiFi.\n  \nIf you want to handle your devices connection individually, open the Android WiFi ADB dashboard you will find at the right of your IDE.  \n\nInstallation\n------------\n\nDownload and install **Android WiFi ADB** directly from Intellij / Android Studio:\n`Preferences/Settings->Plugins->Browse Repositories` \n\nAlternatively, you can [download the plugin][6] from the JetBrains plugin site and install it manually in:\n`Preferences/Settings->Plugins->Install plugin from disk`.\n\nBuild the project\n-----------------\n\nIf you need some information about how to build this project review [IntelliJ Idea's Gradle Plugin documentation](https://github.com/JetBrains/gradle-intellij-plugin).\n\nDo you want to contribute?\n--------------------------\n\nPlease, do it! If you have any improvement or you've found any bug, send a pull request with the code or open an issue :)\n\nLibraries used on the sample project\n------------------------------------\n\n* [JUnit][3]\n* [Mockito][4]\n\nDeveloped By\n------------\n\n* Pedro Vicente Gómez Sánchez - <pedrovicente.gomez@gmail.com>\n\n<a href=\"https://twitter.com/pedro_g_s\">\n  <img alt=\"Follow me on Twitter\" src=\"https://image.freepik.com/iconos-gratis/twitter-logo_318-40209.jpg\" height=\"60\" width=\"60\"/>\n</a>\n<a href=\"https://es.linkedin.com/in/pedrovgs\">\n  <img alt=\"Add me to Linkedin\" src=\"https://image.freepik.com/iconos-gratis/boton-del-logotipo-linkedin_318-84979.png\" height=\"60\" width=\"60\"/>\n</a>\n\nLicense\n-------\n\n    Copyright 2015 Pedro Vicente Gómez Sánchez\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n[1]: ./art/AndroidWiFiADBIcon.png\n[2]: ./art/screenshot1.gif\n[3]: https://github.com/junit-team/junit\n[4]: https://github.com/mockito/mockito\n[5]: ./art/sampleButton.png\n[6]: https://plugins.jetbrains.com/plugin/7983\n[7]: ./art/android_devices_window.png\n"
  },
  {
    "path": "build.gradle",
    "content": "buildscript {\n  repositories {\n    mavenCentral()\n  }\n}\n\nplugins {\n  id \"org.jetbrains.intellij\" version \"0.0.25\"\n}\n\napply plugin: 'org.jetbrains.intellij'\napply plugin: 'java'\napply plugin: 'checkstyle'\napply plugin: 'jacoco'\n\ngroup 'com.github.pedrovgs'\nversion '2.5-SNAPSHOT'\n\nsourceCompatibility = 1.6\n\nrepositories {\n  mavenCentral()\n}\n\nintellij {\n  version '14.1.5'\n  pluginName 'AndroidWiFiADB'\n  plugins 'android'\n  updateSinceUntilBuild false\n}\n\ndependencies {\n  compile 'junit:junit:4.12'\n  compile 'org.mockito:mockito-all:1.10.19'\n}\n\ntask checkstyle(type: Checkstyle) {\n  configFile file(\"${project.rootDir}/config/checkstyle/checkstyle.xml\")\n  source 'src'\n  include '**/*.java'\n  exclude '**/gen/**'\n\n  classpath = files()\n}"
  },
  {
    "path": "config/checkstyle/checkstyle.xml",
    "content": "<?xml version=\"1.0\"?>\n<!DOCTYPE module PUBLIC\n    \"-//Puppy Crawl//DTD Check Configuration 1.2//EN\"\n    \"http://www.puppycrawl.com/dtds/configuration_1_2.dtd\">\n\n\n<!-- THIS CHECKSYTLE CONFIGURATION IS SIMILAR TO THE ONE USED BY SQUARE INC. IF YOU WANT TO\n     CONFIGURE YOUR IDE TO USE THIS CHECKSTYLE TAKE A LOOK AT https://github.com/square/java-code-styles-->\n\n\n<module name=\"Checker\">\n  <!--module name=\"NewlineAtEndOfFile\"/-->\n  <module name=\"FileLength\"/>\n  <module name=\"FileTabCharacter\"/>\n\n  <!-- Trailing spaces -->\n  <module name=\"RegexpSingleline\">\n    <property name=\"format\" value=\"\\s+$\"/>\n    <property name=\"message\" value=\"Line has trailing spaces.\"/>\n  </module>\n\n  <!-- Space after 'for' and 'if' -->\n  <module name=\"RegexpSingleline\">\n    <property name=\"format\" value=\"^\\s*(for|if)[^ ]\"/>\n    <property name=\"message\" value=\"Space needed before opening parenthesis.\"/>\n  </module>\n\n  <!-- For each spacing -->\n  <module name=\"RegexpSingleline\">\n    <property name=\"format\" value=\"^\\s*for \\(.*?([^ ]:|:[^ ])\"/>\n    <property name=\"message\" value=\"Space needed around ':' character.\"/>\n  </module>\n\n  <module name=\"TreeWalker\">\n\n    <!-- Checks for Javadoc comments.                     -->\n    <!-- See http://checkstyle.sf.net/config_javadoc.html -->\n    <!--module name=\"JavadocMethod\"/-->\n    <!--module name=\"JavadocType\"/-->\n    <!--module name=\"JavadocVariable\"/-->\n    <!--module name=\"JavadocStyle\"/-->\n\n\n    <!-- Checks for Naming Conventions.                  -->\n    <!-- See http://checkstyle.sf.net/config_naming.html -->\n\n    <module name=\"MethodName\"/>\n    <module name=\"PackageName\"/>\n    <module name=\"ParameterName\"/>\n    <module name=\"TypeName\"/>\n    <module name=\"ConstantName\"/>\n\n    <!-- Checks for imports                              -->\n    <!-- See http://checkstyle.sf.net/config_import.html -->\n    <module name=\"AvoidStarImport\"/>\n    <module name=\"IllegalImport\"/>\n    <!-- defaults to sun.* packages -->\n    <module name=\"RedundantImport\"/>\n    <module name=\"UnusedImports\">\n      <property name=\"processJavadoc\" value=\"true\"/>\n    </module>\n\n    <!-- Checks for Size Violations.                    -->\n    <!-- See http://checkstyle.sf.net/config_sizes.html -->\n    <module name=\"LineLength\">\n      <property name=\"max\" value=\"120\"/>\n    </module>\n\n    <!--module name=\"ParameterNumber\"/-->\n\n\n    <!-- Checks for whitespace                               -->\n    <!-- See http://checkstyle.sf.net/config_whitespace.html -->\n    <module name=\"GenericWhitespace\"/>\n    <module name=\"EmptyForIteratorPad\"/>\n    <module name=\"MethodParamPad\"/>\n    <module name=\"NoWhitespaceAfter\"/>\n    <module name=\"NoWhitespaceBefore\"/>\n    <module name=\"OperatorWrap\"/>\n    <module name=\"ParenPad\"/>\n    <module name=\"TypecastParenPad\"/>\n    <module name=\"WhitespaceAfter\"/>\n    <module name=\"WhitespaceAround\"/>\n\n\n    <!-- Modifier Checks                                    -->\n    <!-- See http://checkstyle.sf.net/config_modifiers.html -->\n    <!--module name=\"ModifierOrder\"/-->\n    <module name=\"RedundantModifier\"/>\n\n\n    <!-- Checks for blocks. You know, those {}'s         -->\n    <!-- See http://checkstyle.sf.net/config_blocks.html -->\n    <!--module name=\"AvoidNestedBlocks\"/-->\n    <!--module name=\"EmptyBlock\"/-->\n    <module name=\"LeftCurly\"/>\n    <!--module name=\"NeedBraces\"/-->\n    <module name=\"RightCurly\"/>\n\n\n    <!-- Checks for common coding problems               -->\n    <!-- See http://checkstyle.sf.net/config_coding.html -->\n    <!--module name=\"AvoidInlineConditionals\"/-->\n    <module name=\"CovariantEquals\"/>\n    <module name=\"EmptyStatement\"/>\n    <!--<module name=\"EqualsAvoidNull\"/>-->\n    <module name=\"EqualsHashCode\"/>\n    <!--module name=\"HiddenField\"/-->\n    <module name=\"IllegalInstantiation\"/>\n    <!--<module name=\"InnerAssignment\"/>-->\n    <!--module name=\"MagicNumber\"/-->\n    <module name=\"MissingSwitchDefault\"/>\n    <module name=\"SimplifyBooleanExpression\"/>\n    <module name=\"SimplifyBooleanReturn\"/>\n\n    <!-- Checks for class design                         -->\n    <!-- See http://checkstyle.sf.net/config_design.html -->\n    <!--module name=\"DesignForExtension\"/-->\n    <!--module name=\"FinalClass\"/-->\n    <!--module name=\"HideUtilityClassConstructor\"/-->\n    <!--module name=\"InterfaceIsType\"/-->\n    <!--module name=\"VisibilityModifier\"/-->\n\n\n    <!-- Miscellaneous other checks.                   -->\n    <!-- See http://checkstyle.sf.net/config_misc.html -->\n    <!--module name=\"ArrayTypeStyle\"/-->\n    <!--module name=\"FinalParameters\"/-->\n    <!--module name=\"TodoComment\"/-->\n    <module name=\"UpperEll\"/>\n  </module>\n</module>"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "#Tue Dec 15 00:42:48 CET 2015\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-2.7-all.zip\n"
  },
  {
    "path": "gradle.properties",
    "content": ""
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS=\"\"\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn ( ) {\n    echo \"$*\"\n}\n\ndie ( ) {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\nesac\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >&-\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >&-\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n    JAVACMD=`cygpath --unix \"$JAVACMD\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules\nfunction splitJvmOpts() {\n    JVM_OPTS=(\"$@\")\n}\neval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\nJVM_OPTS[${#JVM_OPTS[*]}]=\"-Dorg.gradle.appname=$APP_BASE_NAME\"\n\nexec \"$JAVACMD\" \"${JVM_OPTS[@]}\" -classpath \"$CLASSPATH\" org.gradle.wrapper.GradleWrapperMain \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@rem  Gradle startup script for Windows\r\n@rem\r\n@rem ##########################################################################\r\n\r\n@rem Set local scope for the variables with windows NT shell\r\nif \"%OS%\"==\"Windows_NT\" setlocal\r\n\r\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r\nset DEFAULT_JVM_OPTS=\r\n\r\nset DIRNAME=%~dp0\r\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\r\nset APP_BASE_NAME=%~n0\r\nset APP_HOME=%DIRNAME%\r\n\r\n@rem Find java.exe\r\nif defined JAVA_HOME goto findJavaFromJavaHome\r\n\r\nset JAVA_EXE=java.exe\r\n%JAVA_EXE% -version >NUL 2>&1\r\nif \"%ERRORLEVEL%\" == \"0\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:findJavaFromJavaHome\r\nset JAVA_HOME=%JAVA_HOME:\"=%\r\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\r\n\r\nif exist \"%JAVA_EXE%\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:init\r\n@rem Get command-line arguments, handling Windowz variants\r\n\r\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\r\nif \"%@eval[2+2]\" == \"4\" goto 4NT_args\r\n\r\n:win9xME_args\r\n@rem Slurp the command line arguments.\r\nset CMD_LINE_ARGS=\r\nset _SKIP=2\r\n\r\n:win9xME_args_slurp\r\nif \"x%~1\" == \"x\" goto execute\r\n\r\nset CMD_LINE_ARGS=%*\r\ngoto execute\r\n\r\n:4NT_args\r\n@rem Get arguments from the 4NT Shell from JP Software\r\nset CMD_LINE_ARGS=%$\r\n\r\n:execute\r\n@rem Setup the command line\r\n\r\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\r\n\r\n@rem Execute Gradle\r\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r\n\r\n:end\r\n@rem End local scope for the variables with windows NT shell\r\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\r\n\r\n:fail\r\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r\nrem the _cmd.exe /c_ return code!\r\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\r\nexit /b 1\r\n\r\n:mainEnd\r\nif \"%OS%\"==\"Windows_NT\" endlocal\r\n\r\n:omega\r\n"
  },
  {
    "path": "settigs.gradle",
    "content": "rootProject.name = 'AndroidWiFiADB'"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/AndroidWiFiADB.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb;\n\nimport com.github.pedrovgs.androidwifiadb.adb.ADB;\nimport com.github.pedrovgs.androidwifiadb.view.View;\nimport com.intellij.openapi.project.Project;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Set;\n\npublic class AndroidWiFiADB {\n\n  private static final Set<Device> DEVICES = new HashSet<Device>();\n  private final ADB adb;\n  private final View view;\n\n  public AndroidWiFiADB(ADB adb, View view) {\n    this.adb = adb;\n    this.view = view;\n  }\n\n  public void connectDevices() {\n    if (!isADBInstalled()) {\n      view.showADBNotInstalledNotification();\n      return;\n    }\n    DEVICES.clear();\n    DEVICES.addAll(adb.getDevicesConnectedByUSB());\n    if (DEVICES.isEmpty()) {\n      view.showNoConnectedDevicesNotification();\n      return;\n    }\n\n    DEVICES.addAll(adb.connectDevices(DEVICES));\n    showConnectionResultNotification(DEVICES);\n  }\n\n  public boolean refreshDevicesList() {\n    if (!isADBInstalled()) {\n      return false;\n    }\n    removeNotConnectedDevices();\n    final Collection<Device> connected = adb.getDevicesConnectedByUSB();\n    for (Device connectedDevice : connected) {\n      if (!checkDeviceExistance(connectedDevice)) {\n        connectedDevice.setIp(adb.getDeviceIp(connectedDevice));\n        DEVICES.add(connectedDevice);\n      } else {\n        updateDeviceConnectionState(connectedDevice);\n      }\n    }\n    return true;\n  }\n\n  private void removeNotConnectedDevices() {\n    List<Device> connectedDevices = new LinkedList<Device>();\n    for (Device device : DEVICES) {\n      if (device.isConnected()) {\n        connectedDevices.add(device);\n      }\n    }\n    DEVICES.clear();\n    DEVICES.addAll(connectedDevices);\n  }\n\n  public Collection<Device> getDevices() {\n    return DEVICES;\n  }\n\n  public void connectDevice(Device device) {\n    if (!isADBInstalled()) {\n      view.showADBNotInstalledNotification();\n      return;\n    }\n\n    Collection<Device> connectedDevices = new ArrayList<Device>();\n    connectedDevices.add(device);\n    connectedDevices = adb.connectDevices(connectedDevices);\n    for (Device connected : connectedDevices) {\n      updateDeviceConnectionState(connected);\n    }\n    showConnectionResultNotification(connectedDevices);\n  }\n\n  public void disconnectDevice(Device device) {\n    if (!isADBInstalled()) {\n      view.showADBNotInstalledNotification();\n      return;\n    }\n\n    List<Device> disconnectedDevices = new ArrayList<Device>();\n    disconnectedDevices.add(device);\n    disconnectedDevices = adb.disconnectDevices(disconnectedDevices);\n    for (Device disconnected : disconnectedDevices) {\n      updateDeviceConnectionState(disconnected);\n    }\n    showDisconnectionResultNotification(disconnectedDevices);\n  }\n\n  public void updateProject(Project project) {\n    adb.updateProject(project);\n  }\n\n  private void updateDeviceConnectionState(final Device updatedDevice) {\n    DEVICES.add(updatedDevice);\n  }\n\n  private boolean checkDeviceExistance(Device connectedDevice) {\n    boolean deviceExists = false;\n    for (Device device : DEVICES) {\n      if (connectedDevice.getId().equals(device.getId())) {\n        deviceExists = true;\n      }\n    }\n    return deviceExists;\n  }\n\n  private boolean isADBInstalled() {\n    return adb.isInstalled();\n  }\n\n  private void showConnectionResultNotification(Collection<Device> devices) {\n    for (Device device : devices) {\n      if (device.isConnected()) {\n        view.showConnectedDeviceNotification(device);\n      } else {\n        view.showErrorConnectingDeviceNotification(device);\n      }\n    }\n  }\n\n  private void showDisconnectionResultNotification(Collection<Device> devices) {\n    for (Device device : devices) {\n      if (!device.isConnected()) {\n        view.showDisconnectedDeviceNotification(device);\n      } else {\n        view.showErrorDisconnectingDeviceNotification(device);\n      }\n    }\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/Device.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb;\n\npublic class Device {\n\n  private final String id;\n  private String name;\n  private String ip = \"\";\n  private boolean connected;\n\n  public Device(String name, String id) {\n    this.name = name;\n    this.id = id;\n  }\n\n  public String getName() {\n    return name;\n  }\n\n  public void setName(String name) {\n    this.name = name;\n  }\n\n  public String getId() {\n    return id;\n  }\n\n  public String getIp() {\n    return ip;\n  }\n\n  public void setIp(String ip) {\n    this.ip = ip;\n  }\n\n  public boolean isConnected() {\n    return connected;\n  }\n\n  public void setConnected(boolean connected) {\n    this.connected = connected;\n  }\n\n  @Override public boolean equals(Object o) {\n    if (this == o) {\n      return true;\n    }\n    if (o == null || getClass() != o.getClass()) {\n      return false;\n    }\n\n    Device device = (Device) o;\n\n    return id.equals(device.id);\n  }\n\n  @Override public int hashCode() {\n    return id.hashCode();\n  }\n\n  @Override public String toString() {\n    return name;\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/action/AndroidWiFiADBAction.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.action;\n\nimport com.github.pedrovgs.androidwifiadb.AndroidWiFiADB;\nimport com.github.pedrovgs.androidwifiadb.view.NotificationView;\nimport com.github.pedrovgs.androidwifiadb.adb.ADB;\nimport com.github.pedrovgs.androidwifiadb.adb.ADBParser;\nimport com.github.pedrovgs.androidwifiadb.adb.CommandLine;\nimport com.intellij.openapi.actionSystem.AnAction;\nimport com.intellij.openapi.actionSystem.AnActionEvent;\nimport com.intellij.openapi.application.ApplicationManager;\n\npublic class AndroidWiFiADBAction extends AnAction {\n\n  private final AndroidWiFiADB androidWifiADB;\n\n  public AndroidWiFiADBAction() {\n    CommandLine commandLine = new CommandLine();\n    ADBParser adbParser = new ADBParser();\n    ADB adb = new ADB(commandLine, adbParser);\n    this.androidWifiADB = new AndroidWiFiADB(adb, new NotificationView());\n  }\n\n  public void actionPerformed(final AnActionEvent event) {\n    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {\n      public void run() {\n        androidWifiADB.updateProject(event.getProject());\n        androidWifiADB.connectDevices();\n      }\n    });\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/adb/ADB.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.adb;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\nimport com.intellij.openapi.project.Project;\nimport java.io.File;\nimport java.util.Collection;\nimport java.util.List;\nimport org.jetbrains.android.sdk.AndroidSdkUtils;\n\npublic class ADB {\n\n  private static final String TCPIP_PORT = \"5555\";\n  private final CommandLine commandLine;\n  private final ADBParser adbParser;\n  private Project project;\n\n  public ADB(CommandLine commandLine, ADBParser adbParser) {\n    this.commandLine = commandLine;\n    this.adbParser = adbParser;\n  }\n\n  public void updateProject(Project project) {\n    this.project = project;\n  }\n\n  public boolean isInstalled() {\n    return AndroidSdkUtils.isAndroidSdkAvailable();\n  }\n\n  public Collection<Device> getDevicesConnectedByUSB() {\n    String getDevicesCommand = getCommand(\"devices -l\");\n    String adbDevicesOutput = commandLine.executeCommand(getDevicesCommand);\n    return adbParser.parseGetDevicesOutput(adbDevicesOutput);\n  }\n\n  public Collection<Device> connectDevices(Collection<Device> devices) {\n    for (Device device : devices) {\n      boolean connected = connectDeviceByIp(device);\n      device.setConnected(connected);\n    }\n    return devices;\n  }\n\n  public List<Device> disconnectDevices(List<Device> devices) {\n    for (Device device : devices) {\n      boolean disconnected = disconnectDevice(device.getIp());\n      device.setConnected(disconnected);\n    }\n    return devices;\n  }\n\n  private boolean connectDeviceByIp(Device device) {\n    String deviceIp = getDeviceIp(device);\n    if (deviceIp.isEmpty()) {\n      return false;\n    } else {\n      return connectDevice(deviceIp);\n    }\n  }\n\n  private boolean disconnectDevice(String deviceIp) {\n    enableTCPCommand();\n    String connectDeviceCommand = getCommand(\"disconnect \" + deviceIp);\n    return commandLine.executeCommand(connectDeviceCommand).isEmpty();\n  }\n\n  public String getDeviceIp(Device device) {\n    String getDeviceIpCommand =\n        getCommand(\"-s \" + device.getId() + \" shell ip -f inet addr show wlan0\");\n    String ipInfoOutput = commandLine.executeCommand(getDeviceIpCommand);\n    return adbParser.parseGetDeviceIp(ipInfoOutput);\n  }\n\n  private void enableTCPCommand() {\n    if (!checkTCPCommandExecuted()) {\n      String enableTCPCommand = getCommand(\"tcpip \" + TCPIP_PORT);\n      commandLine.executeCommand(enableTCPCommand);\n    }\n  }\n\n  private boolean checkTCPCommandExecuted() {\n    String getPropCommand = getCommand(\"adb shell getprop | grep adb\");\n    String getPropOutput = commandLine.executeCommand(getPropCommand);\n    String adbTcpPort = adbParser.parseAdbServiceTcpPort(getPropOutput);\n    return TCPIP_PORT.equals(adbTcpPort);\n  }\n\n  private boolean connectDevice(String deviceIp) {\n    String enableTCPCommand = getCommand(\"tcpip 5555\");\n    commandLine.executeCommand(enableTCPCommand);\n    String connectDeviceCommand = getCommand(\"connect \" + deviceIp);\n    String connectOutput = commandLine.executeCommand(connectDeviceCommand);\n    return connectOutput.contains(\"connected\");\n  }\n\n  private String getAdbPath() {\n    String adbPath = \"\";\n    File adbFile = AndroidSdkUtils.getAdb(project);\n    if (adbFile != null) {\n      adbPath = adbFile.getAbsolutePath();\n    }\n    return adbPath;\n  }\n\n  private String getCommand(String command) {\n    return getAdbPath() + \" \" + command;\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/adb/ADBParser.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.adb;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class ADBParser {\n\n  private static final String MODEL_INDICATOR = \"model:\";\n  private static final String DEVICE_INDICATOR = \"device:\";\n  private static final String IP_SEPARATOR = \".\";\n  private static final String END_DEVICE_IP_INDICATOR = \"/\";\n  private static final String START_DEVICE_IP_INDICATOR = \"inet\";\n  private static final String ERROR_PARSING_DEVICE_IP_KEY = \"Object\";\n  private static final String DAEMON_INDICATOR = \"daemon\";\n  private static final String START_TCPIP_PORT_INDICATOR = \"[service.adb.tcp.port]: [\";\n  private static final String DEVICE_NOT_FOUND = \"error: device '(null)' not found\";\n\n  public List<Device> parseGetDevicesOutput(String adbDevicesOutput) {\n    List<Device> devices = new LinkedList<Device>();\n    if (adbDevicesOutput.contains(DAEMON_INDICATOR)) {\n      return devices;\n    }\n    String[] splittedOutput = adbDevicesOutput.split(\"\\\\n\");\n    if (splittedOutput.length == 1) {\n      return devices;\n    }\n    for (int i = 1; i < splittedOutput.length; i++) {\n      String line = splittedOutput[i];\n      String[] deviceLine = line.split(\"\\\\t\");\n      String id = deviceLine[0].substring(0, deviceLine[0].indexOf(\" \"));\n      if (id.contains(IP_SEPARATOR)) {\n        continue;\n      }\n      String name = parseDeviceName(line);\n      Device device = new Device(name, id);\n      devices.add(device);\n    }\n    return devices;\n  }\n\n  public String parseGetDeviceIp(String ipInfo) {\n    if (ipInfo.isEmpty() || ipInfo.contains(ERROR_PARSING_DEVICE_IP_KEY)) {\n      return \"\";\n    }\n    try {\n      int start = ipInfo.indexOf(START_DEVICE_IP_INDICATOR) + 5;\n      int end = ipInfo.indexOf(END_DEVICE_IP_INDICATOR);\n      return ipInfo.substring(start, end);\n    } catch (StringIndexOutOfBoundsException e) {\n      System.out.println(e);\n      return \"\";\n    }\n  }\n\n  public String parseAdbServiceTcpPort(String getPropOutput) {\n    if (getPropOutput.isEmpty() || getPropOutput.contains(DEVICE_NOT_FOUND)\n        || !getPropOutput.contains(START_TCPIP_PORT_INDICATOR)) {\n      return \"\";\n    }\n\n    Matcher portMatcher =\n        Pattern.compile(\"(?<=\\\\[(service\\\\.adb\\\\.tcp\\\\.port).: \\\\[)([^\\\\]]+)(?=\\\\])\")\n            .matcher(getPropOutput);\n    if (portMatcher.find()) {\n      return portMatcher.group(0);\n    }\n    return \"\";\n  }\n\n  private String parseDeviceName(String line) {\n    int start = line.indexOf(MODEL_INDICATOR) + MODEL_INDICATOR.length();\n    int end = line.indexOf(DEVICE_INDICATOR) - 1;\n    if (end < 0) {\n      end = line.length();\n    }\n    return line.substring(start, end);\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/adb/CommandLine.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.adb;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class CommandLine {\n\n  public String executeCommand(String command) {\n    Process process;\n    StringBuilder stringBuilder = new StringBuilder();\n    try {\n      process = Runtime.getRuntime().exec(command);\n      process.waitFor();\n      InputStreamReader in = new InputStreamReader(process.getInputStream());\n      BufferedReader reader = new BufferedReader(in);\n      String line;\n      while ((line = reader.readLine()) != null) {\n        stringBuilder.append(line + \"\\n\");\n      }\n    } catch (InterruptedException e) {\n      e.printStackTrace();\n    } catch (IOException e) {\n      e.printStackTrace();\n    }\n    return stringBuilder.toString();\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/util/NotificationUtils.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.util;\n\nimport com.intellij.notification.Notification;\nimport com.intellij.notification.NotificationGroup;\nimport com.intellij.notification.NotificationType;\nimport com.intellij.notification.Notifications;\nimport com.intellij.openapi.application.ApplicationManager;\n\npublic class NotificationUtils {\n\n  private static final String ANDROID_WIFI_ADB_TITLE = \"Android WiFi ADB\";\n  private static final NotificationGroup NOTIFICATION_GROUP =\n      NotificationGroup.balloonGroup(ANDROID_WIFI_ADB_TITLE);\n\n  public static void showNotification(final String message,\n      final NotificationType type) {\n    ApplicationManager.getApplication().invokeLater(new Runnable() {\n      @Override public void run() {\n        Notification notification =\n            NOTIFICATION_GROUP.createNotification(ANDROID_WIFI_ADB_TITLE, message, type, null);\n        Notifications.Bus.notify(notification);\n      }\n    });\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/view/NotificationView.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.view;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\nimport com.intellij.notification.NotificationType;\n\nimport static com.github.pedrovgs.androidwifiadb.util.NotificationUtils.showNotification;\n\npublic class NotificationView implements View {\n  @Override public void showNoConnectedDevicesNotification() {\n    showNotification(\"There are no devices connected. Review your USB connection and try again.\",\n        NotificationType.INFORMATION);\n  }\n\n  @Override public void showConnectedDeviceNotification(Device device) {\n    showNotification(\"Device '\" + device.getName() + \"' connected.\",\n        NotificationType.INFORMATION);\n  }\n\n  @Override public void showDisconnectedDeviceNotification(Device device) {\n    showNotification(\"Device '\" + device.getName() + \"' disconnected.\",\n        NotificationType.INFORMATION);\n  }\n\n  @Override public void showErrorConnectingDeviceNotification(Device device) {\n    showNotification(\n        \"Unable to connect to device '\" + device.getName() + \"'. Make sure that your computer and your \"\n        + \"device are connected to the same WiFi network.\",\n        NotificationType.INFORMATION);\n  }\n\n  @Override public void showErrorDisconnectingDeviceNotification(Device device) {\n    showNotification(\n        \"Unable to disconnect device '\" + device.getName() + \"'. Make sure that your computer and your \"\n        + \"device are connected to the same WiFi network.\",\n        NotificationType.INFORMATION);\n  }\n\n  @Override public void showADBNotInstalledNotification() {\n    showNotification(\"'adb' command not found. Review your Android SDK installation.\",\n        NotificationType.ERROR);\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/view/View.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.view;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\n\npublic interface View {\n\n  void showNoConnectedDevicesNotification();\n\n  void showConnectedDeviceNotification(Device device);\n\n  void showDisconnectedDeviceNotification(Device device);\n\n  void showErrorConnectingDeviceNotification(Device device);\n\n  void showErrorDisconnectingDeviceNotification(Device device);\n\n  void showADBNotInstalledNotification();\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/ActionButtonListener.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\npublic interface ActionButtonListener {\n  void onConnectClick(int row);\n\n  void onDisconnectClick(int row);\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/AndroidDevicesTableModel.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport javax.swing.table.AbstractTableModel;\n\npublic class AndroidDevicesTableModel extends AbstractTableModel {\n  private static final int COLUMN_DEVICE = 0;\n  private static final int COLUMN_STATE = 1;\n  private static final int COLUMN_ACTION = 2;\n  private static final int COLUMN_COUNT = 3;\n  private static final String DEVICE = \"Device\";\n  private static final String STATE = \"State\";\n  private static final String ACTION = \"Action\";\n  private static final String CONNECTED = \"Connected\";\n  private static final String DISCONNECTED = \"Disconnected\";\n  private final List<Device> devices = new ArrayList<Device>();\n\n  @Override\n  public String getColumnName(int column) {\n    String value = null;\n    switch (column) {\n      case COLUMN_DEVICE:\n        value = DEVICE;\n        break;\n      case COLUMN_STATE:\n        value = STATE;\n        break;\n      case COLUMN_ACTION:\n        value = ACTION;\n        break;\n      default:\n        return value;\n    }\n    return value;\n  }\n\n  @Override\n  public Class<?> getColumnClass(int columnIndex) {\n    Class value = Object.class;\n    switch (columnIndex) {\n      case COLUMN_DEVICE:\n        value = String.class;\n        break;\n      case COLUMN_STATE:\n        value = String.class;\n        break;\n      default:\n        return value;\n    }\n    return value;\n  }\n\n  @Override\n  public int getRowCount() {\n    return devices.size();\n  }\n\n  @Override\n  public int getColumnCount() {\n    return COLUMN_COUNT;\n  }\n\n  @Override\n  public Object getValueAt(int rowIndex, int columnIndex) {\n    Device obj = devices.get(rowIndex);\n    Object value = null;\n    switch (columnIndex) {\n      case COLUMN_DEVICE:\n        value = obj.toString();\n        break;\n      case COLUMN_STATE:\n        value = obj.isConnected() ? CONNECTED : DISCONNECTED;\n        break;\n      case COLUMN_ACTION:\n        break;\n      default:\n        return value;\n    }\n    return value;\n  }\n\n  @Override\n  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {\n    if (columnIndex == COLUMN_ACTION) {\n      fireTableCellUpdated(rowIndex, columnIndex);\n    }\n  }\n\n  @Override\n  public boolean isCellEditable(int rowIndex, int columnIndex) {\n    return columnIndex == COLUMN_ACTION;\n  }\n\n  public void clear() {\n    if (devices != null) {\n      devices.clear();\n    }\n  }\n\n  public void add(Device value) {\n    int startIndex = getRowCount();\n    devices.add(value);\n    fireTableRowsInserted(startIndex, getRowCount() - 1);\n  }\n\n  public Device get(int index) {\n    if (index >= 0 && index < devices.size()) {\n      return devices.get(index);\n    }\n    return null;\n  }\n}"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/AndroidWiFiADBWindow.form",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<form xmlns=\"http://www.intellij.com/uidesigner/form/\" version=\"1\" bind-to-class=\"com.github.pedrovgs.androidwifiadb.window.AndroidWiFiADBWindow\">\n  <grid id=\"27dc6\" binding=\"toolWindowContent\" layout-manager=\"BorderLayout\" hgap=\"0\" vgap=\"0\">\n    <constraints>\n      <xy x=\"20\" y=\"20\" width=\"500\" height=\"400\"/>\n    </constraints>\n    <properties/>\n    <border type=\"none\"/>\n    <children/>\n  </grid>\n</form>\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/AndroidWiFiADBWindow.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport com.github.pedrovgs.androidwifiadb.AndroidWiFiADB;\nimport com.github.pedrovgs.androidwifiadb.Device;\nimport com.github.pedrovgs.androidwifiadb.adb.ADB;\nimport com.github.pedrovgs.androidwifiadb.adb.ADBParser;\nimport com.github.pedrovgs.androidwifiadb.adb.CommandLine;\nimport com.github.pedrovgs.androidwifiadb.view.NotificationView;\nimport com.intellij.openapi.application.ApplicationManager;\nimport com.intellij.openapi.project.Project;\nimport com.intellij.openapi.wm.ToolWindow;\nimport com.intellij.openapi.wm.ToolWindowFactory;\nimport com.intellij.ui.content.Content;\nimport com.intellij.ui.content.ContentFactory;\nimport java.util.Timer;\nimport java.util.TimerTask;\nimport javax.swing.JPanel;\n\npublic class AndroidWiFiADBWindow implements ToolWindowFactory, DeviceAction {\n\n  private static final int INTERVAL_REFRESH_DEVICES = 1000;\n\n  private final AndroidWiFiADB androidWifiADB;\n  private final CardLayoutDevices cardLayoutDevices;\n  private JPanel toolWindowContent;\n\n  public AndroidWiFiADBWindow() {\n    CommandLine commandLine = new CommandLine();\n    ADBParser adbParser = new ADBParser();\n    ADB adb = new ADB(commandLine, adbParser);\n    this.androidWifiADB = new AndroidWiFiADB(adb, new NotificationView());\n    cardLayoutDevices = new CardLayoutDevices(toolWindowContent, this);\n  }\n\n  @Override public void createToolWindowContent(Project project, ToolWindow toolWindow) {\n    androidWifiADB.updateProject(project);\n    createToolWindowContent(toolWindow);\n    setupUI();\n    monitorDevices();\n  }\n\n  @Override public void connectDevice(final Device device) {\n    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {\n      public void run() {\n        androidWifiADB.connectDevice(device);\n        updateUi();\n      }\n    });\n  }\n\n  @Override public void disconnectDevice(final Device device) {\n    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {\n      public void run() {\n        androidWifiADB.disconnectDevice(device);\n        updateUi();\n      }\n    });\n  }\n\n  private void createToolWindowContent(ToolWindow toolWindow) {\n    ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();\n    Content content = contentFactory.createContent(toolWindowContent, \"\", false);\n    toolWindow.getContentManager().addContent(content);\n  }\n\n  private void setupUI() {\n    ApplicationManager.getApplication().invokeLater(new Runnable() {\n      @Override public void run() {\n        cardLayoutDevices.createAndShowGUI();\n      }\n    });\n  }\n\n  private void monitorDevices() {\n    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {\n      public void run() {\n        new Timer().schedule(new TimerTask() {\n          @Override public void run() {\n            boolean refreshRequired = androidWifiADB.refreshDevicesList();\n            if (refreshRequired) {\n              updateUi();\n            }\n          }\n        }, 0, INTERVAL_REFRESH_DEVICES);\n      }\n    });\n  }\n\n  private void updateUi() {\n    ApplicationManager.getApplication().invokeLater(new Runnable() {\n      @Override public void run() {\n        cardLayoutDevices.setDevices(androidWifiADB.getDevices());\n        cardLayoutDevices.updateUi();\n      }\n    });\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/CardLayoutDevices.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\nimport com.intellij.ui.table.JBTable;\nimport java.awt.BorderLayout;\nimport java.awt.CardLayout;\nimport java.awt.Container;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport javax.swing.JCheckBox;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTable;\nimport javax.swing.SwingConstants;\nimport javax.swing.table.DefaultTableCellRenderer;\n\npublic class CardLayoutDevices implements ActionButtonListener {\n\n  private static final String CARD_DEVICES = \"Card with JTable devices\";\n  private static final String CARD_NO_DEVICES = \"Card with no devices info\";\n  private static final String NO_DEVICE_CONNECTED = \"No devices connected.\";\n\n  private Container parentContainer;\n  private JPanel cards;\n  private JPanel panelNoDevices;\n  private JPanel panelDevices;\n  private JTable tableDevices;\n  private Collection<Device> devices;\n  private DeviceAction deviceAction;\n\n  public CardLayoutDevices(Container parentContainer, DeviceAction action) {\n    this.deviceAction = action;\n    this.parentContainer = parentContainer;\n    this.devices = new ArrayList<Device>();\n  }\n\n  public void setDevices(Collection<Device> devices) {\n    this.devices = devices;\n  }\n\n  public void createAndShowGUI() {\n    cards = new JPanel(new CardLayout());\n    createNoDevicesPanel();\n    createTableDevices();\n    cards.add(panelDevices, CARD_DEVICES);\n    cards.add(panelNoDevices, CARD_NO_DEVICES);\n    parentContainer.add(cards, BorderLayout.PAGE_START);\n    setupUi();\n  }\n\n  public void updateUi() {\n    if (devices != null && !devices.isEmpty()) {\n      showCard(CARD_DEVICES);\n      updateDevicesTable();\n    } else {\n      showCard(CARD_NO_DEVICES);\n    }\n  }\n\n  @Override public void onConnectClick(int row) {\n    Device device = getDeviceAt(row);\n    if (device != null) {\n      deviceAction.connectDevice(device);\n    }\n  }\n\n  @Override public void onDisconnectClick(int row) {\n    Device device = getDeviceAt(row);\n    if (device != null) {\n      deviceAction.disconnectDevice(device);\n    }\n  }\n\n  private void setupUi() {\n    if (devices != null && !devices.isEmpty()) {\n      showCard(CARD_DEVICES);\n    } else {\n      showCard(CARD_NO_DEVICES);\n    }\n  }\n\n  private void showCard(String cardName) {\n    CardLayout cardLayout = (CardLayout) cards.getLayout();\n    cardLayout.show(cards, cardName);\n  }\n\n  private void createNoDevicesPanel() {\n    panelNoDevices = new JPanel(new BorderLayout());\n    JLabel labelNoDevices = new JLabel(NO_DEVICE_CONNECTED);\n    labelNoDevices.setHorizontalAlignment(SwingConstants.CENTER);\n    panelNoDevices.add(labelNoDevices);\n  }\n\n  private void createTableDevices() {\n    AndroidDevicesTableModel model = new AndroidDevicesTableModel();\n    for (Device device : devices) {\n      model.add(device);\n    }\n    tableDevices = new JBTable(model);\n    configureTableAppearance();\n\n    panelDevices = new JPanel(new BorderLayout());\n    panelDevices.add(tableDevices.getTableHeader(), BorderLayout.NORTH);\n    panelDevices.add(tableDevices, BorderLayout.CENTER);\n  }\n\n  private void configureTableAppearance() {\n    tableDevices.setOpaque(false);\n    ((DefaultTableCellRenderer) tableDevices.getDefaultRenderer(Object.class)).setOpaque(false);\n    tableDevices.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);\n    tableDevices.getColumnModel().getColumn(0).setPreferredWidth(100);\n    tableDevices.getColumnModel().getColumn(1).setMinWidth(85);\n    tableDevices.getColumnModel().getColumn(1).setMaxWidth(85);\n    tableDevices.getColumnModel().getColumn(2).setMinWidth(215);\n    tableDevices.getColumnModel().getColumn(2).setMaxWidth(215);\n    tableDevices.getColumnModel().getColumn(2).setCellRenderer(new ConnectDisconnectRenderer());\n    tableDevices.getColumnModel()\n        .getColumn(2)\n        .setCellEditor(new ConnectDisconnectEditor(new JCheckBox(), this));\n  }\n\n  private void updateDevicesTable() {\n    AndroidDevicesTableModel model = (AndroidDevicesTableModel) tableDevices.getModel();\n    model.clear();\n    for (Device device : devices) {\n      model.add(device);\n    }\n    tableDevices.setModel(model);\n    model.fireTableDataChanged();\n  }\n\n  private Device getDeviceAt(int row) {\n    AndroidDevicesTableModel model = (AndroidDevicesTableModel) tableDevices.getModel();\n    return model.get(row);\n  }\n}\n"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/ConnectDisconnectEditor.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport java.awt.Component;\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\n\nimport javax.swing.DefaultCellEditor;\nimport javax.swing.JCheckBox;\nimport javax.swing.JTable;\n\npublic class ConnectDisconnectEditor extends DefaultCellEditor {\n    private boolean clicked;\n    private String clickedButtonAction;\n    private int row, col;\n    private ConnectDisconnectPanel buttonsPanel;\n    private ActionButtonListener listener;\n\n    public ConnectDisconnectEditor(JCheckBox checkBox, ActionButtonListener listener) {\n        super(checkBox);\n        this.listener = listener;\n        buttonsPanel = new ConnectDisconnectPanel();\n        buttonsPanel.addActionListeners(new ActionListener() {\n            @Override\n            public void actionPerformed(ActionEvent e) {\n                clickedButtonAction = e.getActionCommand();\n                fireEditingStopped();\n            }\n        });\n    }\n\n    @Override\n    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {\n        this.row = row;\n        this.col = column;\n\n        clicked = true;\n        return buttonsPanel;\n    }\n\n    @Override\n    public Object getCellEditorValue() {\n        if (clicked && listener != null) {\n            if (ConnectDisconnectPanel.ACTION_CONNECT.equals(clickedButtonAction)) {\n                listener.onConnectClick(row);\n            } else if (ConnectDisconnectPanel.ACTION_DISCONNECT.equals(clickedButtonAction)) {\n                listener.onDisconnectClick(row);\n            }\n        }\n        clickedButtonAction = \"\";\n        clicked = false;\n        return \"\";\n    }\n\n    @Override\n    public boolean stopCellEditing() {\n        clicked = false;\n        return super.stopCellEditing();\n    }\n\n    @Override\n    protected void fireEditingStopped() {\n        super.fireEditingStopped();\n    }\n}"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/ConnectDisconnectPanel.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport java.awt.GridBagLayout;\nimport java.awt.event.ActionListener;\n\nimport javax.swing.JButton;\nimport javax.swing.JPanel;\n\npublic class ConnectDisconnectPanel extends JPanel {\n  public static final String ACTION_CONNECT = \"Connect\";\n  public static final String ACTION_DISCONNECT = \"Disconnect\";\n\n  private JButton connect;\n  private JButton disconnect;\n\n  public ConnectDisconnectPanel() {\n    setLayout(new GridBagLayout());\n    setOpaque(false);\n    connect = new JButton(ACTION_CONNECT);\n    connect.setActionCommand(ACTION_CONNECT);\n    connect.setOpaque(false);\n    disconnect = new JButton(ACTION_DISCONNECT);\n    disconnect.setActionCommand(ACTION_DISCONNECT);\n    disconnect.setOpaque(false);\n\n    add(connect);\n    add(disconnect);\n  }\n\n  public void addActionListeners(ActionListener listener) {\n    connect.addActionListener(listener);\n    disconnect.addActionListener(listener);\n  }\n}"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/ConnectDisconnectRenderer.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport java.awt.Component;\n\nimport javax.swing.JPanel;\nimport javax.swing.JTable;\nimport javax.swing.table.TableCellRenderer;\n\npublic class ConnectDisconnectRenderer extends JPanel implements TableCellRenderer {\n  private final ConnectDisconnectPanel connectDisconnectPane = new ConnectDisconnectPanel();\n\n  @Override\n  public Component getTableCellRendererComponent(JTable table, Object value,\n      boolean isSelected, boolean hasFocus,\n      int row, int column) {\n    if (isSelected) {\n      connectDisconnectPane.setBackground(table.getSelectionBackground());\n    } else {\n      connectDisconnectPane.setBackground(table.getBackground());\n    }\n    return connectDisconnectPane;\n  }\n}"
  },
  {
    "path": "src/main/java/com/github/pedrovgs/androidwifiadb/window/DeviceAction.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\n\npublic interface DeviceAction {\n  void connectDevice(Device device);\n\n  void disconnectDevice(Device device);\n}\n"
  },
  {
    "path": "src/main/resources/META-INF/plugin.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<idea-plugin version=\"2\">\n  <id>com.github.pedrovgs.androidwifiadb</id>\n  <name>Android WiFi ADB</name>\n  <version>2.5-SNAPSHOT</version>\n  <vendor email=\"pedrovicente.gomez at gmail dot com\" url=\"http://www.github.com/pedrovgs\">\n    Pedro Vicente Gomez Sanchez\n  </vendor>\n\n  <description><![CDATA[\n      Provides an action which allow you quickly connect your Android device over WiFi to install, run and debug your applications without a USB connected by pressing one button.\n      <br>\n      Connect your device using a USB cable and press the Android WiFi ADB button. Once the device be connected over WiFi you'll see an IntelliJ/Android Studio notification. Now you can disconnect your USB cable and enjoy deploying, running and debugging your applications over WiFi.\n      <br>\n      The version 2.0 enables a window to check which of your devices are connected or not and connect/disconnect it manually if needed.\n    ]]>\n  </description>\n\n  <change-notes><![CDATA[\n      2.4: Generate the plugin binary using Java 1.6 instead of Java 1.8.<br>\n      2.3: Update the main action configuration to be shown in the NavBarToolBar and also in the MainToolBar if the first on is disabled.<br>\n      2.2: Update error message shown when the device is not properly connected.<br>\n      2.1: Fix bug associated to some device installations where the adb installation was not recognized.<br>\n      2.0: Add a new Android WiFi ADB control panel showing all the devices connected by USB to be able to connect/disconnect devices individually.<br>\n      1.2: Remove the usage of the ANDROID_HOME environment variable. This variable is not needed now.<br>\n      1.1: Fixes for Windows and Linux.<br>\n      1.0: Initial version.<br>\n    ]]>\n  </change-notes>\n\n  <idea-version since-build=\"131\"/>\n\n  <extensions defaultExtensionNs=\"com.intellij\">\n\n    <defaultProjectTypeProvider type=\"Android\"/>\n\n      <toolWindow id=\"Android WiFi ADB\"\n              icon=\"/icons/androidWiFiADBIcon.png\"\n              anchor=\"right\"\n              factoryClass=\"com.github.pedrovgs.androidwifiadb.window.AndroidWiFiADBWindow\">\n      </toolWindow>\n  </extensions>\n\n  <application-components>\n\n  </application-components>\n\n  <project-components>\n\n  </project-components>\n\n  <depends>org.jetbrains.android</depends>\n\n  <actions>\n\n    <action id=\"AndroidWiFiADB\"\n        class=\"com.github.pedrovgs.androidwifiadb.action.AndroidWiFiADBAction\"\n        text=\"AndroidWiFiADB\"\n        description=\"Connects your Android devices to your computer over TCP just with one click.\"\n        icon=\"/icons/androidWiFiADBIcon.png\"\n        project-type=\"Android\"\n        >\n      <add-to-group group-id=\"MainToolBar\" anchor=\"last\"/>\n      <add-to-group group-id=\"NavBarToolBar\" anchor=\"first\"/>\n    </action>\n\n  </actions>\n\n</idea-plugin>"
  },
  {
    "path": "src/test/java/com/github/pedrovgs/androidwifiadb/AndroidWiFiADBTest.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb;\n\nimport com.github.pedrovgs.androidwifiadb.adb.ADB;\nimport com.github.pedrovgs.androidwifiadb.view.View;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.List;\nimport org.junit.Test;\nimport org.mockito.Mock;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertFalse;\nimport static org.junit.Assert.assertTrue;\nimport static org.mockito.Matchers.anyObject;\nimport static org.mockito.Mockito.verify;\nimport static org.mockito.Mockito.when;\n\npublic class AndroidWiFiADBTest extends UnitTest {\n\n  private static final int SOME_DEVICES = 4;\n  private static final String ANY_DEVICE_NAME = \"Device nº \";\n  private static final String ANY_DEVICE_ID = \"abcdef123\";\n  private static final String ANY_DEVICE_IP = \"0.0.0.0\";\n\n  @Mock private ADB adb;\n  @Mock private View view;\n\n  @Test public void shouldShowErrorIfADBIsNotInstalled() {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    givenADBIsNotInstalled();\n\n    androidWiFiAdb.connectDevices();\n\n    verify(view).showADBNotInstalledNotification();\n  }\n\n  @Test public void shouldShowNoConnectedDevicesNotificationIfThereAreNotConnectedDevicesByUSB() {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    givenThereAreNoConnectedDevices();\n\n    androidWiFiAdb.connectDevices();\n\n    verify(view).showNoConnectedDevicesNotification();\n  }\n\n  @Test public void shouldShowDevicesConnectedIfADBWiFiWhenConnectionIsEstablished() {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    List<Device> devices = givenThereAreSomeDevicesConnectedByUSB();\n    givenDevicesAreConnectedSuccessfully(devices);\n\n    androidWiFiAdb.connectDevices();\n\n    for (Device device : devices) {\n      verify(view).showConnectedDeviceNotification(device);\n    }\n  }\n\n  @Test public void shouldShowDeviceConnectionErrorWhenConnectionIsNotEstablished() {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    List<Device> devices = givenThereAreSomeDevicesConnectedByUSB();\n    givenDevicesAreNotConnectedSuccessfully(devices);\n\n    androidWiFiAdb.connectDevices();\n\n    for (Device device : devices) {\n      verify(view).showErrorConnectingDeviceNotification(device);\n    }\n  }\n\n  @Test public void shouldNotRefreshDevicesListIfAdbIsNotIstalled() throws Exception {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    givenADBIsNotInstalled();\n\n    assertFalse(androidWiFiAdb.refreshDevicesList());\n  }\n\n  @Test public void shouldRefreshDevicesListAddNewDevice() throws Exception {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    List<Device> devices = givenThereAreSomeDevicesConnectedByUSB();\n    givenDevicesAreConnectedSuccessfully(devices);\n    givenAnyIpToDevices();\n\n    assertEquals(0, androidWiFiAdb.getDevices().size());\n    androidWiFiAdb.refreshDevicesList();\n    assertEquals(devices.size(), androidWiFiAdb.getDevices().size());\n  }\n\n  @Test public void shouldRefreshDevicesListUpdateExistingDevices() throws Exception {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    List<Device> devices = givenThereAreSomeDevicesConnectedByUSB();\n    givenDevicesAreConnectedSuccessfully(devices);\n\n    androidWiFiAdb.connectDevices();\n    androidWiFiAdb.refreshDevicesList();\n\n    assertEquals(devices.size(), androidWiFiAdb.getDevices().size());\n  }\n\n  @Test public void shouldDisconnectDevice() throws Exception {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    givenADBIsInstalled();\n    Device device = givenAnyConnectedDevice();\n    givenDevicesAreDisconnectedSuccessfully(Arrays.asList(device));\n\n    androidWiFiAdb.disconnectDevice(device);\n\n    assertFalse(device.isConnected());\n  }\n\n  @Test public void shouldConnectDevice() throws Exception {\n    AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();\n    givenADBIsInstalled();\n    Device device = givenAnyDisonnectedDevice();\n    givenDevicesAreConnectedSuccessfully(Arrays.asList(device));\n\n    androidWiFiAdb.connectDevice(device);\n\n    assertTrue(device.isConnected());\n  }\n\n  private Device givenAnyConnectedDevice() {\n    Device device = new Device(ANY_DEVICE_NAME, ANY_DEVICE_ID);\n    device.setConnected(true);\n    return device;\n  }\n\n  private Device givenAnyDisonnectedDevice() {\n    return new Device(ANY_DEVICE_NAME, ANY_DEVICE_ID);\n  }\n\n  private void givenDevicesAreNotConnectedSuccessfully(List<Device> devices) {\n    for (Device device : devices) {\n      device.setConnected(false);\n    }\n    when(adb.getDevicesConnectedByUSB()).thenReturn(devices);\n    when(adb.connectDevices(devices)).thenReturn(devices);\n  }\n\n  private void givenDevicesAreConnectedSuccessfully(List<Device> devices) {\n    for (Device device : devices) {\n      device.setConnected(true);\n    }\n    when(adb.getDevicesConnectedByUSB()).thenReturn(devices);\n    when(adb.connectDevices(devices)).thenReturn(new ArrayList<Device>(devices));\n  }\n\n  private void givenDevicesAreDisconnectedSuccessfully(final List<Device> devices) {\n    for (Device device : devices) {\n      device.setConnected(false);\n    }\n    when(adb.disconnectDevices(devices)).thenReturn(devices);\n  }\n\n  private List<Device> givenThereAreSomeDevicesConnectedByUSB() {\n    when(adb.isInstalled()).thenReturn(true);\n    return getSomeDevices(SOME_DEVICES);\n  }\n\n  private List<Device> getSomeDevices(int devicesCount) {\n    List<Device> devices = new LinkedList<Device>();\n    for (int i = 0; i < devicesCount; i++) {\n      String name = ANY_DEVICE_NAME + i;\n      String id = String.valueOf(i);\n      Device device = new Device(name, id);\n      devices.add(device);\n    }\n    return devices;\n  }\n\n  private void givenThereAreNoConnectedDevices() {\n    when(adb.isInstalled()).thenReturn(true);\n    when(adb.getDevicesConnectedByUSB()).thenReturn(new LinkedList<Device>());\n  }\n\n  private void givenADBIsNotInstalled() {\n    when(adb.isInstalled()).thenReturn(false);\n  }\n\n  private void givenADBIsInstalled() {\n    when(adb.isInstalled()).thenReturn(true);\n  }\n\n  private void givenAnyIpToDevices() {\n    when(adb.getDeviceIp((Device) anyObject())).thenReturn(ANY_DEVICE_IP);\n  }\n\n  private AndroidWiFiADB givenAnAndroidWiFiADB() {\n    return new AndroidWiFiADB(adb, view);\n  }\n}\n"
  },
  {
    "path": "src/test/java/com/github/pedrovgs/androidwifiadb/UnitTest.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb;\n\nimport org.junit.Before;\nimport org.mockito.MockitoAnnotations;\n\npublic class UnitTest {\n\n  @Before public void setUp() {\n    MockitoAnnotations.initMocks(this);\n  }\n}\n"
  },
  {
    "path": "src/test/java/com/github/pedrovgs/androidwifiadb/adb/ADBParserTest.java",
    "content": "/*\n * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.pedrovgs.androidwifiadb.adb;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\nimport com.github.pedrovgs.androidwifiadb.UnitTest;\nimport java.util.List;\nimport org.junit.Test;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\npublic class ADBParserTest extends UnitTest {\n\n  private static final String ADB_DEVICES_OUTPUT_ONE_DEVICE = \"List of devices attached\\n\"\n      + \"0810a0dd00e3656f    device usb:336592896X product:hammerhead model:Nexus_5 device:hammerhead\";\n  private static final String ADB_DEVICES_OUTPUT_SOME_DEVICES = \"List of devices attached\\n\"\n      + \"0810a0dd00e3656f    device usb:336592896X product:hammerhead model:Nexus_5 device:hammerhead\\n\"\n      + \"0810a0d333333656f    device usb:336592896X product:hammerhead model:Nexus_6\";\n  private static final String ADB_DEVICES_NO_DEVICES = \"List of devices attached\\n\";\n  private static final String ADB_DEVICES_OUTPUT_WITH_DEVICES_BY_IP = \"List of devices attached\\n\"\n      + \"0810a0dd00e3656f    device usb:336592896X product:hammerhead model:Nexus_5 device:hammerhead\\n\"\n      + \"192.168.1.128:5555f    device usb:336592896X product:hammerhead model:Nexus_6 device:hammerhead\\n\";\n  private static final String GET_IP_OUTPUT =\n      \"21: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000\\n\"\n          + \"    inet 192.168.1.128/24 brd 192.168.1.255 scope global wlan0\";\n  private static final String GET_ADB_PROP_DEVICE_NOT_FOUND = \"error: device '(null)' not found\";\n  private static final String GET_ADP_PROP_NO_TCP_PORT_INFO = \"[init.svc.adbd]: [running]\\n\"\n      + \"[persist.sys.usb.config]: [mtp,adb]\\n\"\n      + \"[ro.adb.secure]: [1]\\n\"\n      + \"[sys.usb.config]: [mtp,adb]\\n\"\n      + \"[sys.usb.state]: [mtp,adb]\";\n  private static final String TCPIP_PORT = \"5555\";\n  private static final String GET_ADB_PROP_WITH_TCP_PORT = \"  [init.svc.adbd]: [running]\\n\"\n      + \"  [persist.sys.usb.config]: [mtp,adb]\\n\"\n      + \"  [ro.adb.secure]: [1]\\n\"\n      + \"  [service.adb.tcp.port]: [\" + TCPIP_PORT + \"]\\n\"\n      + \"  [sys.usb.config]: [mtp,adb]\\n\"\n      + \"  [sys.usb.state]: [mtp,adb]\\n\";\n\n  @Test\n  public void shouldParseAdbDevicesOutputAndReturnTheListOfDevicesWithJustOneDeviceConnected() {\n    ADBParser parser = givenAADBParser();\n\n    List<Device> devices = parser.parseGetDevicesOutput(ADB_DEVICES_OUTPUT_ONE_DEVICE);\n\n    assertEquals(1, devices.size());\n    Device device = devices.get(0);\n    assertEquals(\"0810a0dd00e3656f\", device.getId());\n    assertEquals(\"Nexus_5\", device.getName());\n  }\n\n  @Test public void shouldParseAdbDevicesOutputAndReturnTheListOfDevicesWithMoreThanOneDevice() {\n    ADBParser parser = givenAADBParser();\n\n    List<Device> devices = parser.parseGetDevicesOutput(ADB_DEVICES_OUTPUT_SOME_DEVICES);\n\n    assertEquals(2, devices.size());\n    Device firstDevice = devices.get(0);\n    Device secondDevice = devices.get(1);\n    assertEquals(\"0810a0dd00e3656f\", firstDevice.getId());\n    assertEquals(\"Nexus_5\", firstDevice.getName());\n    assertEquals(\"0810a0d333333656f\", secondDevice.getId());\n    assertEquals(\"Nexus_6\", secondDevice.getName());\n  }\n\n  @Test public void shouldReturnAnEmptyListIfThereAreNoDevices() {\n    ADBParser parser = givenAADBParser();\n\n    List<Device> devices = parser.parseGetDevicesOutput(ADB_DEVICES_NO_DEVICES);\n\n    assertTrue(devices.isEmpty());\n  }\n\n  @Test public void shouldNotReturnDevicesConnectedByIp() {\n    ADBParser parser = givenAADBParser();\n\n    List<Device> devices = parser.parseGetDevicesOutput(ADB_DEVICES_OUTPUT_WITH_DEVICES_BY_IP);\n\n    assertEquals(1, devices.size());\n    Device device = devices.get(0);\n    assertEquals(\"0810a0dd00e3656f\", device.getId());\n    assertEquals(\"Nexus_5\", device.getName());\n  }\n\n  @Test public void shouldReturnDeviceIp() {\n    ADBParser parser = givenAADBParser();\n\n    String deviceIp = parser.parseGetDeviceIp(GET_IP_OUTPUT);\n\n    assertEquals(\"192.168.1.128\", deviceIp);\n  }\n\n  @Test public void shouldReturnEmptyIfDeviceIpIsAnEmptyString() {\n    ADBParser parser = givenAADBParser();\n\n    String deviceIp = parser.parseGetDeviceIp(\"\");\n\n    assertEquals(\"\", deviceIp);\n  }\n\n  @Test\n  public void shouldReturnEmptyStringIfDeviceNotFound() throws Exception {\n    ADBParser parser = givenAADBParser();\n\n    String tcpPort = parser.parseAdbServiceTcpPort(GET_ADB_PROP_DEVICE_NOT_FOUND);\n\n    assertEquals(\"\", tcpPort);\n  }\n\n  @Test\n  public void shouldReturnEmptyStringIfAdbPropertiesDoesNotContainTCPPort() throws Exception {\n    ADBParser parser = givenAADBParser();\n\n    String tcpPort = parser.parseAdbServiceTcpPort(GET_ADP_PROP_NO_TCP_PORT_INFO);\n\n    assertEquals(\"\", tcpPort);\n  }\n\n  @Test\n  public void shouldReturnTCPPort() throws Exception {\n    ADBParser parser = givenAADBParser();\n\n    String tcpPort = parser.parseAdbServiceTcpPort(GET_ADB_PROP_WITH_TCP_PORT);\n\n    assertEquals(TCPIP_PORT, tcpPort);\n  }\n\n  private ADBParser givenAADBParser() {\n    return new ADBParser();\n  }\n}\n"
  },
  {
    "path": "src/test/java/com/github/pedrovgs/androidwifiadb/window/AndroidDevicesTableModelTest.java",
    "content": "/*\n *\n *  * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n *  *\n *  * Licensed under the Apache License, Version 2.0 (the \"License\");\n *  * you may not use this file except in compliance with the License.\n *  * You may obtain a copy of the License at\n *  *\n *  * http://www.apache.org/licenses/LICENSE-2.0\n *  *\n *  * Unless required by applicable law or agreed to in writing, software\n *  * distributed under the License is distributed on an \"AS IS\" BASIS,\n *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *  * See the License for the specific language governing permissions and\n *  * limitations under the License.\n *\n */\n\npackage com.github.pedrovgs.androidwifiadb.window;\n\nimport com.github.pedrovgs.androidwifiadb.Device;\nimport com.github.pedrovgs.androidwifiadb.UnitTest;\nimport javax.swing.event.TableModelEvent;\nimport javax.swing.event.TableModelListener;\nimport org.junit.Test;\nimport org.mockito.Mock;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertFalse;\nimport static org.junit.Assert.assertNull;\nimport static org.junit.Assert.assertTrue;\nimport static org.mockito.Matchers.anyObject;\nimport static org.mockito.Mockito.atLeastOnce;\nimport static org.mockito.Mockito.verify;\n\npublic class AndroidDevicesTableModelTest extends UnitTest {\n\n  private static final int COLUMN_DEVICE = 0;\n  private static final int COLUMN_STATE = 1;\n  private static final int COLUMN_ACTION = 2;\n  private static final int COLUMN_WITH_NOT_VALID_INDEX = -1;\n  private static final String ANY_DEVICE_ID = \"abcdef\";\n  private static final String ANY_DEVICE_NAME = \"test_name\";\n  private static final String CONNECTED = \"Connected\";\n  private static final String DISCONNECTED = \"Disconnected\";\n\n  @Mock\n  TableModelListener tableModelListener;\n\n  @Test\n  public void shouldAddDevice() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n    assertNull(androidDevicesTableModel.get(0));\n\n    Device device = givenAnyDevice();\n    androidDevicesTableModel.add(device);\n\n    assertEquals(device, androidDevicesTableModel.get(0));\n  }\n\n  @Test\n  public void shouldClearDevicesList() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    androidDevicesTableModel.add(givenAnyDevice());\n\n    assertEquals(1, androidDevicesTableModel.getRowCount());\n    androidDevicesTableModel.clear();\n    assertEquals(0, androidDevicesTableModel.getRowCount());\n  }\n\n  @Test\n  public void shouldReturnValueDeviceAsStringForDeviceColumn() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    Device device = givenAnyDevice();\n    androidDevicesTableModel.add(device);\n\n    assertEquals(device.toString(), androidDevicesTableModel.getValueAt(0, COLUMN_DEVICE));\n  }\n\n  @Test\n  public void shouldReturnValueConnectedStringForConnectedDevice() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    Device device = givenAnyDevice();\n    device.setConnected(true);\n    androidDevicesTableModel.add(device);\n\n    assertEquals(CONNECTED, androidDevicesTableModel.getValueAt(0, COLUMN_STATE));\n  }\n\n  @Test\n  public void shouldReturnValueDisconnectedStringForDisconnectedDevice() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    Device device = givenAnyDevice();\n    device.setConnected(false);\n    androidDevicesTableModel.add(device);\n\n    assertEquals(DISCONNECTED, androidDevicesTableModel.getValueAt(0, COLUMN_STATE));\n  }\n\n  @Test\n  public void shouldReturnNullValueForActionColumn() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    androidDevicesTableModel.add(givenAnyDevice());\n\n    assertEquals(null, androidDevicesTableModel.getValueAt(0, COLUMN_ACTION));\n  }\n\n  @Test\n  public void shouldReturnNullValueForUnknownColumn() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    androidDevicesTableModel.add(givenAnyDevice());\n\n    assertEquals(null, androidDevicesTableModel.getValueAt(0, COLUMN_WITH_NOT_VALID_INDEX));\n  }\n\n  @Test\n  public void shouldReturnEditableCellForActionColumn() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    androidDevicesTableModel.add(givenAnyDevice());\n\n    assertFalse(androidDevicesTableModel.isCellEditable(0, COLUMN_STATE)\n        || androidDevicesTableModel.isCellEditable(0, COLUMN_DEVICE));\n    assertTrue(androidDevicesTableModel.isCellEditable(0, COLUMN_ACTION));\n  }\n\n  @Test\n  public void shouldFireCellUpdateOnlyForActionColumn() throws Exception {\n    AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();\n\n    androidDevicesTableModel.addTableModelListener(tableModelListener);\n    androidDevicesTableModel.setValueAt(anyObject(), 0, COLUMN_ACTION);\n\n    verify(tableModelListener, atLeastOnce()).tableChanged((TableModelEvent) anyObject());\n  }\n\n  private Device givenAnyDevice() {\n    return new Device(ANY_DEVICE_NAME, ANY_DEVICE_ID);\n  }\n\n  private AndroidDevicesTableModel givenEmptyDevicesTableModel() {\n    return new AndroidDevicesTableModel();\n  }\n}\n"
  }
]