Skip to content

Commit a715d8d

Browse files
author
vasile.baluta
committed
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 cn be passed from command line and will override the ones in pom.
1 parent 50bbc7e commit a715d8d

File tree

2 files changed

+26
-5
lines changed
  • azure-functions-maven-plugin/src

2 files changed

+26
-5
lines changed

azure-functions-maven-plugin/src/main/java/com/microsoft/azure/maven/function/RunMojo.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
@Mojo(name = "run")
2626
public class RunMojo extends AbstractFunctionMojo {
2727
protected static final String FUNC_CMD = "func -v";
28-
protected static final String FUNC_HOST_START_CMD = "func host start -p %s";
28+
protected static final String FUNC_HOST_START_CMD = "func host start %s";
2929
protected static final String RUN_FUNCTIONS_FAILURE = "Failed to run Azure Functions. Please checkout console output.";
3030
protected static final String RUNTIME_NOT_FOUND = "Azure Functions Core Tools not found. " +
3131
"Please go to https://aka.ms/azfunc-install to install Azure Functions Core Tools first.";
3232
private static final String STAGE_DIR_FOUND = "Function App's staging directory found at: ";
3333
private static final String STAGE_DIR_NOT_FOUND =
3434
"Stage directory not found. Please run mvn package first.";
3535
private static final String RUNTIME_FOUND = "Azure Functions Core Tools found.";
36-
private static final String FUNC_HOST_START_WITH_DEBUG_CMD = "func host start -p %s --language-worker -- " +
36+
private static final String FUNC_HOST_START_WITH_DEBUG_CMD = "func host start %s --language-worker -- " +
3737
"\"-agentlib:jdwp=%s\"";
3838
private static final ComparableVersion JAVA_9 = new ComparableVersion("9");
3939
private static final ComparableVersion FUNC_3 = new ComparableVersion("3");
@@ -58,6 +58,14 @@ public class RunMojo extends AbstractFunctionMojo {
5858
*/
5959
@Parameter(property = "funcPort", defaultValue = "7071")
6060
protected Integer funcPort;
61+
62+
/**
63+
* Config String for other start options than port and local debug
64+
*
65+
* @since 1.29.0
66+
*/
67+
@Parameter(property = "startOptions", defaultValue = "")
68+
protected String startOptions;
6169
//region Getter
6270

6371
public String getLocalDebugConfig() {
@@ -146,12 +154,22 @@ protected String getStartFunctionHostCommand() {
146154
if (StringUtils.isNotEmpty(enableDebug) && enableDebug.equalsIgnoreCase("true")) {
147155
return getStartFunctionHostWithDebugCommand();
148156
} else {
149-
return String.format(FUNC_HOST_START_CMD, funcPort);
157+
return String.format(FUNC_HOST_START_CMD, allStartOptions());
150158
}
151159
}
152160

153161
protected String getStartFunctionHostWithDebugCommand() {
154-
return String.format(FUNC_HOST_START_WITH_DEBUG_CMD, funcPort, this.getLocalDebugConfig());
162+
return String.format(FUNC_HOST_START_WITH_DEBUG_CMD, allStartOptions(), this.getLocalDebugConfig());
163+
}
164+
165+
// Put together port and other start options
166+
protected String allStartOptions() {
167+
final String startOptionsCli = System.getProperty("startOptions");
168+
if (StringUtils.isNotEmpty(startOptionsCli)) {
169+
// override startOptions from maven plugin configuration
170+
startOptions = startOptionsCli;
171+
}
172+
return " -p " + funcPort + " " + startOptions;
155173
}
156174

157175
//endregion

azure-functions-maven-plugin/src/test/java/com/microsoft/azure/maven/function/RunMojoTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ public void getCheckRuntimeCommand() throws Exception {
114114
public void getStartFunctionHostCommand() throws Exception {
115115
final RunMojo mojo = getMojoFromPom();
116116
final RunMojo mojoSpy = spy(mojo);
117-
assertEquals(String.format(FUNC_HOST_START_CMD, mojoSpy.funcPort), mojoSpy.getStartFunctionHostCommand());
117+
final String startOptions = mojoSpy.allStartOptions();
118+
assertEquals(String.format(FUNC_HOST_START_CMD, startOptions), mojoSpy.getStartFunctionHostCommand());
119+
System.setProperty("startOptions", "--enableAuth");
120+
assertTrue(mojoSpy.getStartFunctionHostCommand().contains("--enableAuth"));
118121
System.setProperty("enableDebug", "true");
119122
assertTrue(mojoSpy.getStartFunctionHostCommand().contains("-agentlib:jdwp"));
120123
}

0 commit comments

Comments
 (0)