Skip to content

Commit

Permalink
Merge pull request #1944 from lift/tcn_gardening
Browse files Browse the repository at this point in the history
Code gardening:
Updated build.sbt to use newer syntax
Use JavaConverters instead of JavaConversions in mongodb and mongodb-record modules
  • Loading branch information
farmdawgnation authored Mar 3, 2018
2 parents 9a327e2 + aa1d5a8 commit 31a31a1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 55 deletions.
59 changes: 35 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ publishTo in ThisBuild := {
}
}
scmInfo in ThisBuild := Some(ScmInfo(url("/~https://github.com/lift/framework"), "scm:git:/~https://github.com/lift/framework.git"))
pomExtra in ThisBuild := Developers.toXml
pomExtra in ThisBuild := Developers.toXml

credentials in ThisBuild += Credentials(BuildPaths.getGlobalSettingsDirectory(state.value, BuildPaths.getGlobalBase(state.value)) / ".credentials")

initialize <<= (name, version, scalaVersion).apply(printLogo)
initialize := {
printLogo(name.value, version.value, scalaVersion.value)
}

resolvers in ThisBuild ++= Seq(
"snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
Expand Down Expand Up @@ -161,34 +163,37 @@ lazy val webkit =
jasmineCore,
jasmineAjax
),
initialize in Test <<= (sourceDirectory in Test) { src =>
System.setProperty("net.liftweb.webapptest.src.test.webapp", (src / "webapp").absString)
initialize in Test := {
System.setProperty(
"net.liftweb.webapptest.src.test.webapp",
((sourceDirectory in Test).value / "webapp").absString
)
},
unmanagedSourceDirectories in Compile <+= (sourceDirectory in Compile, scalaBinaryVersion) {
(sourceDirectory, binaryVersion) =>
sourceDirectory / ("scala_" + binaryVersion)
unmanagedSourceDirectories in Compile += {
(sourceDirectory in Compile).value / ("scala_" + scalaBinaryVersion.value)
},
unmanagedSourceDirectories in Test <+= (sourceDirectory in Test, scalaBinaryVersion) {
(sourceDirectory, binaryVersion) =>
sourceDirectory / ("scala_" + binaryVersion)
unmanagedSourceDirectories in Test += {
(sourceDirectory in Test).value / ("scala_" + scalaBinaryVersion.value)
},
(compile in Compile) <<= (compile in Compile) dependsOn (WebKeys.assets),
compile in Compile := (compile in Compile).dependsOn(WebKeys.assets).value,
/**
* This is to ensure that the tests in net.liftweb.webapptest run last
* so that other tests (MenuSpec in particular) run before the SiteMap
* is set.
*/
testGrouping in Test <<= (definedTests in Test).map { tests =>
import Tests._
testGrouping in Test := {
(definedTests in Test).map { tests =>
import Tests._

val (webapptests, others) = tests.partition { test =>
test.name.startsWith("net.liftweb.webapptest")
}
val (webapptests, others) = tests.partition { test =>
test.name.startsWith("net.liftweb.webapptest")
}

Seq(
new Group("others", others, InProcess),
new Group("webapptests", webapptests, InProcess)
)
Seq(
new Group("others", others, InProcess),
new Group("webapptests", webapptests, InProcess)
)
}.value
},

scalacOptions in (Compile, doc) ++= {
Expand Down Expand Up @@ -223,8 +228,11 @@ lazy val mapper =
description := "Mapper Library",
parallelExecution in Test := false,
libraryDependencies ++= Seq(h2, derby),
initialize in Test <<= (crossTarget in Test) { ct =>
System.setProperty("derby.stream.error.file", (ct / "derby.log").absolutePath)
initialize in Test := {
System.setProperty(
"derby.stream.error.file",
((crossTarget in Test).value / "derby.log").absolutePath
)
}
)

Expand All @@ -243,8 +251,11 @@ lazy val mongodb =
.settings(
parallelExecution in Test := false,
libraryDependencies ++= Seq(mongo_java_driver, mongo_java_driver_async),
initialize in Test <<= (resourceDirectory in Test) { rd =>
System.setProperty("java.util.logging.config.file", (rd / "logging.properties").absolutePath)
initialize in Test := {
System.setProperty(
"java.util.logging.config.file",
((resourceDirectory in Test).value / "logging.properties").absolutePath
)
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 WorldWide Conferencing, LLC
* Copyright 2011-2018 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@ package record
import common._

import java.util.regex.Pattern
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

import net.liftweb.record.{Field, MetaRecord, Record}
import net.liftweb.record.field._
Expand Down Expand Up @@ -155,7 +155,7 @@ trait BsonMetaRecord[BaseRecord <: BsonRecord[BaseRecord]] extends MetaRecord[Ba
* @return Unit
*/
def setFieldsFromDBObject(inst: BaseRecord, dbo: DBObject): Unit = {
for (k <- dbo.keySet; field <- inst.fieldByName(k.toString)) {
for (k <- dbo.keySet.asScala; field <- inst.fieldByName(k.toString)) {
field.setFromAny(dbo.get(k.toString))
}
inst.runSafe {
Expand All @@ -164,7 +164,7 @@ trait BsonMetaRecord[BaseRecord <: BsonRecord[BaseRecord]] extends MetaRecord[Ba
}

def setFieldsFromDocument(inst: BaseRecord, doc: Document): Unit = {
for (k <- doc.keySet; field <- inst.fieldByName(k.toString)) {
for (k <- doc.keySet.asScala; field <- inst.fieldByName(k.toString)) {
field.setFromAny(doc.get(k.toString))
}
inst.runSafe {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2017 WorldWide Conferencing, LLC
* Copyright 2010-2018 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,7 @@ import net.liftweb.record.MandatoryTypedField
import org.bson.Document
import org.bson.types.ObjectId

import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.concurrent.{Future, Promise}

trait MongoMetaRecord[BaseRecord <: MongoRecord[BaseRecord]]
Expand Down Expand Up @@ -149,7 +149,7 @@ trait MongoMetaRecord[BaseRecord <: MongoRecord[BaseRecord]]
/** Mongo Cursors are both Iterable and Iterator,
* so we need to reduce ambiguity for implicits
*/
(coll.find: Iterator[DBObject]).map(fromDBObject).toList
coll.find.iterator.asScala.map(fromDBObject).toList
}

/**
Expand Down Expand Up @@ -177,7 +177,7 @@ trait MongoMetaRecord[BaseRecord <: MongoRecord[BaseRecord]]
)
sort.foreach(s => cur.sort(s))
// This retrieves all documents and puts them in memory.
(cur: Iterator[DBObject]).map(fromDBObject).toList
cur.iterator.asScala.map(fromDBObject).toList
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2017 WorldWide Conferencing, LLC
* Copyright 2010-2018 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ package mongodb
package record
package field

import scala.collection.JavaConverters._
import scala.xml.NodeSeq

import net.liftweb.common.{Box, Empty, Failure, Full}
Expand Down Expand Up @@ -101,18 +102,15 @@ class MongoMapField[OwnerType <: BsonRecord[OwnerType], MapValueType](rec: Owner

// set this field's value using a DBObject returned from Mongo.
def setFromDBObject(dbo: DBObject): Box[Map[String, MapValueType]] = {
import scala.collection.JavaConversions._

setBox(Full(
Map() ++ dbo.keySet.map {
Map() ++ dbo.keySet.asScala.map {
k => (k.toString, dbo.get(k).asInstanceOf[MapValueType])
}
))
}

// set this field's value using a bson.Document returned from Mongo.
def setFromDocument(doc: Document): Box[Map[String, MapValueType]] = {
import scala.collection.JavaConverters._
val map: Map[String, MapValueType] = doc.asScala.map {
case (k, v) => k -> v.asInstanceOf[MapValueType]
} (scala.collection.breakOut)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2011 WorldWide Conferencing, LLC
* Copyright 2010-2018 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
package net.liftweb
package mongodb

import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

import java.util.{Date, UUID}
import java.util.regex.Pattern
Expand Down Expand Up @@ -60,14 +60,14 @@ object JObjectParser extends SimpleInjector {
case x if primitive_?(x.getClass) => primitive2jvalue(x)
case x if datetype_?(x.getClass) => datetype2jvalue(x)(formats)
case x if mongotype_?(x.getClass) => mongotype2jvalue(x)(formats)
case x: BasicDBList => JArray(x.toList.map( x => serialize(x)(formats)))
case x: BasicDBList => JArray(x.asScala.toList.map( x => serialize(x)(formats)))
case x: BasicDBObject => JObject(
x.keySet.toList.map { f =>
x.keySet.asScala.toList.map { f =>
JField(f.toString, serialize(x.get(f.toString))(formats))
}
)
case x: Document => JObject(
x.keySet.toList.map { f =>
x.keySet.asScala.toList.map { f =>
JField(f.toString, serialize(x.get(f.toString), formats))
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 WorldWide Conferencing, LLC
* Copyright 2010-2018 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -122,8 +122,8 @@ object MongoDB {
* Calls close on each MongoClient instance and clears the HashMap.
*/
def closeAll(): Unit = {
import scala.collection.JavaConversions._
dbs.values.foreach { case (mngo, _) =>
import scala.collection.JavaConverters._
dbs.values.asScala.foreach { case (mngo, _) =>
mngo.close()
}
dbs.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2011 WorldWide Conferencing, LLC
* Copyright 2010-2018 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,10 @@
package net.liftweb
package mongodb

import util.{ConnectionIdentifier, DefaultConnectionIdentifier}
import net.liftweb.json.JsonAST.JObject
import net.liftweb.util.{ConnectionIdentifier, DefaultConnectionIdentifier}

import json.JsonAST.JObject
import scala.collection.JavaConverters.asScalaIteratorConverter

import java.util.UUID

Expand Down Expand Up @@ -120,22 +121,18 @@ trait MongoDocumentMeta[BaseDocument] extends JsonObjectMeta[BaseDocument] with
* Find all documents in this collection
*/
def findAll: List[BaseDocument] = {
import scala.collection.JavaConversions._

MongoDB.useCollection(connectionIdentifier, collectionName)(coll => {
/** Mongo Cursors are both Iterable and Iterator,
* so we need to reduce ambiguity for implicits
*/
(coll.find: Iterator[DBObject]).map(create).toList
coll.find.iterator.asScala.map(create).toList
})
}

/**
* Find all documents using a DBObject query.
*/
def findAll(qry: DBObject, sort: Option[DBObject], opts: FindOption*): List[BaseDocument] = {
import scala.collection.JavaConversions._

val findOpts = opts.toList

MongoDB.useCollection(connectionIdentifier, collectionName) ( coll => {
Expand All @@ -148,7 +145,7 @@ trait MongoDocumentMeta[BaseDocument] extends JsonObjectMeta[BaseDocument] with
/** Mongo Cursors are both Iterable and Iterator,
* so we need to reduce ambiguity for implicits
*/
(cur: Iterator[DBObject]).map(create).toList
cur.iterator.asScala.map(create).toList
})
}

Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2015 WorldWide Conferencing, LLC
* Copyright 2011-2018 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 31a31a1

Please sign in to comment.