1414import com .intellij .openapi .module .ModuleManager ;
1515import com .intellij .openapi .project .Project ;
1616import com .intellij .openapi .roots .CompilerModuleExtension ;
17+ import com .intellij .openapi .roots .LibraryOrderEntry ;
18+ import com .intellij .openapi .roots .ModuleOrderEntry ;
1719import com .intellij .openapi .roots .OrderEnumerator ;
1820import com .intellij .openapi .roots .OrderRootType ;
1921import com .intellij .openapi .roots .libraries .Library ;
2729import com .intellij .psi .search .GlobalSearchScope ;
2830import com .intellij .psi .search .searches .AnnotatedElementsSearch ;
2931import 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 ;
3034import com .microsoft .azure .toolkit .intellij .common .AzureBundle ;
3135import com .microsoft .azure .toolkit .lib .Azure ;
3236import com .microsoft .azure .toolkit .lib .AzureConfiguration ;
6872import java .util .LinkedHashMap ;
6973import java .util .List ;
7074import java .util .Map ;
75+ import java .util .Objects ;
76+ import java .util .Optional ;
7177import java .util .concurrent .Callable ;
7278import java .util .regex .Matcher ;
7379import java .util .regex .Pattern ;
@@ -289,10 +295,14 @@ public static Map<String, FunctionConfiguration> prepareStagingFolder(Path stagi
289295 if (gradleProject .isValid ()) {
290296 gradleProject .getDependencies ().forEach (lib -> dependencies .add (lib ));
291297 } else {
292- OrderEnumerator .orderEntries (module ).productionOnly ().forEachLibrary (lib -> {
293- Arrays .stream (lib .getFiles (OrderRootType .CLASSES )).map (virtualFile -> new File (stripExtraCharacters (virtualFile .getPath ())))
294- .filter (File ::exists )
295- .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+ }
296306 return true ;
297307 });
298308 }
@@ -304,12 +314,28 @@ public static Map<String, FunctionConfiguration> prepareStagingFolder(Path stagi
304314 final File libFolder = new File (stagingFolder .toFile (), "lib" );
305315 for (final File file : dependencies ) {
306316 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+ }
307320 FileUtils .copyFileToDirectory (file , libFolder );
308321 }
309322 }
310323 return configMap ;
311324 }
312325
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+
313339 private static String getArtifactIdFromFile (@ Nonnull final File file ) {
314340 final Matcher matcher = ARTIFACT_NAME_PATTERN .matcher (file .getName ());
315341 return matcher .matches () ? StringUtils .substringBeforeLast (file .getName (), "-" ) :
0 commit comments