Bug 1842694 - Refactor GithubDetailsTask into a plugin using composite build
[gecko.git] / mobile / android / focus-android / settings.gradle
blobfe26ed2a369b62dec9a96a93fec6eb77cdc5c94c
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 pluginManagement {
6     includeBuild("../android-components/plugins/publicsuffixlist")
7     includeBuild("../android-components/plugins/dependencies")
8     includeBuild("../android-components/plugins/config")
9     includeBuild("../android-components/plugins/github")
10     includeBuild("./plugins/focusdependencies")
13 plugins {
14     id "mozac.ConfigPlugin"
15     id 'mozac.DependenciesPlugin'
16     id 'mozac.GitHubPlugin'
17     id 'FocusDependenciesPlugin'
20 apply from: file('../shared-settings.gradle')
22 include ':app'
23 include ':service-telemetry'
25 gradle.projectsLoaded { ->
26     // Disables A-C tests and lint when building Focus.
27     gradle.allprojects { project ->
28         if (project.projectDir.absolutePath.contains("/android-components/")) {
29             project.tasks.withType(Test) {
30                 enabled = false
31             }
32             project.tasks.whenTaskAdded { task ->
33                 if (task.name.contains("lint")) {
34                     task.enabled = false
35                 }
36             }
37         }
39         def appServicesSrcDir = null
40         if (gradle.hasProperty('localProperties.autoPublish.application-services.dir')) {
41           appServicesSrcDir = gradle.getProperty('localProperties.autoPublish.application-services.dir')
42         } else if (gradle.hasProperty('localProperties.branchBuild.application-services.dir')) {
43           appServicesSrcDir = gradle.getProperty('localProperties.branchBuild.application-services.dir')
44         }
45         if (appServicesSrcDir) {
46             if (appServicesSrcDir.startsWith("/")) {
47                 apply from: "${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
48             } else {
49                 apply from: "${rootProject.projectDir}/${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
50             }
51         }
52     }
55 def log(message) {
56     logger.lifecycle("[settings] ${message}")
59 def runCmd(cmd, workingDir, successMessage, captureStdout=true) {
60     def proc = cmd.execute(null, new File(workingDir))
61     def standardOutput = captureStdout ? new ByteArrayOutputStream() : System.out
62     proc.consumeProcessOutput(standardOutput, System.err)
63     proc.waitFor()
65     if (proc.exitValue() != 0) {
66         throw new GradleException("Process '${cmd}' finished with non-zero exit value ${proc.exitValue()}");
67     } else {
68         log(successMessage)
69     }
70     return captureStdout ? standardOutput : null
73 //////////////////////////////////////////////////////////////////////////
74 // Local development enhancements
75 //////////////////////////////////////////////////////////////////////////
77 Properties localProperties = null
78 String settingAppServicesPath = "autoPublish.application-services.dir"
79 String settingGleanPath = "autoPublish.glean.dir"
81 if (file('local.properties').canRead()) {
82     localProperties = new Properties()
83     localProperties.load(file('local.properties').newDataInputStream())
84     log('Loaded local.properties')
85 } else {
86     log('Missing local.properties; see https://github.com/mozilla-mobile/focus-android#localproperties-helpers for instructions.')
89 if (localProperties != null) {
90     localProperties.each { prop ->
91         gradle.ext.set("localProperties.${prop.key}", prop.value)
92     }
94     String appServicesLocalPath = localProperties.getProperty(settingAppServicesPath)
96     if (appServicesLocalPath != null) {
97         log("Enabling automatic publication of application-services from: $appServicesLocalPath")
98         // Windows can't execute .py files directly, so we assume a "manually installed" python,
99         // which comes with a "py" launcher and respects the shebang line to specify the version.
100         def publishAppServicesCmd = [];
101         if (System.properties['os.name'].toLowerCase().contains('windows')) {
102             publishAppServicesCmd << "py";
103         }
104         publishAppServicesCmd << "./automation/publish_to_maven_local_if_modified.py";
105         runCmd(publishAppServicesCmd, appServicesLocalPath, "Published application-services for local development.", false)
106     } else {
107         log("Disabled auto-publication of application-services. Enable it by settings '$settingAppServicesPath' in local.properties")
108     }
110     String gleanLocalPath = localProperties.getProperty(settingGleanPath)
112     if (gleanLocalPath != null) {
113         log("Enabling automatic publication of Glean from: $gleanLocalPath")
114         // As above, hacks to execute .py files on Windows.
115         def publishGleanCmd = [];
116         if (System.properties['os.name'].toLowerCase().contains('windows')) {
117             publishGleanCmd << "py";
118         }
119         publishGleanCmd << "./build-scripts/publish_to_maven_local_if_modified.py";
120         runCmd(publishGleanCmd, gleanLocalPath, "Published Glean for local development.", false)
121     } else {
122         log("Disabled auto-publication of Glean. Enable it by settings '$settingGleanPath' in local.properties")
123     }