Adds templateResolvers and `new` command #2705

Merged
merged 4 commits into from Aug 23, 2016

Conversation

Projects
None yet
6 participants
@eed3si9n
Member

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.

Adds templateResolvers and `new` command
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

This comment has been minimized.

Show comment
Hide comment
@hseeberger

hseeberger Aug 22, 2016

Member

Welcome back, g8 ;-)

Member

hseeberger commented Aug 22, 2016

Welcome back, g8 ;-)

@ktoso

This comment has been minimized.

Show comment
Hide comment
@ktoso

ktoso Aug 22, 2016

Excellent, looking forward to this!

ktoso commented Aug 22, 2016

Excellent, looking forward to this!

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Aug 22, 2016

Member

LGTM

Member

dwijnand commented Aug 22, 2016

LGTM

@huntc

This comment has been minimized.

Show comment
Hide comment
@huntc

huntc Aug 22, 2016

Love it!

huntc commented Aug 22, 2016

Love it!

eed3si9n added some commits Aug 22, 2016

@eed3si9n eed3si9n merged commit 2407815 into sbt:0.13 Aug 23, 2016

2 checks passed

codacy/pr Good work! A perfect pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@eed3si9n eed3si9n deleted the eed3si9n:wip/new_command branch Aug 23, 2016

@eed3si9n eed3si9n removed the in progress label Aug 23, 2016

@eed3si9n eed3si9n added this to the 0.13.13 milestone Aug 23, 2016

@nafg

This comment has been minimized.

Show comment
Hide comment
@nafg

nafg 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.

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.

@eed3si9n eed3si9n referenced this pull request Oct 13, 2016

Merged

Safer template resolver #2780

@slandelle slandelle referenced this pull request in gatling/gatling Oct 24, 2016

Closed

SBT: provide a giter8 template #3168

@eed3si9n eed3si9n referenced this pull request Nov 15, 2016

Closed

[sbt 1.0] Forward port 0.13 changes #2352

7 of 7 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment