public static void updateRepository(AsposeJavaComponent component, ProgressIndicator p) {
    p.setText2("Downloading " + component.get_name() + " examples ...");
    checkAndCreateFolder(getLocalRepositoryPath(component));

    try {

      updateRepository(getLocalRepositoryPath(component), component.get_remoteExamplesRepository());
      p.setFraction(0.3);
      // Added by [email protected] - Integration of Apache POI Examples / Other FrameWork
      // Examples
      OtherExamplesManager.updateOtherExamplesRepositories(component, p);
      // [email protected]
      p.setFraction(0.5);
    } catch (Exception e) {
    }
  }
 @Override
 public synchronized void setFraction(double fraction) {
   super.setFraction(fraction);
   if (myOriginal.isRunning()) {
     myOriginal.setFraction(fraction);
   }
 }
 private static void runDeterminateProgress(ProgressIndicator indicator) {
   int iterations = 3000;
   for (int i = 0; i < iterations; i++) {
     TimeoutUtil.sleep(1);
     indicator.setFraction(((double) i + 1) / ((double) iterations));
     indicator.setText(String.valueOf(i));
     ProgressManager.checkCanceled();
   }
 }
 private static void updateIndicator(@NotNull final String text, final double progressFraction) {
   final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
   if (indicator != null) {
     final ProgressIndicator progressIndicator = ProgressWrapper.unwrap(indicator);
     progressIndicator.setText(text);
     if (progressFraction == -1) {
       progressIndicator.setIndeterminate(true);
     } else {
       progressIndicator.setIndeterminate(false);
       progressIndicator.setFraction(progressFraction);
     }
   }
 }
예제 #5
0
 private void deleteAddedFilesLocally(final List<Change> changes) {
   if (myIndicator != null) {
     myIndicator.setText("Deleting added files locally...");
     myIndicator.setFraction(0);
   }
   final int changesSize = changes.size();
   for (int i = 0; i < changesSize; i++) {
     final Change c = changes.get(i);
     if (c.getType() == Change.Type.NEW) {
       ContentRevision rev = c.getAfterRevision();
       assert rev != null;
       final File ioFile = rev.getFile().getIOFile();
       if (myIndicator != null) {
         myIndicator.setText2(ioFile.getAbsolutePath());
         myIndicator.setFraction(((double) i) / changesSize);
       }
       FileUtil.delete(ioFile);
     }
   }
   if (myIndicator != null) {
     myIndicator.setText2("");
   }
 }
예제 #6
0
        public void run() {
          synchronized (SmoothProgressAdapter.this) {
            if (!isRunning()) {
              return;
            }

            myOriginal.start();
            myOriginalStarted = true;

            myOriginal.setText(getText());
            myOriginal.setFraction(getFraction());
            myOriginal.setText2(getText2());
          }
        }
 private boolean generateSkeletonsForList(
     @NotNull final PySkeletonRefresher refresher,
     ProgressIndicator indicator,
     @Nullable final String currentBinaryFilesPath)
     throws InvalidSdkException {
   final PySkeletonGenerator generator =
       new PySkeletonGenerator(refresher.getSkeletonsPath(), mySdk, currentBinaryFilesPath);
   indicator.setIndeterminate(false);
   final String homePath = mySdk.getHomePath();
   if (homePath == null) return false;
   final ProcessOutput runResult =
       PySdkUtil.getProcessOutput(
           new File(homePath).getParent(),
           new String[] {
             homePath, PythonHelpersLocator.getHelperPath("extra_syspath.py"), myQualifiedName
           },
           PythonSdkType.getVirtualEnvExtraEnv(homePath),
           5000);
   if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
     final String extraPath = runResult.getStdout();
     final PySkeletonGenerator.ListBinariesResult binaries =
         generator.listBinaries(mySdk, extraPath);
     final List<String> names = Lists.newArrayList(binaries.modules.keySet());
     Collections.sort(names);
     final int size = names.size();
     for (int i = 0; i != size; ++i) {
       final String name = names.get(i);
       indicator.setFraction((double) i / size);
       if (needBinaryList(name)) {
         indicator.setText2(name);
         final PySkeletonRefresher.PyBinaryItem item = binaries.modules.get(name);
         final String modulePath = item != null ? item.getPath() : "";
         //noinspection unchecked
         refresher.generateSkeleton(
             name, modulePath, new ArrayList<String>(), Consumer.EMPTY_CONSUMER);
       }
     }
   }
   return true;
 }
