Support read parameters from command line in webapp/function gradle plugin
This commit is contained in:
Родитель
0fdd4ea216
Коммит
3edd04c8c1
|
@ -14,6 +14,7 @@ dependencies {
|
|||
implementation 'com.google.guava:guava:30.1.1-jre'
|
||||
implementation 'org.apache.maven:maven-artifact:3.8.1'
|
||||
implementation 'org.fusesource.jansi:jansi:1.18'
|
||||
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-properties:2.14.1'
|
||||
|
||||
implementation 'com.microsoft.azure:azure-toolkit-common-lib:' + azureToolkitVersion
|
||||
aspect 'com.microsoft.azure:azure-toolkit-common-lib:' + azureToolkitVersion
|
||||
|
|
|
@ -5,11 +5,15 @@
|
|||
|
||||
package com.microsoft.azure.plugin.functions.gradle;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import com.microsoft.azure.gradle.auth.GradleAuthConfig;
|
||||
import com.microsoft.azure.gradle.configuration.GradleDeploymentSlotConfig;
|
||||
import com.microsoft.azure.gradle.configuration.GradleRuntimeConfig;
|
||||
import com.microsoft.azure.plugin.functions.gradle.configuration.deploy.Deployment;
|
||||
import groovy.lang.Closure;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.Optional;
|
||||
|
@ -18,7 +22,7 @@ import javax.annotation.Nullable;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@NoArgsConstructor
|
||||
public class AzureFunctionsExtension {
|
||||
|
||||
@Nullable
|
||||
|
@ -61,7 +65,8 @@ public class AzureFunctionsExtension {
|
|||
|
||||
private Map<String, String> appSettings;
|
||||
|
||||
private final Project project;
|
||||
@JsonIgnore
|
||||
private Project project;
|
||||
|
||||
@Nullable
|
||||
private String appInsightsInstance;
|
||||
|
@ -255,4 +260,29 @@ public class AzureFunctionsExtension {
|
|||
public void setDisableAppInsights(@Nullable Boolean disableAppInsights) {
|
||||
this.disableAppInsights = disableAppInsights;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setAuth(@Nullable GradleAuthConfig auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setDeployment(@Nullable Deployment deployment) {
|
||||
this.deployment = deployment;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setRuntime(@Nullable GradleRuntimeConfig runtime) {
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setDeploymentSlot(@Nullable GradleDeploymentSlotConfig deploymentSlot) {
|
||||
this.deploymentSlot = deploymentSlot;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setAppSettings(Map<String, String> appSettings) {
|
||||
this.appSettings = appSettings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
package com.microsoft.azure.plugin.functions.gradle;
|
||||
|
||||
import com.azure.core.http.policy.HttpLogDetailLevel;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper;
|
||||
import com.microsoft.azure.gradle.common.GradleAzureTaskManager;
|
||||
import com.microsoft.azure.gradle.temeletry.TelemetryAgent;
|
||||
import com.microsoft.azure.gradle.util.GradleAzureMessager;
|
||||
|
@ -13,11 +15,13 @@ import com.microsoft.azure.plugin.functions.gradle.task.LocalRunTask;
|
|||
import com.microsoft.azure.plugin.functions.gradle.task.PackageTask;
|
||||
import com.microsoft.azure.plugin.functions.gradle.task.PackageZipTask;
|
||||
import com.microsoft.azure.toolkit.lib.Azure;
|
||||
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
|
||||
import com.microsoft.azure.toolkit.lib.common.cache.CacheEvict;
|
||||
import com.microsoft.azure.toolkit.lib.common.cache.CacheManager;
|
||||
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
|
||||
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
|
||||
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
|
||||
import com.microsoft.azure.toolkit.lib.common.utils.Utils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.gradle.api.Plugin;
|
||||
|
@ -25,6 +29,9 @@ import org.gradle.api.Project;
|
|||
import org.gradle.api.tasks.TaskContainer;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class AzureFunctionsPlugin implements Plugin<Project> {
|
||||
|
@ -38,7 +45,7 @@ public class AzureFunctionsPlugin implements Plugin<Project> {
|
|||
AzureMessager.setDefaultMessager(new GradleAzureMessager(project.getLogger()));
|
||||
final AzureFunctionsExtension extension = project.getExtensions().create(GRADLE_FUNCTION_EXTENSION,
|
||||
AzureFunctionsExtension.class, project);
|
||||
|
||||
mergeCommandLineParameters(extension);
|
||||
TelemetryAgent.getInstance().initTelemetry(GRADLE_PLUGIN_NAME,
|
||||
StringUtils.firstNonBlank(AzureFunctionsPlugin.class.getPackage().getImplementationVersion(), "develop"), // default version: develop
|
||||
BooleanUtils.isNotFalse(extension.getAllowTelemetry()));
|
||||
|
@ -86,4 +93,17 @@ public class AzureFunctionsPlugin implements Plugin<Project> {
|
|||
deployTask.configure(task -> task.dependsOn(packageTask));
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static void mergeCommandLineParameters(final AzureFunctionsExtension config) {
|
||||
final JavaPropsMapper mapper = new JavaPropsMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
final Properties properties = System.getProperties();
|
||||
try {
|
||||
final AzureFunctionsExtension commandLineParameters = mapper.readPropertiesAs(properties, AzureFunctionsExtension.class);
|
||||
Utils.copyProperties(config, commandLineParameters, false);
|
||||
} catch (IOException | IllegalAccessException e) {
|
||||
AzureMessager.getMessager().warning(AzureString.format("Failed to read parameters from command line : %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ dependencies {
|
|||
implementation 'com.microsoft.azure:applicationinsights-core:2.6.3'
|
||||
implementation 'org.apache.maven:maven-artifact:3.8.1'
|
||||
implementation 'com.networknt:json-schema-validator:1.0.56'
|
||||
|
||||
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-properties:2.14.1'
|
||||
|
||||
implementation 'com.microsoft.azure:azure-toolkit-common-lib:' + azureToolkitVersion
|
||||
aspect 'com.microsoft.azure:azure-toolkit-common-lib:' + azureToolkitVersion
|
||||
|
|
|
@ -5,15 +5,19 @@
|
|||
|
||||
package com.microsoft.azure.plugin.webapps.gradle;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper;
|
||||
import com.microsoft.azure.gradle.common.GradleAzureTaskManager;
|
||||
import com.microsoft.azure.gradle.temeletry.TelemetryAgent;
|
||||
import com.microsoft.azure.gradle.util.GradleAzureMessager;
|
||||
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem;
|
||||
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
|
||||
import com.microsoft.azure.toolkit.lib.common.cache.CacheEvict;
|
||||
import com.microsoft.azure.toolkit.lib.common.cache.CacheManager;
|
||||
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
|
||||
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
|
||||
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
|
||||
import com.microsoft.azure.toolkit.lib.common.utils.Utils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -28,7 +32,10 @@ import org.gradle.api.tasks.TaskContainer;
|
|||
import org.gradle.api.tasks.TaskOutputs;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class AzureWebappPlugin implements Plugin<Project> {
|
||||
|
@ -41,7 +48,7 @@ public class AzureWebappPlugin implements Plugin<Project> {
|
|||
AzureTaskManager.register(new GradleAzureTaskManager());
|
||||
final AzureWebappPluginExtension extension = project.getExtensions().create(GRADLE_FUNCTION_EXTENSION,
|
||||
AzureWebappPluginExtension.class, project);
|
||||
|
||||
mergeCommandLineParameters(extension);
|
||||
AzureMessager.setDefaultMessager(new GradleAzureMessager(project.getLogger()));
|
||||
String pluginVersion = StringUtils.firstNonBlank(AzureWebappPlugin.class.getPackage().getImplementationVersion(), "develop");
|
||||
TelemetryAgent.getInstance().initTelemetry(GRADLE_PLUGIN_NAME, pluginVersion, BooleanUtils.isNotFalse(extension.getAllowTelemetry()));
|
||||
|
@ -107,4 +114,17 @@ public class AzureWebappPlugin implements Plugin<Project> {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static void mergeCommandLineParameters(final AzureWebappPluginExtension config) {
|
||||
final JavaPropsMapper mapper = new JavaPropsMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
final Properties properties = System.getProperties();
|
||||
try {
|
||||
final AzureWebappPluginExtension commandLineParameters = mapper.readPropertiesAs(properties, AzureWebappPluginExtension.class);
|
||||
Utils.copyProperties(config, commandLineParameters, false);
|
||||
} catch (IOException | IllegalAccessException e) {
|
||||
AzureMessager.getMessager().warning(AzureString.format("Failed to read parameters from command line : %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
|
||||
package com.microsoft.azure.plugin.webapps.gradle;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import com.microsoft.azure.gradle.auth.GradleAuthConfig;
|
||||
import com.microsoft.azure.gradle.configuration.GradleDeploymentSlotConfig;
|
||||
import com.microsoft.azure.gradle.configuration.GradleRuntimeConfig;
|
||||
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem;
|
||||
import com.microsoft.azure.toolkit.lib.legacy.appservice.DockerImageType;
|
||||
import groovy.lang.Closure;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.Input;
|
||||
|
@ -21,6 +23,7 @@ import javax.annotation.Nullable;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class AzureWebappPluginExtension {
|
||||
public static final String JAVA_VERSION_KEY = "javaVersion";
|
||||
public static final String JAVA_WEB_CONTAINER_KEY = "javaWebContainer";
|
||||
|
@ -62,7 +65,7 @@ public class AzureWebappPluginExtension {
|
|||
private Boolean disableAppInsights;
|
||||
|
||||
@Nonnull
|
||||
private final Project project;
|
||||
private Project project;
|
||||
|
||||
@Input
|
||||
@Optional
|
||||
|
@ -230,6 +233,26 @@ public class AzureWebappPluginExtension {
|
|||
this.disableAppInsights = disableAppInsights;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setAuth(GradleAuthConfig auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setRuntime(GradleRuntimeConfig runtime) {
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setDeploymentSlot(GradleDeploymentSlotConfig deploymentSlot) {
|
||||
this.deploymentSlot = deploymentSlot;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
public void setAppSettings(Map<String, String> appSettings) {
|
||||
this.appSettings = appSettings;
|
||||
}
|
||||
|
||||
public AzureWebappPluginExtension(@Nonnull Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче