Skip to content

Commit

Permalink
Merge addd27b into 3c0da7b
Browse files Browse the repository at this point in the history
  • Loading branch information
d10xa committed Jun 22, 2018
2 parents 3c0da7b + addd27b commit e41bc4e
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"scope": "test"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"scope": "test"
}
3 changes: 3 additions & 0 deletions src/main/resources/artifacts/io.specto__hoverfly-java.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"scope": "test"
}
5 changes: 4 additions & 1 deletion src/main/resources/jadd-shortcuts.csv
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ groovy-all,org.codehaus.groovy:groovy-all
gson,com.google.code.gson:gson
guava-testlib,com.google.guava:guava-testlib
h2,com.h2database:h2
hoverfly,io.specto:hoverfly-java
jline,org.jline:jline
joda-time,joda-time:joda-time
jsr305,com.google.code.findbugs:jsr305
Expand Down Expand Up @@ -95,4 +96,6 @@ sqlite,org.xerial:sqlite-jdbc
testcontainers,org.testcontainers:testcontainers
testcontainers-scala,com.dimafeng:testcontainers-scala%%
testng,org.testng:testng
utest,com.lihaoyi:utest%%
utest,com.lihaoyi:utest%%
wiremock,com.github.tomakehurst:wiremock
wiremock-standalone,com.github.tomakehurst:wiremock-standalone
1 change: 1 addition & 0 deletions src/main/scala/ru/d10xa/jadd/JaddRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class JaddRunner(
def readConfig(args: Array[String]): Config = {
val config = cli.parse(args)
if(config.debug) loggingUtil.enableDebug()
if(config.quiet) loggingUtil.quiet()
config
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/scala/ru/d10xa/jadd/LoggingUtil.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package ru.d10xa.jadd

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.LoggerContext
import com.typesafe.scalalogging.LazyLogging
import org.slf4j.LoggerFactory

trait LoggingUtil {
def enableDebug(): Unit
def quiet(): Unit
}

object LoggingUtil extends LoggingUtil with LazyLogging {

private def rootLogger: Logger =
LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext].getLogger("ru.d10xa.jadd")

override def enableDebug(): Unit = {
val loggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
val rootLogger = loggerContext.getLogger("ru.d10xa.jadd")
rootLogger.setLevel(Level.DEBUG)
logger.debug("Debug mode enabled")
}

override def quiet(): Unit = {
rootLogger.setLevel(Level.ERROR)
}
}
4 changes: 4 additions & 0 deletions src/main/scala/ru/d10xa/jadd/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ object Cli extends Cli {
.text("read-only mode")
.action((_, c) => c.copy(dryRun = true))

opt[Unit]('q', "quiet")
.text("log errors only")
.action((_, c) => c.copy(quiet = true))

opt[Unit]("debug")
.text("print debug messages")
.action((_, c) => c.copy(debug = true))
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/ru/d10xa/jadd/cli/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ case class Config(
shortcutsUri: String = "classpath:jadd-shortcuts.csv",
repositories: Seq[String] = Seq.empty,
dryRun: Boolean = false,
quiet: Boolean = false,
debug: Boolean = false
)
29 changes: 29 additions & 0 deletions src/test/scala/ru/d10xa/jadd/it/MainGradleTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.d10xa.jadd.it

import org.scalatest.FunSuiteLike
import org.scalatest.Matchers
import ru.d10xa.jadd.Jadd
import ru.d10xa.jadd.testkit.BuildFileTestBase

class MainGradleTest extends BuildFileTestBase("build.gradle") with FunSuiteLike with Matchers {

test("install dependency"){
write(
"""
|dependencies {
| compile "commons-io:commons-io:2.6"
|}
""".stripMargin)

Jadd.main(Array("install", "-q", projectDirArg, "junit:junit"))

read() shouldEqual
"""
|dependencies {
| compile "commons-io:commons-io:2.6"
| testCompile "junit:junit:4.12"
|}
""".stripMargin
}

}
55 changes: 55 additions & 0 deletions src/test/scala/ru/d10xa/jadd/it/MainMavenTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ru.d10xa.jadd.it

import org.scalatest.FunSuiteLike
import org.scalatest.Matchers
import ru.d10xa.jadd.Jadd
import ru.d10xa.jadd.testkit.BuildFileTestBase

class MainMavenTest extends BuildFileTestBase("pom.xml") with FunSuiteLike with Matchers {

test("insert dependency") {
val content =
"""
|<project>
| <modelVersion>4.0.0</modelVersion>
| <artifactId>a</artifactId>
| <dependencies>
| <dependency>
| <groupId>junit</groupId>
| <artifactId>junit</artifactId>
| <version>4.12</version>
| <scope>test</scope>
| </dependency>
| </dependencies>
|</project>
|""".stripMargin

write(content)

Jadd.main(Array("install", "-q", projectDirArg, "ch.qos.logback:logback-core"))

val expected =
"""
|<project>
| <modelVersion>4.0.0</modelVersion>
| <artifactId>a</artifactId>
| <dependencies>
| <dependency>
| <groupId>ch.qos.logback</groupId>
| <artifactId>logback-core</artifactId>
| <version>1.2.3</version>
| </dependency>
| <dependency>
| <groupId>junit</groupId>
| <artifactId>junit</artifactId>
| <version>4.12</version>
| <scope>test</scope>
| </dependency>
| </dependencies>
|</project>
|""".stripMargin

read() shouldEqual expected
}

}
24 changes: 24 additions & 0 deletions src/test/scala/ru/d10xa/jadd/it/MainSbtTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.d10xa.jadd.it

import org.scalatest.FunSuiteLike
import org.scalatest.Matchers
import ru.d10xa.jadd.Jadd
import ru.d10xa.jadd.testkit.BuildFileTestBase

class MainSbtTest extends BuildFileTestBase("build.sbt") with FunSuiteLike with Matchers {

test("update dependency"){
write(
"""
|libraryDependencies += "ch.qos.logback" % "logback-core" % "1.0.0"
""".stripMargin)

Jadd.main(Array("install", "-q", projectDirArg, "ch.qos.logback:logback-core"))

read() shouldEqual
"""
|libraryDependencies += "ch.qos.logback" % "logback-core" % "1.2.3"
""".stripMargin
}

}
10 changes: 10 additions & 0 deletions src/test/scala/ru/d10xa/jadd/testkit/BuildFileTestBase.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.d10xa.jadd.testkit

abstract class BuildFileTestBase(buildFileName: String) {
private val projectDir = new TempDir()
private val file: TempFile = projectDir.file(buildFileName)
val projectPath: String = projectDir.absolutePath
val projectDirArg: String = s"--project-dir=$projectPath"
def read(): String = file.read()
def write(content: String): Unit = file.write(content)
}
18 changes: 18 additions & 0 deletions src/test/scala/ru/d10xa/jadd/testkit/TempDir.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.d10xa.jadd.testkit

import java.io.File
import java.nio.file.Files

class TempDir {

private lazy val tempDir: File = {
val dir = Files.createTempDirectory("jadd-test-temp-dir").toFile
dir.deleteOnExit()
dir
}

def file(name: String): TempFile = new TempFile(tempDir, name)

def absolutePath: String = tempDir.getAbsolutePath

}
17 changes: 17 additions & 0 deletions src/test/scala/ru/d10xa/jadd/testkit/TempFile.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.d10xa.jadd.testkit

import java.io.File
import java.nio.file.Files

class TempFile(dir: File, name: String) {
lazy val file: File = {
val f = new File(dir, name)
if (!f.exists()) { f.deleteOnExit() }
f
}
def read(): String = new String(Files.readAllBytes(file.toPath))
def write(content: String): Unit = {
Files.write(file.toPath, content.getBytes())
}
def absolutePath: String = file.getAbsolutePath
}

0 comments on commit e41bc4e

Please sign in to comment.