Skip to content

Commit

Permalink
Merge pull request #65 from JetBrains/get-jars-in-internal-configs
Browse files Browse the repository at this point in the history
Extract jars for dependencies with  -internal configurations
  • Loading branch information
azdrojowa123 committed Jul 31, 2024
2 parents 0bacc44 + 1c1908a commit 4de31df
Show file tree
Hide file tree
Showing 6 changed files with 1,912 additions and 13 deletions.
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

0 comments on commit 4de31df

Please sign in to comment.