Skip to content

Commit

Permalink
Merge branch 'main' into eskatos/2024-11
Browse files Browse the repository at this point in the history
  • Loading branch information
eskatos committed Nov 14, 2024
2 parents 7b196aa + b97807c commit 325d7f5
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ jobs:
# Build job
build:
runs-on: ubuntu-latest

permissions:
contents: write
packages: read
pull-requests: write

env:
PR_PATH: pull/${{github.event.number}}
DOMAIN: gradle.github.io
PREVIEW_REPO: community-site-preview

steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -25,3 +36,27 @@ jobs:

- name: Build the docs
run: mkdocs build

- name: Deploy to PR preview
uses: peaceiris/actions-gh-pages@v4
if: github.ref != 'refs/heads/main'
with:
deploy_key: ${{ secrets.PREVIEW_DEPLOYMENT_KEY }}
external_repository: gradle/${{ env.PREVIEW_REPO }}
publish_dir: ./_site
destination_dir: ${{ env.PR_PATH }}

- name: Update comment
uses: hasura/comment-progress@v2.2.0
if: github.ref != 'refs/heads/main'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: >
A preview of ${{ github.event.after }} is uploaded and can be seen here:
✨ https://${{ env.DOMAIN }}/${{ env.PREVIEW_REPO }}/${{ env.PR_PATH}}/ ✨
Changes may take a few minutes to propagate.
37 changes: 37 additions & 0 deletions .github/workflows/preview-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Delete preview on PR close
on:
pull_request:
types: [closed]

jobs:
delete_preview:
runs-on: ubuntu-20.04
env:
PR_PATH: pull/${{github.event.number}}
DOMAIN: gradle.github.io
PREVIEW_REPO: community-site-preview

permissions:
pull-requests: write

steps:
- name: make empty dir
run: mkdir public

- name: delete folder
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.PREVIEW_DEPLOYMENT_KEY }}
external_repository: gradle/${{ env.PREVIEW_REPO }}
publish_dir: ./public
destination_dir: ${{ env.PR_PATH }}

- name: Comment on PR
uses: hasura/comment-progress@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: >
🪓 PR closed, deleted preview at https://github.com/${{ env.PREVIEW_REPO }}/tree/gh-pages/${{ env.PR_PATH }}/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.gradle.api.experimental.android

class AndroidApplicationAgpPreview extends AbstractAndroidBuildInitSpec {
@Override
protected String getProjectSpecType() {
return "android-application-agp-preview"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public void apply(Settings settings) {
getBuildInitSpecRegistry().register(StaticBuildGenerator.class, List.of(
new StaticBuildSpec("android-application", "Android application with Android libraries"),
new StaticBuildSpec("android-application-basic-activity", "Android Application with a basic Activity"),
new StaticBuildSpec("android-application-empty-activity", "Android Application with an empty Activity")
new StaticBuildSpec("android-application-empty-activity", "Android Application with an empty Activity"),
new StaticBuildSpec("android-application-agp-preview", "Android Application using Official AGP Software Types Preview")
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# declarative-samples-android-app
A sample Android application written in the Declarative Gradle DSL, using the official Android Software Types Preview `androidApplication` and `androidLibrary` defined in the `com.android.ecosystem` ecosystem plugin.

## Building and Running

This sample shows the definition of a multiproject Android application implemented using Kotlin source code.

To build the project without running, use:

```shell
./gradlew build
```

To run the application, first install it on a connected Android device using:

```shell
./gradlew :app:installDebug
```

In IntelliJ IDEA or Android Studio you can use the `app` run configuration to launch the app in an emulator to see a hello world message.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
androidApp {
namespace = "org.example.app"
dependenciesDcl {
implementation("org.apache.commons:commons-text:1.11.0")
implementation(project(":utilities"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="@string/app_name">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.example.app

import org.apache.commons.text.WordUtils

import org.example.list.LinkedList
import org.example.utilities.SplitUtils
import org.example.utilities.StringUtils

import android.widget.TextView
import android.os.Bundle
import android.app.Activity

class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val textView = findViewById(R.id.textView) as TextView
textView.text = buildMessage()
}

private fun buildMessage(): String {
val tokens: LinkedList
tokens = SplitUtils.split(MessageUtils.message())
val result: String = StringUtils.join(tokens)
return WordUtils.capitalize(result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.example.app

internal object MessageUtils {
fun message() = "Hello World!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Sample Declarative Gradle Android App</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.app

import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.assertEquals

class MessageUtilsTest {
@Test
fun testGetMessage() {
assertEquals("Hello World!", MessageUtils.message())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.configuration-cache=true
kotlin.code.style=official
android.experimental.declarative=true
android.useAndroidX=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
androidLibrary {
namespace = "org.gradle.experimental.android.list"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.example.list

class LinkedList {
private var head: Node? = null

fun add(element: String?) {
val newNode = Node(element)

val it = tail(head)
if (it == null) {
head = newNode
} else {
it.next = newNode
}
}

fun remove(element: String): Boolean {
var result = false
var previousIt: Node? = null
var it: Node?
it = head
while (!result && it != null) {
if (0 == element.compareTo(it.data!!)) {
result = true
unlink(previousIt, it)
break
}
previousIt = it
it = it.next
}

return result
}

private fun unlink(previousIt: Node?, currentIt: Node) {
if (currentIt === head) {
head = currentIt.next
} else {
previousIt!!.next = currentIt.next
}
}

fun size(): Int {
var size = 0

var it = head
while (it != null) {
++size
it = it.next
}

return size
}

fun get(index: Int): String? {
var currIdx = index
var it = head
while (currIdx > 0 && it != null) {
it = it.next
currIdx--
}

if (it == null) {
throw java.lang.IndexOutOfBoundsException("Index is out of range")
}

return it.data
}

private class Node(val data: String?) {
var next: Node? = null
}

companion object {
private fun tail(head: Node?): Node? {
var it: Node?

it = head
while (it?.next != null) {
it = it.next
}

return it
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
pluginManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("https://androidx.dev/studio/builds/12648882/artifacts/artifacts/repository")
}
}
}

plugins {
id("com.android.ecosystem").version("8.9.0-dev")
}

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("https://androidx.dev/studio/builds/12648882/artifacts/artifacts/repository")
}
}
}

rootProject.name = "example-android-app"

include("app")
include("list")
include("utilities")

defaults {
androidApp {
compileSdk = 34
compileOptions {
sourceCompatibility = VERSION_17
targetCompatibility = VERSION_17
}
defaultConfig {
minSdk = 30
versionCode = 1
versionName = "0.1"
applicationId = "org.gradle.experimental.android.app"
}
dependenciesDcl {
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testImplementation("org.junit.platform:junit-platform-launcher")
androidTestImplementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21")
}
}

androidLibrary {
compileSdk = 34
compileOptions {
sourceCompatibility = VERSION_17
targetCompatibility = VERSION_17
}
defaultConfig {
minSdk = 30
}
dependenciesDcl {
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testImplementation("org.junit.platform:junit-platform-launcher")
androidTestImplementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
androidLibrary {
namespace = "org.gradle.experimental.android.utilities"
dependenciesDcl {
api(project(":list"))
}
}
Loading

0 comments on commit 325d7f5

Please sign in to comment.