Skip to content

Instantly share code, notes, and snippets.

@haxney
Created March 10, 2011 20:47
Show Gist options
  • Save haxney/864895 to your computer and use it in GitHub Desktop.
Save haxney/864895 to your computer and use it in GitHub Desktop.
package org.haxney.aspectj.sbt
import _root_.sbt._
import org.aspectj.tools.ajc.Main
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
trait AspectJ extends BasicScalaProject with FileTasks with MavenStyleScalaPaths {
lazy val aspectjTools = "org.aspectj" % "aspectjtools" % "1.6.11.M2" % "aspectj"
lazy val aspectjRt = "org.aspectj" % "aspectjrt" % "1.6.11.M2" % "aspectj"
lazy val aspectjConf = config("aspectj")
def aspectjPaths: PathFinder = configurationClasspath(aspectjConf)
def aspectjArgs = List("-1.5")
/* use default compile options */
def aspectjCompileOptions: Seq[CompileOption] = compileOptions ++ aspectjArgs
def aspectjLabel = "aspectj"
def aspectjSourcePath = mainJavaSourcePath
def aspectjSourceRoots = (aspectjSourcePath ##)
def aspectjSources = sources(aspectjSourceRoots)
def aspectjCompilePath = mainCompilePath
def aspectjAnalysisPath = mainAnalysisPath
def aspectjClasspath = compileClasspath +++ aspectjPaths
def aspectjCompileConfiguration = new AspectjCompileConfig
def aspectjCompileConditional = new CompileConditional(aspectjCompileConfiguration, buildCompiler)
def aspectjCompileDescription = "Compiles Java sources with AspectJ"
class AspectjCompileConfig extends BaseCompileConfig {
def baseCompileOptions = aspectjCompileOptions
def label = aspectjLabel
def sourceRoots = aspectjSourceRoots
def sources = aspectjSources
def outputDirectory = aspectjCompilePath
def classpath = aspectjClasspath
def analysisPath = aspectjAnalysisPath
def fingerprints = Fingerprints(Nil, Nil)
def javaOptions = javaOptionsAsString(javaCompileOptions)
}
protected def aspectjAction = task {
aspectjCompileConditional.run
None
} describedAs aspectjCompileDescription
lazy val aspectj = aspectjAction
}
package org.haxney.aspectj.sbt
import _root_.sbt._
import org.aspectj.tools.ajc.Main
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
trait AspectJ extends BasicScalaProject with FileTasks with MavenStyleScalaPaths {
lazy val aspectjTools = "org.aspectj" % "aspectjtools" % "1.6.11.M2" % "aspectj"
lazy val aspectjRt = "org.aspectj" % "aspectjrt" % "1.6.11.M2" % "aspectj"
lazy val aspectjConf = config("aspectj")
def aspectjClasspath = configurationClasspath(aspectjConf)
def aspectPaths: PathFinder = configurationClasspath(aspectjConf)
def aspectjTask(args: => List[String], output: => Path, srcRoot: => Path, aspects: => PathFinder) = {
runTask(Some("org.aspectj.tools.ajc.Main"), aspectjClasspath,
"-sourceroots" :: srcRoot.absolutePath ::
"-aspectpath" :: aspects.absString ::
"-d" :: output.absolutePath ::
args)
}
lazy val aspectj = aspectjTask(Nil, outputPath, mainJavaSourcePath, aspectPaths)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment