summaryrefslogtreecommitdiffhomepage
path: root/nonnull.gradle
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-03-09 12:01:52 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-09 12:19:15 -0600
commit8e8643122eb5783d4412c8a81fb03cc789c3f77c (patch)
tree43cc7ea98c33115a7b3bc062104deeb75c580f19 /nonnull.gradle
parentc00a0b12e4bf353a20a520c59961b21374050089 (diff)
global: get rid of nonnull gradle hack
Hacking things up via gradle is not right, and package-info.java poses problems with two modules, so instead we just apply it manually to every class. Remember to add this to new classes! Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'nonnull.gradle')
-rw-r--r--nonnull.gradle86
1 files changed, 0 insertions, 86 deletions
diff --git a/nonnull.gradle b/nonnull.gradle
deleted file mode 100644
index 7fc9b25d..00000000
--- a/nonnull.gradle
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0
- */
-
-task generateNonNullJavaFiles(dependsOn: "assembleDebug", type: Copy) {
- group = "Copying"
- description = "Generate package-info.java classes"
-
- def basePackage = "com" + File.separatorChar + "wireguard"
- def mainSrcPhrase = "src" + File.separatorChar + "main" + File.separatorChar +
- "java" + File.separatorChar
- def mainTestSrcPhrase = "src" + File.separatorChar + "test" + File.separatorChar +
- "java" + File.separatorChar
- def mainAndroidTestSrcPhrase = "src" + File.separatorChar + "androidTest" + File.separatorChar +
- "java" + File.separatorChar
-
- def sourceDir = file( "${projectDir}" + File.separatorChar + "src" + File.separatorChar +
- "main" + File.separatorChar + "java" + File.separatorChar +
- basePackage )
- def testSourceDir = file( "${projectDir}" + File.separatorChar + "src" + File.separatorChar +
- "test" + File.separatorChar + "java" + File.separatorChar +
- basePackage)
- def androidTestSourceDir = file( "${projectDir}" + File.separatorChar + "src" + File
- .separatorChar +
- "androidTest" + File.separatorChar + "java" + File.separatorChar +
- basePackage )
-
- generateInfoFiles(sourceDir, mainSrcPhrase)
- sourceDir.eachDirRecurse { dir ->
- generateInfoFiles(dir, mainSrcPhrase)
- }
- if (file(testSourceDir).exists()) {
- generateInfoFiles(testSourceDir, mainTestSrcPhrase)
- testSourceDir.eachDirRecurse { dir ->
- generateInfoFiles(dir, mainTestSrcPhrase)
- }
- }
- if (file(androidTestSourceDir).exists()) {
- generateInfoFiles(androidTestSourceDir, mainAndroidTestSrcPhrase)
- androidTestSourceDir.eachDirRecurse { dir ->
- generateInfoFiles(dir, mainAndroidTestSrcPhrase)
- }
- }
- println "[SUCCESS] NonNull generator: package-info.java files checked"
-}
-
-private void generateInfoFiles(File dir, String mainSrcPhrase) {
- def infoFileContentHeader = getFileContentHeader()
- def infoFileContentFooter = getFileContentFooter()
- def infoFilePath = dir.getAbsolutePath() + File.separatorChar + "package-info.java"
-
- //file(infoFilePath).delete(); //do not use in production code
- if (!file(infoFilePath).exists()) {
- def infoFileContentPackage = getFileContentPackage(dir.getAbsolutePath(), mainSrcPhrase)
- new File(infoFilePath).write(infoFileContentHeader +
- infoFileContentPackage + infoFileContentFooter)
- println "[dir] " + infoFilePath + " created"
- }
-}
-
-static def getFileContentPackage(String path, String mainSrcPhrase) {
- def mainSrcPhraseIndex = path.indexOf(mainSrcPhrase)
- def output = path.substring(mainSrcPhraseIndex)
-
- // Win hotfix
- if (System.properties['os.name'].toLowerCase().contains('windows')) {
- output = output.replace("\\", "/")
- mainSrcPhrase = mainSrcPhrase.replace("\\", "/")
- }
-
- return "package " + output.replaceAll(mainSrcPhrase, "").replaceAll(
- "/", ".") + ";\n"
-}
-
-static def getFileContentHeader() {
- return "/**\n" +
- " * Make all method parameters @NonNull by default.\n" +
- " */\n" +
- "@NonNullForAll\n"
-}
-
-static def getFileContentFooter() {
- return "\n" +
- "import com.wireguard.util.NonNullForAll;\n"
-}