Skip to content

Commit

Permalink
Merge pull request #5 from mateuszkwiecinski/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored Nov 10, 2023
2 parents 87a3f13 + ca39410 commit 3e0b687
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.squareup.kotlinpoet.MemberName
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.okio.decodeFromBufferedSource
import okio.buffer
import okio.source
import org.gradle.api.DefaultTask
Expand All @@ -17,7 +19,7 @@ import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import se.premex.gross.core.LicenseParser
import se.premex.gross.core.Artifact

@CacheableTask
abstract class CodeGenerationTask : DefaultTask() {
Expand All @@ -42,7 +44,7 @@ abstract class CodeGenerationTask : DefaultTask() {
.addType(licenseeTypesGenerator.artifactTypeSpec)
.build().writeTo(outputDirectory.asFile.get())

val artifacts = LicenseParser().decode(inputFile.asFile.get().source().buffer())
val artifacts = Json.decodeFromBufferedSource<List<Artifact>>(inputFile.asFile.get().source().buffer())

val artifactCodeGenerator = ArtifactCodeGenerator(
packageName = packageName,
Expand Down
46 changes: 22 additions & 24 deletions licensee-for-android/src/main/kotlin/se/premex/gross/GrossPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package se.premex.gross

import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.reporting.ReportingExtension
import java.util.Locale

public class GrossPlugin : Plugin<Project> {
override fun apply(project: Project) {
Expand All @@ -16,57 +15,56 @@ public class GrossPlugin : Plugin<Project> {
val reportingExtension: ReportingExtension =
project.extensions.getByType(ReportingExtension::class.java)

listOf(
"com.android.application",
"com.android.library",
"com.android.dynamic-feature",
)
.forEach { pluginId ->
project.pluginManager.withPlugin(pluginId) {
configureAndroidPlugin(project, extension, reportingExtension)
project.pluginManager.withPlugin("app.cash.licensee") {
listOf(
"com.android.application",
"com.android.library",
"com.android.dynamic-feature",
)
.forEach { pluginId ->
project.pluginManager.withPlugin(pluginId) {
configureAndroidPlugin(project, extension, reportingExtension)
}
}
}
}
}

private fun configureAndroidPlugin(project: Project, extension: GrossExtension, reportingExtension: ReportingExtension) {
val androidComponentsExtension =
project.extensions.getByName("androidComponents") as ApplicationAndroidComponentsExtension
project.extensions.getByName("androidComponents") as AndroidComponentsExtension<*, *, *>

androidComponentsExtension.onVariants { variant ->
val capitalizedVariantName = variant.name.replaceFirstChar {
if (it.isLowerCase()) {
it.titlecase(Locale.getDefault())
} else {
it.toString()
}
}
val target = variant.name
val targetCapitalized = target.replaceFirstChar(Char::titlecase)
val licenseeTaskName = "licenseeAndroid$targetCapitalized"

val artifactsFile = reportingExtension.file("licensee/${variant.name}/artifacts.json")
val artifactsFile = reportingExtension.file("licensee/android$targetCapitalized/artifacts.json")
if (extension.enableAndroidAssetGeneration.get()) {
val copyArtifactsTask =
project.tasks.register("copy${capitalizedVariantName}LicenseeReportToAssets", AssetCopyTask::class.java) {
project.tasks.register("copy${targetCapitalized}LicenseeReportToAssets", AssetCopyTask::class.java) {
it.inputFile.set(artifactsFile)
it.targetFileName.set(extension.androidAssetFileName.get())
}
variant.sources.assets!!.addGeneratedSourceDirectory(
copyArtifactsTask,
AssetCopyTask::outputDirectory,
)
copyArtifactsTask.configure { it.dependsOn("licensee$capitalizedVariantName") }
copyArtifactsTask.configure { it.dependsOn(licenseeTaskName) }
}

if (extension.enableKotlinCodeGeneration.get()) {
val codeGenerationTask =
project.tasks.register("${capitalizedVariantName}LicenseeReportToKotlin", CodeGenerationTask::class.java) {
project.tasks.register("${target}LicenseeReportToKotlin", CodeGenerationTask::class.java) {
it.inputFile.set(artifactsFile)
}

// Do NOT use `.kotlin` here: https://issuetracker.google.com/issues/268248348
variant.sources.java!!.addGeneratedSourceDirectory(
codeGenerationTask,
CodeGenerationTask::outputDirectory,
)

codeGenerationTask.configure { it.dependsOn("licensee$capitalizedVariantName") }
codeGenerationTask.configure { it.dependsOn(licenseeTaskName) }
}
}
}
Expand Down

This file was deleted.

52 changes: 13 additions & 39 deletions sample/app/build.gradle.kts → sample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
plugins {
alias(libs.plugins.com.android.application)
alias(libs.plugins.org.jetbrains.kotlin.android)
alias(libs.plugins.starter.application.android)
alias(libs.plugins.app.cash.licensee)
id("se.premex.gross")
id("io.github.usefulness.licensee-for-android")
}

licensee {
Expand All @@ -14,38 +13,25 @@ gross {
enableAndroidAssetGeneration.set(true)
}
android {
namespace = "se.premex.gross"
compileSdk = 33
namespace "io.githhub.usefulness.licensee.android.app"

defaultConfig {
applicationId = "se.premex.gross"
minSdk = 24
targetSdk = 33
versionCode = 1
versionName = "1.0"
applicationId = "io.githhub.usefulness.licensee.android.app"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
named("release") {
minifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
matchingFallbacks += ["debug"]
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
lint {
checkReleaseBuilds = false
}

buildFeatures {
compose = true
}
Expand All @@ -59,15 +45,7 @@ android {
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.AZUL)
}
}

dependencies {

implementation(libs.core.ktx)
implementation(libs.lifecycle.runtime.ktx)
implementation(libs.activity.compose)
Expand All @@ -77,11 +55,7 @@ dependencies {
implementation(libs.ui.tooling.preview)
implementation(libs.material3)

// In theory we should be able to refer to "se.premex.gross:ui-oss" here and set a mapping up
// in the includeBuild like this
// dependencySubstitution { substitute(module("se.premex.gross:ui-oss")).using(project(":oss")) }
// Unfortunately this does not work - maybe same issue as https://youtrack.jetbrains.com/issue/KTIJ-13435
implementation("se.premex.gross:ui:1.0")
implementation(project(":ui"))

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
Expand All @@ -90,4 +64,4 @@ dependencies {
androidTestImplementation(libs.ui.test.junit4)
debugImplementation(libs.ui.tooling)
debugImplementation(libs.ui.test.manifest)
}
}
10 changes: 10 additions & 0 deletions sample/app/config/baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>FunctionNaming:OssArtifactView.kt$@Composable fun AssetsOssView()</ID>
<ID>FunctionNaming:OssKotlinCodeView.kt$@Composable fun ProgrammaticOssView()</ID>
<ID>FunctionNaming:Theme.kt$@Composable fun GrossTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, content: @Composable () -&gt; Unit, )</ID>
<ID>WildcardImport:ExampleUnitTest.kt$import org.junit.Assert.*</ID>
</CurrentIssues>
</SmellBaseline>
21 changes: 0 additions & 21 deletions sample/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

This file was deleted.

39 changes: 0 additions & 39 deletions sample/app/src/main/java/se/premex/gross/OssKotlinCodeView.kt

This file was deleted.

Loading

0 comments on commit 3e0b687

Please sign in to comment.