Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove unnecessary parameter from configureRepositories #48596

Closed
wants to merge 2 commits into from
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 @@ -67,7 +67,7 @@ class ReactPlugin : Plugin<Project> {
val versionString = versionAndGroupStrings.first
val groupString = versionAndGroupStrings.second
configureDependencies(project, versionString, groupString)
configureRepositories(project, reactNativeDir)
configureRepositories(project)
}

configureReactNativeNdk(project, extension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
package com.facebook.react.utils

import com.facebook.react.utils.PropertyUtils.DEFAULT_INTERNAL_PUBLISHING_GROUP
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_INCLUDE_JITPACK_REPOSITORY
import java.io.File
import java.net.URI
import java.util.*
Expand All @@ -24,7 +27,7 @@ internal object DependencyUtils {
* This method takes care of configuring the repositories{} block for both the app and all the 3rd
* party libraries which are auto-linked.
*/
fun configureRepositories(project: Project, reactNativeDir: File) {
fun configureRepositories(project: Project) {
project.rootProject.allprojects { eachProject ->
with(eachProject) {
if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) {
Expand Down Expand Up @@ -55,12 +58,14 @@ internal object DependencyUtils {
it.excludeGroup("com.facebook.react")
}
}
mavenRepoFromUrl("https://www.jitpack.io") { repo ->
repo.content {
// We don't want to fetch JSC or React from JitPack
it.excludeGroup("org.webkit")
it.excludeGroup("io.github.react-native-community")
it.excludeGroup("com.facebook.react")
if (shouldAddJitPack()) {
mavenRepoFromUrl("https://www.jitpack.io") { repo ->
repo.content { content ->
// We don't want to fetch JSC or React from JitPack
content.excludeGroup("org.webkit")
content.excludeGroup("io.github.react-native-community")
content.excludeGroup("com.facebook.react")
}
}
}
}
Expand Down Expand Up @@ -167,4 +172,13 @@ internal object DependencyUtils {
it.url = uri
action(it)
}

internal fun Project.shouldAddJitPack() =
when {
hasProperty(SCOPED_INCLUDE_JITPACK_REPOSITORY) ->
property(SCOPED_INCLUDE_JITPACK_REPOSITORY).toString().toBoolean()
hasProperty(INCLUDE_JITPACK_REPOSITORY) ->
property(INCLUDE_JITPACK_REPOSITORY).toString().toBoolean()
else -> INCLUDE_JITPACK_REPOSITORY_DEFAULT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ object PropertyUtils {
const val REACT_NATIVE_ARCHITECTURES = "reactNativeArchitectures"
const val SCOPED_REACT_NATIVE_ARCHITECTURES = "react.nativeArchitectures"

/** Public property that allows to control whether the JitPack repository is included or not */
const val INCLUDE_JITPACK_REPOSITORY = "includeJitpackRepository"
const val SCOPED_INCLUDE_JITPACK_REPOSITORY = "react.includeJitpackRepository"

/** By default we include JitPack till React Native 0.80 where this is going to become false */
internal const val INCLUDE_JITPACK_REPOSITORY_DEFAULT = true

/**
* Internal Property that acts as a killswitch to configure the JDK version and align it for app
* and all the libraries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.facebook.react.utils.DependencyUtils.getDependencySubstitutions
import com.facebook.react.utils.DependencyUtils.mavenRepoFromURI
import com.facebook.react.utils.DependencyUtils.mavenRepoFromUrl
import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
import com.facebook.react.utils.DependencyUtils.shouldAddJitPack
import java.net.URI
import org.assertj.core.api.Assertions.assertThat
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
Expand All @@ -33,7 +34,7 @@ class DependencyUtilsTest {
val project = createProject()
project.extensions.extraProperties.set("react.internal.mavenLocalRepo", localMaven.absolutePath)

configureRepositories(project, tempFolder.root)
configureRepositories(project)

assertThat(
project.repositories.firstOrNull {
Expand All @@ -47,7 +48,7 @@ class DependencyUtilsTest {
val repositoryURI = URI.create("https://oss.sonatype.org/content/repositories/snapshots/")
val project = createProject()

configureRepositories(project, tempFolder.root)
configureRepositories(project)

assertThat(
project.repositories.firstOrNull {
Expand All @@ -61,7 +62,7 @@ class DependencyUtilsTest {
val repositoryURI = URI.create("https://repo.maven.apache.org/maven2/")
val project = createProject()

configureRepositories(project, tempFolder.root)
configureRepositories(project)

assertThat(
project.repositories.firstOrNull {
Expand All @@ -75,7 +76,7 @@ class DependencyUtilsTest {
val repositoryURI = URI.create("https://dl.google.com/dl/android/maven2/")
val project = createProject()

configureRepositories(project, tempFolder.root)
configureRepositories(project)

assertThat(
project.repositories.firstOrNull {
Expand All @@ -89,7 +90,61 @@ class DependencyUtilsTest {
val repositoryURI = URI.create("https://www.jitpack.io")
val project = createProject()

configureRepositories(project, tempFolder.root)
configureRepositories(project)

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

@Test
fun configureRepositories_withIncludeJitpackRepositoryFalse_doesNotContainJitPack() {
val repositoryURI = URI.create("https://www.jitpack.io")
var project = createProject()
project.extensions.extraProperties.set("includeJitpackRepository", "false")

configureRepositories(project)

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

// We test both with scoped and unscoped property
project = createProject()
project.extensions.extraProperties.set("react.includeJitpackRepository", "false")

configureRepositories(project)

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

@Test
fun configureRepositories_withincludeJitpackRepositoryTrue_containJitPack() {
val repositoryURI = URI.create("https://www.jitpack.io")
var project = createProject()
project.extensions.extraProperties.set("includeJitpackRepository", "true")

configureRepositories(project)

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

// We test both with scoped and unscoped property
project = createProject()
project.extensions.extraProperties.set("react.includeJitpackRepository", "true")

configureRepositories(project)

assertThat(
project.repositories.firstOrNull {
Expand All @@ -106,7 +161,7 @@ class DependencyUtilsTest {
val project = createProject()
project.extensions.extraProperties.set("react.internal.mavenLocalRepo", localMaven.absolutePath)

configureRepositories(project, tempFolder.root)
configureRepositories(project)

val indexOfLocalRepo =
project.repositories.indexOfFirst {
Expand All @@ -125,7 +180,7 @@ class DependencyUtilsTest {
val mavenCentralURI = URI.create("https://repo.maven.apache.org/maven2/")
val project = createProject()

configureRepositories(project, tempFolder.root)
configureRepositories(project)

val indexOfSnapshotRepo =
project.repositories.indexOfFirst {
Expand All @@ -145,7 +200,7 @@ class DependencyUtilsTest {
val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build()
val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build()

configureRepositories(appProject, tempFolder.root)
configureRepositories(appProject)

assertThat(
appProject.repositories.firstOrNull {
Expand All @@ -171,7 +226,7 @@ class DependencyUtilsTest {
repo.content { content -> content.excludeGroup("com.facebook.react") }
}

configureRepositories(appProject, tempFolder.root)
configureRepositories(appProject)

// We need to make sure we have Maven Central defined twice, one by the library,
// and another is the override by RNGP.
Expand Down Expand Up @@ -404,4 +459,24 @@ class DependencyUtilsTest {

assertThat(mavenRepo.url).isEqualTo(repoFolder.toURI())
}

@Test
fun shouldAddJitPack_withScopedProperty() {
val project = createProject(tempFolder.root)
project.extensions.extraProperties.set("react.includeJitpackRepository", "false")
assertThat(project.shouldAddJitPack()).isFalse()
}

@Test
fun shouldAddJitPack_withUnscopedProperty() {
val project = createProject(tempFolder.root)
project.extensions.extraProperties.set("react.includeJitpackRepository", "false")
assertThat(project.shouldAddJitPack()).isFalse()
}

@Test
fun shouldAddJitPack_defaultIsTrue() {
val project = createProject(tempFolder.root)
assertThat(project.shouldAddJitPack()).isTrue()
}
}
Loading