Skip to content

Commit

Permalink
test: cleanup Android tests and validate CC support for AGP.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Dec 12, 2023
1 parent 3aa33a9 commit 3735805
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.autonomousapps.kit.SourceType
import com.autonomousapps.kit.android.AndroidColorRes
import com.autonomousapps.kit.android.AndroidLayout
import com.autonomousapps.kit.android.AndroidStyleRes
import com.autonomousapps.kit.gradle.BuildscriptBlock
import com.autonomousapps.kit.gradle.Dependency
import com.autonomousapps.kit.gradle.GradleProperties
import com.autonomousapps.kit.gradle.Plugin
Expand Down Expand Up @@ -35,28 +34,21 @@ abstract class AbstractVariantProject extends AbstractAndroidProject {
}

private GradleProject build() {
def builder = newGradleProjectBuilder()
builder.withRootProject { root ->
root.gradleProperties = projectGradleProperties
root.withBuildScript { bs ->
bs.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
return newAndroidGradleProjectBuilder(agpVersion)
.withRootProject { root ->
root.gradleProperties = projectGradleProperties + GradleProperties.enableConfigurationCache()
}
}
builder.withAndroidSubproject('app') { a ->
a.sources = sources
a.layouts = layouts
a.styles = AndroidStyleRes.DEFAULT
a.colors = AndroidColorRes.DEFAULT
a.withBuildScript { bs ->
bs.plugins = plugins
bs.android = defaultAndroidAppBlock()
bs.dependencies = dependencies
}
}

def project = builder.build()
project.writer().write()
return project
.withAndroidSubproject('app') { a ->
a.sources = sources
a.layouts = layouts
a.styles = AndroidStyleRes.DEFAULT
a.colors = AndroidColorRes.DEFAULT
a.withBuildScript { bs ->
bs.plugins = plugins
bs.android = defaultAndroidAppBlock()
bs.dependencies = dependencies
}
}.write()
}

protected final List<Plugin> plugins = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ final class AndroidKotlinInlineProject extends AbstractAndroidProject {
}

private GradleProject build() {
return newGradleProjectBuilder()
.withRootProject { root ->
root.gradleProperties = GradleProperties.minimalAndroidProperties()
root.withBuildScript { bs ->
bs.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
}
}
return newAndroidGradleProjectBuilder(agpVersion)
.withAndroidSubproject('lib') { l ->
l.manifest = AndroidManifest.defaultLib('com.example.lib')
l.withBuildScript { bs ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ final class AndroidThemeProject extends AbstractAndroidProject {
}

private GradleProject build() {
def builder = newGradleProjectBuilder()
builder.withRootProject { root ->
root.gradleProperties = GradleProperties.minimalAndroidProperties()
root.withBuildScript { bs ->
bs.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
return newAndroidGradleProjectBuilder(agpVersion)
.withRootProject { root ->
root.gradleProperties = GradleProperties.minimalAndroidProperties()
root.withBuildScript { bs ->
bs.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
}
}
}
builder.withAndroidSubproject('consumer') { consumer ->
consumer.withBuildScript { bs ->
bs.plugins = androidAppPlugin
bs.android = defaultAndroidAppBlock(false, 'com.consumer')
bs.dependencies = [
project('implementation', ':producer'),
]
}
consumer.styles = AndroidStyleRes.EMPTY
consumer.manifest = AndroidManifest.of(
'''\
.withAndroidSubproject('consumer') { consumer ->
consumer.withBuildScript { bs ->
bs.plugins = androidAppPlugin
bs.android = defaultAndroidAppBlock(false, 'com.consumer')
bs.dependencies = [
project('implementation', ':producer'),
]
}
consumer.styles = AndroidStyleRes.EMPTY
consumer.manifest = AndroidManifest.of(
'''\
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
Expand All @@ -50,31 +50,27 @@ final class AndroidThemeProject extends AbstractAndroidProject {
<application android:theme="@style/AppTheme"/>
</manifest>'''.stripIndent()
)
}
builder.withAndroidSubproject('producer') { producer ->
producer.withBuildScript { bs ->
bs.plugins = androidLibPlugin
bs.android = defaultAndroidLibBlock(false, 'com.example.producer')
bs.dependencies = [
appcompat('implementation'),
]
)
}
producer.manifest = AndroidManifest.defaultLib('com.example.producer')
producer.styles = AndroidStyleRes.of(
'''\
.withAndroidSubproject('producer') { producer ->
producer.withBuildScript { bs ->
bs.plugins = androidLibPlugin
bs.android = defaultAndroidLibBlock(false, 'com.example.producer')
bs.dependencies = [
appcompat('implementation'),
]
}
producer.manifest = AndroidManifest.defaultLib('com.example.producer')
producer.styles = AndroidStyleRes.of(
'''\
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#0568ae</item>
</style>
</resources>'''.stripIndent()
)
}

def project = builder.build()
project.writer().write()
return project
)
}.write()
}

Set<ProjectAdvice> actualBuildHealth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.autonomousapps.android.projects

import com.autonomousapps.kit.GradleProject
import com.autonomousapps.kit.Source
import com.autonomousapps.kit.gradle.BuildscriptBlock
import com.autonomousapps.kit.gradle.GradleProperties
import com.autonomousapps.kit.gradle.Kotlin
import com.autonomousapps.kit.gradle.dependencies.Plugins
import com.autonomousapps.model.ProjectAdvice
Expand All @@ -25,13 +23,7 @@ final class AndroidToJvmInlineProject extends AbstractAndroidProject {
}

private GradleProject build() {
return newGradleProjectBuilder()
.withRootProject { root ->
root.gradleProperties = GradleProperties.minimalAndroidProperties()
root.withBuildScript { bs ->
bs.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
}
}
return newAndroidGradleProjectBuilder(agpVersion)
.withAndroidLibProject('consumer', 'com.example.consumer') { l ->
l.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib, Plugins.kotlinAndroid]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.autonomousapps.android.projects

import com.autonomousapps.kit.GradleProject
import com.autonomousapps.kit.android.AndroidManifest
import com.autonomousapps.kit.gradle.BuildscriptBlock
import com.autonomousapps.kit.gradle.Dependency
import com.autonomousapps.kit.gradle.GradleProperties
import com.autonomousapps.kit.gradle.dependencies.Plugins
import com.autonomousapps.model.ProjectAdvice

Expand All @@ -30,29 +28,20 @@ final class AttrResProject extends AbstractAndroidProject {
}

private GradleProject build() {
def builder = newGradleProjectBuilder()
builder.withRootProject { root ->
root.gradleProperties = GradleProperties.minimalAndroidProperties()
root.withBuildScript { bs ->
bs.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
}
// root.withFile('local.properties', """\
// sdk.dir=/Users/trobalik/Library/Android/Sdk
// """.stripIndent())
}
builder.withAndroidSubproject('consumer') { consumer ->
consumer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.consumer')
bs.dependencies = [
project('implementation', ':producer'),
ANDROIDX_ANNOTATION,
SWIPE_REFRESH_LAYOUT,
APPCOMPAT,
]
}
consumer.manifest = AndroidManifest.defaultLib('com.example.consumer')
consumer.withFile('src/main/res/drawable/ic_pin.xml', """\
return newAndroidGradleProjectBuilder(agpVersion)
.withAndroidSubproject('consumer') { consumer ->
consumer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.consumer')
bs.dependencies = [
project('implementation', ':producer'),
ANDROIDX_ANNOTATION,
SWIPE_REFRESH_LAYOUT,
APPCOMPAT,
]
}
consumer.manifest = AndroidManifest.defaultLib('com.example.consumer')
consumer.withFile('src/main/res/drawable/ic_pin.xml', """\
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
Expand All @@ -65,45 +54,41 @@ final class AttrResProject extends AbstractAndroidProject {
android:fillColor="?themeColor"
android:pathData="M0.000418269 15C0.0223146 17.9111 0.904212 20.846 2.71627 23.4108L12.9056 37.9142C13.9228 39.362 16.0781 39.3619 17.0952 37.9141L27.2873 23.4053C29.0977 20.8428 29.9786 17.9098 30.0002 15C30 6.71573 23.2843 0 15 0C6.71573 0 0 6.71573 0 15" />
</vector>""".stripIndent()
)
consumer.withFile('src/main/res/values/themes.xml', """\
)
consumer.withFile('src/main/res/values/themes.xml', """\
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Consumer.Sample" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- This usage of swipe-refresh-layout was not detected -->
<item name="swipeRefreshLayoutProgressSpinnerBackgroundColor">?android:attr/colorBackground</item>
</style>
</resources>""".stripIndent()
)
}
builder.withAndroidSubproject('producer') { producer ->
producer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.producer')
bs.dependencies = [
ANDROIDX_ANNOTATION,
APPCOMPAT,
]
)
}
producer.manifest = AndroidManifest.defaultLib('com.example.producer')
producer.withFile('src/main/res/values/resources.xml', """\
.withAndroidSubproject('producer') { producer ->
producer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.producer')
bs.dependencies = [
ANDROIDX_ANNOTATION,
APPCOMPAT,
]
}
producer.manifest = AndroidManifest.defaultLib('com.example.producer')
producer.withFile('src/main/res/values/resources.xml', """\
<resources>
<attr name="themeColor" format="color" />
</resources>""".stripIndent()
)
producer.withFile('src/main/res/values/themes.xml', """\
)
producer.withFile('src/main/res/values/themes.xml', """\
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Sample" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="themeColor">@android:color/holo_red_dark</item>
</style>
</resources>""".stripIndent()
)
}

def project = builder.build()
project.writer().write()
return project
)
}.write()
}

Set<ProjectAdvice> actualBuildHealth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.autonomousapps.android.projects

import com.autonomousapps.kit.GradleProject
import com.autonomousapps.kit.android.AndroidManifest
import com.autonomousapps.kit.gradle.BuildscriptBlock
import com.autonomousapps.kit.gradle.Dependency
import com.autonomousapps.kit.gradle.GradleProperties
import com.autonomousapps.kit.gradle.dependencies.Plugins
import com.autonomousapps.model.ProjectAdvice

Expand All @@ -27,24 +25,18 @@ final class AttrResWithNullProject extends AbstractAndroidProject {
}

private GradleProject build() {
def builder = newGradleProjectBuilder()
builder.withRootProject { root ->
root.gradleProperties = GradleProperties.minimalAndroidProperties()
root.withBuildScript { bs ->
bs.buildscript = BuildscriptBlock.defaultAndroidBuildscriptBlock(agpVersion)
}
}
builder.withAndroidSubproject('consumer') { consumer ->
consumer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.consumer')
bs.dependencies = [
Dependency.project('implementation', ':producer'),
ANDROIDX_ANNOTATION,
]
}
consumer.manifest = AndroidManifest.defaultLib('com.example.consumer')
consumer.withFile('src/main/res/drawable/ic_pin.xml', """\
return newAndroidGradleProjectBuilder(agpVersion)
.withAndroidSubproject('consumer') { consumer ->
consumer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.consumer')
bs.dependencies = [
Dependency.project('implementation', ':producer'),
ANDROIDX_ANNOTATION,
]
}
consumer.manifest = AndroidManifest.defaultLib('com.example.consumer')
consumer.withFile('src/main/res/drawable/ic_pin.xml', """\
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
Expand All @@ -59,36 +51,32 @@ final class AttrResWithNullProject extends AbstractAndroidProject {
android:fillColor="?themeColor"
android:pathData="M0.000418269 15C0.0223146 17.9111 0.904212 20.846 2.71627 23.4108L12.9056 37.9142C13.9228 39.362 16.0781 39.3619 17.0952 37.9141L27.2873 23.4053C29.0977 20.8428 29.9786 17.9098 30.0002 15C30 6.71573 23.2843 0 15 0C6.71573 0 0 6.71573 0 15" />
</vector>""".stripIndent()
)
}
builder.withAndroidSubproject('producer') { producer ->
producer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.producer')
bs.dependencies = [
ANDROIDX_ANNOTATION,
APPCOMPAT,
]
)
}
producer.manifest = AndroidManifest.defaultLib('com.example.producer')
producer.withFile('src/main/res/values/resources.xml', """\
.withAndroidSubproject('producer') { producer ->
producer.withBuildScript { bs ->
bs.plugins = [Plugins.androidLib]
bs.android = defaultAndroidLibBlock(false, 'com.example.producer')
bs.dependencies = [
ANDROIDX_ANNOTATION,
APPCOMPAT,
]
}
producer.manifest = AndroidManifest.defaultLib('com.example.producer')
producer.withFile('src/main/res/values/resources.xml', """\
<resources>
<attr name="themeColor" format="color" />
</resources>""".stripIndent()
)
producer.withFile('src/main/res/values/themes.xml', """\
)
producer.withFile('src/main/res/values/themes.xml', """\
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Sample" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="themeColor">@android:color/holo_red_dark</item>
</style>
</resources>""".stripIndent()
)
}

def project = builder.build()
project.writer().write()
return project
)
}.write()
}

Set<ProjectAdvice> actualBuildHealth() {
Expand Down
Loading

0 comments on commit 3735805

Please sign in to comment.