Skip to content

Commit

Permalink
cli: allow several semanticdbTargetroots
Browse files Browse the repository at this point in the history
  • Loading branch information
github-brice-jaglin committed May 16, 2021
1 parent a50b823 commit d0f461c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion project/Mima.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object Mima {
ProblemFilters.exclude[Problem]("scalafix.testkit.SemanticRuleSuite.*"),
ProblemFilters.exclude[MissingClassProblem]("scalafix.testkit.SyntacticRuleSuite$"),
ProblemFilters.exclude[Problem]("scalafix.testkit.SyntacticRuleSuite"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scalafix.interfaces.ScalafixArguments.withSemanticdbTargetroot")
ProblemFilters.exclude[ReversedMissingMethodProblem]("scalafix.interfaces.ScalafixArguments.withSemanticdbTargetroots")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ final case class ScalafixArgumentsImpl(args: Args = Args.default)
copy(args = args.copy(sourceroot = Some(AbsolutePath(path)(args.cwd))))
}

override def withSemanticdbTargetroot(path: Path): ScalafixArguments = {
override def withSemanticdbTargetroots(
paths: util.List[Path]
): ScalafixArguments = {
copy(args =
args.copy(semanticdbTargetroot = Some(AbsolutePath(path)(args.cwd)))
args.copy(semanticdbTargetroots =
paths.asScala.toList.map(AbsolutePath(_)(args.cwd))
)
)
}

Expand Down
17 changes: 9 additions & 8 deletions scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ case class Args(
)
sourceroot: Option[AbsolutePath] = None,
@Description(
"Absolute path passed to semanticdb with -P:semanticdb:targetroot:<path>. " +
"Absolute paths passed to semanticdb with -P:semanticdb:targetroot:<path>. " +
"Used to locate semanticdb files. By default, Scalafix will try to locate semanticdb files in the classpath"
)
semanticdbTargetroot: Option[AbsolutePath] = None,
semanticdbTargetroots: List[AbsolutePath] = Nil,
@Description(
"If set, automatically infer the --classpath flag by scanning for directories with META-INF/semanticdb"
)
Expand Down Expand Up @@ -348,11 +348,12 @@ case class Args(
}

def validatedClasspath: Classpath = {
val targetrootClasspath = semanticdbTargetroot
.map(_.toString())
.orElse(semanticdbOption("targetroot", Some("-semanticdb-target")))
.map(option => Classpath(option))
.getOrElse(Classpath(Nil))
val targetrootClasspath = semanticdbTargetroots match {
case Nil =>
semanticdbOption("targetroot", Some("-semanticdb-target")).toList
.map(AbsolutePath.apply)
case _ => semanticdbTargetroots
}
val baseClasspath =
if (autoClasspath && classpath.entries.isEmpty) {
val roots =
Expand All @@ -362,7 +363,7 @@ case class Args(
} else {
classpath
}
targetrootClasspath ++ baseClasspath
Classpath(targetrootClasspath) ++ baseClasspath
}

def classLoader: ClassLoader =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ ScalafixArguments withToolClasspath(
ScalafixArguments withSourceroot(Path path);

/**
* @param path The SemanticDB targetroot path passed via --targetroot. Must match <code>path</code>
* @param path The SemanticDB targetroot paths passed via --targetroot. Must match <code>path</code>
* in <code>-Xplugin:semanticdb:targetroot:{path}</path></code> if used.
*/
ScalafixArguments withSemanticdbTargetroot(Path path);
ScalafixArguments withSemanticdbTargetroots(List<Path> path);

/**
* @param callback Handler for reported linter messages. If not provided, defaults to printing
Expand Down

0 comments on commit d0f461c

Please sign in to comment.