diff --git a/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala b/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala index 1fb6b6f..62edd70 100644 --- a/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala +++ b/src/main/scala/uk/org/floop/sparqlTestRunner/Run.scala @@ -16,11 +16,6 @@ package uk.org.floop.sparqlTestRunner -import java.io._ -import java.net.URI -import java.nio.charset.StandardCharsets -import java.nio.file.{Files, Path} -import java.util import org.apache.http.HttpHeaders import org.apache.http.auth.{AuthScope, UsernamePasswordCredentials} import org.apache.http.client.protocol.HttpClientContext @@ -35,8 +30,14 @@ import org.apache.jena.sparql.engine.http.QueryEngineHTTP import scopt.OptionParser +import java.io._ +import java.net.URI +import java.nio.charset.StandardCharsets +import java.nio.file.{Files, Path} +import java.util import scala.io.Source -import scala.xml.{NodeSeq, PCData, PrettyPrinter, XML} +import scala.util.Using +import scala.xml.{NodeSeq, PCData, XML} case class Config(dir: File = new File("tests/sparql"), report: File = new File("reports/TESTS-sparql-test-runner.xml"), @@ -199,9 +200,11 @@ } else if (f.isFile && f.getName.endsWith(".sparql")) { val timeTestStart = System.currentTimeMillis() val relativePath = root.relativize(f.toPath).toString - val className = relativePath.substring(0, relativePath.lastIndexOf('.')).replace(File.pathSeparatorChar, '.') + val className = relativePath + .substring(0, relativePath.lastIndexOf('.')) + .replace(File.pathSeparatorChar, '.') val comment = { - val queryLines = Source.fromFile(f).getLines() + val queryLines = Using(Source.fromFile(f))(_.getLines()).get if (queryLines.hasNext) { val line = queryLines.next() if (line.startsWith("# ")) diff --git a/src/main/scala/uk/org/floop/updateInPlace/Run.scala b/src/main/scala/uk/org/floop/updateInPlace/Run.scala index a973b05..b528e45 100644 --- a/src/main/scala/uk/org/floop/updateInPlace/Run.scala +++ b/src/main/scala/uk/org/floop/updateInPlace/Run.scala @@ -16,22 +16,21 @@ package uk.org.floop.updateInPlace -import java.io.{File, FileOutputStream, FileWriter} -import java.nio.file.{Files, Path} - -import org.apache.jena.query.{Dataset, DatasetFactory, QueryExecutionFactory, QueryFactory} -import org.apache.jena.rdf.model.{Model, ModelFactory} -import org.apache.jena.riot.{Lang, RDFDataMgr, RDFLanguages} +import org.apache.jena.query.{Dataset, DatasetFactory} +import org.apache.jena.riot.{RDFDataMgr, RDFLanguages} import org.apache.jena.update.UpdateAction +import java.io.{File, FileOutputStream} +import java.nio.file.Files import scala.io.Source +import scala.util.Using case class Config(dir: File = new File("sparql"), data: File = null) object Run extends App { - val packageVersion: String = getClass.getPackage.getImplementationVersion() + val packageVersion: String = getClass.getPackage.getImplementationVersion val parser = new scopt.OptionParser[Config]("sparql-update-in-place") { head("sparql-update-in-place", packageVersion) opt[File]('q', "querydir") @@ -52,15 +51,17 @@ runQueriesUnder(config.dir, dataset, config.data) val out = new FileOutputStream(config.data) RDFDataMgr.write(out, dataset.getDefaultModel, RDFLanguages.filenameToLang(config.data.toString)) - out.close + out.close() } def runQueriesUnder(dir: File, dataset: Dataset, out: File): Unit = { - Files.walk(dir.toPath()). - filter(Files.isRegularFile(_)). - sorted((p1, p2) => p1.compareTo((p2))). - forEach { p => - UpdateAction.parseExecute(Source.fromFile(p.toFile).mkString, dataset) + Files.walk(dir.toPath) + .filter(Files.isRegularFile(_)) + .sorted((p1, p2) => p1.compareTo(p2)) + .forEach { p => + Using(Source.fromFile(p.toFile)) { src => + UpdateAction.parseExecute(src.mkString, dataset) + } } }