mirror of
https://github.com/sbt/sbt.git
synced 2026-08-22 14:17:13 +02:00
Use IO.write instead of explicit resource management
This commit is contained in:
+2
-10
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
package sbt;
|
package sbt;
|
||||||
|
|
||||||
import java.io.{BufferedWriter, File, OutputStreamWriter, FileOutputStream}
|
import java.io.File
|
||||||
import scala.xml.{Node => XNode, NodeSeq, PrettyPrinter, XML}
|
import scala.xml.{Node => XNode, NodeSeq, PrettyPrinter, XML}
|
||||||
import Configurations.Optional
|
import Configurations.Optional
|
||||||
|
|
||||||
@@ -20,21 +20,13 @@ import plugins.resolver.{ChainResolver, DependencyResolver, IBiblioResolver}
|
|||||||
|
|
||||||
class MakePom(val log: Logger)
|
class MakePom(val log: Logger)
|
||||||
{
|
{
|
||||||
def encoding = "UTF-8"
|
|
||||||
def write(ivy: Ivy, module: ModuleDescriptor, moduleInfo: ModuleInfo, configurations: Option[Iterable[Configuration]], extra: NodeSeq, process: XNode => XNode, filterRepositories: MavenRepository => Boolean, allRepositories: Boolean, output: File): Unit =
|
def write(ivy: Ivy, module: ModuleDescriptor, moduleInfo: ModuleInfo, configurations: Option[Iterable[Configuration]], extra: NodeSeq, process: XNode => XNode, filterRepositories: MavenRepository => Boolean, allRepositories: Boolean, output: File): Unit =
|
||||||
write(process(toPom(ivy, module, moduleInfo, configurations, extra, filterRepositories, allRepositories)), output)
|
write(process(toPom(ivy, module, moduleInfo, configurations, extra, filterRepositories, allRepositories)), output)
|
||||||
// use \n as newline because toString uses PrettyPrinter, which hard codes line endings to be \n
|
// use \n as newline because toString uses PrettyPrinter, which hard codes line endings to be \n
|
||||||
def write(node: XNode, output: File): Unit = write(toString(node), output, "\n")
|
def write(node: XNode, output: File): Unit = write(toString(node), output, "\n")
|
||||||
def write(xmlString: String, output: File, newline: String)
|
def write(xmlString: String, output: File, newline: String)
|
||||||
{
|
{
|
||||||
output.getParentFile.mkdirs()
|
IO.write(output, "<?xml version='1.0' encoding='" + IO.utf8 + "'?>" + newline + xmlString)
|
||||||
val out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), encoding))
|
|
||||||
try
|
|
||||||
{
|
|
||||||
out.write("<?xml version='1.0' encoding='" + encoding + "'?>" + newline)
|
|
||||||
out.write(xmlString)
|
|
||||||
}
|
|
||||||
finally { out.close() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def toString(node: XNode): String = new PrettyPrinter(1000, 4).format(node)
|
def toString(node: XNode): String = new PrettyPrinter(1000, 4).format(node)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ object WriteContentSpecification extends Properties("Write content")
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make the test independent of underlying platform and allow any unicode character in Strings to be encoded
|
// make the test independent of underlying platform and allow any unicode character in Strings to be encoded
|
||||||
val charset = java.nio.charset.Charset.forName("UTF-8")
|
val charset = IO.utf8
|
||||||
|
|
||||||
import IO._
|
import IO._
|
||||||
private def writeAndCheckString(s: String) =
|
private def writeAndCheckString(s: String) =
|
||||||
|
|||||||
Reference in New Issue
Block a user