Skip to content

Commit

Permalink
Merge branch 'master' into ehsann/in-expansion-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannas authored Feb 15, 2023
2 parents 56344f9 + 6071e9d commit 7f141d1
Show file tree
Hide file tree
Showing 54 changed files with 633 additions and 342 deletions.
4 changes: 2 additions & 2 deletions appcheck/firebase-appcheck-debug-testing/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=16.1.1
latestReleasedVersion=16.1.0
version=16.1.2
latestReleasedVersion=16.1.1
4 changes: 2 additions & 2 deletions appcheck/firebase-appcheck-debug/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=16.1.1
latestReleasedVersion=16.1.0
version=16.1.2
latestReleasedVersion=16.1.1
4 changes: 2 additions & 2 deletions appcheck/firebase-appcheck-interop/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=16.1.1
latestReleasedVersion=16.1.0
version=16.1.2
latestReleasedVersion=16.1.1
4 changes: 2 additions & 2 deletions appcheck/firebase-appcheck-playintegrity/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=16.1.1
latestReleasedVersion=16.1.0
version=16.1.2
latestReleasedVersion=16.1.1
4 changes: 2 additions & 2 deletions appcheck/firebase-appcheck-safetynet/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=16.1.1
latestReleasedVersion=16.1.0
version=16.1.2
latestReleasedVersion=16.1.1
4 changes: 2 additions & 2 deletions appcheck/firebase-appcheck/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=16.1.1
latestReleasedVersion=16.1.0
version=16.1.2
latestReleasedVersion=16.1.1
13 changes: 13 additions & 0 deletions appcheck/firebase-appcheck/ktx/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.appcheck.ktx">
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
<!--<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />-->
<uses-permission android:name="android.permission.INTERNET"/>
<application>
<uses-library android:name="android.test.runner" />
</application>

<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.google.firebase.appcheck.ktx" />
</manifest>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ buildscript {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.3.0'
classpath 'gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.9'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.gms:google-services:4.3.15'
classpath "com.ncorti.ktfmt.gradle:plugin:0.11.0"
}
}
Expand All @@ -54,6 +54,7 @@ ext {
robolectricVersion = libs.versions.robolectric.get()
protocVersion = libs.versions.protoc.get()
javaliteVersion = libs.versions.javalite.get()
protobufJavaUtilVersion = libs.versions.protobufjavautil.get()
}

apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ dependencies {
implementation("org.eclipse.jgit:org.eclipse.jgit:6.3.0.202209071007-r")

implementation("com.google.code.gson:gson:2.8.9")
implementation("com.android.tools.build:gradle:7.4.0")
implementation("com.android.tools.build:builder-test-api:7.4.0")
implementation("com.android.tools.build:gradle:7.2.2")
implementation("com.android.tools.build:builder-test-api:7.2.2")
implementation("gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.9")

testImplementation("junit:junit:4.13.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.function.Consumer;
import org.gradle.api.GradleException;

// TODO(b/267668143): With modernization efforts
public class ShellExecutor {
private final Runtime runtime;
private final File cwd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public void apply(Project project) {
test.systemProperty("javax.net.ssl.trustStoreType", "JKS");
})));

// skip debug tests in CI
// TODO(vkryachko): provide ability for teams to control this if needed
if (System.getenv().containsKey("FIREBASE_CI")) {
android.setTestBuildType("release");
project
.getTasks()
.all(
task -> {
if ("testDebugUnitTest".equals(task.getName())) {
task.setEnabled(false);
}
});
}

setupApiInformationAnalysis(project, android);
android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab, android));

Expand All @@ -109,6 +123,8 @@ public void apply(Project project) {
ImmutableList.of("-module-name", kotlinModuleName(project))));

project.getPluginManager().apply(DackkaPlugin.class);
project.getPluginManager().apply(GitSubmodulePlugin.class);
project.getTasks().getByName("preBuild").dependsOn("updateGitSubmodules");
}

private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright 2023 Google LLC
//
// 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
//
// http://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 com.google.firebase.gradle.plugins

import java.io.File
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.register

/**
* Exposes configuration for [GitSubmodulePlugin].
*
* @param submodules the parent directory of the SDK's Git Submodules. Defaults to `src/third_party`
*/
interface GitSubmodulePluginExtension {
val submodules: Property<File>
}

