Enable nonnull generation for tunnel module

Also cleanup nonnull.gradle while we're at it

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-03-09 19:03:06 +05:30
parent adc613d801
commit 6bc3e257f8
3 changed files with 12 additions and 12 deletions

View File

@ -1,6 +1,6 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply from: 'nonnull.gradle' apply from: rootProject.file('nonnull.gradle')
// Create a variable called keystorePropertiesFile, and initialize it to your // Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder. // keystore.properties file, in the rootProject folder.

View File

@ -26,18 +26,18 @@ task generateNonNullJavaFiles(dependsOn: "assembleDebug", type: Copy) {
"androidTest" + File.separatorChar + "java" + File.separatorChar + "androidTest" + File.separatorChar + "java" + File.separatorChar +
basePackage ) basePackage )
generateInfoFiles(sourceDir, mainSrcPhrase); generateInfoFiles(sourceDir, mainSrcPhrase)
sourceDir.eachDirRecurse { dir -> sourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainSrcPhrase) generateInfoFiles(dir, mainSrcPhrase)
} }
if (file(testSourceDir).exists()) { if (file(testSourceDir).exists()) {
generateInfoFiles(testSourceDir, mainTestSrcPhrase); generateInfoFiles(testSourceDir, mainTestSrcPhrase)
testSourceDir.eachDirRecurse { dir -> testSourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainTestSrcPhrase) generateInfoFiles(dir, mainTestSrcPhrase)
} }
} }
if (file(androidTestSourceDir).exists()) { if (file(androidTestSourceDir).exists()) {
generateInfoFiles(androidTestSourceDir, mainAndroidTestSrcPhrase); generateInfoFiles(androidTestSourceDir, mainAndroidTestSrcPhrase)
androidTestSourceDir.eachDirRecurse { dir -> androidTestSourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainAndroidTestSrcPhrase) generateInfoFiles(dir, mainAndroidTestSrcPhrase)
} }
@ -46,20 +46,20 @@ task generateNonNullJavaFiles(dependsOn: "assembleDebug", type: Copy) {
} }
private void generateInfoFiles(File dir, String mainSrcPhrase) { private void generateInfoFiles(File dir, String mainSrcPhrase) {
def infoFileContentHeader = getFileContentHeader(); def infoFileContentHeader = getFileContentHeader()
def infoFileContentFooter = getFileContentFooter(); def infoFileContentFooter = getFileContentFooter()
def infoFilePath = dir.getAbsolutePath() + File.separatorChar + "package-info.java" def infoFilePath = dir.getAbsolutePath() + File.separatorChar + "package-info.java"
//file(infoFilePath).delete(); //do not use in production code //file(infoFilePath).delete(); //do not use in production code
if (!file(infoFilePath).exists()) { if (!file(infoFilePath).exists()) {
def infoFileContentPackage = getFileContentPackage(dir.getAbsolutePath(), mainSrcPhrase); def infoFileContentPackage = getFileContentPackage(dir.getAbsolutePath(), mainSrcPhrase)
new File(infoFilePath).write(infoFileContentHeader + new File(infoFilePath).write(infoFileContentHeader +
infoFileContentPackage + infoFileContentFooter) infoFileContentPackage + infoFileContentFooter)
println "[dir] " + infoFilePath + " created"; println "[dir] " + infoFilePath + " created"
} }
} }
def getFileContentPackage(String path, String mainSrcPhrase) { static def getFileContentPackage(String path, String mainSrcPhrase) {
def mainSrcPhraseIndex = path.indexOf(mainSrcPhrase) def mainSrcPhraseIndex = path.indexOf(mainSrcPhrase)
def output = path.substring(mainSrcPhraseIndex) def output = path.substring(mainSrcPhraseIndex)
@ -73,15 +73,14 @@ def getFileContentPackage(String path, String mainSrcPhrase) {
"/", ".") + ";\n" "/", ".") + ";\n"
} }
def getFileContentHeader() { static def getFileContentHeader() {
return "/**\n" + return "/**\n" +
" * Make all method parameters @NonNull by default.\n" + " * Make all method parameters @NonNull by default.\n" +
" */\n" + " */\n" +
"@NonNullForAll\n" "@NonNullForAll\n"
} }
def getFileContentFooter() { static def getFileContentFooter() {
return "\n" + return "\n" +
"import com.wireguard.util.NonNullForAll;\n" "import com.wireguard.util.NonNullForAll;\n"
} }

View File

@ -1,4 +1,5 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply from: rootProject.file('nonnull.gradle')
android { android {
buildToolsVersion '29.0.3' buildToolsVersion '29.0.3'