Verified Commit bdbc1d67 authored by 35V LG84's avatar 35V LG84

Remove Scala-ARM dependency

Removed Scala-ARM dependency, and replaced it with
similar functionality from better-files.
Signed-off-by: 35V LG84's avatar35V LG84 <35vlg84-x4e6b92@e257.fi>
parent 8fff120b
......@@ -17,7 +17,7 @@ New features and changes in this release are:
* Reformat balance report for better clarity
* Base64 ascii armor for Txn Filters defined by `--api-filter-def` CLI option
** See link:./docs/usage.adoc[Usage Guide] and Txn Filters
* Scala-ARM has been replaced with better-files resource mgmt functionality
==== Fixes
......@@ -30,6 +30,7 @@ Updated deps and tools:
* Updated dependencies
** cats: 1.6.0
** scala-arm: removed
* build
** sbt-wartremover: 2.4.1
* tests
......
......@@ -12,7 +12,6 @@ Components (used with Tackler):
* link:https://circe.github.io/circe/[circe]
* link:http://www.eclipse.org/jgit/[jgit]
* link:https://logback.qos.ch/[Logback Project]
* link:https://github.com/jsuereth/scala-arm[Scala-ARM (automatic resource mgmt)]
* link:https://github.com/scallop/scallop[Scallop]
* link:https://github.com/typesafehub/config[Typesafe Config]
......
......@@ -19,14 +19,11 @@ package fi.e257.tackler.cli
import java.nio.file.{Files, NoSuchFileException, Path, Paths}
import java.util.regex.PatternSyntaxException
import better.files.File
import org.rogach.scallop.exceptions.{ExcessArguments, RequiredOptionNotFound, UnknownOption, ValidationFailure}
import resource._
import better.files._
import fi.e257.tackler.core.{AccountException, CommodityException, GroupByException, ReportException, TacklerException, TxnException}
import fi.e257.tackler.parser.TacklerParseException
import fi.e257.testing.Glob
import fi.e257.testing.DirSuiteLike
import fi.e257.testing.{DirSuiteLike, Glob}
import org.rogach.scallop.exceptions.{ExcessArguments, RequiredOptionNotFound, UnknownOption, ValidationFailure}
/**
......@@ -54,18 +51,17 @@ class DirsuiteConsoleTest extends DirSuiteLike {
runDirSuiteTestCases(basedir, Glob("cli/ok/*.exec")) { args: Array[String] =>
assertResult(TacklerCli.SUCCESS) {
val rv = for {
stdout <- managed(Files.newOutputStream(Paths.get(args(0))))
stderr <- managed(Files.newOutputStream(Paths.get(args(1))))
} yield {
Console.withOut(stdout) {
Console.withErr(stderr) {
TacklerCli.runReturnValue(args.drop(2))
using(Files.newOutputStream(Paths.get(args(0))))(stdout => {
using(Files.newOutputStream(Paths.get(args(1))))(stderr => {
Console.withOut(stdout) {
Console.withErr(stderr) {
TacklerCli.runReturnValue(args.drop(2))
}
}
}
}
// funky map(u=>u): https://github.com/jsuereth/scala-arm/issues/49
rv.map(u => u).opt.getOrElse(TacklerCli.FAILURE)
})
})
}
}
}
......
......@@ -7,7 +7,6 @@ libraryDependencies ++= circe_deps
libraryDependencies += typesafeConfig
libraryDependencies += jgit
libraryDependencies += scalaArm
libraryDependencies += scalatest % "test"
libraryDependencies ++= circe_deps_test
SCALA LICENSE
Copyright (c) 2002-2013 EPFL, Lausanne, unless otherwise specified.
All rights reserved.
This software was developed by the Programming Methods Laboratory of the
Swiss Federal Institute of Technology (EPFL), Lausanne, Switzerland.
Permission to use, copy, modify, and distribute this software in source
or binary form for any purpose with or without fee is hereby granted,
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the EPFL nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
......@@ -27,6 +27,8 @@ import fi.e257.tackler.model.{AccountTreeNode, Commodity, Posting, Posts, Transa
import fi.e257.tackler.parser.TxnParser._
import org.slf4j.{Logger, LoggerFactory}
import scala.util.control.NonFatal
/**
* Handler utilities for ANTLR Parser Contexts.
*
......@@ -277,7 +279,7 @@ abstract class CtxHandler {
try {
handleTxn(txnCtx)
} catch {
case ex: Exception => {
case NonFatal(ex) => {
val lineNro = txnCtx.start.getLine
log.error("Error while processing Transaction on line {}", lineNro.toString)
throw ex
......
......@@ -24,18 +24,19 @@
package fi.e257.tackler.parser
import java.nio.file.Path
import better.files.File
import better.files._
import cats.implicits._
import fi.e257.tackler.api.{GitInputReference, Metadata}
import fi.e257.tackler.core.{Settings, TacklerException}
import fi.e257.tackler.model.{OrderByTxn, TxnData, Txns}
import org.eclipse.jgit.lib.{FileMode, ObjectId, Repository}
import org.eclipse.jgit.revwalk.{RevCommit, RevWalk}
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import org.eclipse.jgit.treewalk.TreeWalk
import org.eclipse.jgit.treewalk.filter.{AndTreeFilter, PathFilter, PathSuffixFilter}
import org.slf4j.{Logger, LoggerFactory}
import resource.{makeManagedResource, managed, _}
import fi.e257.tackler.api.{GitInputReference, Metadata}
import fi.e257.tackler.core.{Settings, TacklerException}
import fi.e257.tackler.model.{OrderByTxn, TxnData, Txns}
import scala.util.control.NonFatal
/**
* Helper methods for [[TacklerTxns]] and Txns Input handling.
......@@ -133,8 +134,13 @@ class TacklerTxns(val settings: Settings) extends CtxHandler {
}).seq.sorted(OrderByTxn))
}
private def getCommitId(repository: Repository, inputRef: TacklerTxns.GitInputSelector): ObjectId = {
inputRef match {
/**
* Get commit id based on input ref
*
* @return git commit id (as ObjectId)
*/
private def getCommitId(repository: Repository, inputSelector: TacklerTxns.GitInputSelector): ObjectId = {
inputSelector match {
case Left(refStr) => {
log.info("GIT: reference = {}", refStr)
......@@ -168,19 +174,19 @@ class TacklerTxns(val settings: Settings) extends CtxHandler {
/**
* Get Git repository as managed resource.
* Repository must be bare.
* Caller must close repository after use
*
* @param gitdir path/to/repo.git
* @return repository as managed resource
* @return repository
*/
private def getRepo(gitdir: File): ManagedResource[Repository] = {
private def getRepo(gitdir: File): Repository = {
log.info("GIT: repo = {}", gitdir.toString())
try {
val repo = (new FileRepositoryBuilder)
(new FileRepositoryBuilder)
.setGitDir(gitdir.toJava)
.setMustExist(true)
.setBare()
.build()
managed(repo)
} catch {
case e: org.eclipse.jgit.errors.RepositoryNotFoundException => {
val msg = "GIT: Repository not found\n" +
......@@ -206,24 +212,20 @@ class TacklerTxns(val settings: Settings) extends CtxHandler {
* @param inputRef Left(ref) or Right(commitId)
* @return TxnData
*/
@SuppressWarnings(Array("org.wartremover.warts.TraversableOps"))
@SuppressWarnings(Array(
"org.wartremover.warts.TraversableOps",
"org.wartremover.warts.Equals"))
def git2Txns(inputRef: TacklerTxns.GitInputSelector): TxnData = {
val tmpResult = getRepo(settings.input_git_repository).map(repository => {
using(getRepo(settings.input_git_repository))(repository => {
val gitdir = settings.input_git_dir
val suffix = settings.input_git_suffix
val commitId = getCommitId(repository, inputRef)
// with managed(new RevWalk(repository))
// [error] ambiguous implicit values:
// [error] both method reflectiveDisposableResource ...
// [error] and method reflectiveCloseableResource ...
// Let's use makeMangedResource
val revWalkM = makeManagedResource(new RevWalk(repository))(_.dispose())(List.empty[Class[Throwable]])
val revWalkResult = revWalkM.map(revWalk => {
// a RevWalk allows to walk over commits based on some filtering that is defined
using(new RevWalk(repository))(revWalk => {
// a RevWalk allows to walk over commits based on defined filtering
val commit: RevCommit = try {
revWalk.parseCommit(commitId)
......@@ -241,7 +243,7 @@ class TacklerTxns(val settings: Settings) extends CtxHandler {
val tree = commit.getTree
// now try to find files
managed(new TreeWalk(repository)).map(treeWalk => {
using(new TreeWalk(repository))(treeWalk => {
treeWalk.addTree(tree)
treeWalk.setRecursive(true)
......@@ -250,7 +252,7 @@ class TacklerTxns(val settings: Settings) extends CtxHandler {
PathSuffixFilter.create(suffix)))
// Handle files
(for {
val txns = (for {
_ <- Iterator.continually(treeWalk.next()).takeWhile(p => p === true)
} yield {
val objectId = treeWalk.getObjectId(0)
......@@ -265,17 +267,6 @@ class TacklerTxns(val settings: Settings) extends CtxHandler {
throw new TacklerException(msg)
}
}).toSeq
}).either.either match {
case Right(foids) => (commit, foids)
case Left(ex) => throw ex.head
}
}).either
revWalkResult.either match {
case Right(result) => {
val commit = result._1
val txns = result._2
val meta = GitInputReference(
commit.getName,
......@@ -286,37 +277,29 @@ class TacklerTxns(val settings: Settings) extends CtxHandler {
)
TxnData(Some(Metadata(Seq(meta))), txns.flatten.sorted(OrderByTxn))
}
case Left(ex) => {
throw ex.head
}
}
}).either
tmpResult.either match {
case Right(t) => t
case Left(ex) => throw ex.head
}
})
})
})
}
@SuppressWarnings(Array("org.wartremover.warts.TraversableOps"))
private def gitObject2Txns(repository: Repository, objectId: ObjectId): Txns = {
val loader = repository.open(objectId)
log.debug("txn: git: object id: {}", objectId.getName)
log.debug("txn: git: object id: " + objectId.getName)
val loader = repository.open(objectId, org.eclipse.jgit.lib.Constants.OBJ_BLOB)
managed(loader.openStream).map(stream => {
handleTxns(TacklerParser.txnsStream(stream))
}).either
.either match {
case Right(txns) => txns
case Left(ex) => {
// todo: handle error, parse error msg, commit id, etc.
log.error("Error git: object id: " + objectId.getName)
throw ex.head
using(loader.openStream())(stream => {
try {
handleTxns(TacklerParser.txnsStream(stream))
} catch {
case NonFatal(ex) => {
// todo: handle error, parse error msg, commit id, etc.
log.error("Error git: object id: " + objectId.getName)
throw ex
}
}
}
})
}
/**
* Parse and converts input string to Txns
......
......@@ -15,14 +15,15 @@
*
*/
package fi.e257.tackler.report
import java.io.{BufferedWriter, OutputStreamWriter}
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Path, Paths}
import org.slf4j.{Logger, LoggerFactory}
import resource._
import better.files._
import fi.e257.tackler.core._
import fi.e257.tackler.model.TxnData
import org.slf4j.{Logger, LoggerFactory}
final case class Reports(settings: Settings) {
......@@ -122,12 +123,10 @@ final case class Reports(settings: Settings) {
outputBase.fold {
log.warn("Report exporting: no output file is defined!")
} { outputPath =>
for {
ostream <- managed(Files.newOutputStream(Paths.get(outputPath.toString + "." + name + ".txn")))
} {
using(Files.newOutputStream(Paths.get(outputPath.toString + "." + name + ".txn")))(ostream => {
val strm: Writer = new BufferedWriter(new OutputStreamWriter(ostream, "UTF-8"))
exporter.writeExport(strm, txnData.txns)
}
})
}
}
......
SCALA LICENSE
Copyright (c) 2002-2013 EPFL, Lausanne, unless otherwise specified.
All rights reserved.
This software was developed by the Programming Methods Laboratory of the
Swiss Federal Institute of Technology (EPFL), Lausanne, Switzerland.
Permission to use, copy, modify, and distribute this software in source
or binary form for any purpose with or without fee is hereby granted,
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the EPFL nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
......@@ -51,5 +51,4 @@ Tackler Enhancement Proposals (TEP) are listed on link:./tep/readme.adoc[TEP Ind
* link:./licenses/JGIT-COOKBOOK-LICENSE.txt[jgit-Cookbook]
* link:./licenses/LOGBACK-LICENSE.txt[Logback]
* link:./licenses/SLF4J-LICENSE.txt[SLF4J]
* link:./licenses/SCALA-ARM-LICENSE.txt[Scala-ARM]
* link:./licenses/SCALLOP-LICENSE.txt[Scallop]
......@@ -31,7 +31,6 @@ object Dependencies {
val dirsuiteVersion = "0.21.0"
val jgitVersion = "5.2.1.201812262042-r"
val logbackVersion = "1.2.3"
val scalaArmVersion = "2.0"
/*
......@@ -54,7 +53,6 @@ object Dependencies {
val scalatest = "org.scalatest" %% "scalatest" % scalatestVersion
val scallop = "org.rogach" %% "scallop" % scallopVersion
val dirsuite = "fi.e257.testing" %% "dirsuite" % dirsuiteVersion
val scalaArm = "com.jsuereth" %% "scala-arm" % scalaArmVersion
/* lib: java */
val jgit = "org.eclipse.jgit" % "org.eclipse.jgit" % jgitVersion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment