Skip to content

Commit 44bef2f

Browse files
committed
Merge branch 'fis_sdk' of github.com:firebase/firebase-android-sdk into ankita_fis
2 parents f4c44b0 + 9794e1f commit 44bef2f

File tree

157 files changed

+6219
-931
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+6219
-931
lines changed

.opensource/project.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"pages": {
99
"README.md": "Development Guide",
1010
"docs/ktx/common.md": "Common KTX",
11-
"docs/ktx/firestore.md": "Firestore KTX"
11+
"docs/ktx/firestore.md": "Firestore KTX",
12+
"docs/ktx/functions.md": "Functions KTX"
1213
},
1314
"related": [
1415
"firebase/quickstart-android"
@@ -23,4 +24,4 @@
2324
"href": "https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/"
2425
}
2526
]
26-
}
27+
}

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@
1515
package com.google.firebase.gradle.plugins;
1616

1717
import com.android.build.gradle.LibraryExtension;
18+
import com.android.build.gradle.api.AndroidSourceSet;
19+
import com.android.build.gradle.api.LibraryVariant;
1820
import com.google.common.collect.ImmutableList;
1921
import com.google.common.collect.ImmutableMap;
22+
import com.google.firebase.gradle.plugins.apiinfo.GenerateApiTxtFileTask;
23+
import com.google.firebase.gradle.plugins.apiinfo.ApiInformationTask;
24+
import com.google.firebase.gradle.plugins.apiinfo.GetMetalavaJarTask;
2025
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer;
26+
2127
import org.gradle.api.Plugin;
2228
import org.gradle.api.Project;
2329
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
30+
import java.io.File;
31+
import java.nio.file.Paths;
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
import java.util.stream.Collectors;
2435

2536
public class FirebaseLibraryPlugin implements Plugin<Project> {
2637

@@ -55,6 +66,8 @@ public void apply(Project project) {
5566
});
5667
}
5768

69+
setupApiInformationAnalysis(project, android);
70+
5871
android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab));
5972

6073
setupStaticAnalysis(project, android, firebaseLibrary);
@@ -71,6 +84,50 @@ public void apply(Project project) {
7184
ImmutableList.of("-module-name", kotlinModuleName(project))));
7285
}
7386

