Skip to content

Commit 53eb552

Browse files
committedApr 10, 2015
migrate to strict scalac options
- no procedure syntax - no value discard - no view bounds - no implicit numeric widen - remove unused imports magnet pattern relies on adapted args, so can’t disable that
1 parent a5b6cbd commit 53eb552

File tree

11 files changed

+178
-116
lines changed

11 files changed

+178
-116
lines changed
 

‎build.sbt

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,24 @@ scalaVersion in ThisBuild := "2.11.6"
99

1010
crossScalaVersions in ThisBuild := Seq("2.10.5", "2.11.6")
1111

12-
scalacOptions in ThisBuild ++= Seq("-feature", "-deprecation", "-unchecked")
12+
scalacOptions in ThisBuild ++= Seq(
13+
"-deprecation",
14+
"-encoding", "UTF-8",
15+
"-feature",
16+
"-unchecked",
17+
"-Xfatal-warnings",
18+
"-Xfuture",
19+
//"-Xlint",
20+
//"-Yno-adapted-args",
21+
"-Ywarn-dead-code",
22+
"-Ywarn-numeric-widen",
23+
"-Ywarn-value-discard"
24+
)
25+
26+
scalacOptions in ThisBuild ++= (
27+
if (scalaVersion.value.startsWith("2.10")) Nil
28+
else List("-Ywarn-unused-import")
29+
)
1330

1431
shellPrompt in ThisBuild := CustomShellPrompt.customPrompt
1532

‎integration/src/it/scala/dynamodb/DynamoDBClient.scala

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.github.dwhjames.awswrap.dynamodb
1919

20-
import scala.collection.JavaConverters._
21-
import scala.concurrent._
2220
import scala.concurrent.ExecutionContext.Implicits.global
2321
import scala.concurrent.duration._
2422

@@ -48,34 +46,35 @@ trait DynamoDBClient
4846

4947
val tableNames: Seq[String]
5048

