Skip to content

Commit 6b532d4

Browse files
jeanmarcJean-Marc van Leerdam
andauthored
Features/8 use assembly settings (#9)
* Use the assembly output as input for our plugin * Update readme, release notes, and descriptions of settings keys * Setting version to 0.4.0 * Setting version to 0.4.1-SNAPSHOT Co-authored-by: Jean-Marc van Leerdam <jean-marc.van.leerdam@ordina.nl>
1 parent 446bfef commit 6b532d4

File tree

7 files changed

+43
-37
lines changed

7 files changed

+43
-37
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Experimental plugin for sbt to create Azure Function artefacts (function.json) n
2020
.settings(
2121
...
2222

23-
azfunZipName := "myFunctions",
24-
azfunJarName := "ScalaFunctions",
25-
assemblyOutputPath in assembly := azfunTargetFolder.value / s"${azfunJarName.value}.jar",
23+
// optional: override the zip and/or jar name (defaults are AzureFunction.zip and AzureFunction.jar)
24+
azfunZipName := "myFunctions.zip",
25+
azfunJarName := "ScalaFunctions.jar",
2626
2727
// you need this dependency to be able to use the annotations
2828
libraryDependencies ++= Seq(
@@ -42,14 +42,13 @@ Experimental plugin for sbt to create Azure Function artefacts (function.json) n
4242
The `azfunCreateZipFile` task will automatically trigger the following intermediate tasks that could also be
4343
called individually:
4444

45-
* `azfunGenerateFunctionJsons` - to make the `function.json` files
45+
* `azfunGenerateFunctionJsons` - to make the `function.json` files (implicitly calls `assembly` task)
4646
* `azfunCopyHostJson` - to copy the `host.json` file
4747
* `azfunCopyLocalSettingsJson` - to copy the `local.settings.json` file
4848

4949
## TODO:
5050
1. add task to upload to Azure
5151
1. add tests against multiple Java versions (java 8 and Java 11)
52-
1. remove setting `azfunJarName` (and related folder settings) and use the `assembly.value` instead
5352

5453

5554
## Cross compiling and testing
@@ -79,10 +78,9 @@ For now I will use these versions
7978
#### Unit tests
8079
* `sbt clean test`
8180
#### Scripted tests
82-
* `sbt publishLocal scripted`
83-
(the publishLocal is needed to ensure the latest snapshot of the library is available to the plugin)
81+
* `sbt scripted`
8482

85-
## Releasing
83+
## Releasing (for plugin maintainers)
8684
To release a new version:
8785
* Get a [bintray](https://bintray.com) account and make sure you're a member of the [`code-star`](https://bintray.com/code-star) organization.
8886
* Set your credentials - you can use `sbt bintrayChangeCredentials`, but when run from the interactive sbt prompt
@@ -91,5 +89,5 @@ To release a new version:
9189

9290
(found a workaround that shows the prompt again: add to build.sbt: `ThisBuild / useSuperShell := false`)
9391
* reload to make new settings known to sbt
94-
* Run `sbt publishLocal release`
92+
* Run `sbt release`
9593

plugin/src/main/scala/sbtazurefunctions/AzureFunctions.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ object AzureFunctionsKeys {
1616
val azfunHostJsonFile =
1717
settingKey[File]("Location of the host.json file")
1818
val azfunJarName =
19-
settingKey[String]("Name of the jar that holds the function definitions (without extension)")
19+
settingKey[String]("Name of the jar that holds the function definitions (default: AzureFunction.jar)")
2020
val azfunLocalSettingsFile =
2121
settingKey[File]("Location of the local.settings.json")
2222
val azfunZipName =
23-
settingKey[String]("Name of the zip file that will contain the results (without extension)")
23+
settingKey[String]("Name of the zip file that will contain the results (default: AzureFunction.zip)")
2424

2525
val azfunCreateZipFile = taskKey[File](
2626
"Generate the zip file containing the complete Azure Function definition"
@@ -50,7 +50,8 @@ object AzureFunctions extends AutoPlugin {
5050
azfunHostJsonFile := (baseDirectory in Compile).value / "host.json",
5151
azfunLocalSettingsFile := (baseDirectory in Compile).value / "local.settings.json",
5252
azfunTargetFolder := (target in Compile).value / azfunZipName.value,
53-
azfunZipName := "AzureFunction",
53+
azfunZipName := "AzureFunction.zip",
54+
azfunJarName := "AzureFunction.jar",
5455
azfunCopyHostJson := {
5556
val log = sbt.Keys.streams.value.log
5657
val folder = azfunTargetFolder.value
@@ -105,23 +106,27 @@ object AzureFunctions extends AutoPlugin {
105106
)
106107

107108
val src = azfunTargetFolder.value
108-
val tgt = tgtFolder / s"${azfunZipName.value}.zip"
109+
val tgt = tgtFolder / azfunZipName.value
109110
IO.zip(allSubpaths(src), tgt)
110111
tgt
111112
},
112113
azfunGenerateFunctionJsons := {
113114
// depend on assembly step
114-
val _ = assembly.value
115+
val assemblyJar = assembly.value
115116
val log = sbt.Keys.streams.value.log
116117

117118
val folder = azfunTargetFolder.value
118119

119120
log.info("Running azureFunctions task...")
120121
log.info(s"Generating function.json files to $folder ...")
121122

122-
val fatJarFile = azfunTargetFolder.value / s"${azfunJarName.value}.jar"
123-
val urls =
124-
ClasspathHelper.forManifest(fatJarFile.toURI.toURL).asScala.toList
123+
val fatJarFile = folder / azfunJarName.value
124+
125+
// copy the assembly jar into the folder that will be zipped eventually
126+
IO.copy(
127+
Seq((assemblyJar, fatJarFile))
128+
)
129+
val urls = ClasspathHelper.forManifest(fatJarFile.toURI.toURL).asScala.toList
125130
val configs = FunctionConfigGenerator.getConfigs(urls)
126131

127132
val baseFolder = azfunTargetFolder.value

plugin/src/sbt-test/sbt-azure-functions/simple/build.sbt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ lazy val root = (project in file("."))
44
.settings(
55
version := "0.1",
66
scalaVersion := "2.12.7",
7-
azfunZipName := "myFunctions",
8-
azfunJarName := "ScalaFunctions",
9-
assemblyOutputPath in assembly := azfunTargetFolder.value / s"${azfunJarName.value}.jar",
107
libraryDependencies ++= Seq(
118
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
12-
)
9+
),
10+
assemblyJarName in assembly := "ScalaFunctions.jar"
1311
)

plugin/src/sbt-test/sbt-azure-functions/simple/test

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@
33

44
# make the Jar
55
> assembly
6-
$ exists target/myFunctions/ScalaFunctions.jar
6+
$ exists target/scala-2.12/ScalaFunctions.jar
77

88
# generate the function.json
99
> azfunGenerateFunctionJsons
1010
# verify that output has been generated
11-
$ exists target/myFunctions/ScalaFunction/function.json
11+
$ exists target/AzureFunction/AzureFunction.jar
12+
$ exists target/AzureFunction/ScalaFunction/function.json
1213

1314
# copy the host.json
1415
> azfunCopyHostJson
1516
# verify that the host.json has been copied
16-
$ exists target/myFunctions/host.json
17+
$ exists target/AzureFunction/host.json
1718

1819
# copy the local.settings.json
1920
> azfunCopyLocalSettingsJson
2021
# verify that the host.json has been copied
21-
$ exists target/myFunctions/local.settings.json
22+
$ exists target/AzureFunction/local.settings.json
2223

2324
# reset to test automatic trigger of preceding tasks
2425
> clean
2526

2627
# zip folder including jar and function json files
2728
> azfunCreateZipFile
28-
$ exists target/myFunctions/ScalaFunctions.jar
29-
$ exists target/myFunctions/host.json
30-
$ exists target/myFunctions/local.settings.json
31-
$ exists target/myFunctions/ScalaFunction/function.json
32-
$ exists target/myFunctions.zip
29+
$ exists target/AzureFunction/AzureFunction.jar
30+
$ exists target/AzureFunction/host.json
31+
$ exists target/AzureFunction/local.settings.json
32+
$ exists target/AzureFunction/ScalaFunction/function.json
33+
$ exists target/AzureFunction.zip
3334

3435
# Uncomment the next lines if you want to look at the results from the scripted test
3536
# $ pause
36-

releasenotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Release notes
22

3+
## Version 0.4.0
4+
New Features:
5+
* Instead of in-place packaging of the result from the assembly step, the plugin now copies and renames the assembly jar
6+
into another folder (default: `./target/AzureFunction/AzureFunction.jar`) and generates the accompanying files
7+
in that same folder.
8+
The end result is a zip file (default: `./target/AzureFunction.zip`)
9+
10+
As a result, there are now no additional settings needed to use the plugin.
11+
312
## Version 0.3.1
413
Identical to 0.3.0, but releasing is now done to the `code-star/sbt-plugins` repository on Bintray
514
(was `code-star/sbt-azure-functions`)

showcase/build.sbt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ lazy val root = (project in file("."))
22
.settings(
33
name := "showcase",
44
version := "1.0",
5-
azfunZipName := "myFunctions",
6-
azfunJarName := "ScalaFunctions",
7-
assemblyOutputPath in assembly := azfunTargetFolder.value / s"${azfunJarName.value}.jar",
85
libraryDependencies ++= Seq(
96
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
10-
),
11-
azfunCreateZipFile := (azfunCreateZipFile dependsOn assembly).value
7+
)
128
)

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "0.3.2-SNAPSHOT"
1+
version in ThisBuild := "0.4.1-SNAPSHOT"

0 commit comments

Comments
 (0)