-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from gradle/tt/declarativize-nia-app-catalog
Add support for NiA :app-nia-catalog project to use declarative syntax
- Loading branch information
Showing
8 changed files
with
265 additions
and
47 deletions.
There are no files selected for viewing
19 changes: 14 additions & 5 deletions
19
unified-prototype/unified-plugin/gradle/libs.versions.toml
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 |
---|---|---|
@@ -1,31 +1,40 @@ | ||
[versions] | ||
# Kotlin Libs | ||
# Find latest version at: https://kotlinlang.org/docs/releases.html#release-details | ||
kotlin = "1.9.23" | ||
ksp = "1.9.23-1.0.20" | ||
|
||
# Android Libs | ||
# Find latest version at: https://developer.android.com/reference/tools/gradle-api | ||
android = "8.3.0" | ||
androidTools = "31.3.0" | ||
hilt = "2.50" | ||
room = "2.6.1" | ||
protobuf = "0.9.4" | ||
|
||
#Other Libs | ||
apache-commons = "3.3.1" | ||
dependency-guard = "0.4.3" | ||
truth = "1.4.2" | ||
protobuf = "0.9.4" | ||
|
||
[libraries] | ||
# Kotlin dependencies | ||
# Kotlin Libs | ||
kotlin-multiplatform = { module = "org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin", version.ref = "kotlin" } | ||
ksp-plugin = { module = "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" } | ||
kotlin-jvm = { module = "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin", version.ref = "kotlin" } | ||
kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } | ||
|
||
# Android dependencies | ||
# Android Libs | ||
android-agp-application = { module = "com.android.application:com.android.application.gradle.plugin", version.ref = "android" } | ||
android-kotlin-android = { module = "org.jetbrains.kotlin.android:org.jetbrains.kotlin.android.gradle.plugin", version.ref = "kotlin" } | ||
android-tools-common = { module = "com.android.tools:common", version.ref = "androidTools" } | ||
hilt-android-plugin = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "hilt" } | ||
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt"} | ||
hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" } | ||
protobuf-plugin = { module = "com.google.protobuf:protobuf-gradle-plugin", version.ref = "protobuf" } | ||
room-plugin = { module = "androidx.room:room-gradle-plugin", version.ref = "room" } | ||
|
||
# Other libraries | ||
#Other Libs | ||
apache-commons-lang = { module = "org.apache.commons:commons-lang3", version.ref = "apache-commons" } | ||
dependency-guard-plugin = { module = "com.dropbox.dependency-guard:com.dropbox.dependency-guard.gradle.plugin", version.ref = "dependency-guard"} | ||
truth = { module = "com.google.truth:truth", version.ref = "truth" } | ||
protobuf-plugin = { module = "com.google.protobuf:protobuf-gradle-plugin", version.ref = "protobuf" } |
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
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
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
29 changes: 29 additions & 0 deletions
29
...android/src/main/java/org/gradle/api/experimental/android/extensions/DependencyGuard.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,29 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gradle.api.experimental.android.extensions; | ||
|
||
import org.gradle.api.provider.Property; | ||
import org.gradle.declarative.dsl.model.annotations.Restricted; | ||
|
||
@Restricted | ||
public interface DependencyGuard { | ||
@Restricted | ||
Property<Boolean> getEnabled(); | ||
|
||
@Restricted | ||
Property<String> getConfigurationName(); | ||
} |
75 changes: 75 additions & 0 deletions
75
...lugin-android/src/main/java/org/gradle/api/experimental/android/nia/CheckBadgingTask.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,75 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gradle.api.experimental.android.nia; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.CacheableTask; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputFile; | ||
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 org.gradle.language.base.plugins.LifecycleBasePlugin; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import static com.google.common.truth.Truth.assertWithMessage; | ||
|
||
@CacheableTask | ||
public abstract class CheckBadgingTask extends DefaultTask { | ||
|
||
// In order for the task to be up-to-date when the inputs have not changed, | ||
// the task must declare an output, even if it's not used. Tasks with no | ||
// output are always run regardless of whether the inputs changed | ||
@OutputDirectory | ||
public abstract DirectoryProperty getOutput(); | ||
|
||
@PathSensitive(PathSensitivity.NONE) | ||
@InputFile | ||
public abstract RegularFileProperty getGoldenBadging(); | ||
|
||
@PathSensitive(PathSensitivity.NONE) | ||
@InputFile | ||
public abstract RegularFileProperty getGeneratedBadging(); | ||
|
||
@Input | ||
public abstract Property<String> getUpdateBadgingTaskName(); | ||
|
||
@Override | ||
public String getGroup() { | ||
return LifecycleBasePlugin.VERIFICATION_GROUP; | ||
} | ||
|
||
@TaskAction | ||
public void taskAction() { | ||
try { | ||
String goldenBadgingContent = new String(Files.readAllBytes(Paths.get(getGoldenBadging().get().getAsFile().getAbsolutePath()))); | ||
String generatedBadgingContent = new String(Files.readAllBytes(Paths.get(getGeneratedBadging().get().getAsFile().getAbsolutePath()))); | ||
assertWithMessage( | ||
"Generated badging is different from golden badging! " + | ||
"If this change is intended, run ./gradlew " + getUpdateBadgingTaskName().get() | ||
).that(generatedBadgingContent).isEqualTo(goldenBadgingContent); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to read badging files", e); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...in-android/src/main/java/org/gradle/api/experimental/android/nia/GenerateBadgingTask.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,66 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gradle.api.experimental.android.nia; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.tasks.CacheableTask; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.PathSensitive; | ||
import org.gradle.api.tasks.PathSensitivity; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.process.ExecOperations; | ||
|
||
import javax.inject.Inject; | ||
import java.io.FileOutputStream; | ||
import java.io.OutputStream; | ||
|
||
@CacheableTask | ||
public abstract class GenerateBadgingTask extends DefaultTask { | ||
@OutputFile | ||
public abstract RegularFileProperty getBadging(); | ||
|
||
@PathSensitive(PathSensitivity.NONE) | ||
@InputFile | ||
public abstract RegularFileProperty getApk(); | ||
|
||
@PathSensitive(PathSensitivity.NONE) | ||
@InputFile | ||
public abstract RegularFileProperty getAapt2Executable(); | ||
|
||
@Inject | ||
public abstract ExecOperations getExecOperations(); | ||
|
||
@TaskAction | ||
public void taskAction() { | ||
getExecOperations().exec(execSpec -> { | ||
execSpec.commandLine( | ||
getAapt2Executable().get().getAsFile().getAbsolutePath(), | ||
"dump", | ||
"badging", | ||
getApk().get().getAsFile().getAbsolutePath() | ||
); | ||
|
||
try (OutputStream os = new FileOutputStream(getBadging().get().getAsFile())) { | ||
execSpec.setStandardOutput(os); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to write badging output", e); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.