From 138d3efb5d799c83dae9882c22e0db3c1a382130 Mon Sep 17 00:00:00 2001 From: "vasile.baluta" Date: Fri, 3 Nov 2023 22:41:32 +0100 Subject: [PATCH] Add support for more start options. Some might need to pass options like --enableAuth, this change enables passing this options and many other than the port and local debug supported today. Start options can be passed from command line and will override the ones in pom. --- .../azure/maven/function/RunMojo.java | 26 ++++++++++++++++--- .../azure/maven/function/RunMojoTest.java | 5 +++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/azure-functions-maven-plugin/src/main/java/com/microsoft/azure/maven/function/RunMojo.java b/azure-functions-maven-plugin/src/main/java/com/microsoft/azure/maven/function/RunMojo.java index c793318039..b2adee5440 100644 --- a/azure-functions-maven-plugin/src/main/java/com/microsoft/azure/maven/function/RunMojo.java +++ b/azure-functions-maven-plugin/src/main/java/com/microsoft/azure/maven/function/RunMojo.java @@ -25,7 +25,7 @@ @Mojo(name = "run") public class RunMojo extends AbstractFunctionMojo { protected static final String FUNC_CMD = "func -v"; - protected static final String FUNC_HOST_START_CMD = "func host start -p %s"; + protected static final String FUNC_HOST_START_CMD = "func host start %s"; protected static final String RUN_FUNCTIONS_FAILURE = "Failed to run Azure Functions. Please checkout console output."; protected static final String RUNTIME_NOT_FOUND = "Azure Functions Core Tools not found. " + "Please go to https://aka.ms/azfunc-install to install Azure Functions Core Tools first."; @@ -33,7 +33,7 @@ public class RunMojo extends AbstractFunctionMojo { private static final String STAGE_DIR_NOT_FOUND = "Stage directory not found. Please run mvn package first."; private static final String RUNTIME_FOUND = "Azure Functions Core Tools found."; - private static final String FUNC_HOST_START_WITH_DEBUG_CMD = "func host start -p %s --language-worker -- " + + private static final String FUNC_HOST_START_WITH_DEBUG_CMD = "func host start %s --language-worker -- " + "\"-agentlib:jdwp=%s\""; private static final ComparableVersion JAVA_9 = new ComparableVersion("9"); private static final ComparableVersion FUNC_3 = new ComparableVersion("3"); @@ -58,6 +58,14 @@ public class RunMojo extends AbstractFunctionMojo { */ @Parameter(property = "funcPort", defaultValue = "7071") protected Integer funcPort; + + /** + * Config String for other start options than port and local debug + * + * @since 1.29.0 + */ + @Parameter(property = "startOptions", defaultValue = "") + protected String startOptions; //region Getter public String getLocalDebugConfig() { @@ -146,12 +154,22 @@ protected String getStartFunctionHostCommand() { if (StringUtils.isNotEmpty(enableDebug) && enableDebug.equalsIgnoreCase("true")) { return getStartFunctionHostWithDebugCommand(); } else { - return String.format(FUNC_HOST_START_CMD, funcPort); + return String.format(FUNC_HOST_START_CMD, allStartOptions()); } } protected String getStartFunctionHostWithDebugCommand() { - return String.format(FUNC_HOST_START_WITH_DEBUG_CMD, funcPort, this.getLocalDebugConfig()); + return String.format(FUNC_HOST_START_WITH_DEBUG_CMD, allStartOptions(), this.getLocalDebugConfig()); + } + + // Put together port and other start options + protected String allStartOptions() { + final String startOptionsCli = System.getProperty("startOptions"); + if (StringUtils.isNotEmpty(startOptionsCli)) { + // override startOptions from maven plugin configuration + startOptions = startOptionsCli; + } + return " -p " + funcPort + " " + startOptions; } //endregion diff --git a/azure-functions-maven-plugin/src/test/java/com/microsoft/azure/maven/function/RunMojoTest.java b/azure-functions-maven-plugin/src/test/java/com/microsoft/azure/maven/function/RunMojoTest.java index 8bb9441552..3af2158333 100644 --- a/azure-functions-maven-plugin/src/test/java/com/microsoft/azure/maven/function/RunMojoTest.java +++ b/azure-functions-maven-plugin/src/test/java/com/microsoft/azure/maven/function/RunMojoTest.java @@ -114,7 +114,10 @@ public void getCheckRuntimeCommand() throws Exception { public void getStartFunctionHostCommand() throws Exception { final RunMojo mojo = getMojoFromPom(); final RunMojo mojoSpy = spy(mojo); - assertEquals(String.format(FUNC_HOST_START_CMD, mojoSpy.funcPort), mojoSpy.getStartFunctionHostCommand()); + final String startOptions = mojoSpy.allStartOptions(); + assertEquals(String.format(FUNC_HOST_START_CMD, startOptions), mojoSpy.getStartFunctionHostCommand()); + System.setProperty("startOptions", "--enableAuth"); + assertTrue(mojoSpy.getStartFunctionHostCommand().contains("--enableAuth")); System.setProperty("enableDebug", "true"); assertTrue(mojoSpy.getStartFunctionHostCommand().contains("-agentlib:jdwp")); }