-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from dwijnand/split
Split into library and sbt plugin
- Loading branch information
Showing
33 changed files
with
140 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,72 @@ | ||
val sbtdynver = project.in(file(".")).settings(name := "sbt-dynver") | ||
val dynverRoot = project.in(file(".")) | ||
val dynverP = LocalProject("dynver") | ||
aggregateProjects(dynverP, sbtdynver) | ||
|
||
organization := "com.dwijnand" | ||
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")) | ||
description := "An sbt plugin to dynamically set your version from git" | ||
developers := List(Developer("dwijnand", "Dale Wijnand", "dale wijnand gmail com", url("https://dwijnand.com"))) | ||
startYear := Some(2016) | ||
homepage := scmInfo.value map (_.browseUrl) | ||
scmInfo := Some(ScmInfo(url("https://github.com/dwijnand/sbt-dynver"), "scm:git:[email protected]:dwijnand/sbt-dynver.git")) | ||
inThisBuild(List( | ||
organization := "com.dwijnand", | ||
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")), | ||
description := "An sbt plugin to dynamically set your version from git", | ||
developers := List(Developer("dwijnand", "Dale Wijnand", "dale wijnand gmail com", url("https://dwijnand.com"))), | ||
startYear := Some(2016), | ||
homepage := scmInfo.value map (_.browseUrl), | ||
scmInfo := Some(ScmInfo(url("https://github.com/dwijnand/sbt-dynver"), "scm:git:[email protected]:dwijnand/sbt-dynver.git")), | ||
|
||
enablePlugins(SbtPlugin) | ||
Global / sbtVersion := "1.0.0" // must be Global, otherwise ^^ won't change anything | ||
crossSbtVersions := List("1.0.0") | ||
Global / sbtVersion := "1.0.0", // must be Global, otherwise ^^ won't change anything | ||
LocalRootProject / crossSbtVersions := List("1.0.0"), | ||
|
||
scalaVersion := "2.12.12" | ||
scalaVersion := "2.12.12", | ||
|
||
maxErrors := 15 | ||
triggeredMessage := Watched.clearWhenTriggered | ||
scalacOptions ++= Seq("-encoding", "utf8"), | ||
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-Xlint"), | ||
scalacOptions += "-Xfuture", | ||
scalacOptions += "-Yno-adapted-args", | ||
scalacOptions += "-Ywarn-dead-code", | ||
scalacOptions += "-Ywarn-numeric-widen", | ||
scalacOptions += "-Ywarn-value-discard", | ||
|
||
scalacOptions ++= Seq("-encoding", "utf8") | ||
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-Xlint") | ||
scalacOptions += "-Xfuture" | ||
scalacOptions += "-Yno-adapted-args" | ||
scalacOptions += "-Ywarn-dead-code" | ||
scalacOptions += "-Ywarn-numeric-widen" | ||
scalacOptions += "-Ywarn-value-discard" | ||
Test / fork := false, | ||
Test / logBuffered := false, | ||
Test / parallelExecution := true, | ||
)) | ||
|
||
libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "5.10.0.202012080955-r" % Test | ||
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.15.2" % Test | ||
val dynver = project.settings( | ||
libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "5.10.0.202012080955-r" % Test, | ||
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.15.2" % Test, | ||
|
||
Test / fork := false | ||
Test / logBuffered := false | ||
Test / parallelExecution := true | ||
mimaSettings, | ||
) | ||
|
||
import com.typesafe.tools.mima.core._, ProblemFilters._ | ||
val sbtdynver = project.dependsOn(dynverP).enablePlugins(SbtPlugin).settings( | ||
name := "sbt-dynver", | ||
|
||
scriptedLaunchOpts ++= Seq("-Xmx1024M", "-XX:MaxPermSize=256M", "-Dplugin.version=" + version.value) | ||
scriptedBufferLog := true | ||
scriptedLaunchOpts ++= Seq("-Xmx1024M", "-XX:MaxPermSize=256M", "-Dplugin.version=" + version.value), | ||
scriptedBufferLog := true, | ||
scriptedDependencies := Seq(dynver / publishLocal, publishLocal).dependOn.value, | ||
|
||
def toSbtPlugin(m: ModuleID) = Def.setting( | ||
Defaults.sbtPluginExtra(m, (pluginCrossBuild / sbtBinaryVersion).value, (update / scalaBinaryVersion).value) | ||
mimaSettings, | ||
) | ||
|
||
mimaPreviousArtifacts := Set(toSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0").value) | ||
|
||
import com.typesafe.tools.mima.core._, ProblemFilters._ | ||
mimaBinaryIssueFilters ++= Seq( | ||
// Migrated from a task key to a setting key | ||
exclude[IncompatibleResultTypeProblem]("sbtdynver.DynVerPlugin#autoImport.isVersionStable"), | ||
// private[sbtdynver] | ||
exclude[DirectMissingMethodProblem]("sbtdynver.GitDescribeOutput.parse"), | ||
// Migrated from a task key to an initialise | ||
exclude[IncompatibleResultTypeProblem]("sbtdynver.DynVerPlugin#autoImport.dynverAssertTagVersion"), | ||
// GitDescribeOutput#Parser is private[sbtdynver] | ||
exclude[Problem]("sbtdynver.GitDescribeOutput#Parser*"), | ||
// lightbend/mima#388 | ||
// static method requires()sbt.Plugins in class sbtdynver.DynVerPlugin does not have a correspondent in current version | ||
exclude[DirectMissingMethodProblem]("sbtdynver.DynVerPlugin.requires"), | ||
lazy val mimaSettings = Seq( | ||
mimaPreviousArtifacts := Set.empty, // Set(projectID.value.withRevision("4.0.0")), | ||
mimaBinaryIssueFilters ++= Seq( | ||
// Migrated from a task key to a setting key | ||
exclude[IncompatibleResultTypeProblem]("sbtdynver.DynVerPlugin#autoImport.isVersionStable"), | ||
// private[sbtdynver] | ||
exclude[DirectMissingMethodProblem]("sbtdynver.GitDescribeOutput.parse"), | ||
// Migrated from a task key to an initialise | ||
exclude[IncompatibleResultTypeProblem]("sbtdynver.DynVerPlugin#autoImport.dynverAssertTagVersion"), | ||
// GitDescribeOutput#Parser is private[sbtdynver] | ||
exclude[Problem]("sbtdynver.GitDescribeOutput#Parser*"), | ||
// lightbend/mima#388 | ||
// static method requires()sbt.Plugins in class sbtdynver.DynVerPlugin does not have a correspondent in current version | ||
exclude[DirectMissingMethodProblem]("sbtdynver.DynVerPlugin.requires"), | ||
), | ||
) | ||
|
||
mimaPreviousArtifacts := Set.empty | ||
publish / skip := true | ||
|
||
Global / cancelable := true | ||
|
||
Global / excludeLintKeys += crossSbtVersions // Used by the "^" command (PluginCrossCommand) |
79 changes: 1 addition & 78 deletions
79
src/main/scala/sbtdynver/DynVerPlugin.scala → dynver/src/main/scala/sbtdynver/DynVer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package sbtdynver | ||
|
||
import java.util._ | ||
|
||
import sbt._ | ||
import sbt.Keys._ | ||
|
||
object DynVerPlugin extends AutoPlugin { | ||
override def requires = plugins.JvmPlugin | ||
override def trigger = allRequirements | ||
|
||
object autoImport { | ||
val dynver = taskKey[String]("The version of your project, from git") | ||
val dynverInstance = settingKey[DynVer]("The dynver instance for this build") | ||
val dynverCurrentDate = settingKey[Date]("The current date, for dynver purposes") | ||
val dynverGitDescribeOutput = settingKey[Option[GitDescribeOutput]]("The output from git describe") | ||
val dynverSonatypeSnapshots = settingKey[Boolean]("Whether to append -SNAPSHOT to snapshot versions") | ||
val dynverGitPreviousStableVersion = settingKey[Option[GitDescribeOutput]]("The last stable tag") | ||
val dynverSeparator = settingKey[String]("The separator to use between tag and distance, and the hash and dirty timestamp") | ||
val dynverTagPrefix = settingKey[String]("The prefix to use when matching the version tag") | ||
val dynverVTagPrefix = settingKey[Boolean]("Whether or not tags have a 'v' prefix") | ||
val dynverCheckVersion = taskKey[Boolean]("Checks if version and dynver match") | ||
val dynverAssertVersion = taskKey[Unit]("Asserts if version and dynver match") | ||
|
||
// Asserts if the version derives from git tags | ||
val dynverAssertTagVersion = Def.setting { | ||
val v = version.value | ||
if (dynverGitDescribeOutput.value.hasNoTags) | ||
throw new MessageOnlyException( | ||
s"Failed to derive version from git tags. Maybe run `git fetch --unshallow`? Version: $v" | ||
) | ||
} | ||
|
||
// Would be nice if this were an 'upstream' key | ||
val isVersionStable = settingKey[Boolean]("The version string identifies a specific point in version control, so artifacts built from this version can be safely cached") | ||
val previousStableVersion = settingKey[Option[String]]("The last stable version as seen from the current commit (does not include the current commit's version/tag)") | ||
} | ||
import autoImport._ | ||
|
||
override def buildSettings = Seq( | ||
version := { | ||
val out = dynverGitDescribeOutput.value | ||
val date = dynverCurrentDate.value | ||
val separator = dynverSeparator.value | ||
if (dynverSonatypeSnapshots.value) out.sonatypeVersionWithSep(date, separator) | ||
else out.versionWithSep(date, separator) | ||
}, | ||
isSnapshot := dynverGitDescribeOutput.value.isSnapshot, | ||
isVersionStable := dynverGitDescribeOutput.value.isVersionStable, | ||
previousStableVersion := dynverGitPreviousStableVersion.value.previousVersion, | ||
|
||
dynverInstance := { | ||
val vTagPrefix = dynverVTagPrefix.value | ||
val tagPrefix = dynverTagPrefix.?.value.getOrElse(if (vTagPrefix) "v" else "") | ||
assert(vTagPrefix ^ tagPrefix != "v", s"Incoherence: dynverTagPrefix=$tagPrefix vs dynverVTagPrefix=$vTagPrefix") | ||
DynVer(Some(buildBase.value), dynverSeparator.value, tagPrefix) | ||
}, | ||
|
||
dynverCurrentDate := new Date, | ||
dynverGitDescribeOutput := dynverInstance.value.getGitDescribeOutput(dynverCurrentDate.value), | ||
dynverSonatypeSnapshots := false, | ||
dynverGitPreviousStableVersion := dynverInstance.value.getGitPreviousStableTag, | ||
dynverSeparator := DynVer.separator, | ||
dynverVTagPrefix := dynverTagPrefix.??(DynVer.tagPrefix).value == "v", | ||
|
||
dynver := { | ||
val dynver = dynverInstance.value | ||
if (dynverSonatypeSnapshots.value) dynver.sonatypeVersion(new Date) | ||
else dynver.version(new Date) | ||
}, | ||
dynverCheckVersion := (dynver.value == version.value), | ||
dynverAssertVersion := { | ||
val v = version.value | ||
val dv = dynver.value | ||
if (!dynverCheckVersion.value) | ||
sys.error(s"Version and dynver mismatch - version: $v, dynver: $dv") | ||
} | ||
) | ||
|
||
private val buildBase = baseDirectory in ThisBuild | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.