Skip to content

Commit e969d12

Browse files
committed
Split source of encoders.
1 parent 8015fa6 commit e969d12

File tree

8 files changed

+212
-191
lines changed

8 files changed

+212
-191
lines changed

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

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,18 @@
1616

1717
import com.android.build.gradle.LibraryExtension;
1818
import com.android.build.gradle.api.AndroidSourceSet;
19-
import com.android.build.gradle.api.LibraryVariant;
2019
import com.google.common.collect.ImmutableList;
2120
import com.google.common.collect.ImmutableMap;
22-
import com.google.firebase.gradle.plugins.apiinfo.GenerateApiTxtFileTask;
2321
import com.google.firebase.gradle.plugins.apiinfo.ApiInformationTask;
22+
import com.google.firebase.gradle.plugins.apiinfo.GenerateApiTxtFileTask;
2423
import com.google.firebase.gradle.plugins.apiinfo.GenerateStubsTask;
2524
import com.google.firebase.gradle.plugins.apiinfo.GetMetalavaJarTask;
2625
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer;
27-
26+
import java.io.File;
27+
import java.nio.file.Paths;
2828
import org.gradle.api.Plugin;
2929
import org.gradle.api.Project;
3030
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
31-
import java.io.File;
32-
import java.nio.file.Paths;
33-
import java.util.ArrayList;
34-
import java.util.List;
35-
import java.util.stream.Collectors;
3631

