Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
package com.facebook.react.utils

import com.facebook.react.utils.PropertyUtils.DEFAULT_INTERNAL_PUBLISHING_GROUP
import com.facebook.react.utils.PropertyUtils.EXCLUSIVE_ENTEPRISE_REPOSITORY
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY_DEFAULT
import com.facebook.react.utils.PropertyUtils.INTERNAL_PUBLISHING_GROUP
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO
import com.facebook.react.utils.PropertyUtils.INTERNAL_USE_HERMES_NIGHTLY
import com.facebook.react.utils.PropertyUtils.INTERNAL_VERSION_NAME
import com.facebook.react.utils.PropertyUtils.SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY
import com.facebook.react.utils.PropertyUtils.SCOPED_INCLUDE_JITPACK_REPOSITORY
import java.io.File
import java.net.URI
Expand All @@ -28,6 +30,12 @@ internal object DependencyUtils {
* party libraries which are auto-linked.
*/
fun configureRepositories(project: Project) {
val exclusiveEnterpriseRepository = project.rootProject.exclusiveEnterpriseRepository()
if (exclusiveEnterpriseRepository != null) {
project.logger.lifecycle(
"Replacing ALL Maven Repositories with: $exclusiveEnterpriseRepository")
}

project.rootProject.allprojects { eachProject ->
with(eachProject) {
if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) {
Expand All @@ -36,6 +44,16 @@ internal object DependencyUtils {
repo.content { it.excludeGroup("org.webkit") }
}
}

if (exclusiveEnterpriseRepository != null) {
// We remove all previously set repositories and only configure the proxy provided by the
// user.
rootProject.repositories.clear()
mavenRepoFromUrl(exclusiveEnterpriseRepository)
// We return here as we don't want to configure other repositories as well.
return@allprojects
}

// We add the snapshot for users on nightlies.
mavenRepoFromUrl("https://central.sonatype.com/repository/maven-snapshots/") { repo ->
repo.content { it.excludeGroup("org.webkit") }
Expand Down Expand Up @@ -181,4 +199,13 @@ internal object DependencyUtils {
property(INCLUDE_JITPACK_REPOSITORY).toString().toBoolean()
else -> INCLUDE_JITPACK_REPOSITORY_DEFAULT
}

internal fun Project.exclusiveEnterpriseRepository() =
when {
hasProperty(SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY) ->
property(SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY).toString()
hasProperty(EXCLUSIVE_ENTEPRISE_REPOSITORY) ->
property(EXCLUSIVE_ENTEPRISE_REPOSITORY).toString()
else -> null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ object PropertyUtils {
const val INCLUDE_JITPACK_REPOSITORY = "includeJitpackRepository"
const val SCOPED_INCLUDE_JITPACK_REPOSITORY = "react.includeJitpackRepository"

/**
* Public property that allows to configure an enterprise repository proxy as exclusive repository
*/
const val EXCLUSIVE_ENTEPRISE_REPOSITORY = "exclusiveEnterpriseRepository"
const val SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY = "react.exclusiveEnterpriseRepository"

/** By default we include JitPack to avoid breaking user builds */
internal const val INCLUDE_JITPACK_REPOSITORY_DEFAULT = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.facebook.react.utils
import com.facebook.react.tests.createProject
import com.facebook.react.utils.DependencyUtils.configureDependencies
import com.facebook.react.utils.DependencyUtils.configureRepositories
import com.facebook.react.utils.DependencyUtils.exclusiveEnterpriseRepository
import com.facebook.react.utils.DependencyUtils.getDependencySubstitutions
import com.facebook.react.utils.DependencyUtils.mavenRepoFromURI
import com.facebook.react.utils.DependencyUtils.mavenRepoFromUrl
Expand Down Expand Up @@ -99,6 +100,24 @@ class DependencyUtilsTest {
.isNotNull()
}

@Test
fun configureRepositories_withExclusiveEnterpriseRepository_replacesAllRepositories() {
val repositoryURI = URI.create("https://maven.myfabolousorganization.it")

val project = createProject()
project.rootProject.extensions.extraProperties.set(
"exclusiveEnterpriseRepository", repositoryURI.toString())

configureRepositories(project)

assertThat(project.repositories).hasSize(1)
assertThat(
project.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
.isNotNull()
}

@Test
fun configureRepositories_withIncludeJitpackRepositoryFalse_doesNotContainJitPack() {
val repositoryURI = URI.create("https://www.jitpack.io")
Expand Down Expand Up @@ -470,7 +489,7 @@ class DependencyUtilsTest {
@Test
fun shouldAddJitPack_withUnscopedProperty() {
val project = createProject(tempFolder.root)
project.extensions.extraProperties.set("react.includeJitpackRepository", "false")
project.extensions.extraProperties.set("includeJitpackRepository", "false")
assertThat(project.shouldAddJitPack()).isFalse()
}

Expand All @@ -479,4 +498,28 @@ class DependencyUtilsTest {
val project = createProject(tempFolder.root)
assertThat(project.shouldAddJitPack()).isTrue()
}

@Test
fun exclusiveEnterpriseRepository_withScopedProperty() {
val project = createProject(tempFolder.root)
project.extensions.extraProperties.set(
"react.exclusiveEnterpriseRepository", "https://maven.myfabolousorganization.it")
assertThat(project.exclusiveEnterpriseRepository())
.isEqualTo("https://maven.myfabolousorganization.it")
}

@Test
fun exclusiveEnterpriseRepository_withUnscopedProperty() {
val project = createProject(tempFolder.root)
project.extensions.extraProperties.set(
"exclusiveEnterpriseRepository", "https://maven.myfabolousorganization.it")
assertThat(project.exclusiveEnterpriseRepository())
.isEqualTo("https://maven.myfabolousorganization.it")
}

@Test
fun exclusiveEnterpriseRepository_defaultIsTrue() {
val project = createProject(tempFolder.root)
assertThat(project.exclusiveEnterpriseRepository()).isNull()
}
}
Loading