mirror of https://github.com/sbt/sbt.git
Remove now unnecessary helper functions
They were useful on Java 6, and aren't anymore now that we require Java >= 8
This commit is contained in:
parent
e1800e74a9
commit
817d6b6d44
|
|
@ -9,7 +9,6 @@ import java.util.regex.Pattern
|
|||
|
||||
import coursier.core.Authentication
|
||||
import coursier.ivy.IvyRepository
|
||||
import coursier.internal.FileUtil
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import java.io.{Serializable => _, _}
|
||||
|
|
@ -689,7 +688,7 @@ object Cache {
|
|||
S.schedule[Either[FileError, Unit]](pool) {
|
||||
if (referenceFileExists) {
|
||||
if (!errFile0.exists())
|
||||
FileUtil.write(errFile0, "".getBytes(UTF_8))
|
||||
Files.write(errFile0.toPath, Array.emptyByteArray)
|
||||
}
|
||||
|
||||
Right(())
|
||||
|
|
@ -891,7 +890,7 @@ object Cache {
|
|||
val sumFile = localFile(sumUrl, cache, artifact.authentication.map(_.user))
|
||||
|
||||
S.schedule(pool) {
|
||||
val sumOpt = parseRawChecksum(FileUtil.readAllBytes(sumFile))
|
||||
val sumOpt = parseRawChecksum(Files.readAllBytes(sumFile.toPath))
|
||||
|
||||
sumOpt match {
|
||||
case None =>
|
||||
|
|
@ -1038,7 +1037,7 @@ object Cache {
|
|||
def notFound(f: File) = Left(s"${f.getCanonicalPath} not found")
|
||||
|
||||
def read(f: File) =
|
||||
try Right(new String(FileUtil.readAllBytes(f), UTF_8))
|
||||
try Right(new String(Files.readAllBytes(f.toPath), UTF_8))
|
||||
catch {
|
||||
case NonFatal(e) =>
|
||||
Left(s"Could not read (file:${f.getCanonicalPath}): ${e.getMessage}")
|
||||
|
|
|
|||
|
|
@ -1,21 +1,12 @@
|
|||
package coursier.internal
|
||||
|
||||
import java.io.{ByteArrayOutputStream, File, FileInputStream, FileOutputStream, InputStream}
|
||||
import java.nio.file.Files
|
||||
import java.io.{ByteArrayOutputStream, InputStream}
|
||||
|
||||
object FileUtil {
|
||||
|
||||
def write(file: File, bytes: Array[Byte]): Unit = {
|
||||
var fos: FileOutputStream = null
|
||||
try {
|
||||
fos = new FileOutputStream(file)
|
||||
fos.write(bytes)
|
||||
fos.close()
|
||||
} finally {
|
||||
if (fos != null) fos.close()
|
||||
}
|
||||
}
|
||||
|
||||
// Won't be necessary anymore with Java 9
|
||||
// (https://docs.oracle.com/javase/9/docs/api/java/io/InputStream.html#readAllBytes--,
|
||||
// via https://stackoverflow.com/questions/1264709/convert-inputstream-to-byte-array-in-java/37681322#37681322)
|
||||
def readFully(is: InputStream): Array[Byte] = {
|
||||
val buffer = new ByteArrayOutputStream
|
||||
val data = Array.ofDim[Byte](16384)
|
||||
|
|
@ -31,18 +22,4 @@ object FileUtil {
|
|||
buffer.toByteArray
|
||||
}
|
||||
|
||||
def readAllBytes(file: File): Array[Byte] = {
|
||||
var fis: FileInputStream = null
|
||||
try {
|
||||
fis = new FileInputStream(file)
|
||||
readFully(fis)
|
||||
} finally {
|
||||
if (fis != null)
|
||||
fis.close()
|
||||
}
|
||||
}
|
||||
|
||||
def createTempDirectory(prefix: String): File =
|
||||
Files.createTempDirectory(prefix).toFile
|
||||
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ object Bootstrap extends CaseApp[BootstrapOptions] {
|
|||
"exec java -jar " + options.options.javaOpt.map(s => "'" + s.replace("'", "\\'") + "'").mkString(" ") + " \"$0\" \"$@\""
|
||||
).mkString("", "\n", "\n")
|
||||
|
||||
try FileUtil.write(output0, shellPreamble.getBytes(UTF_8) ++ buffer.toByteArray)
|
||||
try Files.write(output0.toPath, shellPreamble.getBytes(UTF_8) ++ buffer.toByteArray)
|
||||
catch { case e: IOException =>
|
||||
Console.err.println(s"Error while writing $output0${Option(e.getMessage).fold("")(" (" + _ + ")")}")
|
||||
sys.exit(1)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ package coursier.cli
|
|||
|
||||
import java.io.{BufferedReader, File, InputStream, InputStreamReader, PipedInputStream, PipedOutputStream, PrintStream}
|
||||
import java.nio.charset.StandardCharsets.UTF_8
|
||||
|
||||
import coursier.internal.FileUtil
|
||||
import java.nio.file.Files
|
||||
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
|
|
@ -56,7 +55,7 @@ object SparkOutputHelper {
|
|||
if (!written) {
|
||||
println(s"Detected YARN app ID $id")
|
||||
Option(yarnAppFile.getParentFile).foreach(_.mkdirs())
|
||||
FileUtil.write(yarnAppFile, id.getBytes(UTF_8))
|
||||
Files.write(yarnAppFile.toPath, id.getBytes(UTF_8))
|
||||
written = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import coursier.Cache
|
|||
import coursier.cli.Helper
|
||||
import coursier.cli.options.CommonOptions
|
||||
import coursier.cli.util.Zip
|
||||
import coursier.internal.FileUtil
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
|
|
@ -225,7 +224,7 @@ object Assembly {
|
|||
throw new Exception(s"SHA-1 file not found for ${a.url}")
|
||||
}
|
||||
|
||||
val sumOpt = Cache.parseRawChecksum(FileUtil.readAllBytes(f))
|
||||
val sumOpt = Cache.parseRawChecksum(Files.readAllBytes(f.toPath))
|
||||
|
||||
sumOpt match {
|
||||
case Some(sum) =>
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ import argonaut.Argonaut._
|
|||
import caseapp.core.RemainingArgs
|
||||
import coursier.cli.options._
|
||||
import coursier.cli.util.{DepNode, ReportNode}
|
||||
import coursier.internal.FileUtil
|
||||
import java.io._
|
||||
import java.net.URLEncoder.encode
|
||||
import java.nio.charset.StandardCharsets.UTF_8
|
||||
import java.nio.file.Files
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.FlatSpec
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
|
@ -831,14 +832,14 @@ class CliFetchIntegrationTest extends FlatSpec with CliTestLib {
|
|||
}
|
||||
|
||||
val junitPomFile: File = runFetchJunit
|
||||
val originalPomContent = FileUtil.readAllBytes(junitPomFile)
|
||||
val originalPomContent = Files.readAllBytes(junitPomFile.toPath)
|
||||
|
||||
// Corrupt the pom content
|
||||
FileUtil.write(junitPomFile, "bad pom".getBytes(UTF_8))
|
||||
Files.write(junitPomFile.toPath, "bad pom".getBytes(UTF_8))
|
||||
|
||||
// Run fetch again and it should pass because of retrying om the bad pom.
|
||||
val pom = runFetchJunit
|
||||
assert(FileUtil.readAllBytes(pom).sameElements(originalPomContent))
|
||||
assert(Files.readAllBytes(pom.toPath).sameElements(originalPomContent))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -856,14 +857,14 @@ class CliFetchIntegrationTest extends FlatSpec with CliTestLib {
|
|||
}
|
||||
|
||||
val originalJunitJar: File = runFetchJunit
|
||||
val originalJunitJarContent = FileUtil.readAllBytes(originalJunitJar)
|
||||
val originalJunitJarContent = Files.readAllBytes(originalJunitJar.toPath)
|
||||
|
||||
// Corrupt the jar content
|
||||
FileUtil.write(originalJunitJar, "bad jar".getBytes(UTF_8))
|
||||
Files.write(originalJunitJar.toPath, "bad jar".getBytes(UTF_8))
|
||||
|
||||
// Run fetch again and it should pass because of retrying on the bad jar.
|
||||
val jar = runFetchJunit
|
||||
assert(FileUtil.readAllBytes(jar).sameElements(originalJunitJarContent))
|
||||
assert(Files.readAllBytes(jar.toPath).sameElements(originalJunitJarContent))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -882,7 +883,7 @@ class CliFetchIntegrationTest extends FlatSpec with CliTestLib {
|
|||
|
||||
val originalJunitJar: File = runFetchJunit
|
||||
|
||||
val originalJunitJarContent = FileUtil.readAllBytes(originalJunitJar)
|
||||
val originalJunitJarContent = Files.readAllBytes(originalJunitJar.toPath)
|
||||
|
||||
// Move the jar to partial (but complete) download
|
||||
val newJunitJar: File = new File(originalJunitJar.getAbsolutePath + ".part")
|
||||
|
|
@ -890,7 +891,7 @@ class CliFetchIntegrationTest extends FlatSpec with CliTestLib {
|
|||
|
||||
// Run fetch again and it should pass because of retrying on the partial jar.
|
||||
val jar = runFetchJunit
|
||||
assert(FileUtil.readAllBytes(jar).sameElements(originalJunitJarContent))
|
||||
assert(Files.readAllBytes(jar.toPath).sameElements(originalJunitJarContent))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package coursier.cli
|
||||
|
||||
import coursier.internal.FileUtil
|
||||
import java.io.{File, FileWriter}
|
||||
import java.nio.file.Files
|
||||
|
||||
|
||||
trait CliTestLib {
|
||||
|
|
@ -24,7 +24,7 @@ trait CliTestLib {
|
|||
def withTempDir(
|
||||
prefix: String
|
||||
)(testCode: File => Any) {
|
||||
val dir = FileUtil.createTempDirectory(prefix) // create the fixture
|
||||
val dir = Files.createTempDirectory(prefix).toFile // create the fixture
|
||||
try {
|
||||
testCode(dir) // "loan" the fixture to the test
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package coursier
|
||||
|
||||
import java.nio.charset.StandardCharsets.UTF_8
|
||||
import java.nio.file.Files
|
||||
|
||||
import coursier.internal.FileUtil
|
||||
import org.apache.ivy.core.module.id.ModuleRevisionId
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.xml.{Node, PrefixedAttribute}
|
||||
|
||||
import sbt.internal.librarymanagement.IvySbt
|
||||
|
||||
object IvyXml {
|
||||
|
|
@ -54,11 +53,11 @@ object IvyXml {
|
|||
val content0 = rawContent(currentProject, shadedConfigOpt)
|
||||
cacheIvyFile.getParentFile.mkdirs()
|
||||
log.info(s"Writing Ivy file $cacheIvyFile")
|
||||
FileUtil.write(cacheIvyFile, content0.getBytes(UTF_8))
|
||||
Files.write(cacheIvyFile.toPath, content0.getBytes(UTF_8))
|
||||
|
||||
// Just writing an empty file here... Are these only used?
|
||||
cacheIvyPropertiesFile.getParentFile.mkdirs()
|
||||
FileUtil.write(cacheIvyPropertiesFile, Array())
|
||||
Files.write(cacheIvyPropertiesFile.toPath, Array.emptyByteArray)
|
||||
}
|
||||
|
||||
def content(project0: Project, shadedConfigOpt: Option[String]): Node = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue