Skip to content

Commit 8e47e54

Browse files
cortinicocipolleschi
authored andcommitted
RNGP - Add support for exclusiveEnterpriseRepository (#52378)
Summary: Pull Request resolved: #52378 This adds a Gradle property called `exclusiveEnterpriseRepository` that users can set in their `android/gradle.properties` as such: ```diff # Use this property to enable or disable the Hermes JS engine. # If set to false, you will be using JSC instead. hermesEnabled=true +exclusiveEnterpriseRepository=https://my.internal.proxy.net/ ``` This will remove all the existing Maven repositories and only use the internal mirror they have. Changelog: [Android] [Added] - RNGP - Add support for `exclusiveEnterpriseRepository` to specify an internal Maven mirror. Reviewed By: mdvacca Differential Revision: D77667573 fbshipit-source-id: 835004d2ae7aa4e250b6f7a88a41918b573f5bd5
1 parent d8b5a55 commit 8e47e54

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
package com.facebook.react.utils
99

1010
import com.facebook.react.utils.PropertyUtils.DEFAULT_INTERNAL_PUBLISHING_GROUP
11+
import com.facebook.react.utils.PropertyUtils.EXCLUSIVE_ENTEPRISE_REPOSITORY
1112
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY
1213
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY_DEFAULT
1314
import com.facebook.react.utils.PropertyUtils.INTERNAL_PUBLISHING_GROUP
1415
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO
1516
import com.facebook.react.utils.PropertyUtils.INTERNAL_USE_HERMES_NIGHTLY
1617
import com.facebook.react.utils.PropertyUtils.INTERNAL_VERSION_NAME
18+
import com.facebook.react.utils.PropertyUtils.SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY
1719
import com.facebook.react.utils.PropertyUtils.SCOPED_INCLUDE_JITPACK_REPOSITORY
1820
import java.io.File
1921
import java.net.URI
@@ -28,6 +30,12 @@ internal object DependencyUtils {
2830
* party libraries which are auto-linked.
2931
*/
3032
fun configureRepositories(project: Project) {
33+
val exclusiveEnterpriseRepository = project.rootProject.exclusiveEnterpriseRepository()
34+
if (exclusiveEnterpriseRepository != null) {
35+
project.logger.lifecycle(
36+
"Replacing ALL Maven Repositories with: $exclusiveEnterpriseRepository")
37+
}
38+
3139
project.rootProject.allprojects { eachProject ->
3240
with(eachProject) {
3341
if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) {
@@ -36,6 +44,16 @@ internal object DependencyUtils {
3644
repo.content { it.excludeGroup("org.webkit") }
3745
}
3846
}
47+
48+
if (exclusiveEnterpriseRepository != null) {
49+
// We remove all previously set repositories and only configure the proxy provided by the
50+
// user.
51+
rootProject.repositories.clear()
52+
mavenRepoFromUrl(exclusiveEnterpriseRepository)
53+
// We return here as we don't want to configure other repositories as well.
54+
return@allprojects
55+
}
56+
3957
// We add the snapshot for users on nightlies.
4058
mavenRepoFromUrl("https://central.sonatype.com/repository/maven-snapshots/") { repo ->
4159
repo.content { it.excludeGroup("org.webkit") }
@@ -181,4 +199,13 @@ internal object DependencyUtils {
181199
property(INCLUDE_JITPACK_REPOSITORY).toString().toBoolean()
182200
else -> INCLUDE_JITPACK_REPOSITORY_DEFAULT
183201
}
202+
203+
internal fun Project.exclusiveEnterpriseRepository() =
204+
when {
205+
hasProperty(SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY) ->
206+
property(SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY).toString()
207+
hasProperty(EXCLUSIVE_ENTEPRISE_REPOSITORY) ->
208+
property(EXCLUSIVE_ENTEPRISE_REPOSITORY).toString()
209+
else -> null
210+
}
184211
}

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PropertyUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ object PropertyUtils {
3030
const val INCLUDE_JITPACK_REPOSITORY = "includeJitpackRepository"
3131
const val SCOPED_INCLUDE_JITPACK_REPOSITORY = "react.includeJitpackRepository"
3232

33+
/**
34+
* Public property that allows to configure an enterprise repository proxy as exclusive repository
35+
*/
36+
const val EXCLUSIVE_ENTEPRISE_REPOSITORY = "exclusiveEnterpriseRepository"
37+
const val SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY = "react.exclusiveEnterpriseRepository"
38+
3339
/** By default we include JitPack to avoid breaking user builds */
3440
internal const val INCLUDE_JITPACK_REPOSITORY_DEFAULT = true
3541

packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package com.facebook.react.utils
1010
import com.facebook.react.tests.createProject
1111
import com.facebook.react.utils.DependencyUtils.configureDependencies
1212
import com.facebook.react.utils.DependencyUtils.configureRepositories
13+
import com.facebook.react.utils.DependencyUtils.exclusiveEnterpriseRepository
1314
import com.facebook.react.utils.DependencyUtils.getDependencySubstitutions
1415
import com.facebook.react.utils.DependencyUtils.mavenRepoFromURI
1516
import com.facebook.react.utils.DependencyUtils.mavenRepoFromUrl
@@ -99,6 +100,24 @@ class DependencyUtilsTest {
99100
.isNotNull()
100101
}
101102

103+
@Test
104+
fun configureRepositories_withExclusiveEnterpriseRepository_replacesAllRepositories() {
105+
val repositoryURI = URI.create("https://maven.myfabolousorganization.it")
106+
107+
val project = createProject()
108+
project.rootProject.extensions.extraProperties.set(
109+
"exclusiveEnterpriseRepository", repositoryURI.toString())
110+
111+
configureRepositories(project)
112+
113+
assertThat(project.repositories).hasSize(1)
114+
assertThat(
115+
project.repositories.firstOrNull {
116+
it is MavenArtifactRepository && it.url == repositoryURI
117+
})
118+
.isNotNull()
119+
}
120+
102121
@Test
103122
fun configureRepositories_withIncludeJitpackRepositoryFalse_doesNotContainJitPack() {
104123
val repositoryURI = URI.create("https://www.jitpack.io")
@@ -470,7 +489,7 @@ class DependencyUtilsTest {
470489
@Test
471490
fun shouldAddJitPack_withUnscopedProperty() {
472491
val project = createProject(tempFolder.root)
473-
project.extensions.extraProperties.set("react.includeJitpackRepository", "false")
492+
project.extensions.extraProperties.set("includeJitpackRepository", "false")
474493
assertThat(project.shouldAddJitPack()).isFalse()
475494
}
476495

@@ -479,4 +498,28 @@ class DependencyUtilsTest {
479498
val project = createProject(tempFolder.root)
480499
assertThat(project.shouldAddJitPack()).isTrue()
481500
}
501+
502+
@Test
503+
fun exclusiveEnterpriseRepository_withScopedProperty() {
504+
val project = createProject(tempFolder.root)
505+
project.extensions.extraProperties.set(
506+
"react.exclusiveEnterpriseRepository", "https://maven.myfabolousorganization.it")
507+
assertThat(project.exclusiveEnterpriseRepository())
508+
.isEqualTo("https://maven.myfabolousorganization.it")
509+
}
510+
511+
@Test
512+
fun exclusiveEnterpriseRepository_withUnscopedProperty() {
513+
val project = createProject(tempFolder.root)
514+
project.extensions.extraProperties.set(
515+
"exclusiveEnterpriseRepository", "https://maven.myfabolousorganization.it")
516+
assertThat(project.exclusiveEnterpriseRepository())
517+
.isEqualTo("https://maven.myfabolousorganization.it")
518+
}
519+
520+
@Test
521+
fun exclusiveEnterpriseRepository_defaultIsTrue() {
522+
val project = createProject(tempFolder.root)
523+
assertThat(project.exclusiveEnterpriseRepository()).isNull()
524+
}
482525
}

0 commit comments

Comments
 (0)