3732
public class FirebaseLibraryPlugin implements Plugin<Project> {
3833

@@ -88,53 +83,74 @@ public void apply(Project project) {
8883
private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {
8984
File metalavaOutputJarFile = new File(project.getRootProject().getBuildDir(), "metalava.jar");
9085
AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main");
91-
File outputFile = project.getRootProject().file(Paths.get(
92-
project.getRootProject().getBuildDir().getPath(),
93-
"apiinfo",
94-
project.getPath().substring(1).replace(":", "_")));
86+
File outputFile =
87+
project
88+
.getRootProject()
89+
.file(
90+
Paths.get(
91+
project.getRootProject().getBuildDir().getPath(),
92+
"apiinfo",
93+
project.getPath().substring(1).replace(":", "_")));
9594
File outputApiFile = new File(outputFile.getAbsolutePath() + "_api.txt");
96-
List<File> sourcePath = mainSourceSet.getJava().getSrcDirs().stream().collect(Collectors.toList());
97-
if(mainSourceSet.getJava().getSrcDirs().stream().noneMatch(File::exists)) {
98-
return;
99-
}
100-
project.getTasks().register("getMetalavaJar", GetMetalavaJarTask.class, task -> {
101-
task.setOutputFile(metalavaOutputJarFile);
102-
});
103-
project.getTasks().register("apiInformation", ApiInformationTask.class, task -> {
104-
task.setApiTxt(project.file("api.txt"));
105-
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
106-
task.setSourcePath(sourcePath);
107-
task.setOutputFile(outputFile);
108-
task.setBaselineFile(project.file("baseline.txt"));
109-
task.setOutputApiFile(outputApiFile);
110-
if (project.hasProperty("updateBaseline")) {
111-
task.setUpdateBaseline(true);
112-
} else {
113-
task.setUpdateBaseline(false);
114-
}
115-
task.dependsOn("getMetalavaJar");
116-
});
117-
118-
project.getTasks().register("generateApiTxtFile", GenerateApiTxtFileTask.class, task -> {
119-
task.setApiTxt(project.file("api.txt"));
120-
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
121-
task.setSourcePath(sourcePath);
122-
task.setBaselineFile(project.file("baseline.txt"));
123-
if (project.hasProperty("updateBaseline")) {
124-
task.setUpdateBaseline(true);
125-
} else {
126-
task.setUpdateBaseline(false);
127-
}
128-
task.dependsOn("getMetalavaJar");
129-
});
130-
131-
project.getTasks().register("docStubs", GenerateStubsTask.class, task -> {
132-
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
133-
task.setOutputDir(new File(project.getBuildDir(), "doc-stubs"));
134-
task.dependsOn("getMetalavaJar");
135-
136-
task.setSourceDirs(android.getSourceSets().getByName("main").getJava().getSrcDirs());
137-
});
95+
96+
project
97+
.getTasks()
98+
.register(
99+
"getMetalavaJar",
100+
GetMetalavaJarTask.class,
101+
task -> {
102+
task.setOutputFile(metalavaOutputJarFile);
103+
});
104+
project
105+
.getTasks()
106+
.register(
107+
"apiInformation",
108+
ApiInformationTask.class,
109+
task -> {
110+
task.setApiTxt(project.file("api.txt"));
111+
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
112+
task.setSourceSet(mainSourceSet);
113+
task.setOutputFile(outputFile);
114+
task.setBaselineFile(project.file("baseline.txt"));
115+
task.setOutputApiFile(outputApiFile);
116+
if (project.hasProperty("updateBaseline")) {
117+
task.setUpdateBaseline(true);
118+
} else {
119+
task.setUpdateBaseline(false);
120+
}
121+
task.dependsOn("getMetalavaJar");
122+
});
123+
124+
project
125+
.getTasks()
126+
.register(
127+
"generateApiTxtFile",
128+
GenerateApiTxtFileTask.class,
129+
task -> {
130+
task.setApiTxt(project.file("api.txt"));
131+
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
132+
task.setSourceSet(mainSourceSet);
133+
task.setBaselineFile(project.file("baseline.txt"));
134+
if (project.hasProperty("updateBaseline")) {
135+
task.setUpdateBaseline(true);
136+
} else {
137+
task.setUpdateBaseline(false);
138+
}
139+
task.dependsOn("getMetalavaJar");
140+
});
141+
142+
project
143+
.getTasks()
144+
.register(
145+
"docStubs",
146+
GenerateStubsTask.class,
147+
task -> {
148+
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
149+
task.setOutputDir(new File(project.getBuildDir(), "doc-stubs"));
150+
task.dependsOn("getMetalavaJar");
151+
152+
task.setSourceSet(mainSourceSet);
153+
});
138154
}
139155

140156
private static void setupStaticAnalysis(

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

Lines changed: 80 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,110 +14,116 @@
1414

1515
package com.google.firebase.gradle.plugins.apiinfo;
1616

17+
import com.android.build.gradle.api.AndroidSourceSet;
18+
import java.io.File;
19+
import java.io.FileNotFoundException;
20+
import java.io.FileOutputStream;
1721
import java.util.ArrayList;
22+
import java.util.Arrays;
1823
import java.util.List;
19-
import java.util.stream.Collector;
2024
import java.util.stream.Collectors;
21-
import java.util.stream.Stream;
2225
import org.gradle.api.DefaultTask;
2326
import org.gradle.api.GradleException;
2427
import org.gradle.api.tasks.Input;
25-
import org.gradle.api.tasks.InputDirectory;
2628
import org.gradle.api.tasks.InputFile;
27-
import org.gradle.api.tasks.InputFiles;
2829
import org.gradle.api.tasks.OutputFile;
2930
import org.gradle.api.tasks.TaskAction;
3031

31-
import java.io.File;
32-
import java.io.FileNotFoundException;
33-
import java.io.FileOutputStream;
34-
import java.util.Arrays;
35-
3632
/**
37-
Task generates the api diff of the current source code against the api.txt file stored
38-
alongside the project's src directory.
33+
* Task generates the api diff of the current source code against the api.txt file stored alongside
34+
* the project's src directory.
3935
*/
4036
public abstract class ApiInformationTask extends DefaultTask {
4137

42-
@Input
43-
abstract String getMetalavaJarPath();
38+
@Input
39+
abstract String getMetalavaJarPath();
4440

45-
@InputFile
46-
abstract File getApiTxt();
41+
@InputFile
42+
abstract File getApiTxt();
4743

48-
@InputFiles
49-
abstract List<File> getSourcePath();
44+
abstract AndroidSourceSet getSourceSet();
5045

51-
@OutputFile
52-
abstract File getBaselineFile();
46+
@OutputFile
47+
abstract File getBaselineFile();
5348

54-
@OutputFile
55-
abstract File getOutputApiFile();
49+
@OutputFile
50+
abstract File getOutputApiFile();
5651

57-
@Input
58-
abstract boolean getUpdateBaseline();
52+
@Input
53+
abstract boolean getUpdateBaseline();
5954

60-
@OutputFile
61-
abstract File getOutputFile();
55+
@OutputFile
56+
abstract File getOutputFile();
6257

63-
public abstract void setSourcePath(List<File> value);
58+
public abstract void setSourceSet(AndroidSourceSet value);
6459

65-
public abstract void setBaselineFile(File value);
60+
public abstract void setBaselineFile(File value);
6661

67-
public abstract void setUpdateBaseline(boolean value);
62+
public abstract void setUpdateBaseline(boolean value);
6863

69-
public abstract void setMetalavaJarPath(String value);
64+
public abstract void setMetalavaJarPath(String value);
7065

71-
public abstract void setApiTxt(File value);
66+
public abstract void setApiTxt(File value);
7267

73-
public abstract void setOutputApiFile(File value);
68+
public abstract void setOutputApiFile(File value);
7469

75-
public abstract void setOutputFile(File value);
70+
public abstract void setOutputFile(File value);
7671

72+
@TaskAction
73+
void execute() {
74+
String sourcePath =
75+
getSourceSet().getJava().getSrcDirs().stream()
76+
.filter(File::exists)
77+
.map(File::getAbsolutePath)
78+
.collect(Collectors.joining(":"));
79+
File outputFileDir = getOutputFile().getParentFile();
80+
if (!outputFileDir.exists()) {
81+
outputFileDir.mkdirs();
82+
}
7783

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()) {
84+
// Generate api.txt file and store it in the build directory.
85+
getProject()
86+
.javaexec(
87+
spec -> {
88+
spec.setMain("-jar");
89+
spec.setArgs(
90+
Arrays.asList(
91+
getMetalavaJarPath(),
92+
"--source-path",
93+
sourcePath,
94+
"--api",
95+
getOutputApiFile().getAbsolutePath(),
96+
"--format=v2"));
97+
spec.setIgnoreExitValue(true);
98+
});
99+
getProject()
100+
.javaexec(
101+
spec -> {
102+
spec.setMain("-jar");
103+
List<String> args =
104+
new ArrayList<>(
105+
Arrays.asList(
106+
getMetalavaJarPath(),
107+
"--source-files",
108+
getOutputApiFile().getAbsolutePath(),
109+
"--check-compatibility:api:current",
110+
getApiTxt().getAbsolutePath(),
111+
"--format=v2",
112+
"--no-color",
113+
"--delete-empty-baselines"));
114+
if (getUpdateBaseline()) {
115+
args.addAll(
116+
Arrays.asList("--update-baseline", getBaselineFile().getAbsolutePath()));
117+
} else if (getBaselineFile().exists()) {
110118
args.addAll(Arrays.asList("--baseline", getBaselineFile().getAbsolutePath()));
111-
}
112-
spec.setArgs(args);
113-
spec.setIgnoreExitValue(true);
114-
try {
119+
}
120+
spec.setArgs(args);
121+
spec.setIgnoreExitValue(true);
122+
try {
115123
spec.setStandardOutput(new FileOutputStream(getOutputFile()));
116-
} catch (FileNotFoundException e) {
124+
} catch (FileNotFoundException e) {
117125
throw new GradleException("Unable to run the command", e);
118-
}
119-
});
120-
121-
}
122-
126+
}
127+
});
128+
}
123129
}

0 commit comments

Comments
 (0)