Skip to content

Commit

Permalink
Merge pull request scalacenter#490 from olafurpg/unmanagedSources
Browse files Browse the repository at this point in the history
Use unmanagedSources instead of unmanagedSourceDirectories.
  • Loading branch information
MasseGuillaume authored Dec 10, 2017
2 parents 4d46001 + e9b2b0a commit b48d7f0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
20 changes: 14 additions & 6 deletions scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,17 @@ object ScalafixPlugin extends AutoPlugin {
Def.taskDyn {
compile.all(filter).value // trigger compilation
val classpath = classDirectory.all(filter).value.asPath
val directoriesToFix: Seq[File] =
unmanagedSourceDirectories.all(filter).value.flatten.collect {
case p if p.exists() => p.getAbsoluteFile
}
val sourcesToFix = for {
sources <- unmanagedSources.all(filter).value
source <- sources
if source.exists()
if canFix(source)
} yield source
val options: Seq[String] = List("--classpath", classpath) ++ extraOptions
scalafixTaskImpl(
inputArgs,
options,
directoriesToFix,
sourcesToFix,
thisProject.value.id,
streams.value
)
Expand Down Expand Up @@ -285,13 +287,19 @@ object ScalafixPlugin extends AutoPlugin {
)
}
val finalArgs = args ++ files.map(_.getAbsolutePath)
val nonBaseArgs = finalArgs.filterNot(baseArgs).mkString(" ")
val nonBaseArgs = args.filterNot(baseArgs).mkString(" ")
log.info(s"Running scalafix $nonBaseArgs")
main.main(finalArgs.toArray)
}
}
}

private def canFix(file: File): Boolean = {
val path = file.getPath
path.endsWith(".scala") ||
path.endsWith(".sbt")
}

private[scalafix] implicit class XtensionFormatClasspath(paths: Seq[File]) {
def asPath: String =
paths.toIterator
Expand Down
4 changes: 4 additions & 0 deletions scalafix-sbt/src/sbt-test/sbt-scalafix/cross-build/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ inThisBuild(
lazy val root = project
.in(file("."))
.aggregate(
javaProject,
customSourceroot,
scala211,
scala210,
Expand All @@ -28,6 +29,9 @@ lazy val customSourceroot = project.settings(
scalaVersion := Versions.scala212,
scalafixSourceroot := sourceDirectory.value
)
lazy val javaProject = project.settings(
scalaVersion := Versions.scala212
)

TaskKey[Unit]("check") := {
val s = streams.value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package example;

class Foo {
public static void main(String[] args) {
System.out.println(args);
}
}
1 change: 1 addition & 0 deletions scalafix-sbt/src/sbt-test/sbt-scalafix/cross-build/test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-> scalafixTest ProcedureSyntax
> scalafix ProcedureSyntax
> scalafixTest ProcedureSyntax
> javaProject/scalafix ProcedureSyntax
# Should fail because 2.10 has no semanticdb
# Other >2.10 projects should succeed
-> scalafix
Expand Down

0 comments on commit b48d7f0

Please sign in to comment.