Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
G00fY2 committed Jun 5, 2020
2 parents e0a14cc + 509362c commit 321a7ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "eu.nanogiants"
version = "2.0.0"
version = "2.0.1"

repositories {
google()
Expand Down
27 changes: 14 additions & 13 deletions src/main/kotlin/eu/nanogiants/gradle/VersioningPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import com.android.build.gradle.internal.dsl.DefaultConfig
import eu.nanogiants.gradle.ext.listContains
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.UnknownDomainObjectException
import org.gradle.api.plugins.BasePluginConvention
import org.gradle.api.tasks.Copy
import java.io.File
import java.util.Locale

Expand All @@ -29,12 +29,10 @@ class VersioningPlugin : Plugin<Project> {
try {
appExtension = project.extensions.getByType(AppExtension::class.java)
} catch (e: UnknownDomainObjectException) {
error("Project '${project.name}' is not an Android module. Can't access 'android' extension.")
throw GradleException("Project '${project.name}' is not an Android module. Can't access 'android' extension.")
}

val extension = project.extensions.create("versioning", VersioningPluginExtension::class.java)
val artifactBaseName =
project.convention.findPlugin(BasePluginConvention::class.java)?.archivesBaseName ?: project.name

project.tasks.register("printVersions") {
it.group = "Versioning"
Expand All @@ -51,31 +49,34 @@ class VersioningPlugin : Plugin<Project> {

appExtension.applicationVariants.all { variant ->
if (variant.name == variantName && !extension.excludeBuildTypes.listContains(variant.buildType.name)) {
val artifactBaseName = project.convention.findPlugin(BasePluginConvention::class.java)?.archivesBaseName
?: project.name
val bundleName = "$artifactBaseName-${variant.baseName}.aab"
val bundleOutputPath = "${project.buildDir.absolutePath}/outputs/bundle/$variantName/"
val newOutputName = getOutputName(artifactBaseName, variant, appExtension.defaultConfig, "aab")
println(newOutputName)

val moveAabTask =
project.tasks.register("rename${variant.name.capitalize(Locale.ROOT)}Aab", Copy::class.java) {
it.from(bundleOutputPath)
it.into(bundleOutputPath)
it.rename(bundleName, newOutputName)
val renameAabTask =
project.tasks.register("versioningPluginRename${variant.name.capitalize(Locale.ROOT)}Aab") {
it.doLast {
if (File(bundleOutputPath + newOutputName).exists()) {
project.delete(bundleOutputPath + bundleName)
println("Moved $bundleName to $newOutputName")
val success = File(bundleOutputPath + bundleName).renameTo(File(bundleOutputPath + newOutputName))
if (success) {
println("Renamed $bundleName to $newOutputName")
} else {
project.logger.error("Renaming $bundleName to $newOutputName failed.")
}
}
}
task.finalizedBy(moveAabTask)
task.finalizedBy(renameAabTask)
}
}
} else if (task.name.matches(assembleRegex)) {
val variantName = task.name.substringAfter("assemble").decapitalize(Locale.ROOT)

appExtension.applicationVariants.all { variant ->
if (variant.name == variantName && !extension.excludeBuildTypes.listContains(variant.buildType.name)) {
val artifactBaseName = project.convention.findPlugin(BasePluginConvention::class.java)?.archivesBaseName
?: project.name
val newOutputName = getOutputName(artifactBaseName, variant, appExtension.defaultConfig, "apk")
println(newOutputName)
variant.outputs.all {
Expand Down

0 comments on commit 321a7ed

Please sign in to comment.