Fix feature warnings
We enable the feature flag so sbt displays the warnings.
The following warnings are fixed:
[warn] /home/darius/dev/gerritforge/analytics/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/AggregatedHistogramFilterByDates.scala:32:36: postfix operator >= should be enabled
[warn] by making the implicit value scala.language.postfixOps visible.
[warn] This can be achieved by adding the import clause 'import scala.language.postfixOps'
[warn] or by setting the compiler option -language:postfixOps.
[warn] See the Scaladoc for value scala.language.postfixOps for a discussion
[warn] why the feature should be explicitly enabled.
[warn] if (from.fold(true)(commitDate >=) && to.fold(true)(commitDate <)) {
[warn] ^
[warn] /home/darius/dev/gerritforge/analytics/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/AggregatedHistogramFilterByDates.scala:32:68: postfix operator < should be enabled
[warn] by making the implicit value scala.language.postfixOps visible.
[warn] if (from.fold(true)(commitDate >=) && to.fold(true)(commitDate <)) {
[warn] ^
[warn] /home/darius/dev/gerritforge/analytics/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/DateConversions.scala:21:16: implicit conversion method isoStringToLongDate should be enabled
[warn] by making the implicit value scala.language.implicitConversions visible.
[warn] This can be achieved by adding the import clause 'import scala.language.implicitConversions'
[warn] or by setting the compiler option -language:implicitConversions.
[warn] See the Scaladoc for value scala.language.implicitConversions for a discussion
[warn] why the feature should be explicitly enabled.
[warn] implicit def isoStringToLongDate(s: String): Long = JavaSqlTimestampHelper.parseTimestamp(s).getTime
[warn] ^
This warning will be fixed in a subsequent commit once we've bumped
Scala to a version containing `Using`.
[warn] /home/darius/dev/gerritforge/analytics/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/ManagedResources.scala:22:16: reflective access of structural type member method close should be enabled
[warn] by making the implicit value scala.language.reflectiveCalls visible.
[warn] This can be achieved by adding the import clause 'import scala.language.reflectiveCalls'
[warn] or by setting the compiler option -language:reflectiveCalls.
[warn] See the Scaladoc for value scala.language.reflectiveCalls for a discussion
[warn] why the feature should be explicitly enabled.
[warn] resource.close()
[warn] ^
[warn] four warnings found
Change-Id: I0f7ee02cba2cae2878fe4d5299044e15e5aead56
diff --git a/build.sbt b/build.sbt
index 55e9522..a0ebc39 100644
--- a/build.sbt
+++ b/build.sbt
@@ -8,6 +8,8 @@
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
+ThisBuild / scalacOptions += "-feature"
+
lazy val root = (project in file("."))
.settings(
name := pluginName,
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala
index 98e4e06..d3adb33 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala
@@ -44,7 +44,7 @@
usage = "(included) begin timestamp. Must be in the format 2006-01-02[ 15:04:05[.890][ -0700]]")
def setBeginDate(date: String) {
try {
- beginDate = Some(date)
+ beginDate = Some(date.isoStringToLongDate)
} catch {
case e: Exception => throw die(s"Invalid begin date ${e.getMessage}")
}
@@ -54,7 +54,7 @@
usage = "(excluded) end timestamp. Must be in the format 2006-01-02[ 15:04:05[.890][ -0700]]")
def setEndDate(date: String) {
try {
- endDate = Some(date)
+ endDate = Some(date.isoStringToLongDate)
} catch {
case e: Exception => throw die(s"Invalid end date ${e.getMessage}")
}
@@ -90,7 +90,7 @@
usage = "(included) begin timestamp. Must be in the format 2006-01-02[ 15:04:05[.890][ -0700]]")
def setBeginDate(date: String) {
try {
- beginDate = Some(date)
+ beginDate = Some(date.isoStringToLongDate)
} catch {
case e: Exception => throw new BadRequestException(s"Invalid begin date ${e.getMessage}")
}
@@ -100,7 +100,7 @@
usage = "(excluded) end timestamp. Must be in the format 2006-01-02[ 15:04:05[.890][ -0700]]")
def setEndDate(date: String) {
try {
- endDate = Some(date)
+ endDate = Some(date.isoStringToLongDate)
} catch {
case e: Exception => throw new BadRequestException(s"Invalid end date ${e.getMessage}")
}
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/AggregatedHistogramFilterByDates.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/AggregatedHistogramFilterByDates.scala
index bc1315e..305c388 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/AggregatedHistogramFilterByDates.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/AggregatedHistogramFilterByDates.scala
@@ -29,7 +29,7 @@
val commitDate = commit.getCommitterIdent.getWhen.getTime
val author = commit.getAuthorIdent
- if (from.fold(true)(commitDate >=) && to.fold(true)(commitDate <)) {
+ if (from.fold(true)(commitDate >= _) && to.fold(true)(commitDate < _)) {
if(branchesExtractor.isDefined) {
val branches = branchesExtractor.get.branchesOfCommit(commit.getId)
getHistogram.includeWithBranches(commit, author, branches)
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/DateConversions.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/DateConversions.scala
index 874dc0d..4bf7dfe 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/DateConversions.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/DateConversions.scala
@@ -18,5 +18,7 @@
object DateConversions {
- implicit def isoStringToLongDate(s: String): Long = JavaSqlTimestampHelper.parseTimestamp(s).getTime
+ implicit class StringOps(val s: String) extends AnyVal {
+ def isoStringToLongDate: Long = JavaSqlTimestampHelper.parseTimestamp(s).getTime
+ }
}
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/AggregationSpec.scala b/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/AggregationSpec.scala
index c3d2087..7a0fc84 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/AggregationSpec.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/analytics/test/AggregationSpec.scala
@@ -15,10 +15,9 @@
package com.googlesource.gerrit.plugins.analytics.test
import java.util.Date
-
import com.google.gerrit.acceptance.UseLocalDisk
import com.googlesource.gerrit.plugins.analytics.common.AggregationStrategy._
-import com.googlesource.gerrit.plugins.analytics.common.DateConversions.isoStringToLongDate
+import com.googlesource.gerrit.plugins.analytics.common.DateConversions.StringOps
import com.googlesource.gerrit.plugins.analytics.common.TestUtils
import org.eclipse.jgit.revwalk.RevCommit
import org.scalatest.{FlatSpec, Inspectors, Matchers}
@@ -27,7 +26,7 @@
class AggregationSpec extends FlatSpec with Matchers with GerritTestDaemon with TestUtils with Inspectors {
def commitAtDate(committer: String, when: String, content: String): RevCommit = {
- val personIdent = newPersonIdent(committer, committer, new Date(isoStringToLongDate(when)))
+ val personIdent = newPersonIdent(committer, committer, new Date(when.isoStringToLongDate))
testFileRepository.commitFile("somefile", content, committer = personIdent, author = personIdent)
}