1616
1717import com .google .firebase .gradle .plugins .FirebaseLibraryExtension ;
1818import 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 ;
2023import java .util .Set ;
2124import java .util .stream .Collectors ;
25+ import java .util .stream .Stream ;
2226import org .gradle .api .Plugin ;
2327import org .gradle .api .Project ;
2428import org .gradle .api .Task ;
4145 * <p><strong>Prepare a release</strong>
4246 *
4347 * <pre>
48+ * ./gradlew -PpublishConfigFilePath=release.cfg
49+ * -PpublishMode=(RELEASE|SNAPSHOT) \
50+ * firebasePublish
51+ * </pre>
52+ *
53+ * <pre>
4454 * ./gradlew -PprojectsToPublish="firebase-inappmessaging,firebase-inappmessaging-display"\
4555 * -PpublishMode=(RELEASE|SNAPSHOT) \
4656 * firebasePublish
4757 * </pre>
4858 *
4959 * <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>
5075 * <li>{@code projectsToPublish} is a list of projects to release separated by {@code
5176 * projectsToPublishSeparator}(default: ","), these projects will have their versions depend
5277 * on the {@code publishMode} parameter.
@@ -73,6 +98,7 @@ public PublishingPlugin() {}
7398 public void apply (Project project ) {
7499 String projectNamesToPublish = getPropertyOr (project , "projectsToPublish" , "" );
75100 String projectsToPublishSeparator = getPropertyOr (project , "projectsToPublishSeparator" , "," );
101+ String publishConfigFilePath = getPropertyOr (project , "publishConfigFilePath" , "" );
76102 Mode publishMode = Enum .valueOf (Mode .class , getPropertyOr (project , "publishMode" , "SNAPSHOT" ));
77103
78104 Task publishAllToLocal = project .task ("publishAllToLocal" );
@@ -83,8 +109,16 @@ public void apply(Project project) {
83109 .getGradle ()
84110 .projectsEvaluated (
85111 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+
86120 Set <FirebaseLibraryExtension > projectsToPublish =
87- Arrays .stream (projectNamesToPublish . split ( projectsToPublishSeparator , - 1 ) )
121+ projectsNames .stream ()
88122 .filter (name -> !name .isEmpty ())
89123 .map (
90124 name ->
@@ -194,6 +228,19 @@ public void apply(Project project) {
194228 });
195229 }
196230
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+
197244 private static String getPropertyOr (Project p , String property , String defaultValue ) {
198245 Object value = p .findProperty (property );
199246 if (value != null ) {
0 commit comments