예제 #8
0
  @NotNull
  private File copyToMirror(@NotNull File original, @NotNull File mirror) {
    ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
    if (progress != null) {
      progress.pushState();
      progress.setText(VfsBundle.message("jar.copy.progress", original.getPath()));
      progress.setFraction(0);
    }

    try {
      FileUtil.copy(original, mirror);
    } catch (final IOException e) {
      reportIOErrorWithJars(original, mirror, e);
      return original;
    }

    if (progress != null) {
      progress.popState();
    }

    return mirror;
  }
  protected void runOverFiles(
      @NotNull final Project project, @NotNull final List<VirtualFile> dartFiles) {
    if (dartFiles.isEmpty()) {
      Messages.showInfoMessage(
          project,
          DartBundle.message("dart.style.files.no.dart.files"),
          DartBundle.message("dart.style.action.name"));
      return;
    }

    if (Messages.showOkCancelDialog(
            project,
            DartBundle.message("dart.style.files.dialog.question", dartFiles.size()),
            DartBundle.message("dart.style.action.name"),
            null)
        != Messages.OK) {
      return;
    }

    final Map<VirtualFile, String> fileToNewContentMap = new THashMap<VirtualFile, String>();
    final int lineLength = getRightMargin(project);

    final Runnable runnable =
        () -> {
          double fraction = 0.0;
          for (final VirtualFile virtualFile : dartFiles) {
            fraction += 1.0;
            final ProgressIndicator indicator =
                ProgressManager.getInstance().getProgressIndicator();
            if (indicator != null) {
              indicator.checkCanceled();
              indicator.setFraction(fraction / dartFiles.size());
              indicator.setText2(FileUtil.toSystemDependentName(virtualFile.getPath()));
            }

            final DartAnalysisServerService.FormatResult formatResult =
                DartAnalysisServerService.getInstance().edit_format(virtualFile, 0, 0, lineLength);
            if (formatResult != null
                && formatResult.getEdits() != null
                && formatResult.getEdits().size() == 1) {
              final String replacement =
                  StringUtil.convertLineSeparators(formatResult.getEdits().get(0).getReplacement());
              fileToNewContentMap.put(virtualFile, replacement);
            }
          }
        };

    DartAnalysisServerService.getInstance().updateFilesContent();

    final boolean ok =
        ApplicationManagerEx.getApplicationEx()
            .runProcessWithProgressSynchronously(
                runnable, DartBundle.message("dart.style.action.name"), true, project);

    if (ok) {
      final Runnable onSuccessRunnable =
          () -> {
            CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);

            for (Map.Entry<VirtualFile, String> entry : fileToNewContentMap.entrySet()) {
              final VirtualFile file = entry.getKey();
              final Document document = FileDocumentManager.getInstance().getDocument(file);
              final String newContent = entry.getValue();

              if (document != null && newContent != null) {
                document.setText(newContent);
              }
            }
          };

      ApplicationManager.getApplication()
          .runWriteAction(
              () ->
                  CommandProcessor.getInstance()
                      .executeCommand(
                          project,
                          onSuccessRunnable,
                          DartBundle.message("dart.style.action.name"),
                          null));
    }
  }
  private void searchInFiles(
      @NotNull Collection<PsiFile> psiFiles,
      @NotNull FindUsagesProcessPresentation processPresentation,
      @NotNull final Processor<UsageInfo> consumer) {
    int i = 0;
    long totalFilesSize = 0;
    int count = 0;

    for (final PsiFile psiFile : psiFiles) {
      final VirtualFile virtualFile = psiFile.getVirtualFile();
      final int index = i++;
      if (virtualFile == null) continue;

      long fileLength = UsageViewManagerImpl.getFileLength(virtualFile);
      if (fileLength == -1) continue; // Binary or invalid

      final boolean skipProjectFile =
          ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)
              && !myFindModel.isSearchInProjectFiles();
      if (skipProjectFile && !Registry.is("find.search.in.project.files")) continue;

      if (fileLength > SINGLE_FILE_SIZE_LIMIT) {
        myLargeFiles.add(psiFile);
        continue;
      }

      myProgress.checkCanceled();
      myProgress.setFraction((double) index / psiFiles.size());
      String text =
          FindBundle.message(
              "find.searching.for.string.in.file.progress",
              myFindModel.getStringToFind(),
              virtualFile.getPresentableUrl());
      myProgress.setText(text);
      myProgress.setText2(
          FindBundle.message("find.searching.for.string.in.file.occurrences.progress", count));

      int countInFile =
          FindInProjectUtil.processUsagesInFile(
              psiFile,
              myFindModel,
              new Processor<UsageInfo>() {
                @Override
                public boolean process(UsageInfo info) {
                  return skipProjectFile || consumer.process(info);
                }
              });

      if (countInFile > 0 && skipProjectFile) {
        processPresentation.projectFileUsagesFound(
            new Runnable() {
              @Override
              public void run() {
                FindModel model = myFindModel.clone();
                model.setSearchInProjectFiles(true);
                FindInProjectManager.getInstance(myProject).startFindInProject(model);
              }
            });
        continue;
      }

      count += countInFile;
      if (countInFile > 0) {
        totalFilesSize += fileLength;
        if (totalFilesSize > FILES_SIZE_LIMIT && !myWarningShown) {
          myWarningShown = true;
          String message =
              FindBundle.message(
                  "find.excessive.total.size.prompt",
                  UsageViewManagerImpl.presentableSize(totalFilesSize),
                  ApplicationNamesInfo.getInstance().getProductName());
          UsageLimitUtil.showAndCancelIfAborted(
              myProject, message, processPresentation.getUsageViewPresentation());
        }
      }
    }
  }
    @Override
    public void run() {
      HierarchyService service = HierarchyService.instance(myProject);
      if (service.getSingleClassHierarchy() != null) {
        return;
      }
      LOG.info("BuildHierarchy started");
      final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();

      final double classes = 0.3;
      final double completeClasses = 0.1;
      final double sources = 0.3;
      final double collectPsiFilesFraction = 0.2;

      final UnitProcessor processor = new UnitProcessor(myProject, service);

      // 1. entering classes
      LOG.info("read classes start");
      indicator.setText("Reading classes");
      ApplicationManager.getApplication()
          .runReadAction(
              () -> {
                StubIndex.getInstance()
                    .processAllKeys(JavaStubIndexKeys.UNITS, myProject, processor);
              });
      indicator.setFraction(classes);
      testMemory("0");

      // 2. completing classes
      LOG.info("complete classes start");
      indicator.setText("Completing classes");
      service.connect1();
      indicator.setFraction(classes + completeClasses);
      testMemory("1");

      // 3. reading sources
      LOG.info("read sources start");
      indicator.setText("Reading sources");
      processor.isInSourceMode = true;
      ApplicationManager.getApplication()
          .runReadAction(
              () -> {
                StubIndex.getInstance()
                    .processAllKeys(JavaStubIndexKeys.UNITS, myProject, processor);
              });
      indicator.setFraction(classes + completeClasses + sources);

      // 4. reading PSI
      LOG.info("read PSI start");
      indicator.setText("Collecting PSI Files");
      final Set<VirtualFile> srcSet = new HashSet<VirtualFile>();
      collectFiles(srcSet, processor.myProcessedSet);

      double total = srcSet.size();
      LOG.info("Processing PSI");
      indicator.setText("Processing PSI Files");

      int loadedCound = 0;
      for (final VirtualFile vFile : srcSet) {
        String presentableUrl = vFile.getPresentableUrl();
        if (HierarchyService.PROCESS_PSI) {
          PsiFile psiFile =
              ApplicationManager.getApplication()
                  .runReadAction(
                      new Computable<PsiFile>() {
                        @Override
                        public PsiFile compute() {
                          return PsiManager.getInstance(myProject).findFile(vFile);
                        }
                      });
          if (psiFile instanceof PsiClassOwner) {
            service.processPsiClassOwner((PsiClassOwner) psiFile);
            LOG.info("PSI: " + presentableUrl);
          }
        }
        loadedCound++;
        indicator.setFraction(
            classes + completeClasses + sources + collectPsiFilesFraction * (loadedCound / total));
      }
      testMemory("2");

      // 5. completing sources + PSI
      indicator.setText("Completing sources + PSI");
      service.complete2();
      LOG.info("Complete end");
      testMemory("3");
      indicator.setFraction(0.9);

      // 6. connect subtypes
      indicator.setText("Connecting subtypes");
      service.connectSubtypes();
      LOG.info("Subtypes connected");
      indicator.setFraction(1);
    }
 @Override
 public void setFraction(final double fraction) {
   myIndicator.setFraction(fraction);
 }
