Skip to content

Commit

Permalink
Upgrade sbt to 1.x and other breaking changes (#2)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
caoilte authored Apr 19, 2020
1 parent e7dd4e7 commit f3fc566
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ project/project/credentials.sbt
.worksheet
.idea
.idea_modules/

# Metals specific
.bloop
.metals
20 changes: 20 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 22 additions & 29 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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",
"[email protected]",
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 := {
<url>https://github.com/caoilte/sbt-import-scala-files/</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git:github.com/caoilte/sbt-import-scala-files.git</connection>
<developerConnection>scm:git:git@github.com:caoilte/sbt-import-scala-files.git</developerConnection>
<url>github.com/caoilte/sbt-import-scala-files/</url>
</scm>
<developers>
<developer>
<id>caoilte</id>
<name>Caoilte O'Connor</name>
<url>http://caoilte.org</url>
</developer>
</developers>
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=1.3.9
1 change: 0 additions & 1 deletion project/build.sbt

This file was deleted.

5 changes: 2 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,7 +41,7 @@ object ImportScalaFilesPlugin extends AutoPlugin {
copiedFile
}
},
sourceGenerators in Compile += importFiles.taskValue
sourceGenerators in Compile += importScalaFiles.taskValue
)
}

Expand All @@ -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)
Expand All @@ -66,15 +69,15 @@ 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 = {
val toFile = toDirectory / file.name
IO.copyFile(file, toFile, preserveLastModified = true)
toFile
}
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
4 changes: 2 additions & 2 deletions src/sbt-test/sbt-import-scala-files/from-meta-build/build.sbt
Original file line number Diff line number Diff line change
@@ -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"))
1 change: 0 additions & 1 deletion version.sbt

This file was deleted.

0 comments on commit f3fc566

Please sign in to comment.