From f3fc566afbb0df856387018a43ea9a310a2e0e6c Mon Sep 17 00:00:00 2001 From: caoilTe O'Connor Date: Sun, 19 Apr 2020 21:21:04 +0100 Subject: [PATCH] Upgrade sbt to 1.x and other breaking changes (#2) - Everything upgraded - particularly sbt to 1.x **BREAKING** - Renamed the keys to follow sbt guidelines **BREAKING** - Integrated into travis-ci using sbt-ci-release - added scalafmt --- .gitignore | 4 ++ .scalafmt.conf | 20 ++++++++ .travis.yml | 18 +++++++ README.md | 4 +- build.sbt | 51 ++++++++----------- project/build.properties | 2 +- project/build.sbt | 1 - project/plugins.sbt | 5 +- .../ImportScalaFilesPlugin.scala | 41 ++++++++------- .../build.sbt | 4 +- .../project/plugins.sbt | 2 +- .../project/project/Library.scala | 4 +- .../src/main/scala/Main.scala | 4 +- .../from-meta-build/build.sbt | 4 +- version.sbt | 1 - 15 files changed, 100 insertions(+), 65 deletions(-) create mode 100644 .scalafmt.conf create mode 100644 .travis.yml delete mode 100644 project/build.sbt delete mode 100644 version.sbt diff --git a/.gitignore b/.gitignore index e496b3f..890f7bf 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ project/project/credentials.sbt .worksheet .idea .idea_modules/ + +# Metals specific +.bloop +.metals \ No newline at end of file diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..88ff874 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,20 @@ +version = "2.5.0-RC1" + +maxColumn = 120 + +align = none +align.arrowEnumeratorGenerator = true + +spaces.beforeContextBoundColon = Always +spaces.afterTripleEquals = true + +verticalMultiline.atDefnSite = true +verticalMultiline.arityThreshold = 4 +verticalMultiline.newlineAfterOpenParen = true + +rewrite.rules = [SortImports, SortModifiers] +rewrite.redundantBraces.stringInterpolation = true + +importSelectors = binPack + +trailingCommas = preserve \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e5422b1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: scala +jdk: openjdk8 +before_install: + - git fetch --tags +stages: + - name: test + - name: release + if: ((branch = master AND type = push) OR (tag IS present)) AND NOT fork +jobs: + include: + # stage="test" if no stage is specified + - name: test + script: sbt scripted + - name: formatting + script: sbt scalafmtCheckAll scalafmtSbtCheck + # run ci-release only if previous stages passed + - stage: release + script: sbt ci-release diff --git a/README.md b/README.md index f736a65..aea2829 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ If this sounds like _turtles all the way down..._ it really is. Add the following to your `project/plugins.sbt` file: ```scala -addSbtPlugin("org.caoilte" % "sbt-import-scala-files" % "1.0.0") +addSbtPlugin("org.caoilte" % "sbt-import-scala-files" % "2.0.0") ``` -The plugin is now enabled, but will not do anything until you define a `Seq[File]` to be imported with the `filesToImport` setting. It will then copy those files into your build's managed source directory before every compilation phase using the [source generation task][generating-files]. +The plugin is now enabled, but will not do anything until you define a `Seq[File]` to be imported with the `importScalaFilesList` setting. It will then copy those files into your build's managed source directory before every compilation phase using the [source generation task][generating-files]. # Licence diff --git a/build.sbt b/build.sbt index 4c22a96..068b84a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,39 +1,32 @@ +inThisBuild( + List( + organization := "org.caoilte", + homepage := Some(url("https://github.com/caoilte/sbt-import-scala-files/")), + licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), + developers := List( + Developer( + "caoilte", + "Caoilte O'Connor", + "caoilte@gmail.com", + url("https://caoilte.org") + ) + ) + ) +) + sbtPlugin := true name := "sbt-import-scala-files" -organization := "org.caoilte" - -scalaVersion := "2.10.6" +scalaVersion := "2.12.10" -libraryDependencies += "com.lihaoyi" %% "fansi" % "0.2.3" +libraryDependencies += "com.lihaoyi" %% "fansi" % "0.2.9" -ScriptedPlugin.scriptedSettings +enablePlugins(SbtPlugin) -scriptedLaunchOpts := { scriptedLaunchOpts.value ++ - Seq("-Xmx1024M", "-Dplugin.version=" + version.value) +scriptedLaunchOpts := { + scriptedLaunchOpts.value ++ + Seq("-Xmx1024M", "-Dplugin.version=" + version.value) } scriptedBufferLog := false - -pomExtra in Global := { - https://github.com/caoilte/sbt-import-scala-files/ - - - Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - scm:git:github.com/caoilte/sbt-import-scala-files.git - scm:git:git@github.com:caoilte/sbt-import-scala-files.git - github.com/caoilte/sbt-import-scala-files/ - - - - caoilte - Caoilte O'Connor - http://caoilte.org - - -} \ No newline at end of file diff --git a/project/build.properties b/project/build.properties index 5f32afe..ea09419 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.13 \ No newline at end of file +sbt.version=1.3.9 \ No newline at end of file diff --git a/project/build.sbt b/project/build.sbt deleted file mode 100644 index 0bc9712..0000000 --- a/project/build.sbt +++ /dev/null @@ -1 +0,0 @@ -libraryDependencies += { "org.scala-sbt" % "scripted-plugin" % sbtVersion.value } \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index eba4a3e..627413a 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,2 @@ -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") - -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") \ No newline at end of file +addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.2") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4") diff --git a/src/main/scala/org/caoilte/sbtimportscalafiles/ImportScalaFilesPlugin.scala b/src/main/scala/org/caoilte/sbtimportscalafiles/ImportScalaFilesPlugin.scala index 4cd3941..4ffcbf4 100644 --- a/src/main/scala/org/caoilte/sbtimportscalafiles/ImportScalaFilesPlugin.scala +++ b/src/main/scala/org/caoilte/sbtimportscalafiles/ImportScalaFilesPlugin.scala @@ -11,24 +11,26 @@ object ImportScalaFilesPlugin extends AutoPlugin { override def trigger = allRequirements object autoImport { - lazy val filesToImport = settingKey[Seq[File]]( - "Scala files to be imported into this build's generated source directory by 'importFiles' task" + lazy val importScalaFilesList = settingKey[Seq[File]]( + "Scala files to be imported into this build's generated source directory by 'importScalaFiles' task" ) - lazy val importFiles = taskKey[Seq[File]]( - "Import files defined in 'filesToImport' setting to this builds generated source directory" + lazy val importScalaFiles = taskKey[Seq[File]]( + "Import files defined in 'importScalaFilesList' setting to this build's generated source directory" ) } import autoImport._ override lazy val projectSettings = Seq( - filesToImport := Nil, - importFiles := { - filesToImport.value.map { metaProjectFileToImport => + importScalaFilesList := Nil, + importScalaFiles := { + val sts = streams.value + val logger = sts.log + importScalaFilesList.value.map { metaProjectFileToImport => val copiedFile: File = ImportScalaFiles(sourceManaged.value, metaProjectFileToImport) val baseDirOfLocalRootProject = (baseDirectory in LocalRootProject).value - streams.value.log.info( + logger.info( ImportScalaFiles.copiedFileString( baseDirOfLocalRootProject = baseDirOfLocalRootProject, from = metaProjectFileToImport, @@ -39,7 +41,7 @@ object ImportScalaFilesPlugin extends AutoPlugin { copiedFile } }, - sourceGenerators in Compile += importFiles.taskValue + sourceGenerators in Compile += importScalaFiles.taskValue ) } @@ -51,12 +53,13 @@ object ImportScalaFiles { } else "." } - private val relativeLocation: File => File => String = baseDirectory => file => { - val index = baseDirectory.getPath.length + 1 - file.getAbsolutePath.substring(index) - } + private val relativeLocation: File => File => String = baseDirectory => + file => { + val index = baseDirectory.getPath.length + 1 + file.getAbsolutePath.substring(index) + } - def copiedFileString(baseDirOfLocalRootProject: File, from: File, to: File):String = { + def copiedFileString(baseDirOfLocalRootProject: File, from: File, to: File): String = { val relativeToBaseDir = relativeLocation(baseDirOfLocalRootProject) val baseDirStr = relativeBaseDir(baseDirOfLocalRootProject) @@ -66,10 +69,10 @@ object ImportScalaFiles { import fansi.Color._ ( Cyan("ImportScalaFiles") ++ - Str(": In '") ++ Green(baseDirStr) ++ - Str("' copied '") ++ Green(fromStr) ++ - Str("' to '") ++ Green(toStr) ++ White("'") - ).render + Str(": In '") ++ Green(baseDirStr) ++ + Str("' copied '") ++ Green(fromStr) ++ + Str("' to '") ++ Green(toStr) ++ White("'") + ).render } def apply(toDirectory: File, file: File): File = { @@ -77,4 +80,4 @@ object ImportScalaFiles { IO.copyFile(file, toFile, preserveLastModified = true) toFile } -} \ No newline at end of file +} diff --git a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/build.sbt b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/build.sbt index db20a51..1f7ff26 100644 --- a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/build.sbt +++ b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/build.sbt @@ -1,8 +1,8 @@ version := "0.1" -scalaVersion := "2.10.6" +scalaVersion := "2.12.10" -filesToImport := Seq(file("project/project/Library.scala")) +importScalaFilesList := Seq(file("project/project/Library.scala")) sbtPlugin := true diff --git a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/plugins.sbt b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/plugins.sbt index a0bf915..1be715b 100644 --- a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/plugins.sbt +++ b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/plugins.sbt @@ -4,6 +4,6 @@ sys.props.get("plugin.version") match { |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) } -filesToImport := Seq(file("project/project/Library.scala")) +importScalaFilesList := Seq(file("project/project/Library.scala")) org.caoilte.Library.pluginDependenciesAsPluginSettings \ No newline at end of file diff --git a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/project/Library.scala b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/project/Library.scala index 571bd77..44dabf6 100644 --- a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/project/Library.scala +++ b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/project/project/Library.scala @@ -3,11 +3,11 @@ package org.caoilte import sbt._ object V { - val scalafmt = "0.5.5" + val scalafmt = "2.0.0" } object Library { - val scalafmtPlugin = "com.geirsson" % "sbt-scalafmt" % V.scalafmt + val scalafmtPlugin = "org.scalameta" % "sbt-scalafmt" % V.scalafmt val pluginDependencies = Seq( scalafmtPlugin diff --git a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/src/main/scala/Main.scala b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/src/main/scala/Main.scala index 424e2ae..5a322f8 100644 --- a/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/src/main/scala/Main.scala +++ b/src/sbt-test/sbt-import-scala-files/from-meta-build-and-meta-meta-build/src/main/scala/Main.scala @@ -4,7 +4,7 @@ import org.caoilte.V object Main extends App { println("Test is running") val test = s"I added version ${V.scalafmt} as a dependency" - if (V.scalafmt != "0.5.5") - throw new RuntimeException(s"'${V.scalafmt}' should have been '0.5.5'") + if (V.scalafmt != "2.0.0") + throw new RuntimeException(s"'${V.scalafmt}' should have been '2.0.0'") println(test + " Test succeeded!") } \ No newline at end of file diff --git a/src/sbt-test/sbt-import-scala-files/from-meta-build/build.sbt b/src/sbt-test/sbt-import-scala-files/from-meta-build/build.sbt index 6da6f2b..67baff6 100644 --- a/src/sbt-test/sbt-import-scala-files/from-meta-build/build.sbt +++ b/src/sbt-test/sbt-import-scala-files/from-meta-build/build.sbt @@ -1,5 +1,5 @@ version := "0.1" -scalaVersion := "2.10.6" +scalaVersion := "2.12.10" -filesToImport := Seq(file("project/MetaBuildConstants.scala")) +importScalaFilesList := Seq(file("project/MetaBuildConstants.scala")) diff --git a/version.sbt b/version.sbt deleted file mode 100644 index b400ca4..0000000 --- a/version.sbt +++ /dev/null @@ -1 +0,0 @@ -version in ThisBuild := "1.1.0-SNAPSHOT" \ No newline at end of file