예제 #13
0
 public void setFraction(double fraction) {
   if (myProgressIndicator != null) {
     myProgressIndicator.setFraction(fraction);
   }
 }
 private void updateProgress() {
   ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
   if (indicator != null) {
     indicator.setFraction(indicator.getFraction() + myProgressStep);
   }
 }
  private void processBatch(
      @NotNull final ProgressIndicator indicator, @NotNull Set<VirtualFile> files) {
    assert !myApplication.isDispatchThread();
    final int resolvedInPreviousBatch = this.resolvedInPreviousBatch;
    final int totalSize = files.size() + resolvedInPreviousBatch;
    final ConcurrentIntObjectMap<int[]> fileToForwardIds =
        ContainerUtil.createConcurrentIntObjectMap();
    final Set<VirtualFile> toProcess = Collections.synchronizedSet(files);
    indicator.setIndeterminate(false);
    ProgressIndicatorUtils.forceWriteActionPriority(indicator, (Disposable) indicator);
    long start = System.currentTimeMillis();
    Processor<VirtualFile> processor =
        file -> {
          double fraction = 1 - toProcess.size() * 1.0 / totalSize;
          indicator.setFraction(fraction);
          try {
            if (!file.isDirectory() && toResolve(file, myProject)) {
              int fileId = getAbsId(file);
              int i = totalSize - toProcess.size();
              indicator.setText(i + "/" + totalSize + ": Resolving " + file.getPresentableUrl());
              int[] forwardIds = processFile(file, fileId, indicator);
              if (forwardIds == null) {
                // queueUpdate(file);
                return false;
              }
              fileToForwardIds.put(fileId, forwardIds);
            }
            toProcess.remove(file);
            return true;
          } catch (RuntimeException e) {
            indicator.checkCanceled();
          }
          return true;
        };
    boolean success = true;
    try {
      success = processFilesConcurrently(files, indicator, processor);
    } finally {
      this.resolvedInPreviousBatch = toProcess.isEmpty() ? 0 : totalSize - toProcess.size();
      queue(toProcess, "re-added after fail. success=" + success);
      storeIds(fileToForwardIds);

      long end = System.currentTimeMillis();
      log(
          "Resolved batch of "
              + (totalSize - toProcess.size())
              + " from "
              + totalSize
              + " files in "
              + ((end - start) / 1000)
              + "sec. (Gap: "
              + storage.gap
              + ")");
      synchronized (filesToResolve) {
        upToDate = filesToResolve.isEmpty();
        log("upToDate = " + upToDate);
        if (upToDate) {
          for (Listener listener : myListeners) {
            listener.allFilesResolved();
          }
        }
      }
    }
  }
 private void report(int len) {
   pos += len;
   if (indicator != null) {
     indicator.setFraction((double) pos / size);
   }
 }
 private void updateIndicatorFraction(int processed) {
   ProgressIndicator indicator = myCompositeTask.getIndicator();
   if (indicator != null) {
     indicator.setFraction((double) processed / myTotalFiles);
   }
 }