Skip to content

Commit

Permalink
Add support for more start options.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vasile.baluta committed Nov 5, 2023
1 parent 50bbc7e commit 138d3ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
@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.";
private static final String STAGE_DIR_FOUND = "Function App's staging directory found at: ";
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");
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down

0 comments on commit 138d3ef

Please sign in to comment.