Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to auto-plugin (closes #14) #35

Merged
merged 1 commit into from
Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 8 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
import bintray.Keys._
import sbt.Keys._

sbtPlugin := true

organization := "pl.project13.scala"

name := "sbt-jmh"

scalaVersion := "2.10.4"
scalacOptions ++= List(
"-unchecked",
"-deprecation",
"-language:_",
"-target:jvm-1.7",
"-encoding", "UTF-8"
)

val jmhVersion = "1.8"

libraryDependencies += "org.openjdk.jmh" % "jmh-core" % jmhVersion // GPLv2

libraryDependencies += "org.openjdk.jmh" % "jmh-generator-bytecode" % jmhVersion // GPLv2

libraryDependencies += "org.openjdk.jmh" % "jmh-generator-reflection" % jmhVersion // GPLv2

libraryDependencies += "org.openjdk.jmh" % "jmh-generator-asm" % jmhVersion // GPLv2

publishTo <<= isSnapshot { snapshot =>
if (snapshot) Some(Classpaths.sbtPluginSnapshots) else Some(Classpaths.sbtPluginReleases)
}


// publishing settings

publishMavenStyle := false

licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html"))
bintrayPublishSettings

repository in bintray := "sbt-plugins"

licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html"))

bintrayOrganization in bintray := None

scriptedSettings

scriptedLaunchOpts <+= version(v => s"-Dproject.version=$v")
5 changes: 1 addition & 4 deletions project/bintray.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
resolvers += Resolver.url("bintray-sbt-plugin-releases",
url("http://dl.bintray.com/content/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

addSbtPlugin("me.lessis" % "bintray-sbt" % "0.1.1")
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.2.1")
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value
3 changes: 3 additions & 0 deletions sbt-jmh-tester/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lazy val plugins = project
.in(file("."))
.dependsOn(file("../").getCanonicalFile.toURI)
19 changes: 19 additions & 0 deletions sbt-jmh-tester/src/main/scala/test/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test

import org.openjdk.jmh.annotations.Benchmark

class Test {

@Benchmark
def range(): Int =
1.to(100000)
.filter(_ % 2 == 0)
.count(_.toString.length == 4)

@Benchmark
def iterator(): Int =
Iterator.from(1)
.takeWhile(_ < 100000)
.filter(_ % 2 == 0)
.count(_.toString.length == 4)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,37 @@ package pl.project13.scala.sbt

import sbt._
import sbt.Keys._
import java.io.PrintWriter
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator
import sbt.CommandStrings._
import java.io.PrintWriter

import scala.tools.nsc.util.ScalaClassLoader.URLClassLoader

object SbtJmh extends Plugin {
object JmhPlugin extends AutoPlugin {

object JmhKeys {
val Jmh = config("jmh") extend Compile

val generateJavaSources = taskKey[Seq[File]]("Generate benchmark JMH Java code")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change invalidates README and activator project template.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it warrants bump of the first version (e.g. 0.2.0) as API is slightly different now and requires changes to existing builds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a plan, I can roll the fixes tonight #38
Unless someone beats me to it :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!


val outputTarget = settingKey[File]("Directory where the bytecode to be consumed and generated sources should be written to (`target` or sometimes `target/scala-2.10`)")

val generatorType = settingKey[String]("Benchmark code generator type. Available: `default`, `reflection` or `asm`.")

val generateInstrumentedClasses = taskKey[Seq[File]]("Generate instrumented JMH code")
}

import JmhKeys._

lazy val jmhSettings = Seq(
val autoImport = JmhKeys

/** All we need is Java. */
override def requires = plugins.JvmPlugin

/** This enables the plugin once all requirements are fulfilled. */
override def trigger = allRequirements

override def projectSettings = Seq(
sourceGenerators in Jmh := (sourceGenerators in Compile).value,
sourceGenerators in Jmh <+= generateJavaSources in Jmh,

Expand Down Expand Up @@ -63,7 +82,6 @@ object SbtJmh extends Plugin {
run in Jmh <<= (run in Compile).dependsOn(compile in Jmh),
run in Compile <<= (run in Compile).dependsOn(compile in Jmh),


// Allows users to write custom runners and `runMain my.Runner -i 10 .*`.
// This is needed because it brings in the compiled classes onto the runs classpath
runMain in Compile <<= (runMain in Compile).dependsOn(compile in JmhKeys.Jmh)
Expand All @@ -88,7 +106,7 @@ object SbtJmh extends Plugin {

/** Compiler run, with additional files to compile (JMH generated sources) */
def myCompile(s: TaskStreams, ci: Compiler.Inputs, javaToCompile: Seq[File]): inc.Analysis = {
lazy val x = s.text(ExportStream)
lazy val x = s.text(CommandStrings.ExportStream)
def onArgs(cs: Compiler.Compilers) = {
cs.copy(
scalac = cs.scalac.onArgs(exported(x, "scalac")),
Expand All @@ -102,19 +120,4 @@ object SbtJmh extends Plugin {

def exported(w: PrintWriter, command: String): Seq[String] => Unit = args =>
w.println((command +: args).mkString(" "))


object JmhKeys {
val Jmh = config("jmh") extend Compile

val generateJavaSources = taskKey[Seq[File]]("Generate benchmark JMH Java code")

val outputTarget = settingKey[File]("Directory where the bytecode to be consumed and generated sources should be written to (`target` or sometimes `target/scala-2.10`)")

val generatorType = settingKey[String]("Benchmark code generator type. Available: `default`, `reflection` or `asm`.")

val generateInstrumentedClasses = taskKey[Seq[File]]("Generate instrumented JMH code")

}

}
5 changes: 5 additions & 0 deletions src/main/scala/pl/project13/scala/sbt/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pl.project13.scala

package object sbt {
val SbtJmh = JmhPlugin
}