Permalink
Browse files

merge chamges from master

  • Loading branch information...
jtournay
jtournay committed Aug 6, 2012
2 parents 7d51c21 + 1e7a70d commit d379f1901d7d4cb380ac2df2e591b2055af3a81f
View
@@ -185,7 +185,7 @@ A `name` field with a value of `My Project` could be rendered in several ways:
$name$ -> "My Project"
$name;format="camel"$ -> "myProject"
$name;format="Camel"$ -> "MyProject"
- $name;format="normalized"$ -> "my-project"
+ $name;format="normalize"$ -> "my-project"
$name;format="lower,hyphen"$ -> "my-project"
Note that multiple format options can be specified (comma-separated) which will
@@ -216,7 +216,7 @@ object PluginDef extends Build {
And settings must be applied in a `build.sbt` file in the project base:
- seq(giter8Settings :_*)
+ seq(giter8Settings :_*)
When you enter sbt's interactive mode in the base directory of a
template project that is configured to use this plugin, the action
View
@@ -0,0 +1,30 @@
+
+{
+ "organization":"net.databinder.giter8",
+ "name":"giter8",
+ "version":"0.4.5",
+ "description":"Command line tool to apply templates defined on github",
+ "site":"https://github.com/n8han/giter8",
+ "tags":[],
+ "docs":"",
+ "licenses": [{
+ "name": "LGPL v3",
+ "url": "http://www.gnu.org/licenses/lgpl.txt"
+ }],
+ "resolvers": ["https://oss.sonatype.org/content/repositories/releases"],
+ "dependencies": [{
+ "organization":"org.clapper",
+ "name": "scalasti",
+ "version": "0.5.5"
+ },{
+ "organization":"org.scala-sbt",
+ "name": "launcher-interface_2.9.1",
+ "version": "0.11.3"
+ },{
+ "organization":"net.databinder",
+ "name": "dispatch-lift-json",
+ "version": "0.8.5"
+ }],
+ "scalas": ["2.9.1"],
+ "sbt": false
+}
@@ -2,43 +2,41 @@ package giter8
trait Apply { self: Giter8 =>
import java.io.File
+ import scalax.file.Path
+ import scalax.file.ImplicitConversions.defaultPath2jfile
import org.eclipse.jgit.api._
import scala.util.control.Exception.{allCatch,catching}
-
- val TMP = new File(System.getProperty("java.io.tmpdir"), java.util.UUID.randomUUID().toString)
+
+ val tempdir = Path.createTempDirectory(deleteOnExit = true)
+
def inspect(repo: String,
- branch: Option[String],
- arguments: Seq[String]) = {
+ branch: Option[String],
+ arguments: Seq[String]): Either[String, String] = {
val tmpl = clone(repo, branch)
- tmpl.right.map(G8Helpers.applyTemplate(_, new File("."), arguments))
+ tmpl.right.flatMap(G8Helpers.applyTemplate(_, new File("."), arguments))
}
- // TODO: exeptions handling
def clone(repo: String, branch: Option[String]) = {
import org.eclipse.jgit.api.ListBranchCommand.ListMode
import org.eclipse.jgit.lib._
-
import scala.collection.JavaConverters._
val cmd = Git.cloneRepository()
.setURI(repo)
- .setDirectory(TMP)
+ .setDirectory(tempdir)
val branchName = branch.map("refs/heads/" + _)
for(b <- branchName)
cmd.setBranch(b)
val g = cmd.call()
- TMP.deleteOnExit()
-
branchName.map { b =>
if(g.branchList().call().asScala.map(_.getName).contains(b))
- Right(TMP)
+ Right(tempdir)
else
Left("Branch not found: " + b)
- } getOrElse(Right(TMP))
+ } getOrElse(Right(tempdir))
}
}
-
@@ -14,39 +14,45 @@ class Giter8 extends xsbti.AppMain with Apply {
/** Runner shared my main-class runner */
def run(args: Array[String]): Int = {
(args.partition { s => Param.pattern.matcher(s).matches } match {
- case (params, Array(Local(repo))) =>
+ case (params, Array(Local(repo))) =>
inspect(repo, None, params)
- case (params, Array(Local(repo), Branch(_), branch)) =>
+ case (params, Array(Local(repo), Branch(_), branch)) =>
inspect(repo, Some(branch), params)
- case (params, Array(Git(remote))) =>
+ case (params, Array(Git(remote))) =>
inspect(remote, None, params)
case (params, Array(Git(remote), Branch(_), branch)) =>
inspect(remote, Some(branch), params)
case (params, Array(Repo(user, proj))) =>
- inspect("git@github.com:%s/%s.g8.git".format(user, proj), None, params)
+ ghInspect(user, proj, None, params)
case (params, Array(Repo(user, proj), Branch(_), branch)) =>
- inspect("git@github.com:%s/%s.g8.git".format(user, proj), Some(branch), params)
+ ghInspect(user, proj, Some(branch), params)
case _ => Left(usage)
- }) fold ({ error =>
+ }) fold ({ (error: String) =>
System.err.println("\n%s\n" format error)
1
- }, { message =>
- println("\n%s\n" format message)
+ }, { (message: String) =>
+ println("\n%s\n" format message )
0
})
}
- def http = new Http {
- override def make_logger = new dispatch.Logger {
- val jdklog = java.util.logging.Logger.getLogger("dispatch")
- def info(msg: String, items: Any*) {
- jdklog.info(msg.format(items: _*))
- }
- def warn(msg: String, items: Any*) {
- jdklog.warning(msg.format(items: _*))
- }
+ def ghInspect(user: String,
+ proj: String,
+ branch: Option[String],
+ params: Seq[String]) = {
+ try {
+ inspect("git://github.com/%s/%s.g8.git".format(user, proj),
+ branch,
+ params)
+ } catch {
+ case _: org.eclipse.jgit.api.errors.JGitInternalException =>
+ tempdir.deleteRecursively()
+ inspect("git@github.com:%s/%s.g8.git".format(user, proj),
+ branch,
+ params)
}
}
+
def usage = """giter8 %s
|Usage: g8 [TEMPLATE] [OPTION]...
|Apply specified template.
@@ -67,6 +73,9 @@ class Giter8 extends xsbti.AppMain with Apply {
|Apply template from a remote branch
| g8 n8han/giter8 -b some-branch
|
+ |Apply template from a local repo
+ | g8 file://path/to/the/repo
+ |
|Apply given name parameter and use defaults for all others.
| g8 n8han/giter8 --name=template-test
|
@@ -0,0 +1,26 @@
+
+{
+ "organization":"net.databinder.giter8",
+ "name":"giter8-lib",
+ "version":"0.4.5",
+ "description":"shared library for app and plugin",
+ "site":"https://github.com/n8han/giter8",
+ "tags":[],
+ "docs":"",
+ "licenses": [{
+ "name": "LGPL v3",
+ "url": "http://www.gnu.org/licenses/lgpl.txt"
+ }],
+ "resolvers": ["https://oss.sonatype.org/content/repositories/releases"],
+ "dependencies": [{
+ "organization":"org.clapper",
+ "name": "scalasti",
+ "version": "0.5.5"
+ },{
+ "organization":"me.lessis",
+ "name": "ls",
+ "version": "0.1.2-RC2"
+ }],
+ "scalas": ["2.9.1"],
+ "sbt": false
+}
@@ -93,7 +93,7 @@ object G8Helpers {
private def applyT(fetch: File => (Map[String, String], Stream[File], File, Option[File]))(tmpl: File, outputFolder: File, arguments: Seq[String] = Nil) = {
val (defaults, templates, templatesRoot, scaffoldsRoot) = fetch(tmpl)
-
+
val parameters = arguments.headOption.map { _ =>
(defaults /: arguments) {
case (map, Param(key, value)) if map.contains(key) =>
@@ -116,6 +116,7 @@ object G8Helpers {
private def fetchProjectTemplateinfo = fetchInfo(_: File, Some("src/main/g8"), Some("src/main/scaffolds"))
private def fetchRawTemplateinfo = fetchInfo(_: File, None, None)
+
def applyTemplate = applyT(fetchProjectTemplateinfo) _
def applyRaw = applyT(fetchRawTemplateinfo) _
@@ -132,10 +133,11 @@ object G8Helpers {
val templatesRoot = tmplFolder.map(new File(f, _)).getOrElse(f)
val fs = getVisibleFiles(templatesRoot)
+ val propertiesLoc = new File(templatesRoot, "default.properties")
val scaffoldsRoot = scaffoldFolder.map(new File(f, _))
val (propertiesFiles, tmpls) = fs.partition {
- _.getName == "default.properties"
+ _ == propertiesLoc
}
val parameters = propertiesFiles.headOption.map{ f =>
@@ -144,6 +146,7 @@ object G8Helpers {
}.getOrElse(Map.empty)
val g8templates = tmpls.filter(!_.isDirectory)
+
(parameters, g8templates, templatesRoot, scaffoldsRoot)
}
@@ -170,12 +173,17 @@ object G8Helpers {
}
val reader = new jline.ConsoleReader
+ val fixed = Set("verbatim")
others map { case (k,v) =>
- val in = sbt.SimpleReader.readLine("%s [%s]: ".format(k,v)).map{ r =>
- val x = r.trim
- if(x.isEmpty) v else x
+ if (fixed.contains(k))
+ (k, v)
+ else {
+ val in = sbt.SimpleReader.readLine("%s [%s]: ".format(k,v)).map{ r =>
+ val x = r.trim
+ if(x.isEmpty) v else x
+ }
+ (k, in.getOrElse(v))
}
- (k, in.getOrElse(v))
}
}
@@ -213,7 +221,7 @@ object G8Helpers {
Right("Template applied in %s" format (base.toString))
}
-
+
def copyScaffolds(sf: File, output: File) {
val scaffolds = if(sf.exists) Some(getVisibleFiles(sf)) else None
@@ -0,0 +1,27 @@
+
+{
+ "organization":"net.databinder",
+ "name":"giter8-plugin",
+ "version":"0.3.2",
+ "description":"sbt 0.11 plugin for testing giter8 templates",
+ "site":"",
+ "tags":[],
+ "docs":"",
+ "licenses": [],
+ "resolvers": ["http://scala-tools.org/repo-releases"],
+ "dependencies": [{
+ "organization":"org.clapper",
+ "name": "scalasti",
+ "version": "0.5.5"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "sbt_2.9.1",
+ "version": "0.11.2"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "scripted-plugin",
+ "version": "0.11.2"
+ }],
+ "scalas": ["2.9.1"],
+ "sbt": true
+}
@@ -0,0 +1,30 @@
+
+{
+ "organization":"net.databinder.giter8",
+ "name":"giter8-plugin",
+ "version":"0.4.0",
+ "description":"sbt 0.11 plugin for testing giter8 templates",
+ "site":"https://github.com/n8han/giter8",
+ "tags":[],
+ "docs":"",
+ "licenses": [{
+ "name": "LGPL v3",
+ "url": "http://www.gnu.org/licenses/lgpl.txt"
+ }],
+ "resolvers": ["http://scala-tools.org/repo-releases"],
+ "dependencies": [{
+ "organization":"org.clapper",
+ "name": "scalasti",
+ "version": "0.5.5"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "sbt_2.9.1",
+ "version": "0.11.2"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "scripted-plugin",
+ "version": "0.11.2"
+ }],
+ "scalas": ["2.9.1"],
+ "sbt": true
+}
@@ -0,0 +1,30 @@
+
+{
+ "organization":"net.databinder.giter8",
+ "name":"giter8-plugin",
+ "version":"0.4.1",
+ "description":"sbt 0.11 plugin for testing giter8 templates",
+ "site":"https://github.com/n8han/giter8",
+ "tags":[],
+ "docs":"",
+ "licenses": [{
+ "name": "LGPL v3",
+ "url": "http://www.gnu.org/licenses/lgpl.txt"
+ }],
+ "resolvers": ["http://scala-tools.org/repo-releases"],
+ "dependencies": [{
+ "organization":"org.clapper",
+ "name": "scalasti",
+ "version": "0.5.5"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "sbt_2.9.1",
+ "version": "0.11.2"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "scripted-plugin",
+ "version": "0.11.2"
+ }],
+ "scalas": ["2.9.1"],
+ "sbt": true
+}
@@ -0,0 +1,30 @@
+
+{
+ "organization":"net.databinder.giter8",
+ "name":"giter8-plugin",
+ "version":"0.4.2",
+ "description":"sbt 0.11 plugin for testing giter8 templates",
+ "site":"https://github.com/n8han/giter8",
+ "tags":[],
+ "docs":"",
+ "licenses": [{
+ "name": "LGPL v3",
+ "url": "http://www.gnu.org/licenses/lgpl.txt"
+ }],
+ "resolvers": ["http://scala-tools.org/repo-releases"],
+ "dependencies": [{
+ "organization":"org.clapper",
+ "name": "scalasti",
+ "version": "0.5.5"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "sbt_2.9.1",
+ "version": "0.11.2"
+ },{
+ "organization":"org.scala-tools.sbt",
+ "name": "scripted-plugin",
+ "version": "0.11.2"
+ }],
+ "scalas": ["2.9.1"],
+ "sbt": true
+}
Oops, something went wrong.

0 comments on commit d379f19

Please sign in to comment.