Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cchantep committed May 15, 2020
1 parent 47226a2 commit e603156
Show file tree
Hide file tree
Showing 10 changed files with 647 additions and 218 deletions.
114 changes: 100 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
version: 2
version: 2.1

commands:
collect_test_reports:
description: Collect test reports
steps:
- run:
name: Collect test report
command: |
mkdir test-reports
find . -path '*/test-reports/*' -name '*.xml' \
-print -exec cp {} test-reports \;
when: always

publish_snapshots:
description: Publish artifacts to Snapshots repository
steps:
- deploy:
name: Publish artifacts to Sonatype Snapshots
command: |
if [ ! "${CIRCLE_BRANCH}" = "master" ]; then
echo "Skipped on branch ${CIRCLE_BRANCH}"
exit 0
fi
export PUBLISH_REPO_NAME="Sonatype Nexus Repository Manager"
export PUBLISH_REPO_ID="oss.sonatype.org"
export PUBLISH_REPO_URL="https://oss.sonatype.org/content/repositories/snapshots"
if [ "x$PUBLISH_USER" = "x" -o "x$PUBLISH_PASS" = "x" ]; then
echo "Missing publication credentials"
exit 1
fi
sbt +publish
jobs:
build:
build_n_tests:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk

working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
TERM: dumb

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.sbt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- &scala_cache_key scala-{{ checksum "version.sbt" }}-{{ checksum "compiler.sbt" }}-{{ checksum "build.sbt" }}

- run:
name: Tests
Expand All @@ -29,7 +55,67 @@ jobs:
- save_cache:
paths:
- ~/.ivy2
key: v1-dependencies--{{ checksum "build.sbt" }}
- ~/.coursier/cache
- ~/.sbt
key: *scala_cache_key

- collect_test_reports
- store_test_results:
path: .
path: test-reports

publish_snapshots:
docker:
- image: circleci/openjdk:8-jdk

working_directory: ~/repo

steps:
- checkout

- restore_cache:
keys:
- *scala_cache_key

- publish_snapshots

- save_cache:
paths:
- ~/.ivy2
- ~/.coursier/cache
- ~/.sbt
key: *scala_cache_key

trigger_dependent_builds:
docker:
- image: cimg/base:2020.01

working_directory: ~/repo

steps:
- run:
name: Trigger build @ Reactivemongo-Site
command: |
curl -X POST "https://circleci.com/api/v1.1/project/github/ReactiveMongo/reactivemongo-site/build?circle-token=${REACTIVEMONGO_SITE_API_TOKEN}"
workflows:
version: 2

main_suite:
jobs:
- build_n_tests

- publish_snapshots:
filters:
branches:
only:
- master
requires:
- build_n_tests

- trigger_dependent_builds:
filters:
branches:
only:
- master
requires:
- publish_snapshots
78 changes: 78 additions & 0 deletions input/src/main/scala/fix/ApiUsage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
rule = ReactiveMongoUpgrade
*/
package fix

import scala.concurrent.{ ExecutionContext, Future }

import reactivemongo.api.{ MongoDriver, MongoConnection }
import reactivemongo.api.commands.{ CollStatsResult, WriteConcern }

import reactivemongo.api.commands.MultiBulkWriteResult

import reactivemongo.api.collections.GenericCollection
import reactivemongo.api.collections.bson.BSONCollection

import com.github.ghik.silencer.silent

object Commands {
def collStats(drv: MongoDriver, wc: WriteConcern): Future[CollStatsResult] = ???

def bulk: Future[MultiBulkWriteResult] = ???
}

object Drv {
def connect(d: MongoDriver) = d.connection("mongodb://...")

def closeCon(con: MongoConnection) = con.askClose()(null)

@silent
def conFromStr(uri: String)(implicit ec: ExecutionContext) =
MongoConnection.parseURI(uri)
}

object Coll {
import reactivemongo.bson.BSONDocument

@silent def rename1(coll: GenericCollection[_])(
implicit
ec: ExecutionContext) = coll.rename("foo")

@silent def rename2(coll: BSONCollection)(
implicit
ec: ExecutionContext) = coll.rename("foo", false)

def query1(coll: BSONCollection) = {
val qry = coll.find(BSONDocument.empty, BSONDocument("bar" -> 1)).
partial

val b = qry.sortOption
val c = qry.projectionOption
val d = qry.hintOption
val e = qry.explainFlag
val f = qry.snapshotFlag
val g = qry.commentString
val h = qry.maxTimeMsOption

if (System.currentTimeMillis() == -1) {
println(s"b=$b,c=$c,d=$d,e=$e,f=$f,g=$g,h=$h")
}
}

def query2(coll: BSONCollection) = coll.find(
projection = BSONDocument("lorem" -> 1),
selector = BSONDocument.empty)

@silent
def agg1(coll: BSONCollection)(implicit ec: ExecutionContext) =
coll.aggregateWith1[BSONDocument](explain = true, true) { f =>
import f._

val m = Match(BSONDocument("foo" -> 1))
val _ = m.makePipe

m -> List(Out("bar"))
}

def agg2(coll: BSONCollection) = coll.BatchCommands.AggregationFramework
}
4 changes: 2 additions & 2 deletions input/src/main/scala/fix/LinterUsage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package fix

import scala.concurrent.Future

import reactivemongo.api.{ DB, DefaultDB }
import reactivemongo.api.DB

