diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..741701b --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,17 @@ + + +### Issue describing the changes in this PR + +resolves #issue_for_this_pr + +### Pull request checklist + +* [ ] My changes **do not** require documentation changes + * [ ] Otherwise: Documentation issue linked to PR +* [ ] My changes are added to the `CHANGELOG.md` +* [ ] I have added all required tests (Unit tests, E2E tests) + + +### Additional information + +Additional PR information \ No newline at end of file diff --git a/.gitignore b/.gitignore index 044af7d..ace21a3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* /.idea/* -/target/* +target /bin /.classpath /.settings/* diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c507d4c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +## azure-functions-java-spi_1.0.0 + +### New +* to be update + +### Updates +* to be update + +### Breaking changes +* to be update \ No newline at end of file diff --git a/README.md b/README.md index 6596f26..0a4fffc 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,12 @@ |master|[![Build status](https://ci.appveyor.com/api/projects/status/ebphtfegnposba6w?svg=true)](https://ci.appveyor.com/project/appsvc/azure-functions-java-library?branch=master)| |dev|[![Build status](https://ci.appveyor.com/api/projects/status/ebphtfegnposba6w?svg=true)](https://ci.appveyor.com/project/appsvc/azure-functions-java-library?branch=dev)| -# Library for Azure Java Functions -This repo contains library for building Azure Java Functions. Visit the [complete documentation of Azure Functions - Java Developer Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java) for more details. +# Additional artifacts for Azure Java Functions +This repo contains two additional artifacts for building Azure Java Functions. +* [azure-functions-java-core-library](https://github.com/Azure/azure-functions-java-additions/azure-functions-java-core-library) +* [azure-functions-java-spi](https://github.com/Azure/azure-functions-java-additions/azure-functions-java-spi) + +For more information about Azure Java Functions please visit the [complete documentation of Azure Functions - Java Developer Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java) for more details. ## azure-functions-maven plugin [How to use azure-functions-maven plugin to create, update, deploy and test azure java functions](https://docs.microsoft.com/en-us/java/api/overview/azure/maven/azure-functions-maven-plugin/readme?view=azure-java-stable) @@ -21,207 +25,12 @@ Please see for details on Parent POM https://github.com/Microsoft/maven-java-par ## Summary -Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it. Functions can make development even more productive.Pay only for the time your code runs and trust Azure to scale as needed. Azure Functions lets you develop [serverless](https://azure.microsoft.com/en-us/solutions/serverless/) applications on Microsoft Azure. - -Azure Functions supports triggers, which are ways to start execution of your code, and bindings, which are ways to simplify coding for input and output data. A function should be a stateless method to process input and produce output. Although you are allowed to write instance methods, your function must not depend on any instance fields of the class. You need to make sure all the function methods are `public` accessible and method with annotation @FunctionName is unique as that defines the entry for the the function. - -A deployable unit is an uber JAR containing one or more functions (see below), and a JSON file with the list of functions and triggers definitions, deployed to Azure Functions. The JAR can be created in many ways, although we recommend [Azure Functions Maven Plugin](https://docs.microsoft.com/en-us/java/api/overview/azure/maven/azure-functions-maven-plugin/readme), as it provides templates to get you started with key scenarios. - -All the input and output bindings can be defined in `function.json` (not recommended), or in the Java method by using annotations (recommended). All the types and annotations used in this document are included in the `azure-functions-java-library` package. +[Azure Functions Summary](https://github.com/Azure/azure-functions-java-library#summary) ### Sample -Here is an example of a HttpTrigger Azure function in Java: - - -```java -package com.example; - -import com.microsoft.azure.functions.annotation.*; - -public class Function { - @FunctionName("echo") - public static String echo(@HttpTrigger(name = "req", methods = { HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) String in) { - return "Hello, " + in + "."; - } -} -``` - -### Adding 3rd Party Libraries - -Azure Functions supports the use of 3rd party libraries. If using the Maven plugin for Azure Functions, all of your dependencies specified in your `pom.xml` file will be automatically bundled during the `mvn package` step. - -## Data Types - -You are free to use all the data types in Java for the input and output data, including native types; customized POJO types and specialized Azure types defined in this API. Azure Functions runtime will try its best to convert the actual input value to the type you need (for example, a `String` input will be treated as a JSON string and be parsed to a POJO type defined in your code). - -### JSON Support -The POJO types (Java classes) you may define have to be publicly accessible (`public` modifier). POJO properties/fields may be `private`. For example a JSON string `{ "x": 3 }` is able to be converted to the following POJO type: - -```java -public class PojoData { - private int x; -} -``` - -### Other supported types -Binary data is represented as `byte[]` or `Byte[]` in your Azure functions code. And make sure you specify `dataType = "binary"` in the corresponding triggers/bindings. - -Empty input values could be `null` as your functions argument, but a recommended way to deal with potential empty values is to use `Optional` type. - - -## Inputs - -Inputs are divided into two categories in Azure Functions: one is the trigger input and the other is the additional input. Trigger input is the input who triggers your function. And besides that, you may also want to get inputs from other sources (like a blob), that is the additional input. - -Let's take the following code snippet as an example: - -```java -package com.example; - -import com.microsoft.azure.functions.annotation.*; - -public class Function { - @FunctionName("echo") - public String echo( - @HttpTrigger(name = "req", methods = { HttpMethod.PUT }, authLevel = AuthorizationLevel.ANONYMOUS, route = "items/{id}") String in, - @TableInput(name = "item", tableName = "items", partitionKey = "example", rowKey = "{id}", connection = "AzureWebJobsStorage") TestInputData inputData - ) { - return "Hello, " + in + " and " + inputData.getRowKey() + "."; - } - -} - -public class TestInputData { - public String getRowKey() { return this.rowKey; } - private String rowKey; -} - -``` - -When this function is invoked, the HTTP request payload will be passed as the `String` for argument `in`; and one entry will be retrieved from the Azure Table Storage and be passed to argument `inputData` as `TestInputData` type. - -To receive events in a batch when using EventHubTrigger, set cardinality to many and change input type to an array or List<> - -```java -@FunctionName("ProcessIotMessages") - public void processIotMessages( - @EventHubTrigger(name = "message", eventHubName = "%AzureWebJobsEventHubPath%", connection = "AzureWebJobsEventHubSender", cardinality = Cardinality.MANY) List messages, - final ExecutionContext context) - { - context.getLogger().info("Java Event Hub trigger received messages. Batch size: " + messages.size()); - } - - public class TestEventData { - public String id; -} - -``` - -Note: You can also bind to String[], TestEventData[] or List - -## Outputs - -Outputs can be expressed in return value or output parameters. If there is only one output, you are recommended to use the return value. For multiple outputs, you have to use **output parameters**. - -Return value is the simplest form of output, you just return the value of any type, and Azure Functions runtime will try to marshal it back to the actual type (such as an HTTP response). You could apply any *output annotations* to the function method (the `name` property of the annotation has to be `$return`) to define the return value output. - -For example, a blob content copying function could be defined as the following code. `@StorageAccount` annotation is used here to prevent the duplicating of the `connection` property for both `@BlobTrigger` and `@BlobOutput`. - -```java -package com.example; - -import com.microsoft.azure.functions.annotation.*; - -public class Function { - @FunctionName("copy") - @StorageAccount("AzureWebJobsStorage") - @BlobOutput(name = "$return", path = "samples-output-java/{name}") - public String copy(@BlobTrigger(name = "blob", path = "samples-input-java/{name}") String content) { - return content; - } -} -``` - -To produce multiple output values, use `OutputBinding` type defined in the `azure-functions-java-library` package. If you need to make an HTTP response and push a message to a queue, you can write something like: - -```java -package com.example; - -import com.microsoft.azure.functions.*; -import com.microsoft.azure.functions.annotation.*; - -public class Function { - @FunctionName("push") - public String push( - @HttpTrigger(name = "req", methods = { HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) String body, - @QueueOutput(name = "message", queueName = "myqueue", connection = "AzureWebJobsStorage") OutputBinding queue - ) { - queue.setValue("This is the queue message to be pushed"); - return "This is the HTTP response content"; - } -} -``` - -Use `OutputBinding` type to make a binary output value (for parameters); for return values, just use `byte[]`. - -## Execution Context - -You interact with Azure Functions execution environment via the `ExecutionContext` object defined in the `azure-functions-java-library` package. You are able to get the invocation ID, the function name and a built-in logger (which is integrated prefectly with Azure Function Portal experience as well as AppInsights) from the context object. - -What you need to do is just add one more `ExecutionContext` typed parameter to your function method. Let's take a timer triggered function as an example: - -```java -package com.example; - -import com.microsoft.azure.functions.*; -import com.microsoft.azure.functions.annotation.*; - -public class Function { - @FunctionName("heartbeat") - public static void heartbeat( - @TimerTrigger(name = "schedule", schedule = "*/30 * * * * *") String timerInfo, - ExecutionContext context - ) { - context.getLogger().info("Heartbeat triggered by " + context.getFunctionName()); - } -} -``` - - -## Specialized Data Types - -### HTTP Request and Response - -Sometimes a function need to take a more detailed control of the input and output, and that's why we also provide some specialized types in the `azure-functions-java-library` package for you to manipulate: - -| Specialized Type | Target | Typical Usage | -| ------------------------ | :-----------------: | ------------------------------ | -| `HttpRequestMessage` | HTTP Trigger | Get method, headers or queries | -| `HttpResponseMessage` | HTTP Output Binding | Return status other than 200 | - -### Metadata - -Metadata comes from different sources, like HTTP headers, HTTP queries, and [trigger metadata](https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#trigger-metadata-properties). You can use `@BindingName` annotation together with the metadata name to get the value. - -For example, the `queryValue` in the following code snippet will be `"test"` if the requested URL is `http://{example.host}/api/metadata?name=test`. - -```java -package com.example; - -import java.util.Optional; -import com.microsoft.azure.functions.annotation.*; - -public class Function { - @FunctionName("metadata") - public static String metadata( - @HttpTrigger(name = "req", methods = { HttpMethod.GET, HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) Optional body, - @BindingName("name") String queryValue - ) { - return body.orElse(queryValue); - } -} -``` +For samples of Azure function in Java please refer to [Azure Function Java Samples](https://github.com/Azure/azure-functions-java-library#sample) +and [Azure Functions Java Samples Repository](https://github.com/Azure-Samples/azure-functions-samples-java) ### License diff --git a/azure-functions-java-core-library/README.md b/azure-functions-java-core-library/README.md new file mode 100644 index 0000000..ee4c2a2 --- /dev/null +++ b/azure-functions-java-core-library/README.md @@ -0,0 +1,30 @@ +![Azure Functions Logo](https://raw.githubusercontent.com/Azure/azure-functions-cli/master/src/Azure.Functions.Cli/npm/assets/azure-functions-logo-color-raster.png) + +# Core library for Azure Java Functions +This repo contains core library for building Azure Java Functions. `azure-functions-java-core-library` contains base class for building Azure Java Functions. +However, you don't need to include `azure-functions-java-core-library` as a dependency when you build your function app, because it comes with [azure-functions-java-library](https://github.com/Azure/azure-functions-java-library) +which has a transitive dependency on `azure-functions-java-core-library` + +For more information about Azure Java Functions please visit the [complete documentation of Azure Functions - Java Developer Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java). + +## azure-functions-maven plugin +[How to use azure-functions-maven plugin to create, update, deploy and test azure java functions](https://docs.microsoft.com/en-us/java/api/overview/azure/maven/azure-functions-maven-plugin/readme?view=azure-java-stable) + +## Prerequisites + +* Java 8 + +## Summary + +[Azure Functions Summary](https://github.com/Azure/azure-functions-java-library#summary) + +### Sample + +For samples of Azure function in Java please refer to [Azure Function Java Samples](https://github.com/Azure/azure-functions-java-library#sample) +and [Azure Functions Java Samples Repository](https://github.com/Azure-Samples/azure-functions-samples-java) + +### License + +This project is under the benevolent umbrella of the [.NET Foundation](http://www.dotnetfoundation.org/) and is licensed under [the MIT License](LICENSE.txt) + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/azure-functions-java-core-library/pom.xml b/azure-functions-java-core-library/pom.xml new file mode 100644 index 0000000..8692de2 --- /dev/null +++ b/azure-functions-java-core-library/pom.xml @@ -0,0 +1,103 @@ + + 4.0.0 + com.microsoft.azure.functions + azure-functions-java-core-library + 1.1.0 + jar + + com.microsoft.maven + java-8-parent + 8.0.1 + + + + Microsoft Azure Functions Java Core Types + This package contains core Java classes to interact with Microsoft Azure functions runtime. + https://azure.microsoft.com/en-us/services/functions + + + UTF-8 + + + + + MIT License + https://opensource.org/licenses/MIT + repo + + + + + scm:git:https://github.com/Azure/azure-functions-java-core-library + scm:git:git@github.com:Azure/azure-functions-java-core-library + https://github.com/Azure/azure-functions-java-core-library + HEAD + + + + + Microsoft + Microsoft Corporation + + + + + + maven.snapshots + Maven Central Snapshot Repository + https://oss.sonatype.org/content/repositories/snapshots/ + + false + + + true + + + + + + + + junit + junit + test + + + + + + + maven-compiler-plugin + + + maven-source-plugin + + + maven-javadoc-plugin + 3.4.1 + + + maven-enforcer-plugin + 3.0.0-M2 + + + enforce-maven + + enforce + + + + + 3.2.0 + + + + + + + + + + diff --git a/src/main/java/com/microsoft/azure/functions/BrokerAuthenticationMode.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/BrokerAuthenticationMode.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/BrokerAuthenticationMode.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/BrokerAuthenticationMode.java diff --git a/src/main/java/com/microsoft/azure/functions/BrokerProtocol.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/BrokerProtocol.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/BrokerProtocol.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/BrokerProtocol.java diff --git a/src/main/java/com/microsoft/azure/functions/ExecutionContext.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/ExecutionContext.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/ExecutionContext.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/ExecutionContext.java diff --git a/src/main/java/com/microsoft/azure/functions/HttpMethod.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpMethod.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/HttpMethod.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpMethod.java diff --git a/src/main/java/com/microsoft/azure/functions/HttpRequestMessage.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpRequestMessage.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/HttpRequestMessage.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpRequestMessage.java diff --git a/src/main/java/com/microsoft/azure/functions/HttpResponseMessage.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpResponseMessage.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/HttpResponseMessage.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpResponseMessage.java diff --git a/src/main/java/com/microsoft/azure/functions/HttpStatus.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpStatus.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/HttpStatus.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpStatus.java diff --git a/src/main/java/com/microsoft/azure/functions/HttpStatusType.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpStatusType.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/HttpStatusType.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/HttpStatusType.java diff --git a/src/main/java/com/microsoft/azure/functions/OutputBinding.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/OutputBinding.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/OutputBinding.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/OutputBinding.java diff --git a/src/main/java/com/microsoft/azure/functions/RetryContext.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/RetryContext.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/RetryContext.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/RetryContext.java diff --git a/src/main/java/com/microsoft/azure/functions/RpcException.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/RpcException.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/RpcException.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/RpcException.java diff --git a/src/main/java/com/microsoft/azure/functions/TraceContext.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/TraceContext.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/TraceContext.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/TraceContext.java diff --git a/src/main/java/com/microsoft/azure/functions/package-info.java b/azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/package-info.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/package-info.java rename to azure-functions-java-core-library/src/main/java/com/microsoft/azure/functions/package-info.java diff --git a/src/test/java/com/microsoft/azure/functions/HttpStatusTest.java b/azure-functions-java-core-library/src/test/java/com/microsoft/azure/functions/HttpStatusTest.java similarity index 89% rename from src/test/java/com/microsoft/azure/functions/HttpStatusTest.java rename to azure-functions-java-core-library/src/test/java/com/microsoft/azure/functions/HttpStatusTest.java index 90798fd..a0d75d8 100644 --- a/src/test/java/com/microsoft/azure/functions/HttpStatusTest.java +++ b/azure-functions-java-core-library/src/test/java/com/microsoft/azure/functions/HttpStatusTest.java @@ -1,8 +1,8 @@ package com.microsoft.azure.functions; -import org.junit.*; +import org.junit.Test; -import static junit.framework.TestCase.*; +import static junit.framework.TestCase.assertTrue; /** * Unit tests that enforce annotation contracts and conventions for Functions diff --git a/azure-functions-java-spi/README.md b/azure-functions-java-spi/README.md new file mode 100644 index 0000000..1e67bc6 --- /dev/null +++ b/azure-functions-java-spi/README.md @@ -0,0 +1,30 @@ +![Azure Functions Logo](https://raw.githubusercontent.com/Azure/azure-functions-cli/master/src/Azure.Functions.Cli/npm/assets/azure-functions-logo-color-raster.png) + +# SPI for Azure Java Functions +This repo contains SPI for building Azure Java Functions. **This library should not be used when building your function app.** +This library provides hooks to third parties supporting them to interact with function runtime during function invocation process. +**_This library should be used with scope as `provided`, because customers should not inherit it via a transitive dependency_** + +For more information about Azure Java Functions please visit the [complete documentation of Azure Functions - Java Developer Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java). + +## azure-functions-maven plugin +[How to use azure-functions-maven plugin to create, update, deploy and test azure java functions](https://docs.microsoft.com/en-us/java/api/overview/azure/maven/azure-functions-maven-plugin/readme?view=azure-java-stable) + +## Prerequisites + +* Java 8 + +## Summary + +[Azure Functions Summary](https://github.com/Azure/azure-functions-java-library#summary) + +### Sample + +For samples of Azure function in Java please refer to [Azure Function Java Samples](https://github.com/Azure/azure-functions-java-library#sample) +and [Azure Functions Java Samples Repository](https://github.com/Azure-Samples/azure-functions-samples-java) + +### License + +This project is under the benevolent umbrella of the [.NET Foundation](http://www.dotnetfoundation.org/) and is licensed under [the MIT License](LICENSE.txt) + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/azure-functions-java-spi/pom.xml b/azure-functions-java-spi/pom.xml new file mode 100644 index 0000000..8a5395f --- /dev/null +++ b/azure-functions-java-spi/pom.xml @@ -0,0 +1,103 @@ + + 4.0.0 + com.microsoft.azure.functions + azure-functions-java-spi + 1.0.0 + jar + + com.microsoft.maven + java-8-parent + 8.0.1 + + + + Microsoft Azure Functions Java SPI Types + This package contains all SPI interfaces for third parties to interact with Microsoft Azure functions runtime. + https://azure.microsoft.com/en-us/services/functions + + + UTF-8 + + + + + MIT License + https://opensource.org/licenses/MIT + repo + + + + + scm:git:https://github.com/Azure/azure-functions-java-core-library + scm:git:git@github.com:Azure/azure-functions-java-core-library + https://github.com/Azure/azure-functions-java-core-library + HEAD + + + + + Microsoft + Microsoft Corporation + + + + + + maven.snapshots + Maven Central Snapshot Repository + https://oss.sonatype.org/content/repositories/snapshots/ + + false + + + true + + + + + + + com.microsoft.azure.functions + azure-functions-java-core-library + 1.1.0 + provided + + + + + + + + maven-compiler-plugin + + + maven-source-plugin + + + maven-javadoc-plugin + + + maven-enforcer-plugin + 3.0.0-M2 + + + enforce-maven + + enforce + + + + + 3.2.0 + + + + + + + + + + diff --git a/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/Middleware.java b/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/Middleware.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/internal/spi/middleware/Middleware.java rename to azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/Middleware.java diff --git a/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareChain.java b/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareChain.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareChain.java rename to azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareChain.java diff --git a/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java b/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java similarity index 100% rename from src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java rename to azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java diff --git a/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java b/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java new file mode 100644 index 0000000..1809d78 --- /dev/null +++ b/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java @@ -0,0 +1,23 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ +package com.microsoft.azure.functions.spi.inject; + +/** + * The instance factory used by DI framework to initialize function instance. + * + * @since 1.0.0 + */ +public interface FunctionInstanceInjector { + /** + * This method is used by DI framework to initialize the function instance. This method takes in the customer class and returns + * an instance create by the DI framework, later customer functions will be invoked on this instance. + * @param functionClass the class that contains customer functions + * @param customer functions class type + * @return the instance that will be invoked on by azure functions java worker + * @throws Exception any exception that is thrown by the DI framework during instance creation + */ + T getInstance(Class functionClass) throws Exception; +} diff --git a/build.ps1 b/build.ps1 index ef3a03e..ddaad01 100644 --- a/build.ps1 +++ b/build.ps1 @@ -15,8 +15,8 @@ StopOnFailedExecution Pop-Location -StackName "libraryDir" $archetypePom = Get-Content ".\azure-maven-archetypes\azure-functions-archetype\pom.xml" -Raw $archetypePom -match "(.*)" -$atchetypeVersion = $matches[1] -Write-Host "atchetypeVersion: " $atchetypeVersion +$archetypeVersion = $matches[1] +Write-Host "archetypeVersion: " $archetypeVersion # Clone and install function maven plugin git clone https://github.com/Microsoft/azure-maven-plugins.git -b develop @@ -40,14 +40,18 @@ if ([string]::IsNullOrEmpty($pluginVersion)) StopOnFailedExecution -# Get azure-functions-core-library -Write-Host "Build and install azure-functions-java-core-library" +# Get azure-functions-core-library and azure-functions-spi +Write-Host "Build and install azure-functions-java-core-library and azure-functions-spi" cmd.exe /c '.\mvnBuild.bat' StopOnFailedExecution -$coreLibraryPom = Get-Content "pom.xml" -Raw +$coreLibraryPom = Get-Content "azure-functions-java-core-library\pom.xml" -Raw $coreLibraryPom -match "(.*)" $coreLibraryVersion = $matches[1] Write-Host "coreLibraryVersion: " $coreLibraryVersion +$spiLibraryPom = Get-Content "azure-functions-java-spi\pom.xml" -Raw +$spiLibraryPom -match "(.*)" +$spiLibraryVersion = $matches[1] +Write-Host "spiLibraryVersion: " $spiLibraryVersion # Get azure-functions-library git clone https://github.com/Azure/azure-functions-java-library.git -b dev diff --git a/pom.xml b/pom.xml index 62284a2..287774f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,145 +1,14 @@ - 4.0.0 - com.microsoft.azure.functions - azure-functions-java-core-library - 1.1.0 - jar - - com.microsoft.maven - java-8-parent - 8.0.1 - - - Microsoft Azure Functions Java Core Types - This package contains all Java interfaces and annotations to interact with Microsoft Azure functions runtime. - https://azure.microsoft.com/en-us/services/functions - - - UTF-8 - - - - - MIT License - https://opensource.org/licenses/MIT - repo - - - - - scm:git:https://github.com/Azure/azure-functions-java-worker - scm:git:git@github.com:Azure/azure-functions-java-worker - https://github.com/Azure/azure-functions-java-worker - HEAD - - - - - pgopa - Pragna Gopa - pgopa@microsoft.com - - - xscript - Kevin Zhao - kevinzha@microsoft.com - - - - - - ossrh - Sonatype Snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - true - default - - - - - - maven.snapshots - Maven Central Snapshot Repository - https://oss.sonatype.org/content/repositories/snapshots/ - - false - - - true - - - - - - - - - org.reflections - reflections - test - - - junit - junit - test - - - org.mockito - mockito-core - test - - - - - - - - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M2 - - - enforce-maven - - enforce - - - - - 3.2.0 - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - ${project.build.directory} - - - testing-project-jar - ${project.artifactId}-${project.version}-tests.jar - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + com.microsoft.azure.functions + azure-functions-java-additions + pom + 1.0-SNAPSHOT + + azure-functions-java-core-library + azure-functions-java-spi + + \ No newline at end of file