51-
override def beforeAll() {
49+
override def beforeAll(): Unit = {
5250
deleteAllSpecifiedTables()
5351

5452
super.beforeAll()
5553
}
5654

57-
override def afterAll() {
55+
override def afterAll(): Unit = {
5856
try {
5957
super.afterAll()
6058
} finally {
6159
deleteAllSpecifiedTables()
6260
}
6361
}
6462

65-
private def deleteAllSpecifiedTables() {
63+
private def deleteAllSpecifiedTables(): Unit = {
6664
tableNames foreach tryDeleteTable
6765

6866
tableNames foreach awaitTableDeletion
6967
}
7068

71-
def tryDeleteTable(tableName: String) {
69+
def tryDeleteTable(tableName: String): Unit = {
7270
logger.info(s"Deleting $tableName table")
7371
await {
7472
client.deleteTable(tableName) recover { case e: ResourceNotFoundException => () }
7573
}
74+
()
7675
}
7776

78-
def awaitTableDeletion(tableName: String) {
77+
def awaitTableDeletion(tableName: String): Unit = {
7978
logger.info(s"Waiting for $tableName table to be deleted.")
8079

8180
val deadline = 10.minutes.fromNow
@@ -96,11 +95,12 @@ trait DynamoDBClient
9695
throw new RuntimeException(s"Timed out waiting for $tableName table to be deleted.")
9796
}
9897

99-
def tryCreateTable(createTableRequest: CreateTableRequest) {
98+
def tryCreateTable(createTableRequest: CreateTableRequest): Unit = {
10099
logger.info(s"Creating ${createTableRequest.getTableName()} table")
101100
await {
102101
client.createTable(createTableRequest)
103102
}
103+
()
104104
}
105105

106106
def awaitTableCreation(tableName: String): TableDescription = {

‎integration/src/it/scala/dynamodb/ReadsOnHashKeyTablesSpec.scala

+5-8
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
package com.github.dwhjames.awswrap.dynamodb
1919

2020
import scala.collection.JavaConverters._
21-
import scala.concurrent._
2221
import scala.concurrent.ExecutionContext.Implicits.global
2322
import scala.concurrent.duration._
2423

2524
import org.scalatest.{ FlatSpec, BeforeAndAfterAll, Matchers }
2625

2726
import com.amazonaws.AmazonClientException
28-
import com.amazonaws.services.dynamodbv2._
29-
import com.amazonaws.services.dynamodbv2.model._
3027

3128

3229
class ReadsOnHashKeyTableSpec
@@ -40,7 +37,7 @@ class ReadsOnHashKeyTableSpec
4037

4138
val mapper = AmazonDynamoDBScalaMapper(client)
4239

43-
override def beforeAll() {
40+
override def beforeAll(): Unit = {
4441
super.beforeAll()
4542

4643
tryCreateTable(Forum.tableRequest)
@@ -92,10 +89,10 @@ class ReadsOnHashKeyTableSpec
9289
mapper.batchLoadByKeys[Forum](sampleForums map (_.name))
9390
}
9491

95-
forumScan should have size (sampleForums.size)
96-
forumScanOnce should have size (sampleForums.size)
97-
forumScanOnceLimit should have size (sampleForums.size)
98-
forumBatch should have size (sampleForums.size)
92+
forumScan should have size (sampleForums.size.toLong)
93+
forumScanOnce should have size (sampleForums.size.toLong)
94+
forumScanOnceLimit should have size (sampleForums.size.toLong)
95+
forumBatch should have size (sampleForums.size.toLong)
9996

10097
for (forum <- sampleForums) {
10198
forumScan should contain (forum)

‎scratch/src/main/scala/Scratch.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ object Scratch {
353353
)
354354
)
355355

356-
def main(args: Array[String]) {
356+
def main(args: Array[String]): Unit = {
357357

358358
val credentials = new PropertiesCredentials(
359359
this.getClass()
@@ -384,15 +384,16 @@ object Scratch {
384384
throw new RuntimeException(s"Timed out waiting for $tableName table to become active.")
385385
}
386386

387-
def tryDeleteTable(tableName: String) {
387+
def tryDeleteTable(tableName: String): Unit = {
388388
logger.info(s"Deleting $tableName table")
389389
Await.result(
390390
client.deleteTable(tableName) recover { case e: ResourceNotFoundException => () },
391391
10.seconds
392392
)
393+
()
393394
}
394395

395-
def awaitTableDeletion(tableName: String) {
396+
def awaitTableDeletion(tableName: String): Unit = {
396397
logger.info(s"Waiting for $tableName table to be deleted.")
397398

398399
val deadline = 10.minutes.fromNow
@@ -775,7 +776,7 @@ object ScratchS3 {
775776

776777
import com.github.dwhjames.awswrap.s3._
777778
import com.amazonaws.event.{ProgressListener, ProgressEvent, ProgressEventType}
778-
import com.amazonaws.services.s3._
779+
// import com.amazonaws.services.s3._
779780
import com.amazonaws.services.s3.transfer._
780781
import java.io.File
781782

‎src/main/scala/dynamodb/ConcurrentBatchWriter.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class ConcurrentBatchWriter(
152152
private def pause(attempts: Int): Unit =
153153
if (attempts > 0) {
154154
// 50, 100, 200, 400, 800
155-
val delay = (math.pow(2.0, attempts - 1) * 50.0).toLong
155+
val delay = (math.pow(2.0, (attempts - 1).toDouble) * 50.0).toLong
156156
if (logger.isTraceEnabled) logger.trace(s"backing off for $delay msecs.")
157157
Thread.sleep(delay)
158158
}
@@ -363,6 +363,7 @@ class ConcurrentBatchWriter(
363363
logger.error(s"AWS error occured when attempting to write to table $tableName", e)
364364
errorQueue.offer(
365365
FailedBatch[Metadata](tableName, batch.get(tableName), e, metadata))
366+
()
366367
case e: Throwable =>
367368
// log and rethrow any other exceptions
368369
// AmazonClientException should cover all error cases
@@ -457,7 +458,7 @@ class ConcurrentBatchWriter(
457458
logger.warn(s"batch writer thread pool for table $tableName being forced to shutdown.")
458459
// Wait a while for tasks to respond to being cancelled
459460
if (!writerThreadPool.awaitTermination(60, juc.TimeUnit.SECONDS))
460-
logger.error("batch writer thread pool for table $tableName did not shutdown!")
461+
logger.error(s"batch writer thread pool for table $tableName did not shutdown!")
461462
}
462463
dynamoDBClient.shutdown()
463464
logger.info(s"batch writer DynamoDB client for table $tableName is shutting down.")

‎src/main/scala/dynamodb/SingleThreadedBatchWriter.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SingleThreadedBatchWriter(
5757
private def pause(retries: Int): Unit =
5858
if (retries > 0) {
5959
// 50, 100, 200, 400, 800
60-
val delay = (math.pow(2.0, retries - 1) * 50.0).toLong
60+
val delay = (math.pow(2.0, (retries - 1).toDouble) * 50.0).toLong
6161
logger.debug(s"backing off for $delay msecs.")
6262
Thread.sleep(delay)
6363
}
@@ -144,7 +144,7 @@ class SingleThreadedBatchWriter(
144144

145145
while (source.hasNext) {
146146
logger.debug(s"pausing for $pauseDuration msecs.")
147-
Thread.sleep(pauseDuration)
147+
Thread.sleep(pauseDuration.toLong)
148148

149149
// construct a batch of write requests
150150
val writeRequests = new ju.ArrayList[WriteRequest](batchSize)

‎src/main/scala/dynamodb/mapper.scala

+119-78
Large diffs are not rendered by default.

‎src/main/scala/dynamodb/package.scala

+9-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ package object dynamodb {
4242
* the hash key name and the value it must equal.
4343
* @return a query request
4444
*/
45-
def mkHashKeyQuery[K <% AttributeValue](hashAttr: (String, K)): QueryRequest =
45+
def mkHashKeyQuery[K](hashAttr: (String, K))(implicit ev: K => AttributeValue): QueryRequest =
4646
new QueryRequest()
4747
.withKeyConditions(
4848
Map(
@@ -65,9 +65,10 @@ package object dynamodb {
6565
* an implicit object serializer
6666
* @return a query request
6767
*/
68-
def mkHashKeyQuery[T, K <% AttributeValue]
68+
def mkHashKeyQuery[T, K]
6969
(hashValue: K)
70-
(implicit serializer: DynamoDBSerializer[T])
70+
(implicit serializer: DynamoDBSerializer[T],
71+
ev: K => AttributeValue)
7172
: QueryRequest =
7273
mkHashKeyQuery(serializer.hashAttributeName -> hashValue)
7374

@@ -88,8 +89,9 @@ package object dynamodb {
8889
* @return a query request
8990
* @see [[QueryCondition]]
9091
*/
91-
def mkHashAndRangeKeyQuery[K <% AttributeValue]
92+
def mkHashAndRangeKeyQuery[K]
9293
(hashAttr: (String, K), rangeAttr: (String, Condition))
94+
(implicit ev: K => AttributeValue)
9395
: QueryRequest =
9496
new QueryRequest()
9597
.withKeyConditions(
@@ -117,9 +119,10 @@ package object dynamodb {
117119
* @return a query request
118120
* @see [[QueryCondition]]
119121
*/
120-
def mkHashAndRangeKeyQuery[T, K <% AttributeValue]
122+
def mkHashAndRangeKeyQuery[T, K]
121123
(hashValue: K, rangeCondition: Condition)
122-
(implicit serializer: DynamoDBSerializer[T])
124+
(implicit serializer: DynamoDBSerializer[T],
125+
ev: K => AttributeValue)
123126
: QueryRequest =
124127
mkHashAndRangeKeyQuery(
125128
serializer.hashAttributeName -> hashValue,

‎src/main/scala/package.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ package object awswrap {
2727

2828
private def promiseToAsyncHandler[Request <: AmazonWebServiceRequest, Result](p: Promise[Result]) =
2929
new AsyncHandler[Request, Result] {
30-
override def onError(exception: Exception): Unit = p.failure(exception)
31-
override def onSuccess(request: Request, result: Result): Unit = p.success(result)
30+
override def onError(exception: Exception): Unit = { p.failure(exception); () }
31+
override def onSuccess(request: Request, result: Result): Unit = { p.success(result); () }
3232
}
3333

3434
private def promiseToVoidAsyncHandler[Request <: AmazonWebServiceRequest](p: Promise[Unit]) =
3535
new AsyncHandler[Request, Void] {
36-
override def onError(exception: Exception): Unit = p.failure(exception)
37-
override def onSuccess(request: Request, result: Void): Unit = p.success(())
36+
override def onError(exception: Exception): Unit = { p.failure(exception); () }
37+
override def onSuccess(request: Request, result: Void): Unit = { p.success(()); () }
3838
}
3939

4040
@inline

‎src/main/scala/s3/s3.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ class AmazonS3ScalaClient(
186186
*
187187
* @see [[http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/AmazonWebServiceClient.html#shutdown() AmazonWebServiceClient.shutdown()]]
188188
*/
189-
def shutdown() {
189+
def shutdown(): Unit = {
190190
client.shutdown()
191191
executorService.shutdownNow()
192+
()
192193
}
193194

194195

@@ -199,12 +200,14 @@ class AmazonS3ScalaClient(
199200
): Future[Result] = {
200201
val p = Promise[Result]
201202
executorService.execute(new Runnable {
202-
override def run() =
203+
override def run(): Unit = {
203204
p complete {
204205
Try {
205206
f(request)
206207
}
207208
}
209+
()
210+
}
208211
})
209212
p.future
210213
}

‎src/main/scala/sns/sns.scala

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.github.dwhjames.awswrap
1919
package sns
2020

2121
import scala.concurrent.{Future, ExecutionContext}
22-
import scala.collection.JavaConverters._
2322

2423
import java.util.concurrent.ExecutorService
2524

0 commit comments

Comments
 (0)
Please sign in to comment.