object LinterUsage {
val db1 = resolveDB // assert: ReactiveMongoLinter

val db2: Future[DB] = db1

private def resolveDB: Future[DefaultDB] = ???
private def resolveDB: Future[DB] = ???
}
72 changes: 72 additions & 0 deletions output/src/main/scala/fix/ApiUsage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package fix

import scala.concurrent.{ ExecutionContext, Future }

import reactivemongo.api.MongoConnection


import reactivemongo.api.collections.GenericCollection
import reactivemongo.api.bson.collection.BSONCollection

import com.github.ghik.silencer.silent
import reactivemongo.api.{ AsyncDriver, CollectionStats, WriteConcern }
import reactivemongo.api.bson.BSONDocument

object Commands {
def collStats(drv: AsyncDriver, wc: WriteConcern): Future[CollectionStats] = ???

def bulk: Future[Any /* MultiBulkWriteResult ~> anyCollection.MultiBulkWriteResult */] = ???
}

object Drv {
def connect(d: AsyncDriver) = d.connect("mongodb://...")

def closeCon(con: MongoConnection) = con.close()(null)

@silent
def conFromStr(uri: String)(implicit ec: ExecutionContext) =
MongoConnection.fromString(uri)
}

object Coll {

@silent def rename1(coll: GenericCollection[_])(
implicit
ec: ExecutionContext) = coll.db.connection.database("admin").flatMap(_.renameCollection(coll.db.name, coll.name, "foo"))

@silent def rename2(coll: BSONCollection)(
implicit
ec: ExecutionContext) = coll.db.connection.database("admin").flatMap(_.renameCollection(coll.db.name, coll.name, "foo", false))

def query1(coll: BSONCollection) = {
val qry = coll.find(BSONDocument.empty, Some(BSONDocument("bar" -> 1))).
allowPartialResults

val b = qry.sort
val c = qry.projection
val d = qry.hint
val e = qry.explain
val f = qry.snapshot
val g = qry.comment
val h = qry.maxTimeMs

if (System.currentTimeMillis() == -1) {
println(s"b=$b,c=$c,d=$d,e=$e,f=$f,g=$g,h=$h")
}
}

def query2(coll: BSONCollection) = coll.find(selector = BSONDocument.empty, projection = Some(BSONDocument("lorem" -> 1)))

@silent
def agg1(coll: BSONCollection)(implicit ec: ExecutionContext) =
coll.aggregateWith[BSONDocument](explain = true, true) { f =>
import f._

val m = Match(BSONDocument("foo" -> 1))
val _ = m

m -> List(Out("bar"))
}

def agg2(coll: BSONCollection) = coll.AggregationFramework
}
6 changes: 2 additions & 4 deletions output/src/main/scala/fix/Bson.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package fix

import reactivemongo.api.bson._
import reactivemongo.api.bson.BSONValue
import reactivemongo.api.bson.{ BSONDocument, BSONObjectID }

import reactivemongo.api.bson.collection.BSONSerializationPack
import reactivemongo.api.bson.collection.BSONCollection
import reactivemongo.api.bson.{ BSONDocument, BSONObjectID, BSONValue, _ }
import reactivemongo.api.bson.collection.BSONSerializationPack

object Bson {
@com.github.ghik.silencer.silent
Expand Down
4 changes: 2 additions & 2 deletions output/src/main/scala/fix/LinterUsage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package fix

import scala.concurrent.Future

import reactivemongo.api.{ DB, DefaultDB }
import reactivemongo.api.DB

object LinterUsage {
val db1 = resolveDB

val db2: Future[DB] = db1

private def resolveDB: Future[DefaultDB] = ???
private def resolveDB: Future[DB] = ???
}
10 changes: 5 additions & 5 deletions output/src/main/scala/fix/gridfs/Compatible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package fix.gridfs

import scala.concurrent.ExecutionContext

import reactivemongo.api.bson.BSONValue

import reactivemongo.api.bson.collection.BSONSerializationPack
import reactivemongo.api.DefaultDB
import reactivemongo.api.gridfs.{ GridFS, ReadFile }
import reactivemongo.api.DB
import reactivemongo.api.bson.BSONValue
import reactivemongo.api.bson.collection.BSONSerializationPack

object Compatible {
def resolve1(db: DefaultDB) =
def resolve1(db: DB) =
db.gridfs

def resolve2(db: DefaultDB) =
def resolve2(db: DB) =
db.gridfs("foo")

// ---
Expand Down
2 changes: 1 addition & 1 deletion output/src/main/scala/fix/gridfs/RequireMigration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.github.ghik.silencer.silent

import scala.concurrent.ExecutionContext

import reactivemongo.api.bson.collection.BSONSerializationPack
import reactivemongo.api.gridfs.GridFS
import reactivemongo.api.bson.collection.BSONSerializationPack

object RequireMigration {
@silent
Expand Down
3 changes: 2 additions & 1 deletion output/src/main/scala/fix/play/Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import scala.concurrent.Future
import play.modules.reactivemongo.{
MongoController,
ReactiveMongoComponents
}, MongoController.GridFS
}

import com.github.ghik.silencer.silent
import MongoController.GridFS

trait Controller extends MongoController { self: ReactiveMongoComponents =>
@silent
Expand Down
Loading

0 comments on commit e603156

Please sign in to comment.