Skip to content

Commit

Permalink
Merge pull request #64 from JetBrains/remove-transitive-deps-option
Browse files Browse the repository at this point in the history
remove insertProjectTransitiveDependencies settings
  • Loading branch information
azdrojowa123 authored Jul 4, 2024
2 parents a654990 + 738f320 commit 0bacc44
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 95 deletions.
3 changes: 0 additions & 3 deletions extractor/src/main/scala/org/jetbrains/sbt/Options.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ final case class Options(download: Boolean = false,
resolveJavadocClassifiers: Boolean = false,
resolveSbtClassifiers: Boolean = false,
prettyPrint: Boolean = false,
insertProjectTransitiveDependencies: Boolean = true,
separateProdAndTestSources: Boolean = false)

object Options {
Expand All @@ -27,7 +26,6 @@ object Options {
resolveJavadocClassifiers = options.contains(Keys.ResolveJavadocClassifiers),
resolveSbtClassifiers = options.contains(Keys.ResolveSbtClassifiers),
prettyPrint = options.contains(Keys.PrettyPrint),
insertProjectTransitiveDependencies = options.contains(Keys.InsertProjectTransitiveDependencies),
separateProdAndTestSources = options.contains(Keys.SeparateProdAndTestSources)
)

Expand All @@ -37,7 +35,6 @@ object Options {
val ResolveJavadocClassifiers = "resolveJavadocClassifiers"
val ResolveSbtClassifiers = "resolveSbtClassifiers"
val PrettyPrint = "prettyPrint"
val InsertProjectTransitiveDependencies = "insertProjectTransitiveDependencies"
val SeparateProdAndTestSources = "separateProdAndTestSources"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ import scala.language.postfixOps
* @since 4/10/15.
*/

class DependenciesExtractor(projectRef: ProjectRef,
buildDependencies: BuildDependencies,
unmanagedClasspath: SbtConfiguration => Keys.Classpath,
class DependenciesExtractor(unmanagedClasspath: SbtConfiguration => Keys.Classpath,
externalDependencyClasspath: Option[SbtConfiguration => Keys.Classpath],
dependencyConfigurations: Seq[SbtConfiguration],
testConfigurations: Seq[SbtConfiguration],
sourceConfigurations: Seq[SbtConfiguration],
insertProjectTransitiveDependencies: Boolean,
separateProdTestSources: Boolean,
projectToConfigurations: Map[ProjectType, Seq[Configuration]])
extends ModulesOps {
Expand All @@ -31,11 +28,9 @@ class DependenciesExtractor(projectRef: ProjectRef,
private lazy val sourceConfigurationsNames = sourceConfigurations.map(_.name)

private[extractors] def extract: DependencyData = {
val projectDependencies = (separateProdTestSources, insertProjectTransitiveDependencies) match {
case (true, _) => separatedSourcesProjectDependencies
case (_, true) => transitiveProjectDependencies
case _ => nonTransitiveProjectDependencies
}
val projectDependencies =
if (separateProdTestSources) separatedSourcesProjectDependencies
else transitiveProjectDependencies
DependencyData(projectDependencies, moduleDependencies, jarDependencies)
}

Expand All @@ -62,14 +57,6 @@ class DependenciesExtractor(projectRef: ProjectRef,
}
}

private def nonTransitiveProjectDependencies: Dependencies[ProjectDependencyData] = {
val dependencies = buildDependencies.classpath.getOrElse(projectRef, Seq.empty).map { it =>
val configurations = it.configuration.map(Configuration.fromString).getOrElse(Seq.empty)
ProjectDependencyData(it.project.id, Some(it.project.build), configurations)
}
Dependencies(dependencies, Seq.empty)
}

private def moduleDependencies: Dependencies[ModuleDependencyData] = {
val allModuleDependencies = forAllConfigurations(modulesIn)
if (separateProdTestSources) {
Expand Down Expand Up @@ -289,7 +276,7 @@ object DependenciesExtractor extends SbtStateOps with TaskOps {
externalDependencyClasspathOpt <- externalDependencyClasspathTask
classpathConfiguration <- classpathConfigurationTask
} yield {
val projectToTransitiveDependencies =
val projectDependencies =
if (options.separateProdAndTestSources) {
getTransitiveDependenciesForProjectProdTestSources(
projectRef,
Expand All @@ -298,29 +285,24 @@ object DependenciesExtractor extends SbtStateOps with TaskOps {
settings,
buildDependencies
)
} else if (options.insertProjectTransitiveDependencies) {
} else {
getTransitiveDependenciesForProject(
projectRef,
projectToConfigurations,
classpathConfiguration,
settings,
buildDependencies
)
} else {
Map.empty[ProjectType, Seq[Configuration]]
}

val extractor = new DependenciesExtractor(
projectRef,
buildDependencies,
unmanagedClasspath.getOrElse(_, Nil),
externalDependencyClasspathOpt.map(it => it.getOrElse(_, Nil)),
dependencyConfigurations,
testConfigurations,
sourceConfigurations,
options.insertProjectTransitiveDependencies,
options.separateProdAndTestSources,
projectToTransitiveDependencies
projectDependencies
)
extractor.extract
}).value
Expand Down
2 changes: 1 addition & 1 deletion extractor/src/test/data/0.13/multiple/structure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<projects>
<forTest/>
<forProduction>
<project buildURI="$URI_BASE" configurations="">bar</project>
<project buildURI="$URI_BASE" configurations="compile">bar</project>
</forProduction>
</projects>
<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.jetbrains.sbt.structure._
import org.scalatest.freespec.AnyFreeSpecLike
import org.scalatest.matchers.must.Matchers.{contain, convertToAnyMustWrapper}
import sbt.{Configuration => SbtConfiguration, Attributed, globFilter => _, _}
import sbt.jetbrains.apiAdapter

import scala.collection.Seq

Expand All @@ -16,22 +15,11 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
Seq("project-1", "project-2").map(ProjectRef(file("/tmp/test-project"), _))
val emptyClasspath: sbt.Configuration => Keys.Classpath = _ => Nil
val CustomConf = config("custom-conf").extend(sbt.Test)
val buildDependencies = apiAdapter.buildDependencies(
Map(
projects.head -> Seq(
ResolvedClasspathDependency(projects(1), Some("compile"))
),
projects(1) -> Seq.empty
),
Map.empty
)

"DependenciesExtractor for managed and unmanaged dependencies" - {

"always extract unmanaged dependencies" in {
val actual = new DependenciesExtractor(
projects.head,
buildDependencies = buildDependencies,
unmanagedClasspath = Map(
sbt.Compile -> Seq(
attributed(file("foo.jar")),
Expand All @@ -43,7 +31,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
dependencyConfigurations = Seq(sbt.Compile, sbt.Test),
testConfigurations = Seq(sbt.Test),
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Runtime, Configuration.Test)
Expand Down Expand Up @@ -76,8 +63,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
val moduleId = (name: String) => ModuleID("com.example", name, "SNAPSHOT")

val actual = new DependenciesExtractor(
projects.head,
buildDependencies = buildDependencies,
unmanagedClasspath = emptyClasspath,
externalDependencyClasspath = Some(
Map(
Expand All @@ -93,7 +78,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
dependencyConfigurations = Seq(sbt.Compile, sbt.Test),
testConfigurations = Seq(sbt.Test),
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Test, Configuration.Runtime)
Expand Down Expand Up @@ -136,8 +120,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
val moduleId = (name: String) => ModuleID("com.example", name, "SNAPSHOT")

val actual = new DependenciesExtractor(
projects.head,
buildDependencies = buildDependencies,
unmanagedClasspath = Map(
sbt.Test -> Seq(attributed(file("foo.jar"))),
CustomConf -> Seq(attributed(file("bar.jar")))
Expand All @@ -155,7 +137,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
dependencyConfigurations = Seq(sbt.Test, CustomConf),
testConfigurations = Seq(sbt.Test, CustomConf),
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Test, Configuration.Runtime)
Expand Down Expand Up @@ -199,8 +180,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
val moduleId = "com.example" % "foo" % "SNAPSHOT"

val actual = new DependenciesExtractor(
projects.head,
buildDependencies = buildDependencies,
unmanagedClasspath = emptyClasspath,
externalDependencyClasspath = Some(
Map(
Expand All @@ -216,7 +195,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
dependencyConfigurations = Seq(sbt.Compile),
testConfigurations = Seq.empty,
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Test, Configuration.Runtime)
Expand Down Expand Up @@ -246,8 +224,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
val moduleId = "com.example" % "foo" % "SNAPSHOT"

val actual = new DependenciesExtractor(
projects.head,
buildDependencies = buildDependencies,
unmanagedClasspath = Map(
sbt.Compile -> Seq(attributed(file("bar.jar"))),
sbt.Test -> Seq(attributed(file("bar.jar"))),
Expand All @@ -269,7 +245,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
dependencyConfigurations = Seq(sbt.Compile, sbt.Test, sbt.Runtime),
testConfigurations = Seq.empty,
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Test, Configuration.Runtime)
Expand Down Expand Up @@ -303,8 +278,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
val moduleId = "com.example" % "foo" % "SNAPSHOT"

val actual = new DependenciesExtractor(
projects.head,
buildDependencies = buildDependencies,
unmanagedClasspath = Map(
sbt.Compile -> Seq(attributed(file("bar.jar"))),
sbt.Test -> Seq(attributed(file("bar.jar")))
Expand All @@ -322,7 +295,6 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {
dependencyConfigurations = Seq(sbt.Compile, sbt.Test),
testConfigurations = Seq.empty,
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Test, Configuration.Runtime)
Expand Down Expand Up @@ -357,14 +329,11 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {

"merge (compile, test, runtime) -> compile in transitive project dependencies to match IDEA scopes" in {
val actual = new DependenciesExtractor(
projects.head,
buildDependencies,
unmanagedClasspath = emptyClasspath,
externalDependencyClasspath = None,
dependencyConfigurations = Seq(sbt.Compile, sbt.Test, sbt.Runtime),
testConfigurations = Nil,
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Test, Configuration.Runtime)
Expand All @@ -384,14 +353,11 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {

"merge (compile, test) -> provided in transitive project dependencies to match IDEA scopes" in {
val actual = new DependenciesExtractor(
projects.head,
buildDependencies,
unmanagedClasspath = emptyClasspath,
externalDependencyClasspath = None,
dependencyConfigurations = Seq(sbt.Compile, sbt.Test, sbt.Runtime),
testConfigurations = Nil,
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration.Test)
Expand All @@ -410,14 +376,11 @@ class DependenciesExtractorSpec extends AnyFreeSpecLike {

"merge (custom test configurations, compile) -> provided in transitive project dependencies to match IDEA scopes" in {
val actual = new DependenciesExtractor(
projects.head,
buildDependencies,
unmanagedClasspath = emptyClasspath,
externalDependencyClasspath = None,
dependencyConfigurations = Seq(sbt.Compile, sbt.Test, sbt.Runtime, CustomConf),
testConfigurations = Seq(sbt.Test, CustomConf),
sourceConfigurations = Seq(sbt.Compile, sbt.Runtime),
insertProjectTransitiveDependencies = true,
separateProdTestSources = false,
projectToConfigurations = Map(
ProductionType(projects(1)) -> Seq(Configuration.Compile, Configuration(CustomConf.name))
Expand Down
Loading

0 comments on commit 0bacc44

Please sign in to comment.