Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it possible to and do build against a scalafix SNAPSHOT #211

Merged
merged 1 commit into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import sbt._

object Dependencies {
val x = List(1) // scalafix:ok
// when bumping remove dep on SNAPSHOT in sbt-1.5 scripted tests
def scalafixVersion: String = "0.9.27"
def scalafixVersion: String = "0.9.27+52-6c9eeec9-SNAPSHOT"

val all = List(
"org.eclipse.jgit" % "org.eclipse.jgit" % "5.11.0.202103091610-r",
"ch.epfl.scala" % "scalafix-interfaces" % scalafixVersion,
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/scalafix/sbt/ScalafixTestkitPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ object ScalafixTestkitPlugin extends AutoPlugin {
}
import autoImport._

override def buildSettings: Seq[Def.Setting[_]] =
List(
resolvers += Resolver.sonatypeRepo("snapshots")
Copy link
Collaborator Author

@bjaglin bjaglin May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScalafixTestkitPlugin clients of a SNAPSHOT sbt-scalafix must resolve from sonatype snapshots both scalafix-testkit for the test project (where that sbt plugin is enabled) AND scalafix-core for the actual rules project, thus the need for impacting the entire build and not just the project settings.

)

override def projectSettings: Seq[Def.Setting[_]] =
List(
scalafixTestkitInputScalacOptions := scalacOptions.value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version"))
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package fix

import scalafix.testkit._
import scala.util.control.NonFatal
import org.scalatest.FunSuiteLike
import org.scalatest.exceptions.TestFailedException

object IntputOutputSuite {
def main(args: Array[String]): Unit = {
if (Array("--save-expect").sameElements(args)) {
val suite = new SemanticRuleSuite(
TestkitProperties.loadFromResources(),
isSaveExpect = true
) {
val suite = new AbstractSemanticRuleSuite with FunSuiteLike {
override val props = TestkitProperties.loadFromResources()
override val isSaveExpect = true
Comment on lines +11 to +13
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-trivial usage of SemanticRuleSuite that https://github.com/scalacenter/scalafix/pull/1395/files won't cover. See also scalacenter/scalafix#1147.


testsToRun.foreach { t =>
try evaluateTestBody(t)
catch {
Expand All @@ -29,6 +30,6 @@ object IntputOutputSuite {
}
}

class IntputOutputSuite extends SemanticRuleSuite {
class IntputOutputSuite extends AbstractSemanticRuleSuite with FunSuiteLike {
runAllTests()
}
4 changes: 0 additions & 4 deletions src/sbt-test/sbt-1.5/scala-3/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version"))

//FIXME: remove when scalafixVersion is bumped to 0.9.28
resolvers += Resolver.sonatypeRepo("snapshots")
dependencyOverrides += "ch.epfl.scala" % "scalafix-interfaces" % "0.9.27+52-6c9eeec9-SNAPSHOT"
4 changes: 0 additions & 4 deletions src/sbt-test/sbt-1.5/scalafixEnable/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version"))

//FIXME: remove when scalafixVersion is bumped to 0.9.28
resolvers += Resolver.sonatypeRepo("snapshots")
dependencyOverrides += "ch.epfl.scala" % "scalafix-interfaces" % "0.9.27+52-6c9eeec9-SNAPSHOT"
3 changes: 1 addition & 2 deletions src/sbt-test/sbt-scalafix/basic/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ inThisBuild(
scalafixDependencies := List(
// Custom rule published to Maven Central https://github.com/scalacenter/example-scalafix-rule
"ch.epfl.scala" %% "example-scalafix-rule" % "1.4.0"
),
scalafixResolvers := List(Repository.MavenCentral)
)
)
)

Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/sbt-scalafix/concurrency/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
val V = _root_.scalafix.sbt.BuildInfo

scalaVersion := V.scala212
resolvers += Resolver.sonatypeRepo("snapshots")
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.scalafixVersion % ScalafixConfig

// make it possible to run scalafix in parallel with other tasks via the `all` command
Expand Down
6 changes: 1 addition & 5 deletions src/sbt-test/sbt-scalafix/local-rules/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ inThisBuild(
// Custom rule cross-published to Maven Central https://github.com/scalacenter/example-scalafix-rule
"ch.epfl.scala" %% "example-scalafix-rule" % "1.4.0"
),
// `Repository.central()` can only be used sbt 1.x / scala 2.12
// error: Static methods in interface require -target:jvm-1.8
scalafixResolvers := List(
coursierapi.MavenRepository.of("https://repo1.maven.org/maven2")
),
resolvers += Resolver.sonatypeRepo("snapshots"),
scalaVersion := "2.13.0", // out of sync with scalafix.sbt.BuildInfo.scala213 on purpose
scalafixScalaBinaryVersion :=
// this should be the default in sbt-scalafix 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package fix

import scalafix.testkit._
import scala.util.control.NonFatal
import org.scalatest.FunSuiteLike
import org.scalatest.exceptions.TestFailedException

object IntputOutputSuite {
def main(args: Array[String]): Unit = {
if (Array("--save-expect").sameElements(args)) {
val suite = new SemanticRuleSuite(
TestkitProperties.loadFromResources(),
isSaveExpect = true
) {
val suite = new AbstractSemanticRuleSuite with FunSuiteLike {
override val props = TestkitProperties.loadFromResources()
override val isSaveExpect = true

testsToRun.foreach { t =>
try evaluateTestBody(t)
catch {
Expand All @@ -29,6 +30,6 @@ object IntputOutputSuite {
}
}

class IntputOutputSuite extends SemanticRuleSuite {
class IntputOutputSuite extends AbstractSemanticRuleSuite with FunSuiteLike {
runAllTests()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scalafix.internal.sbt

import coursierapi.Repository
import coursierapi.{MavenRepository, Repository}
import org.eclipse.jgit.lib.AbbreviatedObjectId
import org.scalatest.Tag
import sbt.complete.Parser
Expand Down Expand Up @@ -32,7 +32,12 @@ class SbtCompletionsSuite extends AnyFunSuite {
.fromToolClasspath(
"2.12",
Seq(exampleDependency),
Seq(Repository.central)
Seq(
Repository.central,
MavenRepository.of(
"https://oss.sonatype.org/content/repositories/snapshots"
)
)
)()
val loadedRules = mainArgs.availableRules.toList

Expand Down
9 changes: 7 additions & 2 deletions src/test/scala/scalafix/internal/sbt/ScalafixAPISuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scalafix.internal.sbt
import java.io.{ByteArrayOutputStream, PrintStream}
import java.nio.file.Files

import coursierapi.Repository
import coursierapi.{MavenRepository, Repository}
import org.scalactic.source.Position
import sbt._
import sbt.internal.sbtscalafix.Compat
Expand Down Expand Up @@ -31,7 +31,12 @@ class ScalafixAPISuite extends AnyFunSuite {
.fromToolClasspath(
"2.12",
List("ch.epfl.scala" %% "example-scalafix-rule" % "1.4.0"),
Seq(Repository.central),
Seq(
Repository.central,
MavenRepository.of(
"https://oss.sonatype.org/content/repositories/snapshots"
)
),
logger
)()
.withArgs(Arg.PrintStream(new PrintStream(baos)))
Expand Down