-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
src/main/resources/artifacts/com.github.tomakehurst__wiremock-standalone.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"scope": "test" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/artifacts/com.github.tomakehurst__wiremock.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"scope": "test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"scope": "test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
src/test/scala/ru/d10xa/jadd/testkit/BuildFileTestBase.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |