@@ -42,7 +42,7 @@ private AnalysisData() {}
4242
4343 private static final Logger LOG = LoggerFactory .getLogger ("DeepCode.AnalysisData" );
4444 private static final Map <PsiFile , List <SuggestionForFile >> EMPTY_MAP = Collections .emptyMap ();
45- private static String analysisUrl = "" ;
45+ private static Map < Project , String > mapProject2analysisUrl = new ConcurrentHashMap <>() ;
4646
4747 // todo: keep few latest file versions (Guava com.google.common.cache.CacheBuilder ?)
4848 private static final Map <PsiFile , List <SuggestionForFile >> mapFile2Suggestions =
@@ -94,8 +94,8 @@ public static Map<PsiFile, List<SuggestionForFile>> getAnalysis(
9494 return result ;
9595 }
9696
97- public static String getAnalysisUrl () {
98- return analysisUrl ;
97+ public static String getAnalysisUrl (@ NotNull Project project ) {
98+ return mapProject2analysisUrl . computeIfAbsent ( project , p -> "" ) ;
9999 }
100100
101101 static boolean addProjectToCache (@ NotNull Project project ) {
@@ -184,11 +184,17 @@ public static void updateCachedResultsForFiles(
184184 .filter (file -> !mapFile2Suggestions .containsKey (file ))
185185 .collect (Collectors .toSet ());
186186 if (!filesToProceed .isEmpty ()) {
187- info ("Files to proceed (not found in cache): " + filesToProceed .size ());
188- // fixme debug only
189187 // deepcode ignore checkIsPresent~Optional: collection already checked to be not empty
190188 final PsiFile firstFile = filesToProceed .stream ().findFirst ().get ();
191- info ("Hash for first file " + firstFile .getName () + " [" + getHash (firstFile ) + "]" );
189+ info (
190+ "Files to proceed (not found in cache): "
191+ + filesToProceed .size ()
192+ // fixme debug only
193+ + "\n Hash for first file "
194+ + firstFile .getName ()
195+ + " ["
196+ + getHash (firstFile )
197+ + "]" );
192198
193199 mapFile2Suggestions .putAll (retrieveSuggestions (project , filesToProceed , filesToRemove ));
194200
@@ -251,10 +257,6 @@ private static Map<PsiFile, List<SuggestionForFile>> retrieveSuggestions(
251257 info (PREPARE_FILES_TEXT );
252258 ProgressManager .checkCanceled ();
253259 mapPsiFile2Content .clear ();
254- List <String > removedFiles =
255- filesToRemove .stream ()
256- .map (DeepCodeUtils ::getDeepCodedFilePath )
257- .collect (Collectors .toList ());
258260 Map <String , String > mapPath2Hash = new HashMap <>();
259261 long sizePath2Hash = 0 ;
260262 int fileCounter = 0 ;
@@ -280,7 +282,7 @@ private static Map<PsiFile, List<SuggestionForFile>> retrieveSuggestions(
280282 }
281283 }
282284 // todo break removeFiles in chunks less then MAX_BANDLE_SIZE
283- CreateBundleResponse createBundleResponse = makeNewBundle (project , mapPath2Hash , removedFiles );
285+ CreateBundleResponse createBundleResponse = makeNewBundle (project , mapPath2Hash , filesToRemove );
284286 if (isNotSucceed (project , createBundleResponse , "Bad Create/Extend Bundle request: " ))
285287 return EMPTY_MAP ;
286288 info (
@@ -353,7 +355,7 @@ private static Map<PsiFile, List<SuggestionForFile>> retrieveSuggestions(
353355 progress .setText (WAITING_FOR_ANALYSIS_TEXT );
354356 ProgressManager .checkCanceled ();
355357 GetAnalysisResponse getAnalysisResponse = doRetrieveSuggestions (project , bundleId , progress );
356- result = parseGetAnalysisResponse (psiFiles , getAnalysisResponse , progress );
358+ result = parseGetAnalysisResponse (project , psiFiles , getAnalysisResponse , progress );
357359 info ("--- Get Analysis took: " + (System .currentTimeMillis () - startTime ) + " milliseconds" );
358360 // progress.stop();
359361 return result ;
@@ -362,9 +364,21 @@ private static Map<PsiFile, List<SuggestionForFile>> retrieveSuggestions(
362364 private static CreateBundleResponse makeNewBundle (
363365 @ NotNull Project project ,
364366 @ NotNull Map <String , String > mapPath2Hash ,
365- @ NotNull List < String > removedFiles ) {
367+ @ NotNull Collection < PsiFile > filesToRemove ) {
366368 final FileHashRequest fileHashRequest = new FileHashRequest (mapPath2Hash );
367369 final String parentBundleId = mapProject2BundleId .getOrDefault (project , "" );
370+ if (!parentBundleId .isEmpty ()
371+ && !filesToRemove .isEmpty ()
372+ && mapPath2Hash .isEmpty ()
373+ && filesToRemove .containsAll (cachedFilesOfProject (project ))) {
374+ warn (
375+ "Attempt to Extending a bundle by removing all the parent bundle's files: "
376+ + filesToRemove );
377+ }
378+ List <String > removedFiles =
379+ filesToRemove .stream ()
380+ .map (DeepCodeUtils ::getDeepCodedFilePath )
381+ .collect (Collectors .toList ());
368382 String message =
369383 (parentBundleId .isEmpty ()
370384 ? "Creating new Bundle with "
@@ -385,10 +399,19 @@ private static CreateBundleResponse makeNewBundle(
385399 parentBundleId ,
386400 new ExtendBundleRequest (fileHashRequest .getFiles (), removedFiles ));
387401 }
388- mapProject2BundleId .put (project , bundleResponse .getBundleId ());
402+ String newBundleId = bundleResponse .getBundleId ();
403+ // By man: "Extending a bundle by removing all the parent bundle's files is not allowed."
404+ // In reality new bundle returned with next bundleID:
405+ // gh/ArtsiomCh/DEEPCODE_PRIVATE_BUNDLE/0000000000000000000000000000000000000000000000000000000000000000
406+ if (newBundleId .equals (
407+ "gh/ArtsiomCh/DEEPCODE_PRIVATE_BUNDLE/0000000000000000000000000000000000000000000000000000000000000000" )) {
408+ newBundleId = "" ;
409+ }
410+ mapProject2BundleId .put (project , newBundleId );
389411 return bundleResponse ;
390412 }
391413
414+ // ?? com.intellij.openapi.util.text.StringUtil.toHexString
392415 // https://www.baeldung.com/sha-256-hashing-java#message-digest
393416 private static String bytesToHex (byte [] hash ) {
394417 StringBuilder hexString = new StringBuilder ();
@@ -512,13 +535,14 @@ private static GetAnalysisResponse doRetrieveSuggestions(
512535
513536 @ NotNull
514537 private static Map <PsiFile , List <SuggestionForFile >> parseGetAnalysisResponse (
538+ @ NotNull Project project ,
515539 @ NotNull Collection <PsiFile > psiFiles ,
516540 GetAnalysisResponse response ,
517541 @ NotNull ProgressIndicator progressIndicator ) {
518542 Map <PsiFile , List <SuggestionForFile >> result = new HashMap <>();
519543 if (!response .getStatus ().equals ("DONE" )) return EMPTY_MAP ;
520544 AnalysisResults analysisResults = response .getAnalysisResults ();
521- analysisUrl = response .getAnalysisURL ();
545+ mapProject2analysisUrl . put ( project , response .getAnalysisURL () );
522546 if (analysisResults == null ) {
523547 LOG .error ("AnalysisResults is null for: {}" , response );
524548 return EMPTY_MAP ;
@@ -603,7 +627,7 @@ public static void clearCache(@Nullable final Project project) {
603627 for (Project prj : projects ) {
604628 removeProjectFromCache (prj );
605629 ServiceManager .getService (prj , myTodoView .class ).refresh ();
630+ mapProject2analysisUrl .put (prj , "" );
606631 }
607- analysisUrl = "" ;
608632 }
609633}
0 commit comments