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.
  • Loading branch information
vasile.baluta committed Nov 3, 2023
1 parent 50bbc7e commit 22c15fe
Showing 1 changed file with 19 additions and 6 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")
protected String startOptions;
//region Getter

public String getLocalDebugConfig() {
Expand Down Expand Up @@ -126,8 +134,8 @@ private void checkRuntimeCompatibility(final CommandHandler handler) throws Azur
return;
}
final ComparableVersion funcVersion = new ComparableVersion(handler.runCommandAndGetOutput(FUNC_VERSION_CMD, false, null));
final ComparableVersion minimumVersion = funcVersion.compareTo(FUNC_3) >= 0 ? MINIMUM_JAVA_9_SUPPORTED_VERSION :
MINIMUM_JAVA_9_SUPPORTED_VERSION_V2;
final ComparableVersion minimumVersion = funcVersion.compareTo(FUNC_3) >= 0 ? MINIMUM_JAVA_9_SUPPORTED_VERSION
: MINIMUM_JAVA_9_SUPPORTED_VERSION_V2;
if (funcVersion.compareTo(minimumVersion) < 0) {
throw new AzureExecutionException(FUNCTION_CORE_TOOLS_OUT_OF_DATE);
}
Expand All @@ -146,12 +154,17 @@ 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() {
return " -p " + funcPort + " " + startOptions;
}

//endregion
Expand Down

0 comments on commit 22c15fe

Please sign in to comment.