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

Adds templateResolvers and new command #2705

Merged
merged 4 commits into from
Aug 23, 2016
Merged

Conversation

eed3si9n
Copy link
Member

@eed3si9n eed3si9n commented Aug 22, 2016

This adds new command, which helps create a new build definition. The
new command is extensible via a mechanism called the template
resolver, which evaluates the arbitrary arguments passed to the command to find
and run a template.

See https://github.com/sbt/template-resolver/blob/master/src/main/java/sbt/template/TemplateResolver.java

As a reference implementation, Giter8 integration is provided, which works as follows:

$ sbt new eed3si9n/hello.g8

This will run eed3si9n/hello.g8 using Giter8.

templateResolvers is just a key in the Global scope, so you can write your own auto plugin to extend it:

object Giter8TemplatePlugin extends AutoPlugin {
  override def requires = CorePlugin
  override def trigger = allRequirements

  override lazy val globalSettings: Seq[Setting[_]] =
    Seq(
      templateResolvers += Giter8TemplateResolver
    )
}

The credit for the idea of extensible template support goes to @corruptmemory, but I take the blame for implementation details :)

update

If you want to make your own Giter8 template, see Making your own templates. All you need is a Git repo.

If you want to extend template resolving mechanism to something other than Giter8, just extend this Java class:

package sbt.template;

/** A way of specifying template resolver.
 */
public interface TemplateResolver {
  /** Returns true if this resolver can resolve the given argument.
   */
  public boolean isDefined(String[] arguments);
  /** Resolve the given argument and run the template.
   */
  public void run(String[] arguments);
}

and define an auto plugin that adds to templateResolvers. For example you might want to create Maven archetype-like template, or whatever mechanism that exists in-house.

This adds `new` command, which helps create a new build definition. The
`new` command is extensible via a mechanism called the template
resolver,
which evaluates the arbitrary arguments passed to the command to find
and run a template.

As a reference implementation [Giter8][g8] is provided as follows:

    sbt new eed3si9n/hello.g8

This will run eed3si9n/hello.g8 using Giter8.

  [g8]: http://www.foundweekends.org/giter8/
@hseeberger
Copy link
Member

Welcome back, g8 ;-)

@ktoso
Copy link
Member

ktoso commented Aug 22, 2016

Excellent, looking forward to this!

@dwijnand
Copy link
Member

LGTM

@huntc
Copy link

huntc commented Aug 22, 2016

Love it!

@eed3si9n eed3si9n merged commit 2407815 into sbt:0.13 Aug 23, 2016
@eed3si9n eed3si9n deleted the wip/new_command branch August 23, 2016 07:17
@eed3si9n eed3si9n added this to the 0.13.13 milestone Aug 23, 2016
@nafg
Copy link
Contributor

nafg commented Aug 23, 2016

You can use code like https://gist.github.com/nafg/05fafb7050ed38854184b4ca64612da7 to use Activator templates.

It seems the way IntelliJ (and I think also Activator itself) gets activator templates is through a very complex API that ultimately gives you a zip file containing a full-text search database (perhaps it was lucene?) which you can then use the client library for locally to search. Sounds like lightbend is really trying to be enterprise-ready... :trollface:

What my code does instead, is simply scrape the Activator index page for template ids. You can then download the template bundle by appending the id to https://www.lightbend.com/activator/template/bundle/.

It shouldn't be a big deal to write a templateResolver that takes the same shortcut.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants