-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8022 from wmontwe/change-k9mail-signing-config
Change K9-Mail signing to new setup
- Loading branch information
Showing
5 changed files
with
105 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import com.android.build.api.dsl.ApkSigningConfig | ||
import java.io.FileInputStream | ||
import java.util.Properties | ||
import org.gradle.api.NamedDomainObjectContainer | ||
import org.gradle.api.Project | ||
|
||
private const val SIGNING_FOLDER = ".signing" | ||
private const val SIGNING_FILE_ENDING = ".signing.properties" | ||
|
||
private const val PROPERTY_STORE_FILE = "storeFile" | ||
private const val PROPERTY_STORE_PASSWORD = "storePassword" | ||
private const val PROPERTY_KEY_ALIAS = "keyAlias" | ||
private const val PROPERTY_KEY_PASSWORD = "keyPassword" | ||
|
||
/** | ||
* Creates an [ApkSigningConfig] for the given signing type. | ||
* | ||
* The signing properties are read from a file in the `.signing` folder in the project root directory. | ||
* File names are expected to be in the format `$app.$type.signing.properties`. | ||
* | ||
* The file should contain the following properties: | ||
* - `$app.$type.storeFile` | ||
* - `$app.$type.storePassword` | ||
* - `$app.$type.keyAlias` | ||
* - `$app.$type.keyPassword` | ||
* | ||
* @param project the project to create the signing config for | ||
* @param signingType the signing type to create the signing config for | ||
*/ | ||
fun NamedDomainObjectContainer<out ApkSigningConfig>.createSigningConfig(project: Project, signingType: SigningType) { | ||
val properties = project.readSigningProperties(signingType) | ||
|
||
if (properties.hasSigningConfig(signingType)) { | ||
create(signingType.type) { | ||
storeFile = project.file(properties.getSigningProperty(signingType, PROPERTY_STORE_FILE)) | ||
storePassword = properties.getSigningProperty(signingType, PROPERTY_STORE_PASSWORD) | ||
keyAlias = properties.getSigningProperty(signingType, PROPERTY_KEY_ALIAS) | ||
keyPassword = properties.getSigningProperty(signingType, PROPERTY_KEY_PASSWORD) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns the [ApkSigningConfig] for the given signing type. | ||
* | ||
* @param signingType the signing type to get the signing config for | ||
*/ | ||
fun NamedDomainObjectContainer<out ApkSigningConfig>.getByType(signingType: SigningType): ApkSigningConfig? { | ||
return findByName(signingType.type) | ||
} | ||
|
||
private fun Project.readSigningProperties(signingType: SigningType) = Properties().apply { | ||
val signingPropertiesFile = rootProject.file("$SIGNING_FOLDER/${signingType.id}$SIGNING_FILE_ENDING") | ||
if (signingPropertiesFile.exists()) { | ||
FileInputStream(signingPropertiesFile).use { inputStream -> | ||
load(inputStream) | ||
} | ||
} else { | ||
println("Signing properties file not found: $signingPropertiesFile") | ||
} | ||
} | ||
|
||
private fun Properties.hasSigningConfig(signingType: SigningType): Boolean { | ||
return isNotEmpty() && | ||
containsKey(signingType, PROPERTY_STORE_FILE) && | ||
containsKey(signingType, PROPERTY_STORE_PASSWORD) && | ||
containsKey(signingType, PROPERTY_KEY_ALIAS) && | ||
containsKey(signingType, PROPERTY_KEY_PASSWORD) | ||
} | ||
|
||
private fun Properties.containsKey(signingType: SigningType, key: String): Boolean { | ||
return containsKey("${signingType.id}.$key") | ||
} | ||
|
||
private fun Properties.getSigningProperty(signingType: SigningType, key: String): String { | ||
return getProperty("${signingType.id}.$key") | ||
?: throw IllegalArgumentException("Missing property: ${signingType.type}.$key") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum class SigningType( | ||
val app: String, | ||
val type: String, | ||
val id: String = "$app.$type", | ||
) { | ||
K9_RELEASE(app = "k9", type = "release"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters