Skip to content

Commit

Permalink
Merge pull request ceedubs#18 from tpolecat/adelbertc-multiproject
Browse files Browse the repository at this point in the history
Add SBT multi-project support, fixes ceedubs#4
  • Loading branch information
NightWhistler authored Apr 1, 2018
2 parents b817466 + 877d675 commit 9296248
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 21 additions & 17 deletions src/main/scala/net/ceedubs/sbtctags/SbtCtags.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.ceedubs.sbtctags

import java.io.File

import sbt._
import sbt.std.TaskStreams
import java.io.File

final case class CtagsGenerationContext(
ctagsParams: CtagsParams,
Expand Down Expand Up @@ -31,26 +32,25 @@ object CtagsKeys {
object SbtCtags extends Plugin {

override val projectSettings = Seq(
CtagsKeys.dependencySrcUnzipDir <<= Keys.target (_ / "sbt-ctags-dep-srcs"),
CtagsKeys.dependencySrcUnzipDir <<= Keys.target(_ / "sbt-ctags-dep-srcs"),

CtagsKeys.ctagsParams in ThisBuild := defaultCtagsParams,
CtagsKeys.ctagsParams in ThisBuild := defaultCtagsParams,

CtagsKeys.ctagsSrcFileFilter <<= CtagsKeys.ctagsParams(_.languages.foldLeft(NameFilter.fnToNameFilter(_ => false))((filter, lang) => filter | GlobFilter(s"*.$lang"))),
CtagsKeys.ctagsSrcFileFilter <<= CtagsKeys.ctagsParams(_.languages.foldLeft(NameFilter.fnToNameFilter(_ => false))((filter, lang) => filter | GlobFilter(s"*.$lang"))),

CtagsKeys.ctagsSrcDirs <<= (Keys.scalaSource in Compile, Keys.scalaSource in Test, Keys.javaSource in Compile, Keys.javaSource in Test, CtagsKeys.dependencySrcUnzipDir){ (srcDir, testDir, javaSrcDir, javaTestDir, depSrcDir) =>
Seq(srcDir, testDir, javaSrcDir, javaTestDir, depSrcDir)
},
CtagsKeys.ctagsSrcDirs <<= (Keys.scalaSource in Compile, Keys.scalaSource in Test, Keys.javaSource in Compile, Keys.javaSource in Test, CtagsKeys.dependencySrcUnzipDir) { (srcDir, testDir, javaSrcDir, javaTestDir, depSrcDir) =>
Seq(srcDir, testDir, javaSrcDir, javaTestDir, depSrcDir)
},

CtagsKeys.ctagsGeneration in ThisBuild := defaultCtagsGeneration(Keys.baseDirectory.value) _,

CtagsKeys.genCtags <<= (Keys.state, CtagsKeys.dependencySrcUnzipDir, CtagsKeys.ctagsParams, CtagsKeys.ctagsSrcFileFilter, CtagsKeys.ctagsGeneration, CtagsKeys.ctagsSrcDirs, Keys.streams) map genCtags
)
CtagsKeys.genCtags <<= (Keys.thisProjectRef, Keys.state, CtagsKeys.dependencySrcUnzipDir, CtagsKeys.ctagsParams, CtagsKeys.ctagsSrcFileFilter, CtagsKeys.ctagsGeneration, CtagsKeys.ctagsSrcDirs, Keys.streams) map genCtags)

val defaultCtagsParams: CtagsParams = CtagsParams(
executable = "ctags",
excludes = Seq("log"),
languages = Seq("scala", "java"),
tagFileName = ".tags",
tagFileName = "tags",
useRelativePaths = false,
extraArgs = Seq.empty)

Expand All @@ -74,17 +74,19 @@ object SbtCtags extends Plugin {
}
// will look something like "ctags --exclude=.git --exclude=log --languages=scala -f .tags -R src/main/scala target/sbt-ctags-dep-srcs"
val ctagsCmd = s"${ctagsParams.executable} $excludeArgs $languagesArgs -f ${ctagsParams.tagFileName} $extraArgs -R $dirArgs"
context.log.info(s"running this command to generate ctags: $ctagsCmd")
context.log.info(s"Running this command to generate ctags: $ctagsCmd")
Process(ctagsCmd, Some(new File(context.buildStructure.root)), Seq.empty: _*).!
}


def genCtags(state: State, dependencySrcUnzipDir: File, ctagsParams: CtagsParams, srcFileFilter: NameFilter, ctagsGeneration: CtagsGenerationContext => Unit, ctagsSrcDirs: Seq[File], streams: TaskStreams[_]) {
def genCtags(projectRef: ProjectRef, state: State, dependencySrcUnzipDir: File, ctagsParams: CtagsParams, srcFileFilter: NameFilter, ctagsGeneration: CtagsGenerationContext => Unit, ctagsSrcDirs: Seq[File], streams: TaskStreams[_]): Unit = {
// TODO this could be pretty bad if someone overrides the install dir with an important dir
val extracted = Project.extract(state)
val buildStruct = extracted.structure
val log = streams.log
log.info(s"Grabbing all dependency source jars. This may take a while if you don't have them in your Ivy cache")
EvaluateTask(buildStruct, Keys.updateClassifiers, state, extracted.currentRef).fold(state)(Function.tupled { (state, result) =>
val project = Project.getProject(projectRef, buildStruct)

log.info(s"Processing project named: ${project.get.id}")
EvaluateTask(buildStruct, Keys.updateClassifiers, state, projectRef).fold(state)(Function.tupled { (state, result) =>
result match {
case Value(updateReport) =>
log.info(s"Clearing $dependencySrcUnzipDir")
Expand All @@ -102,13 +104,15 @@ object SbtCtags extends Plugin {
val existingCtagsSrcDirs = ctagsSrcDirs.filter(_.exists)
log.debug(s"existing ctags src dirs: $existingCtagsSrcDirs")
log.info(s"Generating tag file")
ctagsGeneration(CtagsGenerationContext(ctagsParams, existingCtagsSrcDirs, buildStruct, streams.log))

val tagPath = s"${project.get.base.getAbsolutePath}/.${ctagsParams.tagFileName}"
val projectCtagParams = ctagsParams.copy(tagFileName = tagPath)
ctagsGeneration(CtagsGenerationContext(projectCtagParams, existingCtagsSrcDirs, buildStruct, streams.log))
state
case x =>
log.error(s"error trying to update classifiers to find source jars: $x")
state
}
})
}

}
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.2.0"
version in ThisBuild := "0.3.0"

0 comments on commit 9296248

Please sign in to comment.