Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more start options. #2391

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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