azure-functions-java-worker/README.md

149 строки
6.3 KiB
Markdown
Исходник Обычный вид История

2019-02-28 01:42:16 +03:00
![Azure Functions Logo](https://raw.githubusercontent.com/Azure/azure-functions-cli/master/src/Azure.Functions.Cli/npm/assets/azure-functions-logo-color-raster.png)
2018-06-04 23:48:14 +03:00
|Branch|Status|
|---|---|
2020-06-15 21:50:03 +03:00
|master|[![Build status](https://dev.azure.com/azfunc/Azure%20Functions/_apis/build/status/Azure.azure-functions-java-worker?branchName=master)](https://dev.azure.com/azfunc/Azure%20Functions/_build/latest?definitionId=20&branchName=master)|
|dev|[![Build status](https://dev.azure.com/azfunc/Azure%20Functions/_apis/build/status/Azure.azure-functions-java-worker?branchName=dev)](https://dev.azure.com/azfunc/Azure%20Functions/_build/latest?definitionId=20&branchName=dev)|
2018-06-04 23:48:14 +03:00
2018-05-18 01:35:32 +03:00
# Contributing
Please refer to [CONTRIBUTING.md](./CONTRIBUTING.md) for more information.
2018-05-18 01:35:32 +03:00
# Environment Setup
2018-05-18 01:35:32 +03:00
## Maven
2018-05-18 01:35:32 +03:00
* Run all maven commands under the root folder of this repository
2018-05-18 01:35:32 +03:00
## IntelliJ
2018-05-18 01:35:32 +03:00
* Import the root folder of this repository as an existing project in IntelliJ
* Configure the Language level (under Project Structure -> Modules -> Sources) to 8
2018-05-18 01:35:32 +03:00
## Eclipse
2018-05-18 01:35:32 +03:00
* Set workspace to the parent folder of this repository
* Import the root folder of this repository as an existing Maven project in Eclipse
* Configure the project Java compiler compliance level to 1.8
* Set the JRE libraries to JRE 1.8
* "Ignore optional compiler problems" in "Java Build Path" for "target/generated-sources/\*\*/\*.java"
2018-05-18 01:35:32 +03:00
# Development Cycle
2018-05-18 01:35:32 +03:00
## Build
2018-05-18 01:35:32 +03:00
This is a maven based project, thus you can use any command line tools or IDEs which support maven to build it. Here we will use command line as the example (you could configure your own development environment accordingly).
2018-05-18 01:35:32 +03:00
To build the project, you just need to run one command from the root folder of this project:
2018-05-18 01:35:32 +03:00
```sh
mvn clean package
```
2018-05-18 01:35:32 +03:00
And the binary will be built to `"./azure-functions-java-worker/target/azure-functions-java-worker-<version>.jar"`.
2018-05-18 01:35:32 +03:00
If you have updated the core interface (azure-functions-java-core), a `mvn clean install` is required for your test functions app to reference the latest core package.
## Updating Dependencies and Plugins
* Update dependencies
```
mvn versions:use-latest-versions
```
* Update plugins
```
mvn versions:display-plugin-updates
```
For each of the plugin that displayed, update pom.xml
* Update version
```
mvn release:update-versions
```
2018-05-18 01:35:32 +03:00
## Debug
2018-05-18 01:35:32 +03:00
The Java worker alone is not enough to establish the functions app, we also need the support from [Azure Functions Host](https://github.com/Azure/azure-functions-host). You may either use a published host CLI or use the in-development host. But both of the methods require you to attach to the java process if you want a step-by-step debugging experience.
2018-05-18 01:35:32 +03:00
### Published Host
2018-05-18 01:35:32 +03:00
You can install the latest Azure functions CLI tool by:
2018-05-18 01:35:32 +03:00
```sh
npm install -g azure-functions-core-tools@core
```
2018-05-18 01:35:32 +03:00
By default, the binaries are located in `"<Home Folder>/.azurefunctions/bin"`. Copy the `"<Azure Functions Java Worker Root>/azure-functions-java-worker/target/azure-functions-java-worker-<version>.jar"` to `"<Home Folder>/.azurefunctions/bin/workers/java/azure-functions-java-worker.jar"`. And start it normally using:
2018-05-18 01:35:32 +03:00
```sh
func start
```
2018-05-18 01:35:32 +03:00
### Latest Host
2018-05-18 01:35:32 +03:00
A developer may also use the latest host code by cloning the git repository [Azure Functions Host](https://github.com/Azure/azure-functions-host). Now you need to navigate to the root folder of the host project and build it through:
2018-05-18 01:35:32 +03:00
```sh
dotnet restore WebJobs.Script.sln
dotnet build WebJobs.Script.sln
```
2018-05-18 01:35:32 +03:00
After the build succeeded, set the environment variable `"AzureWebJobsScriptRoot"` to the root folder path (the folder which contains the `host.json`) of your test functions app; and copy the `"<Azure Functions Java Worker Root>/azure-functions-java-worker/target/azure-functions-java-worker-<version>.jar"` to `"<Azure Functions Host Root>/src/WebJobs.Script.WebHost/bin/Debug/netcoreapp2.0/workers/java/azure-functions-java-worker.jar"`. Now it's time to start the host:
2018-05-18 01:35:32 +03:00
```sh
dotnet ./src/WebJobs.Script.WebHost/bin/Debug/netcoreapp2.0/Microsoft.Azure.WebJobs.Script.WebHost.dll
```
2018-05-18 01:35:32 +03:00
> Note: Remember to remove `"AzureWebJobsScriptRoot"` environment variable after you have finished debugging, because it will also influence the `func` CLI tool.
2018-05-18 01:35:32 +03:00
## Generate JavaDoc
2018-05-18 01:35:32 +03:00
Simply using the following command to do so (if there are dependency errors, run `mvn clean install` beforehand):
2018-05-18 01:35:32 +03:00
```sh
mvn javadoc:javadoc
```
2020-06-15 21:50:03 +03:00
# Development Notes
Java worker now shades all its jars, to introduce any new jars it is required by the developers to add a section in the pom file to relocate it.
2018-05-18 01:35:32 +03:00
# Coding Convention
2018-05-18 01:35:32 +03:00
## Version Management
2018-05-18 01:35:32 +03:00
Our version strategy just follows the maven package version convention: `<major>.<minor>.<hotfix>-<prerelease>`, where:
2018-05-18 01:35:32 +03:00
* `<major>`: Increasing when incompatible breaking changes happened
* `<minor>`: Increasing when new features added
* `<hotfix>`: Increasing when a hotfix is pushed
* `<prerelease>`: A string representing a pre-release version
2018-05-18 01:35:32 +03:00
**Use `SNAPSHOT` pre-release tag for packages under development**. Here is the sample workflow:
2018-05-18 01:35:32 +03:00
1. Initially the package version is `1.0-SNAPSHOT`. *There is no hotfix for SNAPSHOT*
2. Modify the version to `1.0.0-ALPHA` for internal testing purpose. *Notice the hotfix exists here*
3. After several BUG fixes, update the version to `1.0.0`.
4. Create a new development version `1.1-SNAPSHOT`.
5. Make a new hotfix into `1.0-SNAPSHOT`, and release to version `1.0.1`.
6. New features are added to `1.1-SNAPSHOT`.
2018-05-18 01:35:32 +03:00
Every time you release a non-development version (like `1.0.0-ALPHA` or `1.0.1`), you also need to update the tag in your git repository.
2018-05-18 01:35:32 +03:00
# Advanced Java Concepts
2018-05-18 01:35:32 +03:00
## Reflection for Type
2018-05-18 01:35:32 +03:00
Primitives have two different type definitions, for example: `int.class` (which is identical to `Integer.TYPE`) is not `Integer.class`.
2018-05-18 01:35:32 +03:00
All Java types are represented by `Type` interface, which may be one of the following implementations:
* `Class<?>`: normal class type like `String`
* `ParameterizedType`: generic class type like `List<Integer>`
* `WildcardType`: generic argument contains question mark like `? extends Number`
* `TypeVariable<?>`: generic argument like `T`
* `GenericArrayType`: generic array like `T[]`
For the generic type behaviors (including compile-time validation and runtime type erasure) in Java, please refer to *[Generics in the Java Programming Language
](https://www.cs.rice.edu/~cork/312/Readings/GenericsTutorial.pdf)*.