Skip to content

Commit

Permalink
*Scala Language Updates*
Browse files Browse the repository at this point in the history
- Updated `scala-2.13 ` from 2.13.1 to 2.13.5

*Dependencies Updates*
- Updated `fs2` dependency from 2.5.0 to 3.0.2
- Updated `scala-collection-compat` dependency from 2.3.2 to 2.4.3
- Updated `commons-net` dependency from 3.7.2 to 3.8.0

*Plugin Updates*
- Updated `sbt-scoverage` plugin from 1.6.1 to 1.7.0
- Updated `sbt-sonatype` plugin from 3.9.5 to 3.9.7
  • Loading branch information
rehanone committed Apr 29, 2021
1 parent 3022137 commit 5b90537
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ project/metals.sbt

.metals/
.bloop/
.bsp/
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
- &build-test
stage: build & test
jdk: openjdk11
scala: 2.13.1
scala: 2.13.5
script:
- set -e
- docker-compose up -d
- sbt ++$TRAVIS_SCALA_VERSION! coverage test coverageReport coverageAggregate

- <<: *build-test
jdk: openjdk8
scala: 2.13.1
scala: 2.13.5

- <<: *build-test
jdk: openjdk11
Expand Down
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lazy val scala213 = "2.13.1"
lazy val scala213 = "2.13.5"
lazy val scala212 = "2.12.11"

lazy val `fs2-ftp` = project
Expand Down Expand Up @@ -39,11 +39,11 @@ lazy val `fs2-ftp` = project
)
.settings(
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "2.5.0",
"co.fs2" %% "fs2-io" % "2.5.0",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.3.2",
"co.fs2" %% "fs2-core" % "3.0.2",
"co.fs2" %% "fs2-io" % "3.0.2",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.3",
"com.hierynomus" % "sshj" % "0.31.0",
"commons-net" % "commons-net" % "3.7.2",
"commons-net" % "commons-net" % "3.8.0",
"org.apache.logging.log4j" % "log4j-api" % "2.13.0" % Test,
"org.apache.logging.log4j" % "log4j-core" % "2.13.0" % Test,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.13.0" % Test,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.4.5
sbt.version = 1.5.0
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.7.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.2")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.7")
20 changes: 8 additions & 12 deletions src/main/scala/fs2/ftp/SecureFtp.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package fs2.ftp

import java.io._

import cats.effect.{ Blocker, ConcurrentEffect, ContextShift, Resource, Sync }
import cats.effect.{ Async, Resource, Sync }
import cats.syntax.applicativeError._
import cats.syntax.flatMap._
import fs2.{ Pipe, Stream }
Expand All @@ -15,8 +14,7 @@ import fs2.ftp.FtpSettings.{ KeyFileSftpIdentity, RawKeySftpIdentity, SecureFtpS

import scala.jdk.CollectionConverters._

final private class SecureFtp[F[_]: ConcurrentEffect: ContextShift](unsafeClient: SecureFtp.Client, blocker: Blocker)
extends FtpClient[F, JSFTPClient] {
final private class SecureFtp[F[_]: Async](unsafeClient: SecureFtp.Client) extends FtpClient[F, JSFTPClient] {

def ls(path: String): fs2.Stream[F, FtpResource] =
fs2.Stream
Expand Down Expand Up @@ -56,7 +54,7 @@ final private class SecureFtp[F[_]: ConcurrentEffect: ContextShift](unsafeClient
}
}

input <- fs2.io.readInputStream(Sync[F].pure(is), chunkSize, blocker)
input <- fs2.io.readInputStream(Sync[F].pure(is), chunkSize)
} yield input

def rm(path: String): F[Unit] =
Expand All @@ -82,24 +80,22 @@ final private class SecureFtp[F[_]: ConcurrentEffect: ContextShift](unsafeClient
super.close()
}
}
_ <- source.through(fs2.io.writeOutputStream(Sync[F].pure(os), blocker))
_ <- source.through(fs2.io.writeOutputStream(Sync[F].pure(os)))
} yield ())

def execute[T](f: JSFTPClient => T): F[T] =
blocker.delay[F, T](f(unsafeClient))
Sync[F].blocking((f(unsafeClient)))
}

