16
16
17
17
import com .google .firebase .gradle .plugins .FirebaseLibraryExtension ;
18
18
import java .io .File ;
19
- import java .util .Arrays ;
19
+ import java .io .IOException ;
20
+ import java .nio .file .Files ;
21
+ import java .nio .file .Path ;
22
+ import java .util .List ;
20
23
import java .util .Set ;
21
24
import java .util .stream .Collectors ;
25
+ import java .util .stream .Stream ;
22
26
import org .gradle .api .Plugin ;
23
27
import org .gradle .api .Project ;
24
28
import org .gradle .api .Task ;
41
45
* <p><strong>Prepare a release</strong>
42
46
*
43
47
* <pre>
48
+ * ./gradlew -PpublishConfigFilePath=release.cfg
49
+ * -PpublishMode=(RELEASE|SNAPSHOT) \
50
+ * firebasePublish
51
+ * </pre>
52
+ *
53
+ * <pre>
44
54
* ./gradlew -PprojectsToPublish="firebase-inappmessaging,firebase-inappmessaging-display"\
45
55
* -PpublishMode=(RELEASE|SNAPSHOT) \
46
56
* firebasePublish
47
57
* </pre>
48
58
*
49
59
* <ul>
60
+ * <li>{@code publishConfigFilePath} is the path to the configuration file from which to read the
61
+ * list of projects to release. The file format should be consistent with Python's
62
+ * configparser, and the list of projects should be in a section called "modules". If both
63
+ * this, and {@code projectsToPublish} are specified, this property takes precedence. <br>
64
+ * <br>
65
+ * Example config file content:
66
+ * <pre>
67
+ * [release]
68
+ * name = M126
69
+ * ...
70
+ * [modules]
71
+ * firebase-database
72
+ * firebase-common
73
+ * firebase-firestore
74
+ * </pre>
50
75
* <li>{@code projectsToPublish} is a list of projects to release separated by {@code
51
76
* projectsToPublishSeparator}(default: ","), these projects will have their versions depend
52
77
* on the {@code publishMode} parameter.
@@ -73,6 +98,7 @@ public PublishingPlugin() {}
73
98
public void apply (Project project ) {
74
99
String projectNamesToPublish = getPropertyOr (project , "projectsToPublish" , "" );
75
100
String projectsToPublishSeparator = getPropertyOr (project , "projectsToPublishSeparator" , "," );
101
+ String publishConfigFilePath = getPropertyOr (project , "publishConfigFilePath" , "" );
76
102
Mode publishMode = Enum .valueOf (Mode .class , getPropertyOr (project , "publishMode" , "SNAPSHOT" ));
77
103
78
104
Task publishAllToLocal = project .task ("publishAllToLocal" );
@@ -83,8 +109,16 @@ public void apply(Project project) {
83
109
.getGradle ()
84
110
.projectsEvaluated (
85
111
gradle -> {
112
+ List <String > projectsNames ;
113
+ if (!publishConfigFilePath .isEmpty ()) {
114
+ projectsNames = readReleaseConfigFile (publishConfigFilePath );
115
+ } else {
116
+ projectsNames =
117
+ List .of (projectNamesToPublish .split (projectsToPublishSeparator , -1 ));
118
+ }
119
+
86
120
Set <FirebaseLibraryExtension > projectsToPublish =
87
- Arrays .stream (projectNamesToPublish . split ( projectsToPublishSeparator , - 1 ) )
121
+ projectsNames .stream ()
88
122
.filter (name -> !name .isEmpty ())
89
123
.map (
90
124
name ->
@@ -194,6 +228,19 @@ public void apply(Project project) {
194
228
});
195
229
}
196
230
231
+ private List <String > readReleaseConfigFile (String publishConfigurationFilePath ) {
232
+ try (Stream <String > stream = Files .lines (Path .of (publishConfigurationFilePath ))) {
233
+ return stream
234
+ .dropWhile ((line ) -> !line .equals ("[modules]" ))
235
+ // We need to skip the "[modules]" line since it's not dropped
236
+ .skip (1 )
237
+ .collect (Collectors .toList ());
238
+ } catch (IOException e ) {
239
+ throw new IllegalArgumentException (
240
+ "Error reading configuration file " + publishConfigurationFilePath , e );
241
+ }
242
+ }
243
+
197
244
private static String getPropertyOr (Project p , String property , String defaultValue ) {
198
245
Object value = p .findProperty (property );
199
246
if (value != null ) {
0 commit comments