Skip to content

Commit

Permalink
updated to scala 2.13.4
Browse files Browse the repository at this point in the history
and added fixes to make compiler happy
  • Loading branch information
neowit committed Feb 7, 2021
1 parent edbaddb commit b591065
Show file tree
Hide file tree
Showing 27 changed files with 65 additions and 53 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name := "tooling-force.com"

version := "0.1-SNAPSHOT"

scalaVersion := "2.13.1"
scalaVersion := "2.13.4"

scalacOptions ++= Seq(
"-deprecation",
Expand All @@ -18,6 +18,8 @@ scalacOptions ++= Seq(
//"-Ywarn-value-discard",
//"-Xfuture",
//"-Ywarn-unused-import"
// Excluding -byname-implicit is required for Scala 2.13 due to https://github.com/scala/bug/issues/12072
"-Xlint:_,-byname-implicit", // without this parameter circe deriveDecoder results in: Block result was adapted via implicit conversion
)

// disable generation of scala-<version> folders, we do not need cross compilation
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/neowit/TcpServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TcpServer (port: Int, timeoutMillis: Int){
if (!TcpServer.isShutdownReceived) {
// default Actor constructor
//val helloActor = system.actorOf(Props[EchoActor], name = "helloactor")
val handlerActor = TcpServer.system.actorOf(Props[CommandParser])
val handlerActor = TcpServer.system.actorOf(Props[CommandParser]())
//helloActor ! "hello"
handlerActor ! new Message(clientSocket)
count = count + 1
Expand All @@ -127,7 +127,7 @@ class CommandParser extends Actor {
println("Client connected from " + socket.getInetAddress + ":" + socket.getPort)
//parse command
val line = new BufferedReader(new InputStreamReader(socket.getInputStream)).readLine()
val processorActor = TcpServer.system.actorOf(Props[CommandProcessor])
val processorActor = TcpServer.system.actorOf(Props[CommandProcessor]())
line match {
case "ping" => processorActor ! new Ping(socket)
case "shutdown" => processorActor ! new Shutdown(socket)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/neowit/apex/ApexTestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ object ApexTestUtils extends JsonSupport {
//Class.Test1.prepareData: line 13, column 1
//val (typeName, fileName, methodName, line, column) =
try {
val TypeFileMethodLineColumnRegex(_typeName, _fileName, _methodName, _line, _column) = traceLine
val TypeFileMethodLineColumnRegex(_typeName, _fileName, _methodName, _line, _column) = (traceLine: @unchecked) // @unchecked used to disable: match may not be exhaustive.
Some(StackTraceLine(_typeName, _fileName, _methodName, _line.toInt, _column.toInt))
} catch {
case _:scala.MatchError =>
//Class.Test1: line 19, column 1
try {
val TypeFileLineColumnRegex(_typeName, _fileName, _line, _column) = traceLine
val TypeFileLineColumnRegex(_typeName, _fileName, _line, _column) = (traceLine: @unchecked) // @unchecked used to disable: match may not be exhaustive.
Some(StackTraceLine(_typeName, _fileName, "", _line.toInt, _column.toInt))
} catch {
case _:scala.MatchError =>
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/neowit/apex/MetadataType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ object MetadataType extends Logging {
if (calculateMD5) FileUtils.getMD5Hash(fMeta) else "",
if (calculateCRC32) FileUtils.getCRC32Hash(fMeta) else -1L
)
case None => (-1L, "", -1L)
case _ => (-1L, "", -1L)
}
getValueMap(file.getName, xmlType, id, lastModifiedDate, localMills, md5Hash, crc32Hash, metaLocalMills, metaMD5Hash, metaCRC32Hash)
}
Expand All @@ -86,7 +86,7 @@ object MetadataType extends Logging {
case None => Map()
}
// set localMills only if the value is provided and > 0
val localMillsVal = if (localMills > 0) {
val localMillsVal: Map[String, Any] = if (localMills > 0) {
val localMillsStr = new Date(localMills).toString
Map(LOCAL_MILLS -> localMills, LOCAL_MILLS + "Str" -> localMillsStr, MD5 -> md5Hash, CRC32 -> crc32)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/neowit/apex/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Executor extends Logging {
val start = System.currentTimeMillis
//report usage if allowed
val usage = new UsageReporter(basicConfig)
val usageFuture = Future {
Future {
usage.report()
}

Expand Down
12 changes: 5 additions & 7 deletions src/main/scala/com/neowit/apex/Session.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.neowit.apex.LogUtils.{ApexLogInfoCreatorProvider, MetadataLogInfoCrea
import com.neowit.apex.actions.{ActionError, DescribeMetadata}
import com.neowit.auth.{LoginPasswordCredentials, Oauth2Credentials}

import scala.collection.MapView
import scala.util.{Failure, Success, Try}

/**
Expand Down Expand Up @@ -391,7 +390,7 @@ class Session(val basicConfig: BasicConfig, isReadOnly: Boolean = true) extends
val projectPath = srcFolder.getParentFile.getAbsolutePath + File.separator
val res = file.getAbsolutePath.substring(projectPath.length)
normalizePath(res)
case None => file.getAbsolutePath
case _ => file.getAbsolutePath
}
}
/**
Expand Down Expand Up @@ -613,8 +612,8 @@ class Session(val basicConfig: BasicConfig, isReadOnly: Boolean = true) extends
* @return
*/
private def getRestContent(connectorConfig: com.sforce.ws.ConnectorConfig, apiPath: String,
path: String, urlParameters: String = "",
httpHeaders: java.util.HashMap[String, String] = new java.util.HashMap[String, String]()
path: String, urlParameters: String,
httpHeaders: java.util.HashMap[String, String]
): Try[String] = {
val endpointUrl = new URL(connectorConfig.getServiceEndpoint)
//get protocol and domain, e.g.: https://na1.salesforce.com/
Expand Down Expand Up @@ -664,7 +663,7 @@ class Session(val basicConfig: BasicConfig, isReadOnly: Boolean = true) extends
*/
private def postRestContent(connectorConfig: com.sforce.ws.ConnectorConfig, apiPath: String,
path: String, jsonBody: String,
httpHeaders: java.util.HashMap[String, String] = new java.util.HashMap[String, String]()
httpHeaders: java.util.HashMap[String, String]
): Try[JsValue] = {

//import spray.json._
Expand Down Expand Up @@ -933,8 +932,6 @@ class Session(val basicConfig: BasicConfig, isReadOnly: Boolean = true) extends
def microBatch(queriesBatch: Array[ListMetadataQuery], conn: MetadataConnection,
propsSoFar: Array[FileProperties]):Array[FileProperties] = {
queriesBatch match {
case Array() => //end of query list, return result
propsSoFar
case Array(_, _*) =>
val _queries = queriesBatch.take(3)
logger.trace("About to process " + _queries.map(_.getType).mkString("; "))
Expand All @@ -944,6 +941,7 @@ class Session(val basicConfig: BasicConfig, isReadOnly: Boolean = true) extends
val propsFiltered = props.filter(_.getType != null)
logger.trace("Props: " + propsFiltered.map(_.getType).mkString("; "))
microBatch(queriesBatch.drop(3), conn, propsFiltered ++ propsSoFar)
case _ => propsSoFar //end of query list, return result

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/neowit/apex/actions/CheckSyntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CheckSyntax extends ApexActionWithReadOnlySession {
val config = session.getConfig

val filePath = config.getRequiredProperty("currentFileContentPath")
val sourceFilePath = config.getRequiredProperty("currentFilePath")
//val sourceFilePath = config.getRequiredProperty("currentFilePath")
val actionResultOpt =
config.projectDirOpt.map{ projectDir =>
val inputFile = new File(filePath)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/neowit/apex/actions/Deploy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ class DeployAllDestructive extends DeployAll {
diffWithRemote.load[DiffWithRemote](session)

val actionResultFuture =
diffWithRemote.getDiffReport match {
(diffWithRemote.getDiffReport: @unchecked) match {
case report @ DiffWithRemoteReportFailure(_) =>
//responseWriter.println(FAILURE)
//responseWriter.println(ErrorMessage("Failed to load remote version of current project"))
Expand Down Expand Up @@ -1480,7 +1480,7 @@ class DeployModifiedDestructive extends DeployModified {
case Some(deployResult) if !deployResult.isSuccess =>
// deployment failed
Future.successful(ActionFailure(DeployModifiedDestructiveResult(deployResultOpt)))
case None =>
case _ =>
// nothing to delete
Future.successful(ActionSuccess(DeployModifiedDestructiveResult(None)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class DescribeMetadata extends ApexActionWithReadOnlySession with JsonSupport {

override def getParamDescription(paramName: String): String = paramName match {
case "allMetaTypesFilePath" => "--allMetaTypesFilePath - path to file where results shall be saved"
case p => s"parameter $p is not supported"
}

override def getParamNames: List[String] = List("allMetaTypesFilePath")
Expand Down Expand Up @@ -237,7 +238,7 @@ class DescribeMetadata extends ApexActionWithReadOnlySession with JsonSupport {

describeMetadataObjectMap.get(xmlName) match {
case Some(_describeObject) =>
val data = Map(
val data = Map[String, Any](
"ChildObjects" -> _describeObject.getChildXmlNames.toJson,
"DirName" -> _describeObject.getDirectoryName,
"InFolder" -> _describeObject.isInFolder,
Expand Down Expand Up @@ -303,6 +304,7 @@ class ListMetadata extends ApexActionWithWritableSession with JsonSupport {

override def getParamDescription(paramName: String): String = paramName match {
case "specificTypes" => "--specificTypes=/path/to/file with Xml types list. Each type must be on its own line"
case p => s"parameter $p is not supported"
}

override def getParamNames: List[String] = List("specificTypes")
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/com/neowit/apex/actions/RetrieveMetadata.scala
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ class DiffWithRemote extends RetrieveMetadata {

protected def act()(implicit ec: ExecutionContext): Future[ActionResult] = {
val actionResult =
getDiffReport match {
(getDiffReport: @unchecked) match {
case report @ DiffWithRemoteReportSuccess(_, _) =>
//responseWriter.println("RESULT=SUCCESS")
//writeReportToResponseFile(diffReport, actionResultBuilder)
Expand All @@ -820,7 +820,7 @@ class DiffWithRemote extends RetrieveMetadata {
def getDiffReport: DiffWithRemoteReport = {
val tempFolder = getTargetFolder match {
case Some(x) => new File(x)
case None => FileUtils.createTempDir(config)
case _ => FileUtils.createTempDir(config)
}
val bulkRetrieve = new BulkRetrieve {
override protected def isUpdateSessionDataOnSuccess: Boolean = false
Expand Down Expand Up @@ -922,7 +922,7 @@ class DiffWithRemote extends RetrieveMetadata {
)

val remoteFilesByRelativePaths = remoteFiles.map(file => (
FileUtils.normalizePath(file.getAbsolutePath.replaceAllLiterally(remoteSrcFolder.getParentFile.getAbsolutePath + File.separator, "")), file
FileUtils.normalizePath(file.getAbsolutePath.replace(remoteSrcFolder.getParentFile.getAbsolutePath + File.separator, "")), file
)).toMap

//list files where remote version has different size or crc32 compared to local version
Expand Down
7 changes: 3 additions & 4 deletions src/main/scala/com/neowit/apex/actions/SoqlQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ class SoqlQuery extends ApexActionWithReadOnlySession {
FileUtils.writeFile(lines.mkString("\n"), outputFile, append = true)
}
private def writeAsPlainStrings(records: List[JsObject], outputFile: File): Unit = {
var i = 0
for (record <- records) {
for (field <- record.fields) {
val fName = field._1
Expand All @@ -191,7 +190,7 @@ class SoqlQuery extends ApexActionWithReadOnlySession {
}
}

private def writeAsPipeSeparatedLines(records: List[JsObject], outputFile: File, displayHeader: Boolean = false): Unit = {
private def writeAsPipeSeparatedLines(records: List[JsObject], outputFile: File, displayHeader: Boolean): Unit = {

if (records.nonEmpty) {
//find max column length for each column
Expand Down Expand Up @@ -278,7 +277,7 @@ object SoqlQuery {
entityTypeName: Option[String], records: List[JsObject])

def getMaxWidthByColumn(records: List[ResultRecord]): Map[String, Int] = {
var maxWidthByName = new scala.collection.mutable.HashMap[String, Int]()
val maxWidthByName = new scala.collection.mutable.HashMap[String, Int]()
//find max column length for each column
if (records.nonEmpty) {
//init with column names
Expand Down Expand Up @@ -538,7 +537,7 @@ object SoqlQuery {
hasChildRecords = true
val maxWidthByName = getMaxWidthByColumn(childRecords)
val sampleRecord = childRecords.head
val relationshipName = sampleRecord.getAttribute("type").getOrElse("").toString
val relationshipName: String = sampleRecord.getAttribute("type").map(_.toString()).getOrElse("")
val indentation = relationshipName + " => |"
val shiftLeft = indentation.length
val header = sampleRecord.getHeader(sampleRecord.getFieldNames, maxWidthByName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class TestSuiteActions extends ApexActionWithReadOnlySession with TestSuiteProto
private def getTestSuiteClassesByTestSuite(session: Session): Map[String, TestSuite] = {
val soql = s"select Id, ApexClass.Id, ApexTestSuite.Id, ApexClass.Name, ApexTestSuite.TestSuiteName from TestSuiteMembership"
val memberships = SoqlQuery.getQueryIteratorTyped[com.sforce.soap.tooling.sobject.TestSuiteMembership](session, session.queryTooling(soql))
val mapBuilder = Map.newBuilder[TestSuite, List[ApexClass]]
//val mapBuilder = Map.newBuilder[TestSuite, List[ApexClass]]

val testSuitePerClass =
memberships.map{membership =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class DescribeTooling extends ApexActionWithReadOnlySession with JsonSupport {

override def getParamDescription(paramName: String): String = paramName match {
case "allToolingTypesFilePath" => "--allToolingTypesFilePath - path to file where results shall be saved"
case p => s"parameter $p is not supported"
}

override def getParamNames: List[String] = List("allToolingTypesFilePath")
Expand Down Expand Up @@ -155,7 +156,7 @@ class DescribeTooling extends ApexActionWithReadOnlySession with JsonSupport {
describeToolingObjectMap.get(name) match {
case Some(_describeObject) =>

val data = Map(
val data = Map[String, Any](
"isActivateable" -> _describeObject.isActivateable,
"isCustomSetting" -> _describeObject.isCustomSetting,
"isCustom" -> _describeObject.isCustom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class LoadApexCodeCoverageAggregate extends ApexActionWithReadOnlySession with R

val actionResult = config.getProperty("classOrTriggerName") match {
case Some(classOrTriggerNameProvided) =>
var classOrTriggerName = FileUtils.removeExtension(classOrTriggerNameProvided)
val classOrTriggerName = FileUtils.removeExtension(classOrTriggerNameProvided)
val queryIterator = SoqlQuery.getQueryIteratorTooling(session,
s""" select ApexClassOrTrigger.Name, ApexClassOrTriggerId, NumLinesCovered, NumLinesUncovered, Coverage
| from ApexCodeCoverageAggregate
| where ApexClassOrTrigger.Name = '$classOrTriggerName'
|""".stripMargin)

var errorBuilder = Array.newBuilder[String]
val errorBuilder = Array.newBuilder[String]

val coverageResultOpt =
if (queryIterator.hasNext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class ChangeLogLevels extends ApexActionWithReadOnlySession {
// debug level exists but its config does not match traceFlagMap
session.deleteTooling(debugLevel.getId)
createDebugLevel(traceFlagMap).toOption.foreach(traceFlag.setDebugLevelId)
case None => // no debug level exists, create one
case _ => // no debug level exists, create one
createDebugLevel(traceFlagMap).toOption.foreach(traceFlag.setDebugLevelId)
}

Expand Down Expand Up @@ -364,7 +364,7 @@ class DeleteLogs extends ApexActionWithReadOnlySession {

//this method should implement main logic of the action
override protected def act()(implicit ec: ExecutionContext): Future[ActionResult] = {
var errorBuilder = Array.newBuilder[String]
val errorBuilder = Array.newBuilder[String]
var totalRecords = 0
val BATCH_SIZE = 200

Expand Down
19 changes: 12 additions & 7 deletions src/main/scala/com/neowit/apex/actions/tooling/RunTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class RunTests extends DeployModified with RunTestJsonSupport {
List.empty

}
//Map("classids" -> "id1,id2,id3")
//Map("classIds" -> "id1,id2,id3")
val classIdData = config.getProperty("testsToRun") match {
case Some(_) => // test class names provided

Expand All @@ -374,10 +374,11 @@ class RunTests extends DeployModified with RunTestJsonSupport {
case _ => Map.empty[String, JsValue]
}

//Map(suiteids -> "id1,id2,id3")
val (suiteIds: Map[String, JsValue], classesAndMethodsOpt: Option[Map[String, JsValue]]) =
//Map(suiteIds -> "id1,id2,id3")
//val (suiteIds: Map[String, JsValue], classesAndMethodsOpt: Option[Map[String, JsValue]]) =
val suiteIdsAndOptionOfClassesAndMethods =
getTestSuiteNames match {
case names @ head :: tail if isAsync =>
case names if names.nonEmpty && isAsync =>
// test suite names provided
val suiteIds = TestSuiteActions.getTestSuiteIdByName(names, session).values.mkString(",")
if (suiteIds.nonEmpty) {
Expand All @@ -392,21 +393,25 @@ class RunTests extends DeployModified with RunTestJsonSupport {
getTestClassMethodJson(
records.map(r => r.getFieldAsString("Name").get -> r.getFieldAsString("Id").get).toMap
)

if (_clsAndMethods.nonEmpty) {
(Map.empty, Option(_clsAndMethods))
} else {
(Map.empty, None)
}
}

val (suiteIds: Map[String, JsValue], classesAndMethodsOpt: Option[Map[String, JsValue]]) = (suiteIdsAndOptionOfClassesAndMethods: @unchecked)

if (isAsync) {
classesAndMethodsOpt match {
case Some(classesAndMethods) => classesAndMethods
case None => classIdData ++ suiteIds
case _ => classIdData ++ suiteIds
}
} else {
classesAndMethodsOpt match {
case Some(classesAndMethods) => classesAndMethods
case None => classIdData
case _ => classIdData
}
}

Expand Down Expand Up @@ -656,7 +661,7 @@ class RunTests extends DeployModified with RunTestJsonSupport {
private def getTestSuiteNames: List[String] = {
config.getProperty("testSuitesToRun") match {
case Some(value) if value.nonEmpty => value.split(",").toList
case None => List.empty
case _ => List.empty
}
}

Expand Down
Loading

0 comments on commit b591065

Please sign in to comment.