Skip to content

Commit

Permalink
Add scripted test
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrice10 committed Sep 1, 2020
1 parent 94921be commit e0c68bb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,21 @@ object ScalafixPlugin extends AutoPlugin {
override lazy val globalSettings: Seq[Def.Setting[_]] = Seq(
scalafixConfig := None, // let scalafix-cli try to infer $CWD/.scalafix.conf
scalafixOnCompile := false,
scalafixResolvers := Repository.defaults().asScala.toSeq ++ Seq(
coursierapi.MavenRepository
.of("https://oss.sonatype.org/content/repositories/public"),
coursierapi.MavenRepository.of(
"https://oss.sonatype.org/content/repositories/snapshots"
)
),
scalafixResolvers :=
// Repository.defaults() defaults to Repository.ivy2Local() and Repository.central(). These can be overridden per
// env variable, e.g., export COURSIER_REPOSITORIES="ivy2Local|central|sonatype:releases|jitpack|https://corporate.com/repo".
// See https://github.com/coursier/coursier/blob/master/modules/coursier/jvm/src/main/scala/coursier/PlatformResolve.scala#L19-L68
// and https://get-coursier.io/docs/other-repositories for more details.
// Also see src/sbt-test/sbt-scalafix/scalafixResolvers/test for a scripted test preserving this behavior.
Repository.defaults().asScala.toSeq ++
Seq(
coursierapi.MavenRepository.of(
"https://oss.sonatype.org/content/repositories/public"
),
coursierapi.MavenRepository.of(
"https://oss.sonatype.org/content/repositories/snapshots"
)
),
scalafixDependencies := Nil,
commands += ScalafixEnable.command,
scalafixInterfaceProvider := ScalafixInterface.fromToolClasspath(
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/sbt-scalafix/scalafixResolvers/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COURSIER_REPOSITORIES="ivy2Local|central|ivy:https://a.b.com/artifactory/snapshots/[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]"
29 changes: 29 additions & 0 deletions src/sbt-test/sbt-scalafix/scalafixResolvers/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
scalaVersion := "2.12.7"

TaskKey[Unit]("check") := {
val expectedRepositories: Seq[String] = Seq(
// Repository.central()
"https://repo1.maven.org/maven2",
//Repository.ivy2Local()
".ivy2/local/",
"https://oss.sonatype.org/content/repositories/public",
"https://oss.sonatype.org/content/repositories/snapshots",
// custom repository
"https://a.b.com/artifactory/snapshots"
)

// scalafixResolvers is lazily evaluated as a stream of coursier.internal.api.ApiHelper.ApiRepo's. To fully evaluate
// the stream and overcome object equality issues, build a string from scalafixResolvers.
var scalafixRepos: String = ""
scalafixResolvers.in(ThisBuild).value.foreach { repo =>
scalafixRepos += repo.toString
}

expectedRepositories.foreach { repository =>
if (!scalafixRepos.contains(repository)) {
throw new Exception(
s"repository=$repository not included in scalafixResolvers"
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version"))
addSbtPlugin("au.com.onegeek" %% "sbt-dotenv" % "2.1.146")
3 changes: 3 additions & 0 deletions src/sbt-test/sbt-scalafix/scalafixResolvers/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# reload to ensure env variable COURSIER_REPOSITORIES is picked up by scalafixResolvers
> reload
> check

0 comments on commit e0c68bb

Please # to comment.