Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bc40bd8
Showing
14 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.class | ||
*.log | ||
|
||
target | ||
project/project | ||
project/target | ||
.cache | ||
.classpath | ||
.project | ||
.settings | ||
bin | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
style = defaultWithAlign # For pretty alignment. | ||
align = most | ||
maxColumn = 100 | ||
rewrite.rules = [SortImports, RedundantBraces] | ||
project.git = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
language: scala | ||
|
||
jdk: | ||
- oraclejdk8 | ||
|
||
script: | ||
## runs both regular tests and sbt-scripted integration tests | ||
- sbt -Dfile.encoding=UTF8 test scripted | ||
|
||
sudo: false | ||
|
||
# https://docs.travis-ci.com/user/languages/java/ | ||
addons: | ||
apt: | ||
packages: | ||
- oracle-java8-installer | ||
|
||
before_cache: | ||
# Tricks to avoid unnecessary cache updates | ||
- find $HOME/.sbt -name "*.lock" | xargs rm | ||
- find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm | ||
|
||
# These directories are cached to S3 at the end of the build | ||
cache: | ||
directories: | ||
- $HOME/.ivy2/cache | ||
- $HOME/.sbt/boot/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# sbt i18n | ||
|
||
An sbt plugin to generate a scala i18n bundle for various sources | ||
|
||
## Usage | ||
|
||
This plugin requires sbt 1.0.0+ | ||
|
||
### Testing | ||
|
||
Run `test` for regular unit tests. | ||
|
||
Run `scripted` for [sbt script tests](http://www.scala-sbt.org/1.x/docs/Testing-sbt-plugins.html). | ||
|
||
### Publishing | ||
|
||
1. publish your source to GitHub | ||
2. [create a bintray account](https://bintray.com/signup/index) and [set up bintray credentials](https://github.com/sbt/sbt-bintray#publishing) | ||
3. create a bintray repository `sbt-plugins` | ||
4. update your bintray publishing settings in `build.sbt` | ||
5. `sbt publish` | ||
6. [request inclusion in sbt-plugin-releases](https://bintray.com/sbt/sbt-plugin-releases) | ||
7. [Add your plugin to the community plugins list](https://github.com/sbt/website#attention-plugin-authors) | ||
8. [Claim your project an Scaladex](https://github.com/scalacenter/scaladex-contrib#claim-your-project) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name := "sbt-i18n" | ||
organization := "tech.ant8e" | ||
version := "0.1-SNAPSHOT" | ||
|
||
sbtPlugin := true | ||
|
||
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.5" % "test" | ||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test" | ||
|
||
bintrayPackageLabels := Seq("sbt", "plugin") | ||
bintrayVcsUrl := Some("git@github.com:ant8e/sbt-i18n.git") | ||
|
||
initialCommands in console := """import tech.ant8e.sbt.i18n._""" | ||
|
||
// set up 'scripted; sbt plugin for testing sbt plugins | ||
scriptedLaunchOpts ++= | ||
Seq("-Xmx1024M", "-Dplugin.version=" + version.value) | ||
|
||
scalafmtOnCompile in ThisBuild := true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.1.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value | ||
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4") | ||
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package tech.ant8e.sbt.i18n | ||
|
||
import sbt._ | ||
import sbt.Keys._ | ||
import sbt.plugins.JvmPlugin | ||
import sbt.internal.io.Source | ||
|
||
object SbtI18nPlugin extends AutoPlugin { | ||
|
||
override def trigger = allRequirements | ||
override def requires = JvmPlugin | ||
|
||
object autoImport { | ||
val i18nBundlePackageSetting = | ||
settingKey[String]("Package name for the i18n bundle ") | ||
val generateI18NBundleTask = | ||
taskKey[Seq[File]]("A task that is automatically imported to the build") | ||
|
||
} | ||
|
||
import autoImport._ | ||
private val i18nSource = | ||
settingKey[File]("Default directory containing i18n configuration sources.") | ||
|
||
override lazy val projectSettings = | ||
inConfig(Compile)( | ||
watchSourceSettings ++ | ||
Seq( | ||
i18nSource := sourceDirectory.value / "i18n", | ||
generateI18NBundleTask := generateFromTemplates(streams.value, | ||
i18nSource.value, | ||
sourceManaged.value / "sbt-i18n", | ||
i18nBundlePackageSetting.value), | ||
mappings in packageSrc ++= managedSources.value pair (Path | ||
.relativeTo(sourceManaged.value) | Path.flat), | ||
sourceGenerators += generateI18NBundleTask.taskValue | ||
)) ++ Seq(i18nBundlePackageSetting := "org.example.i18n") | ||
|
||
def generateFromTemplates(streams: TaskStreams, | ||
srcDir: sbt.File, | ||
outDir: File, | ||
packageName: String): Seq[File] = { | ||
val inputs = srcDir.allPaths | ||
streams.log.debug(s"Found ${inputs.get.size} template files in $srcDir.") | ||
streams.log.info(s"Generating i18n bundle in package $packageName.") | ||
val bundleFile = outDir / "Bundle.scala" | ||
IO.write(bundleFile, | ||
s"""package $packageName | ||
| | ||
|object Bundle {}""".stripMargin) | ||
|
||
Seq(bundleFile) | ||
} | ||
|
||
override lazy val buildSettings = Seq() | ||
|
||
override lazy val globalSettings = Seq() | ||
|
||
def allPaths(f: File) = f.allPaths | ||
|
||
def watchSourceSettings = Def.settings { | ||
Seq( | ||
watchSources in Defaults.ConfigGlobal += | ||
new Source(i18nSource.value, AllPassFilter, NothingFilter) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version := "0.1" | ||
scalaVersion := "2.12.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
val pluginVersion = System.getProperty("plugin.version") | ||
if(pluginVersion == null) | ||
throw new RuntimeException("""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin) | ||
else addSbtPlugin("tech.ant8e" % """sbt-i18n""" % pluginVersion) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package simple | ||
|
||
/** | ||
* A simple class and objects to write tests against. | ||
*/ | ||
class Main { | ||
val default = "the function returned" | ||
def method = default + " " + Main.function | ||
} | ||
|
||
object Main { | ||
|
||
val constant = 1 | ||
def function = 2*constant | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(new Main().default) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
> show generateI18NBundleTask | ||
|
||
> compile | ||
|
||
$ exists target/scala-2.12/src_managed/main/sbt-i18n/Bundle.scala | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package tech.ant8e.sbt.i18n | ||
|
||
class SbtI18nTest { | ||
// write tests with your preferred framework | ||
} |