Bubble android client. Fork of https://git.zx2c4.com/wireguard-android/
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

88 řádky
3.4 KiB

  1. /*
  2. * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. task generateNonNullJavaFiles(dependsOn: "assembleDebug", type: Copy) {
  6. group = "Copying"
  7. description = "Generate package-info.java classes"
  8. def basePackage = "com" + File.separatorChar + "wireguard"
  9. def mainSrcPhrase = "src" + File.separatorChar + "main" + File.separatorChar +
  10. "java" + File.separatorChar
  11. def mainTestSrcPhrase = "src" + File.separatorChar + "test" + File.separatorChar +
  12. "java" + File.separatorChar
  13. def mainAndroidTestSrcPhrase = "src" + File.separatorChar + "androidTest" + File.separatorChar +
  14. "java" + File.separatorChar
  15. def sourceDir = file( "${projectDir}" + File.separatorChar + "src" + File.separatorChar +
  16. "main" + File.separatorChar + "java" + File.separatorChar +
  17. basePackage )
  18. def testSourceDir = file( "${projectDir}" + File.separatorChar + "src" + File.separatorChar +
  19. "test" + File.separatorChar + "java" + File.separatorChar +
  20. basePackage)
  21. def androidTestSourceDir = file( "${projectDir}" + File.separatorChar + "src" + File
  22. .separatorChar +
  23. "androidTest" + File.separatorChar + "java" + File.separatorChar +
  24. basePackage )
  25. generateInfoFiles(sourceDir, mainSrcPhrase);
  26. sourceDir.eachDirRecurse { dir ->
  27. generateInfoFiles(dir, mainSrcPhrase)
  28. }
  29. if (file(testSourceDir).exists()) {
  30. generateInfoFiles(testSourceDir, mainTestSrcPhrase);
  31. testSourceDir.eachDirRecurse { dir ->
  32. generateInfoFiles(dir, mainTestSrcPhrase)
  33. }
  34. }
  35. if (file(androidTestSourceDir).exists()) {
  36. generateInfoFiles(androidTestSourceDir, mainAndroidTestSrcPhrase);
  37. androidTestSourceDir.eachDirRecurse { dir ->
  38. generateInfoFiles(dir, mainAndroidTestSrcPhrase)
  39. }
  40. }
  41. println "[SUCCESS] NonNull generator: package-info.java files checked"
  42. }
  43. private void generateInfoFiles(File dir, String mainSrcPhrase) {
  44. def infoFileContentHeader = getFileContentHeader();
  45. def infoFileContentFooter = getFileContentFooter();
  46. def infoFilePath = dir.getAbsolutePath() + File.separatorChar + "package-info.java"
  47. //file(infoFilePath).delete(); //do not use in production code
  48. if (!file(infoFilePath).exists()) {
  49. def infoFileContentPackage = getFileContentPackage(dir.getAbsolutePath(), mainSrcPhrase);
  50. new File(infoFilePath).write(infoFileContentHeader +
  51. infoFileContentPackage + infoFileContentFooter)
  52. println "[dir] " + infoFilePath + " created";
  53. }
  54. }
  55. def getFileContentPackage(String path, String mainSrcPhrase) {
  56. def mainSrcPhraseIndex = path.indexOf(mainSrcPhrase)
  57. def output = path.substring(mainSrcPhraseIndex)
  58. // Win hotfix
  59. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  60. output = output.replace("\\", "/")
  61. mainSrcPhrase = mainSrcPhrase.replace("\\", "/")
  62. }
  63. return "package " + output.replaceAll(mainSrcPhrase, "").replaceAll(
  64. "/", ".") + ";\n"
  65. }
  66. def getFileContentHeader() {
  67. return "/**\n" +
  68. " * Make all method parameters @NonNull by default.\n" +
  69. " */\n" +
  70. "@NonNullForAll\n"
  71. }
  72. def getFileContentFooter() {
  73. return "\n" +
  74. "import com.wireguard.util.NonNullForAll;\n"
  75. }