<commit_before>package sbt

	import Load._
	import Project._
	import Scoped._
	import Keys._
	import Configurations.Runtime
	import java.io.File
	import org.apache.ivy.core.module.{descriptor, id}
	import descriptor.ModuleDescriptor, id.ModuleRevisionId

object GlobalPlugin
{
		// constructs a sequence of settings that may be appended to a project's settings to
		//  statically add the global plugin as a classpath dependency.
		//  static here meaning that the relevant tasks for the global plugin have already been evaluated
	def inject(gp: GlobalPluginData): Seq[Setting[_]] =
		Seq[Setting[_]](
			projectDescriptors ~= { _ ++ gp.descriptors },
			projectDependencies ++= gp.projectID +: gp.dependencies,
			internalDependencyClasspath in Runtime ~= { prev => (prev ++ gp.internalClasspath).distinct }
		)
	
	def build(base: File, s: State, config: LoadBuildConfiguration): (BuildStructure, State) =
	{
		val globalConfig = config.copy(injectSettings = config.injectSettings.copy(global = config.injectSettings.global ++ globalPluginSettings))
		val (eval, structure) = Load(base, s, globalConfig)
		val session = Load.initialSession(structure, eval)
		(structure, Project.setProject(session, structure, s))
	}
	def load(base: File, s: State, config: LoadBuildConfiguration): GlobalPlugin =
	{
		val (structure, state) = build(base, s, config)
		val data = extract(state, structure)
		GlobalPlugin(data, structure, inject(data), base)
	}
	def extract(state: State, structure: BuildStructure): GlobalPluginData =
	{
		import structure.{data, root, rootProject}
		val p: Scope = Scope.GlobalScope in ProjectRef(root, rootProject(root))
		val taskInit = (projectID, projectDependencies, projectDescriptors, fullClasspath in Runtime, internalDependencyClasspath in Runtime, exportedProducts in Runtime, ivyModule) map {
			(pid, pdeps, pdescs, cp, intcp, prods, mod) =>
				val depMap = pdescs + mod.dependencyMapping(log(state))
				GlobalPluginData(pid, pdeps, depMap, cp, prods ++ intcp)
		}
		val task = taskInit mapReferenced Project.mapScope(Scope replaceThis p) evaluate data
		evaluate(state, structure, task)
	}
	def evaluate[T](state: State, structure: BuildStructure, t: Task[T]): T =
	{
			import EvaluateTask._
		withStreams(structure) { str =>
			val nv = nodeView(state, str)
			processResult(runTask(t, str, structure.index.triggers)(nv), log(state))
		}
	}
	private[this] def log(s: State) = CommandSupport.logger(s)
	val globalPluginSettings = inScope(Scope.GlobalScope in LocalRootProject)(Seq(
		organization := "org.scala-tools.sbt",
		onLoadMessage <<= Keys.baseDirectory("Loading global plugins from " + _),
		name := "global-plugin",
		sbtPlugin := true,
		version := "0.0"
	))
}
final case class GlobalPluginData(projectID: ModuleID, dependencies: Seq[ModuleID], descriptors: Map[ModuleRevisionId, ModuleDescriptor], fullClasspath: Classpath, internalClasspath: Classpath)
final case class GlobalPlugin(data: GlobalPluginData, structure: BuildStructure, inject: Seq[Setting[_]], base: File)
<commit_msg>Add custom resolvers from global plugin project to project/.  Fixes #177.<commit_after>package sbt

	import Load._
	import Project._
	import Scoped._
	import Keys._
	import Configurations.Runtime
	import java.io.File
	import org.apache.ivy.core.module.{descriptor, id}
	import descriptor.ModuleDescriptor, id.ModuleRevisionId

object GlobalPlugin
{
		// constructs a sequence of settings that may be appended to a project's settings to
		//  statically add the global plugin as a classpath dependency.
		//  static here meaning that the relevant tasks for the global plugin have already been evaluated
	def inject(gp: GlobalPluginData): Seq[Setting[_]] =
		Seq[Setting[_]](
			projectDescriptors ~= { _ ++ gp.descriptors },
			projectDependencies ++= gp.projectID +: gp.dependencies,
			resolvers <<= resolvers { rs => (rs ++ gp.resolvers).distinct },
			internalDependencyClasspath in Runtime ~= { prev => (prev ++ gp.internalClasspath).distinct }
		)
	
	def build(base: File, s: State, config: LoadBuildConfiguration): (BuildStructure, State) =
	{
		val globalConfig = config.copy(injectSettings = config.injectSettings.copy(global = config.injectSettings.global ++ globalPluginSettings))
		val (eval, structure) = Load(base, s, globalConfig)
		val session = Load.initialSession(structure, eval)
		(structure, Project.setProject(session, structure, s))
	}
	def load(base: File, s: State, config: LoadBuildConfiguration): GlobalPlugin =
	{
		val (structure, state) = build(base, s, config)
		val data = extract(state, structure)
		GlobalPlugin(data, structure, inject(data), base)
	}
	def extract(state: State, structure: BuildStructure): GlobalPluginData =
	{
		import structure.{data, root, rootProject}
		val p: Scope = Scope.GlobalScope in ProjectRef(root, rootProject(root))
		val taskInit = (projectID, projectDependencies, projectDescriptors, resolvers, fullClasspath in Runtime, internalDependencyClasspath in Runtime, exportedProducts in Runtime, ivyModule) map {
			(pid, pdeps, pdescs, rs, cp, intcp, prods, mod) =>
				val depMap = pdescs + mod.dependencyMapping(log(state))
				GlobalPluginData(pid, pdeps, depMap, rs, cp, prods ++ intcp)
		}
		val task = taskInit mapReferenced Project.mapScope(Scope replaceThis p) evaluate data
		evaluate(state, structure, task)
	}
	def evaluate[T](state: State, structure: BuildStructure, t: Task[T]): T =
	{
			import EvaluateTask._
		withStreams(structure) { str =>
			val nv = nodeView(state, str)
			processResult(runTask(t, str, structure.index.triggers)(nv), log(state))
		}
	}
	private[this] def log(s: State) = CommandSupport.logger(s)
	val globalPluginSettings = inScope(Scope.GlobalScope in LocalRootProject)(Seq(
		organization := "org.scala-tools.sbt",
		onLoadMessage <<= Keys.baseDirectory("Loading global plugins from " + _),
		name := "global-plugin",
		sbtPlugin := true,
		version := "0.0"
	))
}
final case class GlobalPluginData(projectID: ModuleID, dependencies: Seq[ModuleID], descriptors: Map[ModuleRevisionId, ModuleDescriptor], resolvers: Seq[Resolver], fullClasspath: Classpath, internalClasspath: Classpath)
final case class GlobalPlugin(data: GlobalPluginData, structure: BuildStructure, inject: Seq[Setting[_]], base: File)

{'fraction_non_alphanumeric': 0.11178829190056135, 'fraction_numerical': 0.0011226944667201283, 'mean_word_length': 5.305358948432761, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6055002', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1824, 'n_words': 534}