87+
private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {
88+
File metalavaOutputJarFile = new File(project.getRootProject().getBuildDir(), "metalava.jar");
89+
AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main");
90+
File outputFile = project.getRootProject().file(Paths.get(
91+
project.getRootProject().getBuildDir().getPath(),
92+
"apiinfo",
93+
project.getPath().substring(1).replace(":", "_")));
94+
File outputApiFile = new File(outputFile.getAbsolutePath() + "_api.txt");
95+
List<File> sourcePath = mainSourceSet.getJava().getSrcDirs().stream().collect(Collectors.toList());
96+
if(mainSourceSet.getJava().getSrcDirs().stream().noneMatch(File::exists)) {
97+
return;
98+
}
99+
project.getTasks().register("getMetalavaJar", GetMetalavaJarTask.class, task -> {
100+
task.setOutputFile(metalavaOutputJarFile);
101+
});
102+
project.getTasks().register("apiInformation", ApiInformationTask.class, task -> {
103+
task.setApiTxt(project.file("api.txt"));
104+
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
105+
task.setSourcePath(sourcePath);
106+
task.setOutputFile(outputFile);
107+
task.setBaselineFile(project.file("baseline.txt"));
108+
task.setOutputApiFile(outputApiFile);
109+
if (project.hasProperty("updateBaseline")) {
110+
task.setUpdateBaseline(true);
111+
} else {
112+
task.setUpdateBaseline(false);
113+
}
114+
task.dependsOn("getMetalavaJar");
115+
});
116+
117+
project.getTasks().register("generateApiTxtFile", GenerateApiTxtFileTask.class, task -> {
118+
task.setApiTxt(project.file("api.txt"));
119+
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
120+
task.setSourcePath(sourcePath);
121+
task.setBaselineFile(project.file("baseline.txt"));
122+
if (project.hasProperty("updateBaseline")) {
123+
task.setUpdateBaseline(true);
124+
} else {
125+
task.setUpdateBaseline(false);
126+
}
127+
task.dependsOn("getMetalavaJar");
128+
});
129+
}
130+
74131
private static void setupStaticAnalysis(
75132
Project project, LibraryExtension android, FirebaseLibraryExtension library) {
76133
project.afterEvaluate(
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins.apiinfo;
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
import java.util.stream.Collector;
20+
import java.util.stream.Collectors;
21+
import java.util.stream.Stream;
22+
import org.gradle.api.DefaultTask;
23+
import org.gradle.api.GradleException;
24+
import org.gradle.api.tasks.Input;
25+
import org.gradle.api.tasks.InputDirectory;
26+
import org.gradle.api.tasks.InputFile;
27+
import org.gradle.api.tasks.InputFiles;
28+
import org.gradle.api.tasks.OutputFile;
29+
import org.gradle.api.tasks.TaskAction;
30+
31+
import java.io.File;
32+
import java.io.FileNotFoundException;
33+
import java.io.FileOutputStream;
34+
import java.util.Arrays;
35+
36+
/**
37+
Task generates the api diff of the current source code against the api.txt file stored
38+
alongside the project's src directory.
39+
*/
40+
public abstract class ApiInformationTask extends DefaultTask {
41+
42+
@Input
43+
abstract String getMetalavaJarPath();
44+
45+
@InputFile
46+
abstract File getApiTxt();
47+
48+
@InputFiles
49+
abstract List<File> getSourcePath();
50+
51+
@OutputFile
52+
abstract File getBaselineFile();
53+
54+
@OutputFile
55+
abstract File getOutputApiFile();
56+
57+
@Input
58+
abstract boolean getUpdateBaseline();
59+
60+
@OutputFile
61+
abstract File getOutputFile();
62+
63+
public abstract void setSourcePath(List<File> value);
64+
65+
public abstract void setBaselineFile(File value);
66+
67+
public abstract void setUpdateBaseline(boolean value);
68+
69+
public abstract void setMetalavaJarPath(String value);
70+
71+
public abstract void setApiTxt(File value);
72+
73+
public abstract void setOutputApiFile(File value);
74+
75+
public abstract void setOutputFile(File value);
76+
77+
78+
@TaskAction
79+
void execute() {
80+
String sourcePath = getSourcePath().stream().map(File::getAbsolutePath).collect(Collectors.joining(":"));
81+
File outputFileDir = getOutputFile().getParentFile();
82+
if(!outputFileDir.exists()) {
83+
outputFileDir.mkdirs();
84+
}
85+
86+
// Generate api.txt file and store it in the build directory.
87+
getProject().javaexec(spec-> {
88+
spec.setMain("-jar");
89+
spec.setArgs(Arrays.asList(
90+
getMetalavaJarPath(),
91+
"--source-path", sourcePath,
92+
"--api", getOutputApiFile().getAbsolutePath(),
93+
"--format=v2"
94+
));
95+
spec.setIgnoreExitValue(true);
96+
});
97+
getProject().javaexec(spec-> {
98+
spec.setMain("-jar");
99+
List<String> args = new ArrayList<>(Arrays.asList(
100+
getMetalavaJarPath(),
101+
"--source-files", getOutputApiFile().getAbsolutePath(),
102+
"--check-compatibility:api:current", getApiTxt().getAbsolutePath(),
103+
"--format=v2",
104+
"--no-color",
105+
"--delete-empty-baselines"
106+
));
107+
if(getUpdateBaseline()) {
108+
args.addAll(Arrays.asList("--update-baseline", getBaselineFile().getAbsolutePath()));
109+
} else if(getBaselineFile().exists()) {
110+
args.addAll(Arrays.asList("--baseline", getBaselineFile().getAbsolutePath()));
111+
}
112+
spec.setArgs(args);
113+
spec.setIgnoreExitValue(true);
114+
try {
115+
spec.setStandardOutput(new FileOutputStream(getOutputFile()));
116+
} catch (FileNotFoundException e) {
117+
throw new GradleException("Unable to run the command", e);
118+
}
119+
});
120+
121+
}
122+
123+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins.apiinfo;
16+
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
import org.gradle.api.DefaultTask;
21+
import org.gradle.api.tasks.Input;
22+
import org.gradle.api.tasks.InputDirectory;
23+
import org.gradle.api.tasks.InputFiles;
24+
import org.gradle.api.tasks.OutputFile;
25+
import org.gradle.api.tasks.TaskAction;
26+
import java.io.File;
27+
28+
import java.util.Arrays;
29+
import java.util.stream.Collector;
30+
import java.util.stream.Collectors;
31+
32+
33+
public abstract class GenerateApiTxtFileTask extends DefaultTask {
34+
35+
@Input
36+
abstract String getMetalavaJarPath();
37+
38+
@OutputFile
39+
abstract File getApiTxt();
40+
41+
@InputFiles
42+
abstract List<File> getSourcePath();
43+
44+
45+
@OutputFile
46+
abstract File getBaselineFile();
47+
48+
@Input
49+
abstract boolean getUpdateBaseline();
50+
51+
52+
public abstract void setSourcePath(List<File> value);
53+
54+
public abstract void setBaselineFile(File value);
55+
56+
public abstract void setUpdateBaseline(boolean value);
57+
58+
public abstract void setMetalavaJarPath(String value);
59+
60+
public abstract void setApiTxt(File value);
61+
62+
@TaskAction
63+
void execute() {
64+
String sourcePath = getSourcePath().stream().map(File::getAbsolutePath).collect(Collectors.joining(":"));
65+
List<String> args = new ArrayList<String>(Arrays.asList(
66+
getMetalavaJarPath(),
67+
"--source-path", sourcePath,
68+
"--api", getApiTxt().getAbsolutePath(),
69+
"--format=v2",
70+
"--delete-empty-baselines"
71+
));
72+
73+
if(getUpdateBaseline()) {
74+
args.addAll(Arrays.asList("--update-baseline", getBaselineFile().getAbsolutePath()));
75+
} else if(getBaselineFile().exists()) {
76+
args.addAll(Arrays.asList("--baseline", getBaselineFile().getAbsolutePath()));
77+
}
78+
79+
getProject().javaexec(spec -> {
80+
spec.setMain("-jar");
81+
spec.setArgs(args);
82+
spec.setIgnoreExitValue(true);
83+
});
84+
85+
}
86+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins.apiinfo;
16+
17+
import java.io.BufferedInputStream;
18+
import java.io.File;
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.net.JarURLConnection;
22+
import java.net.MalformedURLException;
23+
import java.net.URL;
24+
import java.nio.file.FileSystems;
25+
import java.nio.file.Files;
26+
import java.nio.file.StandardCopyOption;
27+
import org.gradle.api.DefaultTask;
28+
import org.gradle.api.GradleException;
29+
import org.gradle.api.invocation.Gradle;
30+
import org.gradle.api.tasks.Input;
31+
import org.gradle.api.tasks.OutputFile;
32+
import org.gradle.api.tasks.TaskAction;
33+
34+
public abstract class GetMetalavaJarTask extends DefaultTask {
35+
36+
37+
@OutputFile
38+
abstract File getOutputFile();
39+
40+
public abstract void setOutputFile(File outputFile);
41+
42+
@TaskAction
43+
void execute() {
44+
if (getOutputFile().exists()) {
45+
return;
46+
}
47+
48+
try (InputStream stream = new URL("https://storage.googleapis.com/android-ci/metalava-full-1.3.0-SNAPSHOT.jar").openStream()){
49+
Files.copy(stream, getOutputFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
50+
} catch (IOException e) {
51+
throw new GradleException("Unable to read the jar file from GCS", e);
52+
}
53+
}
54+
55+
}

0 commit comments

Comments
 (0)