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

Extract jars for dependencies with -internal configurations #65

Merged
merged 2 commits into from
Jul 31, 2024
Merged
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 @@ -9,12 +9,13 @@ import sbt.{Def, _}
* @author Nikolay Obedin
* @since 4/10/15.
*/
class RepositoryExtractor(projects: Seq[ProjectRef],
updateReports: ProjectRef => UpdateReportAdapter,
updateClassifiersReports: Option[ProjectRef => UpdateReportAdapter],
classpathTypes: ProjectRef => Set[String],
dependencyConfigurations: ProjectRef => Seq[sbt.Configuration])
extends ModulesOps {
class RepositoryExtractor(
projects: Seq[ProjectRef],
updateReports: ProjectRef => UpdateReportAdapter,
updateClassifiersReports: Option[ProjectRef => UpdateReportAdapter],
classpathTypes: ProjectRef => Set[String],
projectToConfigurationsName: Map[ProjectRef, Seq[String]]
) extends ModulesOps {

private[extractors] def extract: RepositoryData = {
val moduleReports = fixModulesIdsToSupportClassifiers(allModulesWithDocs)
Expand Down Expand Up @@ -56,7 +57,7 @@ class RepositoryExtractor(projects: Seq[ProjectRef],
}

private def getModulesForProject(projectRef: ProjectRef, updateReportFn: ProjectRef => UpdateReportAdapter): Seq[ModuleReportAdapter] =
dependencyConfigurations(projectRef).map(_.name).flatMap(updateReportFn(projectRef).modulesFrom).filter(_.artifacts.nonEmpty)
projectToConfigurationsName(projectRef).flatMap(updateReportFn(projectRef).modulesFrom).filter(_.artifacts.nonEmpty)

private def createModuleData(moduleId: ModuleIdentifier, moduleReports: Seq[ModuleReportAdapter]): ModuleData = {
val allArtifacts = moduleReports.flatMap(_.artifacts)
Expand Down Expand Up @@ -90,8 +91,13 @@ object RepositoryExtractor extends SbtStateOps with TaskOps {
private def extractRepositoryData(state: State, options: Options, acceptedProjects: Seq[ProjectRef]): Task[RepositoryData] = {
def classpathTypes(projectRef: ProjectRef) =
Keys.classpathTypes.in(projectRef).getOrElse(state, Set.empty)
def dependencyConfigurations(projectRef: ProjectRef) =
StructureKeys.dependencyConfigurations.in(projectRef).get(state)

val dependencyConfigurations = StructureKeys.dependencyConfigurations
.forAllProjects(state, acceptedProjects)
.toMap

val classpathConfigurationTask = sbt.Keys.classpathConfiguration
.forAllProjectsAndConfigurations(state, acceptedProjects, dependencyConfigurations)

val updateAllTask: Task[Map[ProjectRef, UpdateReportAdapter]] =
Keys.update
Expand All @@ -106,13 +112,27 @@ object RepositoryExtractor extends SbtStateOps with TaskOps {
for {
updateReports <- updateAllTask
updateClassifiersReports <- updateAllClassifiersTask
classpathConfiguration <- classpathConfigurationTask
} yield {

def extractClasspathConfigs(projectToConfigTuple: Seq[((ProjectRef, Configuration), Configuration)]): Seq[Configuration] =
projectToConfigTuple.map { case ((_, _), c2) => c2 }

val projectToClasspathConfig = classpathConfiguration.groupBy(_._1._1)
.mapValues(extractClasspathConfigs)

val classpathAndDependencyConfigs = projectToClasspathConfig.map { case (project, configs) =>
val projectDependencyConfigs = dependencyConfigurations.getOrElse(project, Seq.empty)
val uniqueConfigNames = (projectDependencyConfigs ++ configs).groupBy(_.name).keys.toSeq
project -> uniqueConfigNames
}

val extractor = new RepositoryExtractor(
acceptedProjects,
updateReports.apply,
updateClassifiersReports.map(_.apply),
classpathTypes,
dependencyConfigurations
classpathAndDependencyConfigs
)
extractor.extract
}
Expand Down
10 changes: 10 additions & 0 deletions extractor/src/main/scala/org/jetbrains/sbt/operations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ trait SbtStateOps {
val tasks = configurations.flatMap(c => key.in(c).get(structure(state).data).map(_.map(it => (c, it))))
std.TaskExtra.joinTasks(tasks).join.map(_.toMap)
}

def forAllProjectsAndConfigurations(state: State, projects: Seq[ProjectRef], configurations: Map[ProjectRef, Seq[sbt.Configuration]]): Task[Seq[((ProjectRef, sbt.Configuration), T)]] = {
val tasks = for {
project <- projects
config <- configurations.getOrElse(project, Seq.empty)
task <- key.in(project, config).get(structure(state).data).map(_.map(it => ((project, config), it)))
} yield task

std.TaskExtra.joinTasks(tasks).join
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions extractor/src/test/data/1.9/internal_config/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sbt.librarymanagement.Configurations.{CompileInternal, RuntimeInternal, TestInternal}

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.3.3"

libraryDependencies ++= Seq(
"junit" % "junit" % "4.13.2" % TestInternal,
"org.scalacheck" %% "scalacheck" % "1.17.1" % CompileInternal ,
"com.typesafe" % "config" % "1.4.3" % RuntimeInternal,
)
Loading
Loading