Skip to content

Commit

Permalink
Make the Output API more Java friendly
Browse files Browse the repository at this point in the history
* Make methods in `Output` subclasses public
* Changes to the API. Java idiomatic renames:
  * sourceDirectory -> getSourceDirectory
  * outputDirectory -> getOutputDirectory
  • Loading branch information
jvican committed May 21, 2017
1 parent 73ff81a commit df6f5a4
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sealed abstract class CallbackGlobal(settings: Settings,
output match {
case single: SingleOutput => List(single.getOutputDirectory)
// Use Stream instead of List because Analyzer maps intensively over the directories
case multi: MultipleOutput => multi.getOutputGroups.toStream map (_.outputDirectory)
case multi: MultipleOutput => multi.getOutputGroups.toStream map (_.getOutputDirectory)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ private final class CachedCompiler0(args: Array[String],
case multi: MultipleOutput =>
for (out <- multi.getOutputGroups)
settings.outputDirs
.add(out.sourceDirectory.getAbsolutePath, out.outputDirectory.getAbsolutePath)
.add(out.getSourceDirectory.getAbsolutePath, out.getOutputDirectory.getAbsolutePath)
case single: SingleOutput =>
settings.outputDirs.setSingleOutput(single.getOutputDirectory.getAbsolutePath)
val outputFilepath = single.getOutputDirectory.getAbsolutePath
settings.outputDirs.setSingleOutput(outputFilepath)
}

val command = Command(args.toList, settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface MultipleOutput extends Output {
* don't play with them out of the Zinc API. Zinc already takes care of
* deleting classes before every compilation run.
*/
OutputGroup[] getOutputGroups();
public OutputGroup[] getOutputGroups();

@Override
public default Optional<File> getSingleOutput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface OutputGroup extends Serializable {
* Note that source directories should uniquely identify the group
* for a certain source file.
*/
public File sourceDirectory();
public File getSourceDirectory();

/**
* Return the directory where class files should be generated.
Expand All @@ -24,5 +24,5 @@ public interface OutputGroup extends Serializable {
* <p>
* This directory must be exclusively used for one set of sources.
*/
public File outputDirectory();
public File getOutputDirectory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface SingleOutput extends Output {
* <p>
* This directory must be exclusively used for one set of sources.
*/
File getOutputDirectory();
public File getOutputDirectory();

@Override
public default Optional<File> getSingleOutput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object CompileOutput {
def getOutputGroups = groups.toArray map {
case (src, out) =>
new OutputGroup {
def sourceDirectory = src
def outputDirectory = out
def getSourceDirectory = src
def getOutputDirectory = out
override def toString = s"OutputGroup($src -> $out)"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ object MiniSetupUtil {
implicit val equivOutput: Equiv[APIOutput] = {
new Equiv[APIOutput] {
implicit val outputGroupsOrdering =
Ordering.by((og: OutputGroup) => og.sourceDirectory)
Ordering.by((og: OutputGroup) => og.getSourceDirectory)

def equiv(out1: APIOutput, out2: APIOutput) = (out1, out2) match {
case (m1: MultipleOutput, m2: MultipleOutput) =>
(m1.getOutputGroups.length == m2.getOutputGroups.length) &&
(m1.getOutputGroups.sorted zip m2.getOutputGroups.sorted forall {
case (a, b) =>
equivFile
.equiv(a.sourceDirectory, b.sourceDirectory) && equivFile
.equiv(a.outputDirectory, b.outputDirectory)
.equiv(a.getSourceDirectory, b.getSourceDirectory) && equivFile
.equiv(a.getOutputDirectory, b.getOutputDirectory)
})
case (s1: SingleOutput, s2: SingleOutput) =>
equivFile.equiv(s1.getOutputDirectory, s2.getOutputDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import java.io.File

import xsbti.compile.OutputGroup

case class SimpleOutputGroup(sourceDirectory: File, outputDirectory: File) extends OutputGroup
case class SimpleOutputGroup(getSourceDirectory: File, getOutputDirectory: File)
extends OutputGroup
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class TextAnalysisFormat(override val mappers: AnalysisMappers)
(singleOutputMode, Map(ignored -> s.getOutputDirectory))
case m: MultipleOutput =>
(multipleOutputMode,
m.getOutputGroups.map(x => x.sourceDirectory -> x.outputDirectory).toMap)
m.getOutputGroups.map(x => x.getSourceDirectory -> x.getOutputDirectory).toMap)
}

writeSeq(out)(Headers.outputMode, mode :: Nil, identity[String])
Expand Down Expand Up @@ -364,20 +364,18 @@ class TextAnalysisFormat(override val mappers: AnalysisMappers)
case Some(s) =>
s match {
case `singleOutputMode` =>
new SingleOutput {
val getOutputDirectory = outputAsMap.values.head
}
new SingleOutput { val getOutputDirectory = outputAsMap.values.head }
case `multipleOutputMode` =>
new MultipleOutput {
val getOutputGroups: Array[OutputGroup] = outputAsMap.toArray.map {
case (src: File, out: File) =>
new OutputGroup {
val sourceDirectory = src
val outputDirectory = out
val getSourceDirectory = src
val getOutputDirectory = out
override def toString = s"OutputGroup($src -> $out)"
}
}
override def toString = s"MultipleOuput($getOutputGroups)"
override def toString = s"MultipleOutput($getOutputGroups)"
}
case str: String => throw new ReadException("Unrecognized output mode: " + str)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
case multiOutput: MultipleOutput =>
multiOutput
.getOutputGroups()
.map(_.outputDirectory().toString)
.map(_.getOutputDirectory().toString)
.mkString("[", ", ", "]")
case _ =>
s"other output ($output)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ final class MixedAnalyzingCompiler(
private[this] def outputDirectories(output: Output): Seq[File] = {
output match {
case single: SingleOutput => List(single.getOutputDirectory)
case mult: MultipleOutput => mult.getOutputGroups map (_.outputDirectory)
case mult: MultipleOutput => mult.getOutputGroups map (_.getOutputDirectory)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ final class AnalyzingJavaCompiler private[sbt] (
sources.groupBy { src =>
multi.getOutputGroups
.find { out =>
ancestor(out.sourceDirectory, src)
ancestor(out.getSourceDirectory, src)
}
.map(_.outputDirectory)
.map(_.getOutputDirectory)
}
}

Expand Down

0 comments on commit df6f5a4

Please sign in to comment.