Skip to content

Commit

Permalink
Apply refactorings after review
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Feb 2, 2022
1 parent fc2d635 commit f0a70df
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
23 changes: 12 additions & 11 deletions backend/src/main/scala/bloop/BloopClassFileManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ final class BloopClassFileManager(
val toBeBackedUp = (classes ++ invalidatedExtraCompileProducts).filter(c =>
!movedFiles.contains(c) && !generatedFiles(c)
)
for (c <- toBeBackedUp)
if (c.exists)
movedFiles.put(c, move(c)).foreach(move)
for {
c <- toBeBackedUp
if c.exists()
} movedFiles.put(c, move(c)).foreach(move)

classes.foreach { f =>
if (f.exists()) f.delete()
}
for {
f <- classes
if f.exists()
} f.delete()

allInvalidatedExtraCompileProducts.++=(invalidatedExtraCompileProducts)
}
Expand Down Expand Up @@ -227,13 +229,12 @@ final class BloopClassFileManager(
*/
for {
(orig, tmp) <- movedFiles
if tmp.exists
} {
if (tmp.exists) {
if (!orig.getParentFile.exists) {
Files.createDirectory(orig.getParentFile.toPath())
}
Files.move(tmp.toPath(), orig.toPath())
if (!orig.getParentFile.exists) {
Files.createDirectory(orig.getParentFile.toPath())
}
Files.move(tmp.toPath(), orig.toPath())
}
backupDir.toFile().delete()
()
Expand Down
5 changes: 3 additions & 2 deletions backend/src/main/scala/bloop/BloopClasspathEntryLookup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ final class BloopClasspathEntryLookup(
}

override def definesClass(entry: VirtualFile): DefinesClass = {
val file = converter.toPath(entry).toFile()
val path = converter.toPath(entry)
val file = path.toFile()
if (!file.exists) FalseDefinesClass
else {
classpathHashes.find(fh => fh.file() == file) match {
case None => FalseDefinesClass
case Some(entryHash) =>
def computeDefinesClassForJar = {
if (!ClasspathUtil.isArchive(file.toPath(), contentFallback = true)) FalseDefinesClass
if (!ClasspathUtil.isArchive(path, contentFallback = true)) FalseDefinesClass
else new JarDefinesClass(file)
}

Expand Down
1 change: 0 additions & 1 deletion backend/src/main/scala/bloop/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ object Compiler {
def getCompilationOptions(inputs: CompileInputs): CompileOptions = {
// Sources are all files
val sources = inputs.sources.map(path => converter.toVirtualFile(path.underlying))

val classpath = inputs.classpath.map(path => converter.toVirtualFile(path.underlying))
val optionsWithoutFatalWarnings = inputs.scalacOptions.flatMap { option =>
if (option != "-Xfatal-warnings") List(option)
Expand Down
6 changes: 4 additions & 2 deletions backend/src/main/scala/bloop/CompilerCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ final class CompilerCache(
BloopForkedJavaUtils.launch(
javaHome,
"javac",
sources.map(converter.toPath(_).toFile()),
sources.map(converter.toPath(_)),
options,
log,
reporter
Expand Down Expand Up @@ -332,7 +332,9 @@ final class CompilerCache(
zincManager match {
case m: bloop.BloopClassFileManager => m.invalidatedClassFilesSet
// Bloop uses it's own classfile manager so this should not happen
case _ => new HashSet[File]()
case _ =>
logger.warn("Could not find BloopClassfileManager that is needed for invaldiation.")
new HashSet[File]()

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ object BloopComponentCompiler {
}

val (isDotty, organization, version) = scalaInstance match {
case instance: BloopScalaInstance =>
if (instance.isDotty) (true, instance.organization, instance.version)
else (false, "org.scala-sbt", latestVersion)
case instance: ScalaInstance => (false, "org.scala-sbt", latestVersion)
case instance: BloopScalaInstance if instance.isDotty => (true, instance.organization, instance.version)
case _ => (false, "org.scala-sbt", latestVersion)
}

val bridgeId = compilerBridgeId(scalaInstance.version)
Expand Down Expand Up @@ -375,13 +373,13 @@ private[inc] class BloopComponentCompiler(

logger.debug(s"Sources from bloop bridge: $regularSourceContents")

val mergedJar = Files.createTempFile(HydraSupport.bridgeNamePrefix, "merged").toFile
val mergedJar = Files.createTempFile(HydraSupport.bridgeNamePrefix, "merged")
logger.debug(s"Merged jar destination: $mergedJar")
val allSourceContents =
(hydraSourceContents ++ regularSourceContents).map(s => s -> relativize(tempDir, s).get)

zip(allSourceContents.toSeq, mergedJar, time = None)
Right(Vector(mergedJar.toPath()))
zip(allSourceContents.toSeq, mergedJar.toFile(), time = None)
Right(Vector(mergedJar))
}

case Right(Seq()) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package sbt.internal.inc.javac
import java.io.File
import xsbti.Logger
import xsbti.Reporter
import java.nio.file.Path

object BloopForkedJavaUtils {
def launch(
javac: Option[File],
binaryName: String,
sources: Seq[File],
sources: Seq[Path],
options: Seq[String],
log: Logger,
reporter: Reporter
): Boolean = {
def normalizeSlash(s: String) = s.replace(File.separatorChar, '/')

val (jArgs, nonJArgs) = options.partition(_.startsWith("-J"))
val allArguments = nonJArgs ++ sources.map(_.getAbsolutePath)
val allArguments = nonJArgs ++ sources.map(_.toAbsolutePath().toString())

val exe = javac match {
case None => binaryName
Expand Down

0 comments on commit f0a70df

Please sign in to comment.