1
1
package ch .epfl .scala
2
2
3
+ import java .nio .file .Path
4
+ import java .nio .file .Paths
5
+
3
6
import scala .collection .mutable
4
7
import scala .util .Properties
5
8
@@ -26,6 +29,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
26
29
27
30
object autoImport {
28
31
val githubSubmitInputKey : AttributeKey [SubmitInput ] = AttributeKey (" githubSubmitInput" )
32
+ val githubWorkspace : AttributeKey [Path ] = AttributeKey (" githubWorkspace" )
29
33
val githubManifestsKey : AttributeKey [Map [String , githubapi.Manifest ]] = AttributeKey (" githubDependencyManifests" )
30
34
val githubProjectsKey : AttributeKey [Seq [ProjectRef ]] = AttributeKey (" githubProjectRefs" )
31
35
val githubDependencyManifest : TaskKey [Option [githubapi.Manifest ]] = taskKey(
@@ -106,16 +110,20 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
106
110
// updateFull is needed to have information about callers and reconstruct dependency tree
107
111
val reportResult = Keys .updateFull.result.value
108
112
val projectID = Keys .projectID.value
113
+ val root = Paths .get(Keys .loadedBuild.value.root).toAbsolutePath
109
114
val scalaVersion = (Keys .artifactName / Keys .scalaVersion).value
110
115
val scalaBinaryVersion = (Keys .artifactName / Keys .scalaBinaryVersion).value
111
116
val crossVersion = CrossVersion .apply(scalaVersion, scalaBinaryVersion)
112
117
val allDirectDependencies = Keys .allDependencies.value
113
118
val baseDirectory = Keys .baseDirectory.value
114
119
val logger = Keys .streams.value.log
115
- val input = Keys .state.value.get(githubSubmitInputKey)
120
+ val state = Keys .state.value
116
121
117
- val onResolveFailure = input.flatMap(_.onResolveFailure)
118
- val ignoredConfigs = input.toSeq.flatMap(_.ignoredConfigs).toSet
122
+ val inputOpt = state.get(githubSubmitInputKey)
123
+ val workspaceOpt = state.get(githubWorkspace)
124
+
125
+ val onResolveFailure = inputOpt.flatMap(_.onResolveFailure)
126
+ val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet
119
127
val moduleName = crossVersion(projectID).name
120
128
121
129
def getReference (module : ModuleID ): String =
@@ -183,10 +191,16 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
183
191
}
184
192
185
193
val projectModuleRef = getReference(projectID)
186
- // TODO: find exact build file for this project
187
- val file = githubapi.FileInfo (" build.sbt" )
194
+ val buildFile = workspaceOpt match {
195
+ case None => " build.sbt"
196
+ case Some (workspace) =>
197
+ if (root.startsWith(workspace)) workspace.relativize(root).resolve(" build.sbt" ).toString
198
+ else root.resolve(" build.sbt" ).toString
199
+ }
200
+ val file = githubapi.FileInfo (buildFile)
188
201
val metadata = Map (" baseDirectory" -> JString (baseDirectory.toString))
189
202
val manifest = githubapi.Manifest (projectModuleRef, file, metadata, resolved.toMap)
203
+ logger.info(s " Created manifest of $buildFile" )
190
204
Some (manifest)
191
205
}
192
206
}
0 commit comments