/**
* Helper plugin for common actions regarding Git Submodules
*
* At the time of writing this, we only have one SDK with submodules. Although, that could grow in
* the future. More importantly though, this provides a way for us to make sure the submodules are
* initilized whenever we are building said SDKs- while keeping our system clean and modular.
*
* This plugin is automatically applied to all SDKs that utilize [FirebaseLibraryPlugin], and is
* subsequently bound to the `preBuild` task that is apart of all gradle modules.
*
* The following tasks are registered when this plugin is applied:
* - [initializeGitSubmodules][registerInitializeGitSubmodulesTask]
* - [updateGitSubmodules][registerUpdateGitSubmodulesTask]
* - [removeGitSubmodules][registerRemoveGitSubmodulesTask]
*
* __Documentation explaining each task is provided in the annotation for each task__
*
* @see [GitSubmodulePluginExtension]
*/
abstract class GitSubmodulePlugin : Plugin<Project> {

override fun apply(project: Project) {
with(configureExtension(project)) {
registerInitializeGitSubmodulesTask(project, submodules.get())
registerUpdateGitSubmodulesTask(project, submodules.get())
registerRemoveGitSubmodulesTask(project, submodules.get())
}
}

private fun configureExtension(project: Project) =
project.extensions.create<GitSubmodulePluginExtension>("GitSubmodule").apply {
submodules.convention(project.file("src/third_party"))
}

/**
* Registers the initializeGitSubmodules Task for the provided [Project].
*
* Creates a local configuration for the predefined submodules. It does this by running the
* command `git submodule init` from the [project]'s root directory.
*
* If there aren't any submodules to initialize, this task is skipped- saving resources.
*
* @param project the [Project] to register this task to
* @param submodules the root directory of where the submodules live
*/
private fun registerInitializeGitSubmodulesTask(project: Project, submodules: File) =
project.tasks.register<Exec>("initializeGitSubmodules") {
onlyIf { hasEmptySubmodules(submodules) }

workingDir = project.projectDir
commandLine = "git submodule init".split(" ")
}

/**
* Registers the updateGitSubmodules Task for the provided [Project].
*
* Pulls the latest data for each submodule, similiar to `git pull`. It does this by running the
* command `git submodule update` from the [project]'s root directory.
*
* If there aren't any submodules, this task is skipped- saving resources.
*
* @param project the [Project] to register this task to
* @param submodules the root directory of where the submodules live
*/
private fun registerUpdateGitSubmodulesTask(project: Project, submodules: File) =
project.tasks.register<Exec>("updateGitSubmodules") {
onlyIf { hasEmptySubmodules(submodules) }
dependsOn("initializeGitSubmodules")

workingDir = project.projectDir
commandLine = "git submodule update".split(" ")
}

/**
* Registers the removeGitSubmodules Task for the provided [Project].
*
* Removes and de initilizes all submodules for the given [project]. It does this by running the
* command `git submodule deinit --all` from the [project]'s root directory.
*
* If there aren't any submodules to remove, this task is skipped- saving resources.
*
* @param project the [Project] to register this task to
* @param submodules the root directory of where the submodules live
*/
private fun registerRemoveGitSubmodulesTask(project: Project, submodules: File) =
project.tasks.register<Exec>("removeGitSubmodules") {
onlyIf { submodules.exists() }

workingDir = project.projectDir
commandLine = "git submodule deinit --all".split(" ")
}

private fun hasEmptySubmodules(parentFolder: File) =
parentFolder.listFilesOrEmpty().any { it.isDirectory && it.listFilesOrEmpty().isEmpty() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ fun Project.fileFromBuildDir(path: String) = file("$buildDir/$path")
*/
fun Project.childFile(provider: Provider<File>, childPath: String) =
provider.map { file("${it.path}/$childPath") }

/**
* Returns a list of children files, or an empty list if this [File] doesn't exist or doesn't have
* any children.
*
* Syntax sugar for:
*
* ```
* listFiles().orEmpty()
* ```
*/
fun File.listFilesOrEmpty() = listFiles().orEmpty()
Loading

0 comments on commit 7f141d1

Please sign in to comment.