Skip to content

Commit

Permalink
Merge 323d387 into d264b39
Browse files Browse the repository at this point in the history
  • Loading branch information
d10xa committed Jul 16, 2018
2 parents d264b39 + 323d387 commit 97f3a32
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -27,7 +27,7 @@ Just run `jadd` without arguments and enjoy tab completion!

- `analyze` search dependency in multiple repositories and print all available versions

- `show` show build file source
- `show` show artifacts from build file

- `help`

Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/ru/d10xa/jadd/CommandExecutor.scala
@@ -1,5 +1,6 @@
package ru.d10xa.jadd

import ru.d10xa.jadd.analyze.AnalyzeCommandImpl
import ru.d10xa.jadd.cli.Command.Analyze
import ru.d10xa.jadd.cli.Command.Help
import ru.d10xa.jadd.cli.Command.Repl
Expand All @@ -19,12 +20,14 @@ trait CommandExecutor {

class CommandExecutorImpl extends CommandExecutor {

lazy val analyzeCommand = new AnalyzeCommandImpl

override def execute(config: Config, showUsage: () => Unit): Unit = {
config match {
case c if c.command == Repl =>
Unit // already in repl
case c if c.command == Analyze =>
analyze.run(Ctx(c))
analyzeCommand.run(Ctx(c))
case c if c.command == Help =>
showUsage()
case c =>
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/ru/d10xa/jadd/LoggingUtil.scala
Expand Up @@ -23,7 +23,7 @@ object LoggingUtil extends LoggingUtil with LazyLogging {
logger.debug("Debug mode enabled")
case l: SubstituteLoggerFactory =>
def logger = l.getLogger("ru.d10xa.jadd")
println(s"SubstituteLoggerFactory used. Can not enable debug mode ${logger.getClass}")
logger.info(s"SubstituteLoggerFactory used. Can not enable debug mode ${logger.getClass}")
}
}

Expand All @@ -33,7 +33,7 @@ object LoggingUtil extends LoggingUtil with LazyLogging {
l.getLogger("ru.d10xa.jadd").setLevel(Level.ERROR)
case l: SubstituteLoggerFactory =>
def logger = l.getLogger("ru.d10xa.jadd")
println(s"SubstituteLoggerFactory used. Can not enable quiet mode ${logger.getClass}")
logger.info(s"SubstituteLoggerFactory used. Can not enable quiet mode ${logger.getClass}")
}
}
}
19 changes: 12 additions & 7 deletions src/main/scala/ru/d10xa/jadd/Utils.scala
@@ -1,30 +1,36 @@
package ru.d10xa.jadd

import com.typesafe.scalalogging.StrictLogging
import ru.d10xa.jadd.shortcuts.ArtifactInfoFinder
import ru.d10xa.jadd.troubles.ArtifactNotFoundByAlias

import scala.io.BufferedSource
import scala.io.Source

object Utils {
trait Utils {
def unshortAll(rawDependencies: List[String], artifactInfoFinder: ArtifactInfoFinder): List[Artifact]
def sourceFromSpringUri(string: String): BufferedSource
def mkStringFromResource(resource: String): String
}

def unshortAll(rawDependencies: List[String], artifactInfoFinder: ArtifactInfoFinder): List[Artifact] =
object Utils extends Utils with StrictLogging {
override def unshortAll(rawDependencies: List[String], artifactInfoFinder: ArtifactInfoFinder): List[Artifact] =
rawDependencies
.flatMap(raw => artifactInfoFinder.artifactFromString(raw) match {
case Right(artifact) => artifact :: Nil
case Left(_: ArtifactNotFoundByAlias) =>
println(s"$raw - artifact not found by shortcut")
logger.info(s"$raw - artifact not found by shortcut")
Nil
case Left(trouble) =>
println(s"some error occurred $trouble")
logger.info(s"some error occurred $trouble")
Nil
})

def sourceFromSpringUri(string: String): BufferedSource =
override def sourceFromSpringUri(string: String): BufferedSource =
if (string.startsWith("classpath:")) Source.fromResource(string.drop(10))
else Source.fromURL(string)

def mkStringFromResource(resource: String): String = {
override def mkStringFromResource(resource: String): String = {
val source = if (resource.startsWith("classpath:")) {
val str = resource.drop(10)
Source.fromResource(str)
Expand All @@ -35,5 +41,4 @@ object Utils {
source.close()
s
}

}
@@ -1,15 +1,24 @@
package ru.d10xa.jadd
package ru.d10xa.jadd.analyze

import cats.data.EitherT
import cats.implicits._
import com.typesafe.scalalogging.StrictLogging
import ru.d10xa.jadd.Artifact
import ru.d10xa.jadd.Ctx
import ru.d10xa.jadd.repository.MavenMetadata
import ru.d10xa.jadd.repository.RepositoryApi
import ru.d10xa.jadd.shortcuts.ArtifactInfoFinder
import ru.d10xa.jadd.shortcuts.ArtifactShortcuts
import ru.d10xa.jadd.shortcuts.RepositoryShortcutsImpl
import ru.d10xa.jadd.troubles

package object analyze {
def run(ctx: Ctx): Unit = {
trait AnalyzeCommand {
def run(ctx: Ctx): Unit
}

class AnalyzeCommandImpl extends AnalyzeCommand with StrictLogging {

override def run(ctx: Ctx): Unit = {
val config = ctx.config
val repositoryShortcuts = RepositoryShortcutsImpl
val artifactShortcuts = new ArtifactShortcuts()
Expand All @@ -18,7 +27,7 @@ package object analyze {

val defaultRepos = List("https://jcenter.bintray.com", "https://repo1.maven.org/maven2")
val reposFromConfig: List[String] = ctx.config.repositories.map(repositoryShortcuts.unshortRepository).toList
val repos: List[String] = if(reposFromConfig.nonEmpty) reposFromConfig else defaultRepos
val repos: List[String] = if (reposFromConfig.nonEmpty) reposFromConfig else defaultRepos

def loadVersions(a: Artifact, repo: String): Either[troubles.ArtifactTrouble, Artifact] = {
val errorOrMeta: Either[troubles.MetadataLoadTrouble, MavenMetadata] =
Expand Down Expand Up @@ -46,12 +55,13 @@ package object analyze {

as.groupBy(a => s"${a.groupId}:${a.artifactId}").foreach {
case (artifactShow, groupedArtifacts) =>
println(s"## $artifactShow")
groupedArtifacts.foreach(a => println(artifactAnalyzeAsString(a)))
logger.info(s"## $artifactShow")
groupedArtifacts.foreach(a => logger.info(artifactAnalyzeAsString(a)))
}

if(ts.nonEmpty) println("ERRORS:")
ts.foreach(t => troubles.handleTroubles(Seq(t), println))
if (ts.nonEmpty) logger.info("ERRORS:")
ts.foreach(t => troubles.handleTroubles(Seq(t), s => logger.info(s)))

}

}
4 changes: 2 additions & 2 deletions src/main/scala/ru/d10xa/jadd/pipelines/GradlePipeline.scala
Expand Up @@ -31,15 +31,15 @@ class GradlePipeline(override val ctx: Ctx)(implicit artifactInfoFinder: Artifac
override def install(): Unit = {
val artifacts = loadAllArtifacts(VersionTools)
handleArtifacts(artifacts.collect { case Right(v) => v })
handleTroubles(artifacts.collect { case Left(v) => v }, println)
handleTroubles(artifacts.collect { case Left(v) => v }, s => logger.info(s))
}

def handleArtifacts(artifacts: Seq[Artifact]): Unit = {
val artifactStrings: Seq[String] = artifacts
.flatMap(_.showLines)
.toList

artifactStrings.foreach(println)
artifactStrings.foreach(s => logger.info(s))

val newSource: String = new GradleFileInserts()
.appendAll(buildFileSource, artifacts)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/ru/d10xa/jadd/pipelines/MavenPipeline.scala
Expand Up @@ -54,8 +54,8 @@ class MavenPipeline(override val ctx: Ctx)(implicit artifactInfoFinder: Artifact
|</dependency>""".stripMargin
}

strings.foreach(println)
handleTroubles(artifactsWithVersions.collect { case Left(trouble) => trouble }, println)
strings.foreach(s => logger.info(s))
handleTroubles(artifactsWithVersions.collect { case Left(trouble) => trouble }, s => logger.info(s))

def newContent =
MavenFileInserts
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/ru/d10xa/jadd/pipelines/SbtPipeline.scala
Expand Up @@ -34,7 +34,7 @@ class SbtPipeline(override val ctx: Ctx)(implicit artifactInfoFinder: ArtifactIn
.flatMap(_.showLines)
.toList

artifactStrings.foreach(println)
artifactStrings.foreach(s => logger.info(s))

val newSource: String = new SbtFileInserts().appendAll(buildFileSource, artifacts)

Expand All @@ -46,7 +46,7 @@ class SbtPipeline(override val ctx: Ctx)(implicit artifactInfoFinder: ArtifactIn
override def install(): Unit = {
val artifacts = loadAllArtifacts(VersionTools)
handleArtifacts(artifacts.collect { case Right(v) => v })
handleTroubles(artifacts.collect { case Left(v) => v }, println)
handleTroubles(artifacts.collect { case Left(v) => v }, s => logger.info(s))
}

override def show(): Unit = {
Expand Down
Expand Up @@ -21,7 +21,7 @@ class UnknownProjectPipeline(val ctx: Ctx)(implicit artifactInfoFinder: Artifact

override def install(): Unit = {

println(s"build tool not recognized in directory ${ctx.config.projectDir}")
logger.info(s"build tool not recognized in directory ${ctx.config.projectDir}")

implicit val artifactShow: Show[Artifact] =
Show[Artifact] { a =>
Expand All @@ -36,9 +36,9 @@ class UnknownProjectPipeline(val ctx: Ctx)(implicit artifactInfoFinder: Artifact
.value
.separate

a.foreach(println)
if (e.nonEmpty) println("ERRORS:")
handleTroubles(e, println)
a.foreach(i => logger.info(i))
if (e.nonEmpty) logger.info("ERRORS:")
handleTroubles(e, s => logger.info(s))
}

override def show(): Unit = {
Expand Down

0 comments on commit 97f3a32

Please sign in to comment.