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

Allow templates to defined which version of Giter8 should be used #344

Merged
merged 6 commits into from Oct 3, 2017

Conversation

@wolfendale
Copy link
Contributor

wolfendale commented Oct 1, 2017

An implementation of #303

This doesn't work exactly as described above. I have made an effort to change as little of the existing code as possible for the time being. I think the refactoring work described should be completed as a separate task to this feature.

Flow

  1. Decide which version of Giter8 to run:
    • If a --g8Version property exists use that
    • Else, clone the template repo and inspect the project/build.properties file for a giter8.version property. If it exists use that.
    • Else, whatever the launchconfig in master of giter8 is will be used.
  2. Clone the foundweekends/giter8 repo locally and checkout tag for the version resolved above.
  3. Copy the src/main/conscript/g8/launchconfig file to a temporary location.
  4. Find a copy of the sbt-launch jar to use:
    • If the system property SBT_LAUNCH_JAR is set, use this.
    • Else, download a copy of the jar from Maven Central and cache it locally.
  5. Run the sbt-launch jar in a new JVM process with the launchconfig resolved above. Passing along all the args from this instance. Also, set GITER8_FORKED to true so that we prevent recursively launching new instances of Giter8.

The main benefits of this change are:

  1. Once we update the sbt-giter8-resolver to use this logic, we should in theory be decoupled from sbt releases.
  2. We can more liberally change the way Giter8 works in the future as templates should define the intended version used to render them.
wolfendale added 4 commits Sep 28, 2017
Added fallbacks for locating the sbt-launch jar
Replaced Scalaj with Gigahorse
Added checksum support for launch jar maven download
Refactored Launcher code into more sensible files
Replaced `-r` command option with a `GITER8_FORKED` system property to prevent recursive launching
Copy link
Member

eed3si9n left a comment

Overall looking pretty good.
I made some minor suggestions.

* @param template
* @return
*/
private def version(g8Version: Option[String], template: String): Try[Option[VersionNumber]] =

This comment has been minimized.

Copy link
@eed3si9n

eed3si9n Oct 1, 2017

Member

Another fallback it should consider is JVM flag -Dgiter8.version, to be consistent with sbt's sbt.version.

* @param version
* @return
*/
private def launchConfig(version: Option[VersionNumber]): Try[String] =

This comment has been minimized.

Copy link
@eed3si9n

eed3si9n Oct 1, 2017

Member

Could this mean that we need to have a GitHub-public tag for all of the Giter8 versions?
I think it's ok to fallback to the whatever the current one in-memory when it can't find it, for example to support local testing.

This comment has been minimized.

Copy link
@wolfendale

wolfendale Oct 1, 2017

Author Contributor

I'm fine falling back to the current version but I think that might be a problem from sbt new as technically we're launching it from outside of Giter8.

}

Try(Await.result(response, 10.minutes))
}.flatten.tap {

This comment has been minimized.

Copy link
@eed3si9n

eed3si9n Oct 1, 2017

Member

Is this Rubyism? If the following Scala is equivalent, I might prefer it because I'd forget what tap is.

}.flatten match {
  case x@Failure(e) =>
    e.printStackTrace()
    FileUtils.forceDelete(file)
    x
  case x => x
}
private def fetchAndCacheJar(url: String): Try[File] = {

val filename = url.split("/").last
val file = tmpdir / filename

This comment has been minimized.

Copy link
@eed3si9n

eed3si9n Oct 1, 2017

Member

I suggest we cache somewhere more permanent using an env var that Conscript or sbt uses.

opt[String]('t', "tag") action { (t, config) =>
config.copy(ref = Some(Tag(t)))
} text ("Resolve a template within a given branch")
} text "Resolve a template within a given branch"

This comment has been minimized.

Copy link
@laughedelic

laughedelic Oct 3, 2017

I think it should be "... given tag" here

@eed3si9n eed3si9n merged commit a33a7db into foundweekends:master Oct 3, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
xuwei-k added a commit to xuwei-k/giter8 that referenced this pull request Jan 7, 2018
xuwei-k added a commit to xuwei-k/giter8 that referenced this pull request Jan 22, 2018
xuwei-k added a commit to xuwei-k/giter8 that referenced this pull request Feb 3, 2018
xuwei-k added a commit that referenced this pull request Feb 10, 2018
@rbrondgeest

This comment has been minimized.

Copy link

rbrondgeest commented May 7, 2018

@wolfendale Would love to see a fix for #365

eed3si9n added a commit to eed3si9n/giter8 that referenced this pull request Dec 7, 2019
Fixes foundweekends#433
This is a reimplementation of foundweekends#303 / foundweekends#344

This creates a new command-line application called giter8-launcher whose job is analogous to sbt's sbt-launcher. giter8-launcher clones the template and reads `project/build.properties` file to determine the Giter8 version to render the template.

The artifacts for Giter8 is then resolved using Coursier, and `Giter8.run` is called via reflection.
eed3si9n added a commit to eed3si9n/giter8 that referenced this pull request Dec 7, 2019
Fixes foundweekends#433
This is a reimplementation of foundweekends#303 / foundweekends#344

This creates a new command-line application called giter8-launcher whose job is analogous to sbt's sbt-launcher. giter8-launcher clones the template and reads `project/build.properties` file to determine the Giter8 version to render the template.

The artifacts for Giter8 is then resolved using Coursier, and `Giter8.run` is called via reflection.
@eed3si9n eed3si9n mentioned this pull request Dec 7, 2019
eed3si9n added a commit to eed3si9n/giter8 that referenced this pull request Dec 7, 2019
Fixes foundweekends#433
This is a reimplementation of foundweekends#303 / foundweekends#344

This creates a new command-line application called giter8-launcher whose job is analogous to sbt's sbt-launcher. giter8-launcher clones the template and reads `project/build.properties` file to determine the Giter8 version to render the template.

The artifacts for Giter8 is then resolved using Coursier, and `Giter8.run` is called via reflection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.