|
1 | 1 | import sbt._ |
2 | 2 | import Keys._ |
| 3 | +import com.typesafe.sbt.osgi.{OsgiKeys, SbtOsgi} |
3 | 4 |
|
4 | 5 | object ScalaModulePlugin extends Plugin { |
| 6 | + val snapshotScalaBinaryVersion = settingKey[String]("The Scala binary version to use when building against Scala SNAPSHOT.") |
| 7 | + val repoName = settingKey[String]("The name of the repository under github.com/scala/.") |
5 | 8 |
|
6 | | - val includeTestDependencies = settingKey[Boolean]("Include testing dependencies when building. Used to break cycles when doing full builds.") |
7 | | - val partestVersion = settingKey[String]("the partest version we want to use.") |
8 | | - |
9 | | - def scalaModuleSettings: Seq[Setting[_]] = |
10 | | - Seq( |
11 | | - partestVersion := "1.0-RC5", |
12 | | - organization := "org.scala-lang.modules", |
13 | | - // don't use for doc scope, scaladoc warnings are not to be reckoned with |
14 | | - scalacOptions in (Compile, compile) ++= Seq("-optimize", "-Xfatal-warnings", "-feature", "-deprecation", "-unchecked", "-Xlint"), |
15 | | - // Generate $name.properties to store our version as well as the scala version used to build |
16 | | - resourceGenerators in Compile <+= Def.task { |
17 | | - val props = new java.util.Properties |
18 | | - props.put("version.number", version.value) |
19 | | - props.put("scala.version.number", scalaVersion.value) |
20 | | - props.put("scala.binary.version.number", scalaBinaryVersion.value) |
21 | | - val file = (resourceManaged in Compile).value / s"${name.value}.properties" |
22 | | - IO.write(props, null, file) |
23 | | - Seq(file) |
24 | | - }, |
25 | | - mappings in (Compile, packageBin) += { |
26 | | - (baseDirectory.value / s"${name.value}.properties") -> s"${name.value}.properties" |
27 | | - }, |
28 | | - // maven publishing |
29 | | - publishTo := { |
30 | | - val nexus = "https://oss.sonatype.org/" |
31 | | - if (version.value.trim.endsWith("SNAPSHOT")) |
32 | | - Some("snapshots" at nexus + "content/repositories/snapshots") |
33 | | - else |
34 | | - Some("releases" at nexus + "service/local/staging/deploy/maven2") |
35 | | - }, |
36 | | - publishMavenStyle := true, |
37 | | - publishArtifact in Test := false, |
38 | | - pomIncludeRepository := { _ => false }, |
39 | | - pomExtra := ( |
40 | | - <url>http://www.scala-lang.org/</url> |
41 | | - <inceptionYear>2002</inceptionYear> |
42 | | - <licenses> |
43 | | - <license> |
44 | | - <distribution>repo</distribution> |
45 | | - <name>BSD 3-Clause</name> |
46 | | - <url>https://github.com/scala/{name.value}/blob/master/LICENSE.md</url> |
47 | | - </license> |
48 | | - </licenses> |
49 | | - <scm> |
50 | | - <connection>scm:git:git://github.com/scala/{name.value}.git</connection> |
51 | | - <url>https://github.com/scala/{name.value}</url> |
52 | | - </scm> |
53 | | - <issueManagement> |
54 | | - <system>JIRA</system> |
55 | | - <url>https://issues.scala-lang.org/</url> |
56 | | - </issueManagement> |
57 | | - <developers> |
58 | | - <developer> |
59 | | - <id>epfl</id> |
60 | | - <name>EPFL</name> |
61 | | - </developer> |
62 | | - <developer> |
63 | | - <id>Typesafe</id> |
64 | | - <name>Typesafe, Inc.</name> |
65 | | - </developer> |
66 | | - </developers> |
67 | | - ), |
68 | | - // default value must be set here |
69 | | - includeTestDependencies := true, |
70 | | - // the actual partest the interface calls into -- must be binary version close enough to ours |
71 | | - // so that it can link to the compiler/lib we're using (testing) |
72 | | - libraryDependencies ++= ( |
73 | | - if (includeTestDependencies.value) |
74 | | - Seq("org.scala-lang.modules" %% "scala-partest-interface" % "0.2" % "test", |
75 | | - "org.scala-lang.modules" %% "scala-partest" % partestVersion.value % "test") |
76 | | - else Seq.empty |
77 | | - ), |
78 | | - // necessary for partest -- see comments in its build.sbt |
79 | | - conflictWarning ~= { _.copy(failOnConflict = false) }, |
80 | | - fork in Test := true, |
81 | | - javaOptions in Test += "-Xmx1G", |
82 | | - testFrameworks += new TestFramework("scala.tools.partest.Framework"), |
83 | | - definedTests in Test += ( |
84 | | - new sbt.TestDefinition( |
85 | | - "partest", |
86 | | - // marker fingerprint since there are no test classes |
87 | | - // to be discovered by sbt: |
88 | | - new sbt.testing.AnnotatedFingerprint { |
89 | | - def isModule = true |
90 | | - def annotationName = "partest" |
91 | | - }, true, Array()) |
92 | | - ) |
93 | | - |
94 | | - // TODO: mima |
95 | | - // import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings |
96 | | - // import com.typesafe.tools.mima.plugin.MimaKeys.previousArtifact |
97 | | - // previousArtifact := Some(organization.value %% name.value % binaryReferenceVersion.value) |
98 | | - ) |
| 9 | + def deriveBinaryVersion(sv: String, snapshotScalaBinaryVersion: String) = sv match { |
| 10 | + case snap_211 if snap_211.startsWith("2.11") && |
| 11 | + snap_211.contains("-SNAPSHOT") => snapshotScalaBinaryVersion |
| 12 | + case sv => sbt.CrossVersion.binaryScalaVersion(sv) |
| 13 | + } |
99 | 14 |
|
| 15 | + // a setting-transform to turn the regular version into something osgi can deal with |
| 16 | + val osgiVersion = version(_.replace('-', '.')) |
| 17 | + |
| 18 | + lazy val scalaModuleSettings = Seq( |
| 19 | + repoName := name.value, |
| 20 | + |
| 21 | + organization := "org.scala-lang.modules", |
| 22 | + |
| 23 | + scalaBinaryVersion := deriveBinaryVersion(scalaVersion.value, snapshotScalaBinaryVersion.value), |
| 24 | + |
| 25 | + // so we don't have to wait for sonatype to synch to maven central when deploying a new module |
| 26 | + resolvers += Resolver.sonatypeRepo("releases"), |
| 27 | + |
| 28 | + // to allow compiling against snapshot versions of Scala |
| 29 | + resolvers += Resolver.sonatypeRepo("snapshots"), |
| 30 | + |
| 31 | + // don't use for doc scope, scaladoc warnings are not to be reckoned with |
| 32 | + // TODO: turn on for nightlies, but don't enable for PR validation... "-Xfatal-warnings" |
| 33 | + scalacOptions in compile ++= Seq("-optimize", "-feature", "-deprecation", "-unchecked", "-Xlint"), |
| 34 | + |
| 35 | + // Generate $name.properties to store our version as well as the scala version used to build |
| 36 | + resourceGenerators in Compile <+= Def.task { |
| 37 | + val props = new java.util.Properties |
| 38 | + props.put("version.number", version.value) |
| 39 | + props.put("scala.version.number", scalaVersion.value) |
| 40 | + props.put("scala.binary.version.number", scalaBinaryVersion.value) |
| 41 | + val file = (resourceManaged in Compile).value / s"${name.value}.properties" |
| 42 | + IO.write(props, null, file) |
| 43 | + Seq(file) |
| 44 | + }, |
| 45 | + |
| 46 | + mappings in (Compile, packageBin) += { |
| 47 | + (baseDirectory.value / s"${name.value}.properties") -> s"${name.value}.properties" |
| 48 | + }, |
| 49 | + |
| 50 | + publishArtifact in Test := false, |
| 51 | + |
| 52 | + // maven publishing |
| 53 | + publishTo := Some( |
| 54 | + if (version.value.trim.endsWith("SNAPSHOT")) Resolver.sonatypeRepo("snapshots") |
| 55 | + else Opts.resolver.sonatypeStaging |
| 56 | + ), |
| 57 | + credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"), |
| 58 | + |
| 59 | + publishMavenStyle := true, |
| 60 | + scmInfo := Some(ScmInfo(url(s"https://github.com/scala/${repoName.value}"),s"scm:git:git://github.com/scala/${repoName.value}.git")), |
| 61 | + homepage := Some(url("http://www.scala-lang.org/")), |
| 62 | + organizationHomepage := Some(url("http://www.scala-lang.org/")), |
| 63 | + licenses := Seq("BSD 3-clause" -> url("http://opensource.org/licenses/BSD-3-Clause")), |
| 64 | + startYear := Some(2002), |
| 65 | + pomIncludeRepository := { _ => false }, |
| 66 | + pomExtra := ( |
| 67 | + <issueManagement> |
| 68 | + <system>JIRA</system> |
| 69 | + <url>https://issues.scala-lang.org/</url> |
| 70 | + </issueManagement> |
| 71 | + <developers> |
| 72 | + <developer> |
| 73 | + <id>epfl</id> |
| 74 | + <name>EPFL</name> |
| 75 | + </developer> |
| 76 | + <developer> |
| 77 | + <id>Typesafe</id> |
| 78 | + <name>Typesafe, Inc.</name> |
| 79 | + </developer> |
| 80 | + </developers> |
| 81 | + ), |
| 82 | + |
| 83 | + OsgiKeys.bundleSymbolicName := s"${organization.value}.${name.value}", |
| 84 | + OsgiKeys.bundleVersion := osgiVersion.value, |
| 85 | + |
| 86 | + // Sources should also have a nice MANIFEST file |
| 87 | + packageOptions in packageSrc := Seq(Package.ManifestAttributes( |
| 88 | + ("Bundle-SymbolicName", s"${organization.value}.${name.value}.source"), |
| 89 | + ("Bundle-Name", s"${name.value} sources"), |
| 90 | + ("Bundle-Version", osgiVersion.value), |
| 91 | + ("Eclipse-SourceBundle", s"""${organization.value}.${name.value};version="${osgiVersion.value}";roots:="."""") |
| 92 | + )) |
| 93 | + |
| 94 | + |
| 95 | + // TODO: mima |
| 96 | + // resolvers += Classpaths.typesafeResolver |
| 97 | + // addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.5") |
| 98 | + // import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings |
| 99 | + // import com.typesafe.tools.mima.plugin.MimaKeys.previousArtifact |
| 100 | + // previousArtifact := Some(organization.value %% name.value % binaryReferenceVersion.value) |
| 101 | + ) |
100 | 102 | } |
0 commit comments