object SecureFtp {

type Client = JSFTPClient

def connect[F[_]: ContextShift: ConcurrentEffect](
def connect[F[_]: Async](
settings: SecureFtpSettings
): Resource[F, FtpClient[F, SecureFtp.Client]] =
for {
ssh <- Resource.liftF(Sync[F].delay(new SSHClient(settings.sshConfig)))

blocker <- Blocker[F]
ssh <- Resource.eval(Sync[F].delay(new SSHClient(settings.sshConfig)))
r <- Resource.make[F, FtpClient[F, JSFTPClient]](Sync[F].delay {
import settings._

Expand All @@ -118,7 +114,7 @@ object SecureFtp {
setIdentity(_, credentials.username)(ssh)
)

new SecureFtp(ssh.newSFTPClient(), blocker)
new SecureFtp(ssh.newSFTPClient())
})(client =>
client
.execute(_.close())
Expand Down
20 changes: 7 additions & 13 deletions src/main/scala/fs2/ftp/UnsecureFtp.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package fs2.ftp

import java.io.{ FileNotFoundException, InputStream }

import cats.effect.{ Blocker, ConcurrentEffect, ContextShift, Resource, Sync }
import cats.effect.{ Async, Resource, Sync }
import cats.syntax.applicativeError._
import cats.syntax.flatMap._
import cats.syntax.functor._
Expand All @@ -11,9 +10,8 @@ import fs2.{ Pipe, Stream }
import org.apache.commons.net.ftp.{ FTP, FTPClient => JFTPClient, FTPSClient => JFTPSClient }
import FtpSettings.UnsecureFtpSettings

final private class UnsecureFtp[F[_]: ConcurrentEffect: ContextShift](
unsafeClient: UnsecureFtp.Client,
blocker: Blocker
final private class UnsecureFtp[F[_]: Async](
unsafeClient: UnsecureFtp.Client
) extends FtpClient[F, JFTPClient] {

def stat(path: String): F[Option[FtpResource]] =
Expand All @@ -27,7 +25,7 @@ final private class UnsecureFtp[F[_]: ConcurrentEffect: ContextShift](
)
)

fs2.io.readInputStream(is, chunkSize, blocker)
fs2.io.readInputStream(is, chunkSize)
}

def rm(path: String): F[Unit] =
Expand Down Expand Up @@ -72,19 +70,17 @@ final private class UnsecureFtp[F[_]: ConcurrentEffect: ContextShift](
)

def execute[T](f: JFTPClient => T): F[T] =
blocker.delay[F, T](f(unsafeClient))
Sync[F].delay(f(unsafeClient))
}

object UnsecureFtp {

type Client = JFTPClient

def connect[F[_]: ContextShift: ConcurrentEffect](
def connect[F[_]: Async](
settings: UnsecureFtpSettings
): Resource[F, FtpClient[F, UnsecureFtp.Client]] =
for {
blocker <- Blocker[F]

r <- Resource.make[F, FtpClient[F, JFTPClient]] {
Sync[F]
.delay {
Expand All @@ -105,7 +101,7 @@ object UnsecureFtp {
ftpClient.enterLocalPassiveMode()
}

success -> new UnsecureFtp[F](ftpClient, blocker)
success -> new UnsecureFtp[F](ftpClient)
}
.ensure(ConnectionError(s"Fail to connect to server ${settings.host}:${settings.port}"))(_._1)
.map(_._2)
Expand All @@ -120,7 +116,5 @@ object UnsecureFtp {
.flatMap(_ => client.execute(_.disconnect))
} yield ()
}

} yield r

}
4 changes: 2 additions & 2 deletions src/main/scala/fs2/ftp/package.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fs2

import cats.effect.{ ConcurrentEffect, ContextShift, Resource }
import cats.effect.{ Async, Resource }
import fs2.ftp.FtpSettings.{ SecureFtpSettings, UnsecureFtpSettings }

package object ftp {
Expand All @@ -11,7 +11,7 @@ package object ftp {
*
* If operation failed, it emit a `fs2.ftp.ConnectionError` with the cause of the failure
*/
def connect[F[_]: ContextShift: ConcurrentEffect, A](settings: FtpSettings[A]): Resource[F, FtpClient[F, A]] =
def connect[F[_]: Async, A](settings: FtpSettings[A]): Resource[F, FtpClient[F, A]] =
settings match {
case s: UnsecureFtpSettings => UnsecureFtp.connect(s)
case s: SecureFtpSettings => SecureFtp.connect(s)
Expand Down
Loading

0 comments on commit 5b90537

Please sign in to comment.