Remove dependency on functions java library and exclude azure-functions-java-core-library when user use new functions java library

This commit is contained in:
Hanxiao Liu 2022-06-19 23:02:02 +08:00
Родитель 0e9e9960f1
Коммит ad1adfbefe
3 изменённых файлов: 11 добавлений и 8 удалений

Просмотреть файл

@ -9,7 +9,6 @@ dependencies {
implementation 'org.apache.commons:commons-exec:1.3'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.reflections:reflections:0.9.12'
implementation 'com.microsoft.azure.functions:azure-functions-java-library:1.4.2'
implementation 'org.atteo.classindex:classindex:3.11'
implementation 'com.google.code.gson:gson:2.8.7'
implementation 'com.google.guava:guava:30.1.1-jre'

Просмотреть файл

@ -7,7 +7,6 @@ package com.microsoft.azure.plugin.functions.gradle.handler;
import com.azure.core.management.AzureEnvironment;
import com.google.common.base.Preconditions;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.gradle.configuration.GradleRuntimeConfig;
import com.microsoft.azure.gradle.temeletry.TelemetryAgent;
import com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext;
@ -18,6 +17,7 @@ import com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig;
import com.microsoft.azure.toolkit.lib.appservice.entity.FunctionEntity;
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp;
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase;
import com.microsoft.azure.toolkit.lib.appservice.function.core.AzureFunctionsAnnotationConstants;
import com.microsoft.azure.toolkit.lib.appservice.model.FunctionDeployType;
import com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion;
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem;
@ -150,7 +150,7 @@ public class DeployHandler {
.collect(Collectors.toList());
final List<FunctionEntity> anonymousTriggers = httpFunction.stream()
.filter(bindingResource -> bindingResource.getTrigger() != null &&
StringUtils.equalsIgnoreCase(bindingResource.getTrigger().getProperty(AUTH_LEVEL), AuthorizationLevel.ANONYMOUS.toString()))
StringUtils.equalsIgnoreCase(bindingResource.getTrigger().getProperty(AUTH_LEVEL), AzureFunctionsAnnotationConstants.ANONYMOUS))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(httpFunction) || CollectionUtils.isEmpty(anonymousTriggers)) {
AzureMessager.getMessager().info(NO_ANONYMOUS_HTTP_TRIGGER);

Просмотреть файл

@ -82,6 +82,8 @@ public class PackageHandler {
private static final String BUILD_SUCCESS = "Successfully built Azure Functions.";
private static final String FUNCTION_JSON = "function.json";
private static final String EXTENSION_BUNDLE = "extensionBundle";
private static final String AZURE_FUNCTIONS_JAVA_LIBRARY = "azure-functions-java-library";
private static final String AZURE_FUNCTIONS_JAVA_CORE_LIBRARY = "azure-functions-java-core-library";
private static final BindingEnum[] FUNCTION_WITHOUT_FUNCTION_EXTENSION = { BindingEnum.HttpOutput,
BindingEnum.HttpTrigger };
private static final String EXTENSION_BUNDLE_ID = "Microsoft.Azure.Functions.ExtensionBundle";
@ -281,13 +283,15 @@ public class PackageHandler {
if (libFolder.exists()) {
FileUtils.cleanDirectory(libFolder);
}
for (final Path jarFilePath : project.getProjectDependencies()) {
if (!jarFilePath.getFileName().toString().startsWith("azure-functions-java-library-")) {
FileUtils.copyFileToDirectory(jarFilePath.toFile(), libFolder);
final List<File> artifacts = project.getProjectDependencies().stream().map(Path::toFile).collect(Collectors.toList());
final String libraryToExclude = artifacts.stream()
.filter(artifact -> StringUtils.equalsAnyIgnoreCase(artifact.getName(), AZURE_FUNCTIONS_JAVA_CORE_LIBRARY))
.map(File::getName).findFirst().orElse(AZURE_FUNCTIONS_JAVA_LIBRARY);
for (final File file : artifacts) {
if (!StringUtils.containsIgnoreCase(file.getName(), libraryToExclude)) {
FileUtils.copyFileToDirectory(file, libFolder);
}
}
FileUtils.copyFileToDirectory(project.getArtifactFile().toFile(), new File(deploymentStagingDirectoryPath));
AzureMessager.getMessager().info(COPY_SUCCESS);
}