Skip to content

Commit 4811148

Browse files
Merge pull request #7135 from microsoft/hanli-github-fixes-202211
Fix customer reported function issues
2 parents a9fdfea + be63eb8 commit 4811148

File tree

2 files changed

+46
-11
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij
    • azure-intellij-plugin-appservice-java/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/core
    • azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/referencebook

2 files changed

+46
-11
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice-java/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/core/FunctionUtils.java

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package com.microsoft.azure.toolkit.intellij.legacy.function.runner.core;
77

8-
import com.google.gson.JsonObject;
98
import com.intellij.codeInsight.AnnotationUtil;
109
import com.intellij.codeInsight.MetaAnnotationUtil;
1110
import com.intellij.lang.jvm.JvmAnnotation;
@@ -15,6 +14,8 @@
1514
import com.intellij.openapi.module.ModuleManager;
1615
import com.intellij.openapi.project.Project;
1716
import com.intellij.openapi.roots.CompilerModuleExtension;
17+
import com.intellij.openapi.roots.LibraryOrderEntry;
18+
import com.intellij.openapi.roots.ModuleOrderEntry;
1819
import com.intellij.openapi.roots.OrderEnumerator;
1920
import com.intellij.openapi.roots.OrderRootType;
2021
import com.intellij.openapi.roots.libraries.Library;
@@ -28,6 +29,8 @@
2829
import com.intellij.psi.search.GlobalSearchScope;
2930
import com.intellij.psi.search.searches.AnnotatedElementsSearch;
3031
import com.intellij.util.containers.ContainerUtil;
32+
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.roots.ModuleOrderEntryBridge;
33+
import com.microsoft.azure.toolkit.intellij.common.AzureArtifactManager;
3134
import com.microsoft.azure.toolkit.intellij.common.AzureBundle;
3235
import com.microsoft.azure.toolkit.lib.Azure;
3336
import com.microsoft.azure.toolkit.lib.AzureConfiguration;
@@ -52,6 +55,7 @@
5255
import org.jetbrains.idea.maven.project.MavenProject;
5356
import org.jetbrains.idea.maven.project.MavenProjectsManager;
5457

58+
import javax.annotation.Nonnull;
5559
import javax.annotation.Nullable;
5660
import java.io.File;
5761
import java.io.IOException;
@@ -68,7 +72,11 @@
6872
import java.util.LinkedHashMap;
6973
import java.util.List;
7074
import java.util.Map;
75+
import java.util.Objects;
76+
import java.util.Optional;
7177
import java.util.concurrent.Callable;
78+
import java.util.regex.Matcher;
79+
import java.util.regex.Pattern;
7280
import java.util.stream.Collectors;
7381

