Java runtime and core types for Microsoft Azure Functions
Перейти к файлу
Manvir Kaur 8bc5d62bf9
exclude generated temp folder from CodeQL analysis (#796)
2024-11-21 13:45:45 -06:00
.github FabricBot: Onboarding to GitOps.ResourceManagement because of FabricBot decommissioning (#718) 2023-08-22 11:25:30 -05:00
annotationLib Warmup java worker before specialization (#672) 2023-02-02 11:01:30 -06:00
azure-function-examples - Add retry feature test 2021-01-20 16:27:22 -08:00
emulatedtests emulated tests support (#790) 2024-10-19 04:39:08 -07:00
endtoendtests Bump com.google.guava:guava in /endtoendtests (#748) 2024-01-30 11:26:37 -06:00
eng/ci exclude generated temp folder from CodeQL analysis (#796) 2024-11-21 13:45:45 -06:00
samples Delete NuGet.config and Dockerfile from spring cloud example (#758) 2024-05-16 16:06:38 -05:00
src Revert "Set Thread context classloder for entire middleware chain (#717)" (#778) 2024-08-07 10:26:08 -05:00
tools work libs removed and update build pipeline,remove appveyor 2021-09-21 17:03:13 -05:00
warmup-function Warmup java worker before specialization (#672) 2023-02-02 11:01:30 -06:00
.gitignore add examples for spring cloud function on Azure (#697) 2023-01-27 16:10:07 -06:00
CODEOWNERS Remove myself as codeowner 2024-10-18 10:41:34 -07:00
CONTRIBUTING.md Update CONTRIBUTING.md documentation with app settings and extension … (#695) 2023-01-26 08:30:15 -06:00
ISSUE_TEMPLATE.md Added template for issue 2018-07-11 13:42:15 -07:00
LICENSE Adjust the core package POM for maven publishing. 2017-09-26 12:20:11 -07:00
README.md Update README.md 2022-04-08 12:32:28 -05:00
SECURITY.md Microsoft mandatory file (#602) 2022-08-04 11:24:18 -07:00
mvnBuild.bat Update build script (#222) 2018-10-27 16:46:17 -07:00
mvnBuildSkipTests.bat Fix build script (#218) 2018-10-24 11:19:50 -07:00
package-pipeline.ps1 Update application insights agent version to 3.5.4 (#783) 2024-08-23 13:37:28 -05:00
pom.xml Bump com.google.protobuf:protobuf-java from 3.19.6 to 3.25.5 2024-09-19 16:22:04 +00:00
setup-tests-pipeline.ps1 Update application insights agent version to 3.5.4 (#783) 2024-08-23 13:37:28 -05:00
worker.config.json Enable placeholders to start with app insights agent using profiles (#656) 2022-09-22 20:12:01 -05:00

README.md

Azure Functions Logo

Branch Status
Dev Build status
v3 Build status

Contributing

Please refer to CONTRIBUTING.md for more information.

Environment Setup

Maven

  • Run all maven commands under the root folder of this repository

IntelliJ

  • Import the root folder of this repository as an existing project in IntelliJ
  • Configure the Language level (under Project Structure -> Modules -> Sources) to 8

Eclipse

  • 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"

Development Cycle

Build

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

To build the project, you just need to run one command from the root folder of this project:

mvn clean package

And the binary will be built to "./azure-functions-java-worker/target/azure-functions-java-worker-<version>.jar".

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

Debug

The Java worker alone is not enough to establish the functions app, we also need the support from 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.

Published Host

You can install the latest Azure functions CLI tool by:

npm install -g azure-functions-core-tools@core

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:

func start

Latest Host

A developer may also use the latest host code by cloning the git repository Azure Functions Host. Now you need to navigate to the root folder of the host project and build it through:

dotnet restore WebJobs.Script.sln
dotnet build WebJobs.Script.sln

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:

dotnet ./src/WebJobs.Script.WebHost/bin/Debug/netcoreapp2.0/Microsoft.Azure.WebJobs.Script.WebHost.dll

Note: Remember to remove "AzureWebJobsScriptRoot" environment variable after you have finished debugging, because it will also influence the func CLI tool.

Generate JavaDoc

Simply using the following command to do so (if there are dependency errors, run mvn clean install beforehand):

mvn javadoc:javadoc

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.

Coding Convention

Version Management

Our version strategy just follows the maven package version convention: <major>.<minor>.<hotfix>-<prerelease>, where:

  • <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

Use SNAPSHOT pre-release tag for packages under development. Here is the sample workflow:

  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.

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.

Advanced Java Concepts

Reflection for Type

Primitives have two different type definitions, for example: int.class (which is identical to Integer.TYPE) is not Integer.class.

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 .