From e0c68bbdd52d51ca01fa0d1a9a42863539ec9190 Mon Sep 17 00:00:00 2001 From: Scott RIce Date: Mon, 31 Aug 2020 12:39:29 -0500 Subject: [PATCH] Add scripted test --- .../scala/scalafix/sbt/ScalafixPlugin.scala | 22 +++++++++----- .../sbt-scalafix/scalafixResolvers/.env | 1 + .../sbt-scalafix/scalafixResolvers/build.sbt | 29 +++++++++++++++++++ .../scalafixResolvers/project/plugins.sbt | 3 ++ .../sbt-scalafix/scalafixResolvers/test | 3 ++ 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 src/sbt-test/sbt-scalafix/scalafixResolvers/.env create mode 100644 src/sbt-test/sbt-scalafix/scalafixResolvers/build.sbt create mode 100644 src/sbt-test/sbt-scalafix/scalafixResolvers/project/plugins.sbt create mode 100644 src/sbt-test/sbt-scalafix/scalafixResolvers/test diff --git a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala index 52b85559..c091b8b9 100644 --- a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala +++ b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala @@ -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( diff --git a/src/sbt-test/sbt-scalafix/scalafixResolvers/.env b/src/sbt-test/sbt-scalafix/scalafixResolvers/.env new file mode 100644 index 00000000..043d67c2 --- /dev/null +++ b/src/sbt-test/sbt-scalafix/scalafixResolvers/.env @@ -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]" \ No newline at end of file diff --git a/src/sbt-test/sbt-scalafix/scalafixResolvers/build.sbt b/src/sbt-test/sbt-scalafix/scalafixResolvers/build.sbt new file mode 100644 index 00000000..8c618edf --- /dev/null +++ b/src/sbt-test/sbt-scalafix/scalafixResolvers/build.sbt @@ -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" + ) + } + } +} diff --git a/src/sbt-test/sbt-scalafix/scalafixResolvers/project/plugins.sbt b/src/sbt-test/sbt-scalafix/scalafixResolvers/project/plugins.sbt new file mode 100644 index 00000000..c20e9105 --- /dev/null +++ b/src/sbt-test/sbt-scalafix/scalafixResolvers/project/plugins.sbt @@ -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") diff --git a/src/sbt-test/sbt-scalafix/scalafixResolvers/test b/src/sbt-test/sbt-scalafix/scalafixResolvers/test new file mode 100644 index 00000000..e421b66a --- /dev/null +++ b/src/sbt-test/sbt-scalafix/scalafixResolvers/test @@ -0,0 +1,3 @@ +# reload to ensure env variable COURSIER_REPOSITORIES is picked up by scalafixResolvers +> reload +> check