7482
import static com.microsoft.azure.toolkit.intellij.common.AzureBundle.message;
@@ -77,7 +85,6 @@
7785
public class FunctionUtils {
7886
private static final int MAX_PORT = 65535;
7987

80-
public static final String FUNCTION_JAVA_LIBRARY_ARTIFACT_ID = "azure-functions-java-library";
8188
private static final String AZURE_FUNCTION_ANNOTATION_CLASS =
8289
"com.microsoft.azure.functions.annotation.FunctionName";
8390
private static final String FUNCTION_JSON = "function.json";
@@ -94,6 +101,7 @@ public class FunctionUtils {
94101
private static final String AZURE_FUNCTIONS_APP_SETTINGS = "Azure Functions App Settings";
95102
private static final String AZURE_FUNCTIONS_JAVA_LIBRARY = "azure-functions-java-library";
96103
private static final String AZURE_FUNCTIONS_JAVA_CORE_LIBRARY = "azure-functions-java-core-library";
104+
private static final Pattern ARTIFACT_NAME_PATTERN = Pattern.compile("(.*)-(\\d+\\.)?(\\d+\\.)?(\\*|\\d+).*");
97105

98106
static {
99107
//initialize required attributes, which will be saved to function.json even if it equals to its default value
@@ -179,7 +187,7 @@ public static boolean isFunctionProject(Project project) {
179187
}
180188
final List<Library> libraries = new ArrayList<>();
181189
OrderEnumerator.orderEntries(project).productionOnly().forEachLibrary(library -> {
182-
if (StringUtils.contains(library.getName(), FUNCTION_JAVA_LIBRARY_ARTIFACT_ID)) {
190+
if (StringUtils.containsAnyIgnoreCase(library.getName(), AZURE_FUNCTIONS_JAVA_LIBRARY, AZURE_FUNCTIONS_JAVA_CORE_LIBRARY)) {
183191
libraries.add(library);
184192
}
185193
return true;
@@ -287,26 +295,53 @@ public static Map<String, FunctionConfiguration> prepareStagingFolder(Path stagi
287295
if (gradleProject.isValid()) {
288296
gradleProject.getDependencies().forEach(lib -> dependencies.add(lib));
289297
} else {
290-
OrderEnumerator.orderEntries(module).productionOnly().forEachLibrary(lib -> {
291-
Arrays.stream(lib.getFiles(OrderRootType.CLASSES)).map(virtualFile -> new File(stripExtraCharacters(virtualFile.getPath())))
292-
.filter(File::exists)
293-
.forEach(dependencies::add);
298+
OrderEnumerator.orderEntries(module).productionOnly().forEach(lib -> {
299+
if (lib instanceof ModuleOrderEntry) {
300+
Optional.ofNullable(getArtifactFromModule(((ModuleOrderEntry) lib).getModule())).ifPresent(dependencies::add);
301+
} else if (lib instanceof LibraryOrderEntry) {
302+
Arrays.stream(lib.getFiles(OrderRootType.CLASSES)).map(virtualFile -> new File(stripExtraCharacters(virtualFile.getPath())))
303+
.filter(File::exists)
304+
.forEach(dependencies::add);
305+
}
294306
return true;
295307
});
296308
}
297309
final String libraryToExclude = dependencies.stream()
298-
.filter(artifact -> StringUtils.equalsAnyIgnoreCase(artifact.getName(), AZURE_FUNCTIONS_JAVA_CORE_LIBRARY))
299-
.map(File::getName).findFirst().orElse(AZURE_FUNCTIONS_JAVA_LIBRARY);
310+
.map(FunctionUtils::getArtifactIdFromFile)
311+
.filter(name -> StringUtils.equalsAnyIgnoreCase(name, AZURE_FUNCTIONS_JAVA_CORE_LIBRARY))
312+
.findFirst().orElse(AZURE_FUNCTIONS_JAVA_LIBRARY);
300313

301314
final File libFolder = new File(stagingFolder.toFile(), "lib");
302315
for (final File file : dependencies) {
303-
if (!StringUtils.containsIgnoreCase(file.getName(), libraryToExclude)) {
316+
if (!StringUtils.equalsIgnoreCase(getArtifactIdFromFile(file), libraryToExclude)) {
317+
if (!file.exists()) {
318+
throw new AzureToolkitRuntimeException(String.format("Dependency artifact (%s) not found, please correct the dependency and try again", file.getAbsolutePath()));
319+
}
304320
FileUtils.copyFileToDirectory(file, libFolder);
305321
}
306322
}
307323
return configMap;
308324
}
309325

326+
// get artifact based on module
327+
@Nullable
328+
private static File getArtifactFromModule(final Module module) {
329+
final Project project = module.getProject();
330+
final AzureArtifactManager artifactManager = AzureArtifactManager.getInstance(project);
331+
return artifactManager.getAllSupportedAzureArtifacts().stream()
332+
.filter(artifact -> Objects.equals(artifactManager.getModuleFromAzureArtifact(artifact), module))
333+
.findFirst()
334+
.map(azureArtifact -> artifactManager.getFileForDeployment(azureArtifact))
335+
.map(File::new)
336+
.orElse(null);
337+
}
338+
339+
private static String getArtifactIdFromFile(@Nonnull final File file) {
340+
final Matcher matcher = ARTIFACT_NAME_PATTERN.matcher(file.getName());
341+
return matcher.matches() ? StringUtils.substringBeforeLast(file.getName(), "-") :
342+
StringUtils.substringBeforeLast(file.getName(), ".jar");
343+
}
344+
310345
public static String getTargetFolder(Module module) {
311346
if (module == null) {
312347
return StringUtils.EMPTY;

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/referencebook/AzureSdkTreePanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void loadData(final Map<String, List<AzureSdkCategoryEntity>> categoryTo
187187
.stream().sorted(Comparator.comparing(AzureSdkCategoryEntity::getServiceName))
188188
.forEach(categoryService -> {
189189
final AzureSdkServiceEntity service = serviceMap.get(getServiceKeyByName(categoryService.getServiceName()));
190-
this.loadServiceData(service, categoryService, categoryNode, filters);
190+
AzureTaskManager.getInstance().runLater(() -> this.loadServiceData(service, categoryService, categoryNode, filters));
191191
});
192192
if (ArrayUtils.isEmpty(filters) || categoryMatched || categoryNode.getChildCount() > 0) {
193193
this.model.insertNodeInto(categoryNode, root, root.getChildCount());

0 commit comments

Comments
 (0)