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
5 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
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,41 @@ | ||
package ru.d10xa.jadd | ||
|
||
import ru.d10xa.jadd.regex.GradleVerbalExpressions.stringWithGroupIdArtifactId | ||
import ru.d10xa.jadd.regex.GradleVerbalExpressions.stringWithGroupIdArtifactIdVersion | ||
import ru.d10xa.jadd.regex.GradleVerbalExpressions.variableAssignment | ||
import ru.d10xa.jadd.stringinterpolation.GStr | ||
|
||
trait ArtifactProvider[T] { | ||
def provide(t: T): Seq[Artifact] | ||
} | ||
|
||
object ArtifactProvider { | ||
case class GradleBuildDescription(buildFileSource: String) | ||
|
||
implicit val gradleArtifactProvider: ArtifactProvider[GradleBuildDescription] = | ||
(d: GradleBuildDescription) => { | ||
|
||
import ru.d10xa.jadd.regex.RegexImplicits._ | ||
val map: Map[String, String] = variableAssignment.build().groups2(d.buildFileSource).toMap | ||
val interpolated = GStr.interpolate(map) | ||
|
||
val t3 = stringWithGroupIdArtifactIdVersion() | ||
.groups3(d.buildFileSource) | ||
.map { case (g, a, v) => s"$g:$a:$v" } | ||
val t2 = stringWithGroupIdArtifactId() | ||
.groups2(d.buildFileSource) | ||
.map { case (g, a) => s"$g:$a" } | ||
|
||
val all = t3 ++ t2 | ||
|
||
all | ||
.map(new GStr(_).resolve(interpolated)) | ||
.map(Artifact.fromString) | ||
.map(_.right.get) // TODO .get | ||
} | ||
|
||
implicit class BuildDescriptionImplicits[T](val buildDescription: T)(implicit artifactProvider: ArtifactProvider[T]) { | ||
def artifacts: Seq[Artifact] = artifactProvider.provide(buildDescription) | ||
} | ||
|
||
} |
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,24 +1,12 @@ | ||
package ru.d10xa.jadd.show | ||
|
||
import com.typesafe.scalalogging.StrictLogging | ||
import ru.d10xa.jadd.regex.GradleVerbalExpressions._ | ||
import ru.d10xa.jadd.stringinterpolation.GStr | ||
import ru.d10xa.jadd.ArtifactProvider.GradleBuildDescription | ||
|
||
class GradleShowCommand(buildFileSource: String) extends StrictLogging { | ||
def show(): String = { | ||
import ru.d10xa.jadd.regex.RegexImplicits._ | ||
|
||
val t3 = stringWithGroupIdArtifactIdVersion() | ||
.groups3(buildFileSource) | ||
.map { case (g, a, v) => s"$g:$a:$v" } | ||
val t2 = stringWithGroupIdArtifactId() | ||
.groups2(buildFileSource) | ||
.map { case (g, a) => s"$g:$a" } | ||
|
||
val map: Map[String, String] = variableAssignment.build().groups2(buildFileSource).toMap | ||
val interpolated = GStr.interpolate(map) | ||
|
||
val all = t3 ++ t2 | ||
all.map(new GStr(_)).map(_.resolve(interpolated)).mkString("\n") | ||
} | ||
def show(): String = | ||
GradleBuildDescription(buildFileSource) | ||
.artifacts | ||
.map(_.canonicalView) | ||
.mkString("\n") | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/scala/ru/d10xa/jadd/GradleArtifactProviderTest.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,42 @@ | ||
package ru.d10xa.jadd | ||
|
||
import org.scalatest.FunSuite | ||
import org.scalatest.Matchers | ||
import ru.d10xa.jadd.ArtifactProvider.GradleBuildDescription | ||
|
||
class GradleArtifactProviderTest extends FunSuite with Matchers { | ||
|
||
test("GradleBuildDescription as artifacts") { | ||
val d = GradleBuildDescription( | ||
""" | ||
|plugins { | ||
| id 'scala' | ||
|} | ||
|ext { | ||
| scalaTestVersion = '3.0.4' | ||
|} | ||
|repositories { | ||
| jcenter() | ||
|} | ||
|def scalaMajorVersion = "2.12" | ||
|def scalaVersion = "${scalaMajorVersion}.6" | ||
|dependencies { | ||
| compile "org.scala-lang:scala-library:${scalaVersion}" | ||
| testCompile "org.scalatest:scalatest_${scalaMajorVersion}:$scalaTestVersion" | ||
|} | ||
""".stripMargin | ||
) | ||
val artifacts = ArtifactProvider.gradleArtifactProvider.provide(d) | ||
|
||
artifacts(0) shouldEqual Artifact( | ||
groupId = "org.scala-lang", | ||
artifactId = "scala-library", | ||
maybeVersion = Some("2.12.6") | ||
) | ||
artifacts(1) shouldEqual Artifact( | ||
groupId = "org.scalatest", | ||
artifactId = "scalatest_2.12", | ||
maybeVersion = Some("3.0.4") | ||
) | ||
} | ||
} |