-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update project specs to use samples from GH
- Loading branch information
Showing
52 changed files
with
903 additions
and
54 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...ls/src/main/groovy/org/gradle/integtests/fixtures/AbstractProjectInitSpecification.groovy
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,63 @@ | ||
package org.gradle.integtests.fixtures | ||
|
||
import org.gradle.internal.nativeintegration.console.TestOverrideConsoleDetector | ||
import org.gradle.plugin.management.internal.autoapply.AutoAppliedPluginHandler | ||
import org.gradle.test.fixtures.AbstractSpecification | ||
import org.gradle.testkit.runner.GradleRunner | ||
|
||
/** | ||
* Base class for tests that generate, build, and validate (via run, or something else) included project init specifications. | ||
*/ | ||
abstract class AbstractProjectInitSpecification extends AbstractSpecification { | ||
private static final String DECLARATIVE_PROTOTYPE_VERSION = "0.1.11" | ||
|
||
protected File projectDir = file("new-project").tap { mkdirs() } | ||
|
||
abstract String getPluginId() | ||
|
||
// TODO: add project type method here, specify type of project to be generated (need to update Gradle wrapper to new nightly containing getType() first) | ||
|
||
def "can generate project from init project spec"() { | ||
when: | ||
runInitWithPluginAsInitProjectSpecSupplier() | ||
|
||
then: | ||
canBuildGeneratedProject() | ||
|
||
and: | ||
validateGeneratedProjectRuns() | ||
} | ||
|
||
protected void runInitWithPluginAsInitProjectSpecSupplier() { | ||
def args = ["init", | ||
"-D${AutoAppliedPluginHandler.INIT_PROJECT_SPEC_SUPPLIERS_PROP}=$pluginId:$DECLARATIVE_PROTOTYPE_VERSION", | ||
"-D${TestOverrideConsoleDetector.INTERACTIVE_TOGGLE}=true"] as String[] | ||
|
||
result = GradleRunner.create() | ||
.withProjectDir(projectDir) | ||
.withArguments(args) | ||
.withPluginClasspath() | ||
.withDebug(true) | ||
.forwardOutput() | ||
.build() | ||
} | ||
|
||
protected void canBuildGeneratedProject() { | ||
result = GradleRunner.create() | ||
.withProjectDir(projectDir) | ||
.withArguments("build") | ||
.withDebug(true) | ||
.forwardOutput() | ||
.build() | ||
} | ||
|
||
protected void validateGeneratedProjectRuns() { | ||
result = GradleRunner.create() | ||
.withProjectDir(projectDir) | ||
.withArguments(":app:run") | ||
.forwardOutput() | ||
.build() | ||
|
||
assert result.output.contains("Hello World!") | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
...gTest/groovy/org/gradle/api/experimental/android/AndroidApplicationInitProjectSpec.groovy
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,11 @@ | ||
package org.gradle.api.experimental.android | ||
|
||
import org.gradle.integtests.fixtures.AbstractProjectInitSpecification | ||
import org.gradle.testkit.runner.GradleRunner | ||
|
||
class AndroidApplicationInitProjectSpec extends AbstractProjectInitSpecification { | ||
@Override | ||
String getPluginId() { | ||
return "org.gradle.experimental.android-ecosystem" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...gin-android/src/main/java/org/gradle/api/experimental/buildinit/AndroidProjectSource.java
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,25 @@ | ||
package org.gradle.api.experimental.buildinit; | ||
|
||
import org.gradle.buildinit.projectspecs.InitProjectGenerator; | ||
import org.gradle.buildinit.projectspecs.InitProjectSource; | ||
import org.gradle.buildinit.projectspecs.InitProjectSpec; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A {@link InitProjectSource} of project specifications for Android projects. | ||
*/ | ||
@SuppressWarnings("UnstableApiUsage") | ||
public final class AndroidProjectSource implements InitProjectSource { | ||
@Override | ||
public List<InitProjectSpec> getProjectSpecs() { | ||
return List.of( | ||
new StaticProjectSpec("android-application", "Declarative Android Application Project") | ||
); | ||
} | ||
|
||
@Override | ||
public Class<? extends InitProjectGenerator> getProjectGenerator() { | ||
return StaticProjectGenerator.class; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ugin/plugin-android/src/main/java/org/gradle/api/experimental/buildinit/package-info.java
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,5 @@ | ||
/** | ||
* This package uses the experimental API for dynamically providing project specifications for Gradle's {@code init} build task. | ||
*/ | ||
@org.gradle.api.NonNullApi | ||
package org.gradle.api.experimental.buildinit; |
1 change: 1 addition & 0 deletions
1
.../src/main/resources/META-INF/services/org.gradle.buildinit.projectspecs.InitProjectSource
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 @@ | ||
org.gradle.api.experimental.buildinit.AndroidProjectSource |
21 changes: 21 additions & 0 deletions
21
...lugin/plugin-android/src/main/resources/templates/android-application/README.md
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,21 @@ | ||
# declarative-samples-android-app | ||
A sample Android application written in the Declarative Gradle DSL, using the prototype Declarative Gradle `androidApplication` Software Type defined in the `org.gradle.experimental.android-ecosystem` ecosystem plugin. | ||
|
||
## Building and Running | ||
|
||
This sample shows the definition of a multiproject Android application implemented using Kotlin 1.9.23 source code. | ||
The project is the result of reproducing the project produced by the `gradle init` command in Gradle 8.9 as an Android project. | ||
|
||
To build the project without running, use: | ||
|
||
```shell | ||
./gradlew build | ||
``` | ||
|
||
To run the application, first install it on a connected Android device using: | ||
|
||
```shell | ||
:app:installDebug | ||
``` | ||
|
||
Then search for "Sample Declarative Gradle Android App" and launch app to see a hello world message. |
8 changes: 8 additions & 0 deletions
8
...ugin/plugin-android/src/main/resources/templates/android-application/app/build.gradle.dcl
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,8 @@ | ||
androidApplication { | ||
namespace = "org.example.app" | ||
|
||
dependencies { | ||
implementation("org.apache.commons:commons-text:1.11.0") | ||
implementation(project(":utilities")) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...android/src/main/resources/templates/android-application/app/src/main/AndroidManifest.xml
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,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> |
28 changes: 28 additions & 0 deletions
28
...sources/templates/android-application/app/src/main/kotlin/org/example/app/MainActivity.kt
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,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) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...sources/templates/android-application/app/src/main/kotlin/org/example/app/MessageUtils.kt
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,5 @@ | ||
package org.example.app | ||
|
||
internal object MessageUtils { | ||
fun message() = "Hello World!" | ||
} |
12 changes: 12 additions & 0 deletions
12
...rc/main/resources/templates/android-application/app/src/main/res/layout/activity_main.xml
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,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> |
3 changes: 3 additions & 0 deletions
3
...roid/src/main/resources/templates/android-application/app/src/main/res/values/strings.xml
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,3 @@ | ||
<resources> | ||
<string name="app_name">Sample Declarative Gradle Android App</string> | ||
</resources> |
12 changes: 12 additions & 0 deletions
12
...ces/templates/android-application/app/src/test/kotlin/org/example/app/MessageUtilsTest.kt
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,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()) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...-plugin/plugin-android/src/main/resources/templates/android-application/gradle.properties
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,6 @@ | ||
# AndroidX package structure to make it clearer which packages are bundled with the | ||
# Android operating system, and which are packaged with your app's APK | ||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
android.useAndroidX=true | ||
# Kotlin code style for this project: "official" or "obsolete": | ||
kotlin.code.style=official |
3 changes: 3 additions & 0 deletions
3
...gin/plugin-android/src/main/resources/templates/android-application/list/build.gradle.dcl
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,3 @@ | ||
androidLibrary { | ||
namespace = "org.gradle.experimental.android.list" | ||
} |
86 changes: 86 additions & 0 deletions
86
...sources/templates/android-application/list/src/main/kotlin/org/example/list/LinkedList.kt
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,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 | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...d-plugin/plugin-android/src/main/resources/templates/android-application/local.properties
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,8 @@ | ||
## This file must *NOT* be checked into Version Control Systems, | ||
# as it contains information specific to your local configuration. | ||
# | ||
# Location of the SDK. This is only used by Gradle. | ||
# For customization when using a Version Control System, please read the | ||
# header note. | ||
#Tue Jul 30 10:37:16 EDT 2024 | ||
sdk.dir=/Users/ttresansky/Library/Android/sdk |
48 changes: 48 additions & 0 deletions
48
...lugin/plugin-android/src/main/resources/templates/android-application/settings.gradle.dcl
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,48 @@ | ||
pluginManagement { | ||
repositories { | ||
google() // Needed for the Android plugin, applied by the unified plugin | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
plugins { | ||
id("org.gradle.experimental.android-ecosystem") version "0.1.7" | ||
} | ||
|
||
rootProject.name = "example-android-app" | ||
|
||
include("app") | ||
include("list") | ||
include("utilities") | ||
|
||
defaults { | ||
androidApplication { | ||
jdkVersion = 11 | ||
compileSdk = 34 | ||
minSdk = 30 | ||
|
||
versionCode = 1 | ||
versionName = "0.1" | ||
applicationId = "org.gradle.experimental.android.app" | ||
|
||
testing { | ||
dependencies { | ||
implementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
runtimeOnly("org.junit.platform:junit-platform-launcher") | ||
} | ||
} | ||
} | ||
|
||
androidLibrary { | ||
jdkVersion = 11 | ||
compileSdk = 34 | ||
minSdk = 30 | ||
|
||
testing { | ||
dependencies { | ||
implementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
runtimeOnly("org.junit.platform:junit-platform-launcher") | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...lugin-android/src/main/resources/templates/android-application/utilities/build.gradle.dcl
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 @@ | ||
androidLibrary { | ||
namespace = "org.gradle.experimental.android.utilities" | ||
|
||
dependencies { | ||
api(project(":list")) | ||
} | ||
} |
Oops, something went wrong.