Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuration for maven repo in G8_HOME/mvnrepo file #155

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion library/src/main/scala/maven.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package giter8

import java.io.File

import dispatch.host
import scala.concurrent.Await
import scala.concurrent.duration._
Expand All @@ -21,12 +23,24 @@ object Maven extends JavaTokenParsers {
private def unapply(value: String): Option[(String, String)] =
Some(parse(spec, value)).filter { _.successful }.map { _.get }

private def mavenRepo(): Option[String] = {
val home = Option(System.getProperty("G8_HOME")).map(new File(_)).getOrElse(
new File(System.getProperty("user.home"), ".g8")
)
val mvnRepo = new File(home + "/mvnrepo")
if(!home.exists() || !mvnRepo.exists()) None
else {
scala.io.Source.fromFile(mvnRepo).getLines().filter(!_.trim.isEmpty).find(_=>true)
}
}

private def latestVersion(
org: String,
name: String
): Either[String, String] = {
import scala.concurrent.ExecutionContext.Implicits.global
val loc = s"https://repo1.maven.org/maven2/${org.replace('.', '/')}/$name/maven-metadata.xml"
val mvnCentral: String = "https://repo1.maven.org/maven2"
val loc = mavenRepo().getOrElse(mvnCentral) + s"/${org.replace('.', '/')}/$name/maven-metadata.xml"
val fut = for (resp <- G8.http(dispatch.url(loc))) yield {
resp.getStatusCode match {
case 200 =>
Expand Down