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: 'kotlin-android'
apply from: 'nonnull.gradle'
apply from: rootProject.file('nonnull.gradle')
// Create a variable called keystorePropertiesFile, and initialize it to your
// 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 +
basePackage )
generateInfoFiles(sourceDir, mainSrcPhrase);
generateInfoFiles(sourceDir, mainSrcPhrase)
sourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainSrcPhrase)
}
if (file(testSourceDir).exists()) {
generateInfoFiles(testSourceDir, mainTestSrcPhrase);
generateInfoFiles(testSourceDir, mainTestSrcPhrase)
testSourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainTestSrcPhrase)
}
}
if (file(androidTestSourceDir).exists()) {
generateInfoFiles(androidTestSourceDir, mainAndroidTestSrcPhrase);
generateInfoFiles(androidTestSourceDir, mainAndroidTestSrcPhrase)
androidTestSourceDir.eachDirRecurse { dir ->
generateInfoFiles(dir, mainAndroidTestSrcPhrase)
}
@ -46,20 +46,20 @@ task generateNonNullJavaFiles(dependsOn: "assembleDebug", type: Copy) {
}
private void generateInfoFiles(File dir, String mainSrcPhrase) {
def infoFileContentHeader = getFileContentHeader();
def infoFileContentFooter = getFileContentFooter();
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);
def infoFileContentPackage = getFileContentPackage(dir.getAbsolutePath(), mainSrcPhrase)
new File(infoFilePath).write(infoFileContentHeader +
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 output = path.substring(mainSrcPhraseIndex)
@ -73,15 +73,14 @@ def getFileContentPackage(String path, String mainSrcPhrase) {
"/", ".") + ";\n"
}
def getFileContentHeader() {
static def getFileContentHeader() {
return "/**\n" +
" * Make all method parameters @NonNull by default.\n" +
" */\n" +
"@NonNullForAll\n"
}
def getFileContentFooter() {
static def getFileContentFooter() {
return "\n" +
"import com.wireguard.util.NonNullForAll;\n"
}

View File

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