From 32ef58ff118fac05c61753659d833f4009f886fa Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 19 Jul 2019 23:30:20 +0100 Subject: [PATCH] NullPointerException creating scaladoc (#115) * [domain] Drop use of Lenses macro and only create used lenses * [core] Drop use of Lenses macro and only create used lenses * [sbt] drop paradise plugin * [changelog] updated --- CHANGELOG.org | 12 ++++++++++++ build.sbt | 3 --- .../main/scala/net/kemitix/thorp/core/Action.scala | 5 ----- .../scala/net/kemitix/thorp/core/ConfigOption.scala | 7 ------- .../net/kemitix/thorp/core/ConfigOptions.scala | 9 +++++++-- .../scala/net/kemitix/thorp/core/Counters.scala | 11 +++++++++-- .../scala/net/kemitix/thorp/core/LocalFiles.scala | 2 -- .../scala/net/kemitix/thorp/core/SyncPlan.scala | 2 -- .../thorp/core/UnversionedMirrorArchive.scala | 11 +---------- .../scala/net/kemitix/thorp/domain/Bucket.scala | 3 --- .../scala/net/kemitix/thorp/domain/Config.scala | 13 +++++++++++-- .../scala/net/kemitix/thorp/domain/Filter.scala | 4 ---- .../net/kemitix/thorp/domain/HashModified.scala | 3 --- .../net/kemitix/thorp/domain/KeyModified.scala | 3 --- .../net/kemitix/thorp/domain/LastModified.scala | 3 --- .../scala/net/kemitix/thorp/domain/LocalFile.scala | 5 +++-- .../scala/net/kemitix/thorp/domain/MD5Hash.scala | 3 --- .../scala/net/kemitix/thorp/domain/RemoteKey.scala | 7 +++++-- .../net/kemitix/thorp/domain/RemoteMetaData.scala | 3 --- .../scala/net/kemitix/thorp/domain/S3MetaData.scala | 3 --- .../net/kemitix/thorp/domain/S3ObjectsData.scala | 4 ---- .../scala/net/kemitix/thorp/domain/Sources.scala | 3 --- .../kemitix/thorp/domain/StorageQueueEvent.scala | 8 -------- .../scala/net/kemitix/thorp/domain/SyncTotals.scala | 3 --- .../net/kemitix/thorp/domain/UploadEvent.scala | 5 ----- .../kemitix/thorp/domain/UploadEventListener.scala | 3 --- 26 files changed, 48 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 271615b..bb87882 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -6,6 +6,18 @@ The format is based on [[https://keepachangelog.com/en/1.0.0/][Keep a Changelog] [[https://semver.org/spec/v2.0.0.html][Semantic Versioning]]. +* [0.7.2] - 2019-07-19 + +** Changed + + - Apply ~scalafmt~ (#108) + - Uses Lenses (#113) + +** Fixed + + - Creates incorrect MD5 hash for some files (#103) + - NullPointerException creating scaladoc (#115) + * [0.7.1] - 2019-07-15 ** Changed diff --git a/build.sbt b/build.sbt index c000855..49898a7 100644 --- a/build.sbt +++ b/build.sbt @@ -26,9 +26,6 @@ val commonSettings = Seq( "-language:postfixOps", "-language:higherKinds", "-Ypartial-unification"), - addCompilerPlugin( - "org.scalameta" % "paradise" % "3.0.0-M11" cross CrossVersion.full - ), test in assembly := {} ) diff --git a/core/src/main/scala/net/kemitix/thorp/core/Action.scala b/core/src/main/scala/net/kemitix/thorp/core/Action.scala index 830947e..fa75c66 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/Action.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/Action.scala @@ -1,6 +1,5 @@ package net.kemitix.thorp.core -import monocle.macros.Lenses import net.kemitix.thorp.domain.{Bucket, LocalFile, MD5Hash, RemoteKey} sealed trait Action { @@ -9,21 +8,18 @@ sealed trait Action { } object Action { - @Lenses final case class DoNothing( bucket: Bucket, remoteKey: RemoteKey, size: Long ) extends Action - @Lenses final case class ToUpload( bucket: Bucket, localFile: LocalFile, size: Long ) extends Action - @Lenses final case class ToCopy( bucket: Bucket, sourceKey: RemoteKey, @@ -32,7 +28,6 @@ object Action { size: Long ) extends Action - @Lenses final case class ToDelete( bucket: Bucket, remoteKey: RemoteKey, diff --git a/core/src/main/scala/net/kemitix/thorp/core/ConfigOption.scala b/core/src/main/scala/net/kemitix/thorp/core/ConfigOption.scala index 4c2b6fc..c34174b 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/ConfigOption.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/ConfigOption.scala @@ -2,7 +2,6 @@ package net.kemitix.thorp.core import java.nio.file.Path -import monocle.macros.Lenses import net.kemitix.thorp.domain import net.kemitix.thorp.domain.{Config, RemoteKey} import net.kemitix.thorp.domain.Config._ @@ -13,13 +12,11 @@ sealed trait ConfigOption { object ConfigOption { - @Lenses case class Source(path: Path) extends ConfigOption { override def update(config: Config): Config = sources.modify(_ ++ path)(config) } - @Lenses case class Bucket(name: String) extends ConfigOption { override def update(config: Config): Config = if (config.bucket.name.isEmpty) @@ -28,7 +25,6 @@ object ConfigOption { config } - @Lenses case class Prefix(path: String) extends ConfigOption { override def update(config: Config): Config = if (config.prefix.key.isEmpty) @@ -37,19 +33,16 @@ object ConfigOption { config } - @Lenses case class Include(pattern: String) extends ConfigOption { override def update(config: Config): Config = filters.modify(domain.Filter.Include(pattern) :: _)(config) } - @Lenses case class Exclude(pattern: String) extends ConfigOption { override def update(config: Config): Config = filters.modify(domain.Filter.Exclude(pattern) :: _)(config) } - @Lenses case class Debug() extends ConfigOption { override def update(config: Config): Config = debug.set(true)(config) diff --git a/core/src/main/scala/net/kemitix/thorp/core/ConfigOptions.scala b/core/src/main/scala/net/kemitix/thorp/core/ConfigOptions.scala index 2586ede..3b7a523 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/ConfigOptions.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/ConfigOptions.scala @@ -1,9 +1,9 @@ package net.kemitix.thorp.core import cats.Semigroup -import monocle.macros.Lenses +import monocle.Lens +import monocle.macros.GenLens -@Lenses case class ConfigOptions( options: List[ConfigOption] = List() ) extends Semigroup[ConfigOptions] { @@ -24,3 +24,8 @@ case class ConfigOptions( options contains elem } + +object ConfigOptions { + val options: Lens[ConfigOptions, List[ConfigOption]] = + GenLens[ConfigOptions](_.options) +} diff --git a/core/src/main/scala/net/kemitix/thorp/core/Counters.scala b/core/src/main/scala/net/kemitix/thorp/core/Counters.scala index ccfdb58..553b002 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/Counters.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/Counters.scala @@ -1,11 +1,18 @@ package net.kemitix.thorp.core -import monocle.macros.Lenses +import monocle.Lens +import monocle.macros.GenLens -@Lenses final case class Counters( uploaded: Int = 0, deleted: Int = 0, copied: Int = 0, errors: Int = 0 ) + +object Counters { + val uploaded: Lens[Counters, Int] = GenLens[Counters](_.uploaded) + val deleted: Lens[Counters, Int] = GenLens[Counters](_.deleted) + val copied: Lens[Counters, Int] = GenLens[Counters](_.copied) + val errors: Lens[Counters, Int] = GenLens[Counters](_.errors) +} diff --git a/core/src/main/scala/net/kemitix/thorp/core/LocalFiles.scala b/core/src/main/scala/net/kemitix/thorp/core/LocalFiles.scala index 64a31fe..451e47a 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/LocalFiles.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/LocalFiles.scala @@ -1,9 +1,7 @@ package net.kemitix.thorp.core -import monocle.macros.Lenses import net.kemitix.thorp.domain.LocalFile -@Lenses case class LocalFiles( localFiles: Stream[LocalFile] = Stream(), count: Long = 0, diff --git a/core/src/main/scala/net/kemitix/thorp/core/SyncPlan.scala b/core/src/main/scala/net/kemitix/thorp/core/SyncPlan.scala index 0e1e6ea..3e7d5da 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/SyncPlan.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/SyncPlan.scala @@ -1,9 +1,7 @@ package net.kemitix.thorp.core -import monocle.macros.Lenses import net.kemitix.thorp.domain.SyncTotals -@Lenses case class SyncPlan( actions: Stream[Action] = Stream(), syncTotals: SyncTotals = SyncTotals() diff --git a/core/src/main/scala/net/kemitix/thorp/core/UnversionedMirrorArchive.scala b/core/src/main/scala/net/kemitix/thorp/core/UnversionedMirrorArchive.scala index 08f4f50..d353aa6 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/UnversionedMirrorArchive.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/UnversionedMirrorArchive.scala @@ -1,20 +1,11 @@ package net.kemitix.thorp.core import cats.effect.IO -import monocle.macros.Lenses import net.kemitix.thorp.core.Action.{DoNothing, ToCopy, ToDelete, ToUpload} import net.kemitix.thorp.domain.StorageQueueEvent.DoNothingQueueEvent -import net.kemitix.thorp.domain.{ - Bucket, - LocalFile, - Logger, - StorageQueueEvent, - SyncTotals, - UploadEventListener -} +import net.kemitix.thorp.domain._ import net.kemitix.thorp.storage.api.StorageService -@Lenses case class UnversionedMirrorArchive( storageService: StorageService, batchMode: Boolean, diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/Bucket.scala b/domain/src/main/scala/net/kemitix/thorp/domain/Bucket.scala index a153ed6..c152185 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/Bucket.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/Bucket.scala @@ -1,8 +1,5 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - -@Lenses final case class Bucket( name: String ) diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/Config.scala b/domain/src/main/scala/net/kemitix/thorp/domain/Config.scala index aa11441..6389cbc 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/Config.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/Config.scala @@ -1,8 +1,8 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses +import monocle.Lens +import monocle.macros.GenLens -@Lenses final case class Config( bucket: Bucket = Bucket(""), prefix: RemoteKey = RemoteKey(""), @@ -11,3 +11,12 @@ final case class Config( batchMode: Boolean = false, sources: Sources = Sources(List()) ) + +object Config { + val sources: Lens[Config, Sources] = GenLens[Config](_.sources) + val bucket: Lens[Config, Bucket] = GenLens[Config](_.bucket) + val prefix: Lens[Config, RemoteKey] = GenLens[Config](_.prefix) + val filters: Lens[Config, List[Filter]] = GenLens[Config](_.filters) + val debug: Lens[Config, Boolean] = GenLens[Config](_.debug) + val batchMode: Lens[Config, Boolean] = GenLens[Config](_.batchMode) +} diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/Filter.scala b/domain/src/main/scala/net/kemitix/thorp/domain/Filter.scala index 858d2d1..d8b8a8e 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/Filter.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/Filter.scala @@ -3,8 +3,6 @@ package net.kemitix.thorp.domain import java.nio.file.Path import java.util.regex.Pattern -import monocle.macros.Lenses - sealed trait Filter object Filter { @@ -32,7 +30,6 @@ object Filter { } } - @Lenses case class Include( include: String = ".*" ) extends Filter { @@ -43,7 +40,6 @@ object Filter { } - @Lenses case class Exclude( exclude: String ) extends Filter { diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/HashModified.scala b/domain/src/main/scala/net/kemitix/thorp/domain/HashModified.scala index 44530ef..c752573 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/HashModified.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/HashModified.scala @@ -1,8 +1,5 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - -@Lenses final case class HashModified( hash: MD5Hash, modified: LastModified diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/KeyModified.scala b/domain/src/main/scala/net/kemitix/thorp/domain/KeyModified.scala index 0a6e4ec..6627497 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/KeyModified.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/KeyModified.scala @@ -1,8 +1,5 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - -@Lenses final case class KeyModified( key: RemoteKey, modified: LastModified diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/LastModified.scala b/domain/src/main/scala/net/kemitix/thorp/domain/LastModified.scala index f500f30..0e74f99 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/LastModified.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/LastModified.scala @@ -2,9 +2,6 @@ package net.kemitix.thorp.domain import java.time.Instant -import monocle.macros.Lenses - -@Lenses final case class LastModified( when: Instant = Instant.now ) diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/LocalFile.scala b/domain/src/main/scala/net/kemitix/thorp/domain/LocalFile.scala index 30364dd..4688e9e 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/LocalFile.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/LocalFile.scala @@ -3,9 +3,9 @@ package net.kemitix.thorp.domain import java.io.File import java.nio.file.Path -import monocle.macros.Lenses +import monocle.Lens +import monocle.macros.GenLens -@Lenses final case class LocalFile( file: File, source: File, @@ -41,4 +41,5 @@ object LocalFile { pathToKey(resolvedPath)) } + val remoteKey: Lens[LocalFile, RemoteKey] = GenLens[LocalFile](_.remoteKey) } diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/MD5Hash.scala b/domain/src/main/scala/net/kemitix/thorp/domain/MD5Hash.scala index 457b0de..4210f13 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/MD5Hash.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/MD5Hash.scala @@ -4,9 +4,6 @@ import java.util.Base64 import net.kemitix.thorp.domain.QuoteStripper.stripQuotes -import monocle.macros.Lenses - -@Lenses final case class MD5Hash( in: String ) { diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/RemoteKey.scala b/domain/src/main/scala/net/kemitix/thorp/domain/RemoteKey.scala index a8a824e..0c3ed34 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/RemoteKey.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/RemoteKey.scala @@ -3,9 +3,8 @@ package net.kemitix.thorp.domain import java.io.File import java.nio.file.{Path, Paths} -import monocle.macros.Lenses +import monocle.macros.GenLens -@Lenses final case class RemoteKey( key: String ) { @@ -38,3 +37,7 @@ final case class RemoteKey( RemoteKey(List(key, path).filterNot(_.isEmpty).mkString("/")) } + +object RemoteKey { + val key = GenLens[RemoteKey](_.key) +} diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/RemoteMetaData.scala b/domain/src/main/scala/net/kemitix/thorp/domain/RemoteMetaData.scala index 75c8066..a55b46e 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/RemoteMetaData.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/RemoteMetaData.scala @@ -1,8 +1,5 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - -@Lenses final case class RemoteMetaData( remoteKey: RemoteKey, hash: MD5Hash, diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/S3MetaData.scala b/domain/src/main/scala/net/kemitix/thorp/domain/S3MetaData.scala index f350c02..93ba71e 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/S3MetaData.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/S3MetaData.scala @@ -1,9 +1,6 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - // For the LocalFile, the set of matching S3 objects with the same MD5Hash, and any S3 object with the same remote key -@Lenses final case class S3MetaData( localFile: LocalFile, matchByHash: Set[RemoteMetaData], diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/S3ObjectsData.scala b/domain/src/main/scala/net/kemitix/thorp/domain/S3ObjectsData.scala index be5b66d..72b0aed 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/S3ObjectsData.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/S3ObjectsData.scala @@ -1,12 +1,8 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - /** * A list of objects and their MD5 hash values. */ - -@Lenses final case class S3ObjectsData( byHash: Map[MD5Hash, Set[KeyModified]] = Map.empty, byKey: Map[RemoteKey, HashModified] = Map.empty diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/Sources.scala b/domain/src/main/scala/net/kemitix/thorp/domain/Sources.scala index 2652787..fbdb4e9 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/Sources.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/Sources.scala @@ -2,8 +2,6 @@ package net.kemitix.thorp.domain import java.nio.file.Path -import monocle.macros.Lenses - /** * The paths to synchronise with target. * @@ -14,7 +12,6 @@ import monocle.macros.Lenses * * A path should only occur once in paths. */ -@Lenses case class Sources( paths: List[Path] ) { diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/StorageQueueEvent.scala b/domain/src/main/scala/net/kemitix/thorp/domain/StorageQueueEvent.scala index 9ca41fb..31e7e8d 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/StorageQueueEvent.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/StorageQueueEvent.scala @@ -1,7 +1,5 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - sealed trait StorageQueueEvent { val order: Int @@ -10,21 +8,18 @@ sealed trait StorageQueueEvent { object StorageQueueEvent { - @Lenses final case class DoNothingQueueEvent( remoteKey: RemoteKey ) extends StorageQueueEvent { override val order: Int = 0 } - @Lenses final case class CopyQueueEvent( remoteKey: RemoteKey ) extends StorageQueueEvent { override val order: Int = 1 } - @Lenses final case class UploadQueueEvent( remoteKey: RemoteKey, md5Hash: MD5Hash @@ -32,14 +27,12 @@ object StorageQueueEvent { override val order: Int = 2 } - @Lenses final case class DeleteQueueEvent( remoteKey: RemoteKey ) extends StorageQueueEvent { override val order: Int = 3 } - @Lenses final case class ErrorQueueEvent( remoteKey: RemoteKey, e: Throwable @@ -47,7 +40,6 @@ object StorageQueueEvent { override val order: Int = 10 } - @Lenses final case class ShutdownQueueEvent() extends StorageQueueEvent { override val order: Int = 99 } diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/SyncTotals.scala b/domain/src/main/scala/net/kemitix/thorp/domain/SyncTotals.scala index 2ffb1b9..7358e2b 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/SyncTotals.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/SyncTotals.scala @@ -1,8 +1,5 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - -@Lenses case class SyncTotals( count: Long = 0L, totalSizeBytes: Long = 0L, diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/UploadEvent.scala b/domain/src/main/scala/net/kemitix/thorp/domain/UploadEvent.scala index 811d32f..d416904 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/UploadEvent.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/UploadEvent.scala @@ -1,26 +1,21 @@ package net.kemitix.thorp.domain -import monocle.macros.Lenses - sealed trait UploadEvent { def name: String } object UploadEvent { - @Lenses final case class TransferEvent( name: String ) extends UploadEvent - @Lenses final case class RequestEvent( name: String, bytes: Long, transferred: Long ) extends UploadEvent - @Lenses final case class ByteTransferEvent( name: String ) extends UploadEvent diff --git a/domain/src/main/scala/net/kemitix/thorp/domain/UploadEventListener.scala b/domain/src/main/scala/net/kemitix/thorp/domain/UploadEventListener.scala index 7f905d0..48e1cbf 100644 --- a/domain/src/main/scala/net/kemitix/thorp/domain/UploadEventListener.scala +++ b/domain/src/main/scala/net/kemitix/thorp/domain/UploadEventListener.scala @@ -3,9 +3,6 @@ package net.kemitix.thorp.domain import net.kemitix.thorp.domain.UploadEvent.RequestEvent import net.kemitix.thorp.domain.UploadEventLogger.logRequestCycle -import monocle.macros.Lenses - -@Lenses case class UploadEventListener( localFile: LocalFile, index: Int,