Java Code Examples for com.intellij.openapi.progress.ProgressIndicator#setText()

The following examples show how to use com.intellij.openapi.progress.ProgressIndicator#setText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractExternalSystemTask.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(@Nonnull final ProgressIndicator indicator, @Nonnull ExternalSystemTaskNotificationListener... listeners) {
  indicator.setIndeterminate(true);
  ExternalSystemTaskNotificationListenerAdapter adapter = new ExternalSystemTaskNotificationListenerAdapter() {
    @Override
    public void onStatusChange(@Nonnull ExternalSystemTaskNotificationEvent event) {
      indicator.setText(wrapProgressText(event.getDescription()));
    }
  };
  final ExternalSystemTaskNotificationListener[] ls;
  if (listeners.length > 0) {
    ls = ArrayUtil.append(listeners, adapter);
  }
  else {
    ls = new ExternalSystemTaskNotificationListener[]{adapter};
  }

  execute(ls);
}
 
Example 2
Source File: ImportPageModelImpl.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
private boolean pushChangesToRemoteRepo(final Project project, final GitRepository localRepository,
                                        final com.microsoft.alm.sourcecontrol.webapi.model.GitRepository remoteRepository,
                                        final ServerContext localContext, final ProgressIndicator indicator) {
    localRepository.update();
    final String remoteGitUrl = UrlHelper.getCmdLineFriendlyUrl(remoteRepository.getRemoteUrl());

    //push all branches in local Git repo to remote
    indicator.setText(TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_PUSH));
    final Git git = ServiceManager.getService(Git.class);
    final GitCommandResult result = git.push(localRepository, REMOTE_ORIGIN, remoteGitUrl, "*", true);
    if (!result.success()) {
        logger.error("pushChangesToRemoteRepo: push to remote: {} failed with error: {}, outuput: {}",
                remoteGitUrl, result.getErrorOutputAsJoinedString(), result.getOutputAsJoinedString());
        notifyImportError(project, result.getErrorOutputAsJoinedString());
        return false;
    }

    return true;
}
 
Example 3
Source File: ImportPageModelImpl.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
private GitRepository setupGitRepositoryForProject(final Project project, final VirtualFile rootVirtualFile,
                                                   final ServerContext localContext, final ProgressIndicator indicator) {
    //project is not in a local git repository, create one
    indicator.setText(TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_INIT, project.getName()));
    final GitLineHandler hInit = new GitLineHandler(project, rootVirtualFile, GitCommand.INIT);
    GitHandlerUtil.runInCurrentThread(hInit, null, true, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_INIT, project.getName()));
    if (!hInit.errors().isEmpty()) {
        //git init failed
        final String error = hInit.errors().get(0).getMessage();
        logger.error("setupGitRepositoryForProject: git init failed on project: {} at root: {} with error: {}",
                project.getName(), rootVirtualFile.getUrl(), error);
        notifyImportError(project,
                TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_INIT_ERROR, project.getName(), error));
        return null;
    }
    GitInit.refreshAndConfigureVcsMappings(project, rootVirtualFile, rootVirtualFile.getPath());
    final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
    return repositoryManager.getRepositoryForRoot(rootVirtualFile);
}
 
Example 4
Source File: RollbackDeletionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected List<VcsException> processFiles(final AbstractVcs vcs, final List<FilePath> files) {
  RollbackEnvironment environment = vcs.getRollbackEnvironment();
  if (environment == null) return Collections.emptyList();
  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null) {
    indicator.setText(vcs.getDisplayName() + ": performing rollback...");
  }
  final List<VcsException> result = new ArrayList<VcsException>(0);
  try {
    environment.rollbackMissingFileDeletion(files, result, new RollbackProgressModifier(files.size(), indicator));
  }
  catch (ProcessCanceledException e) {
    // for files refresh
  }
  LocalFileSystem.getInstance().refreshIoFiles(ChangesUtil.filePathsToFiles(files));
  return result;
}
 
Example 5
Source File: TranslateTask.java    From AndroidLocalizePlugin with Apache License 2.0 6 votes vote down vote up
private void writeResultData(ProgressIndicator progressIndicator) {
    if (progressIndicator.isCanceled()) return;

    if (mWriteData == null) {
        translateError(new IllegalArgumentException("No translate data."));
        return;
    }

    Set<String> keySet = mWriteData.keySet();
    for (String key : keySet) {
        if (progressIndicator.isCanceled()) break;

        File writeFile = getWriteFileForCode(key);
        progressIndicator.setText("Write to " + writeFile.getParentFile().getName() + " data...");
        write(writeFile, mWriteData.get(key));
        refreshAndOpenFile(writeFile);
    }
}
 
Example 6
Source File: SourceJarGenerator.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public ActionCallback perform(Collection<Library> libraries) {
  ActionCallback callback = new ActionCallback();
  Task task = new Task.Backgroundable(psiFile.getProject(), "Generating source jar from Pants") {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      try {
        indicator.setText("Generating source jar");
        File sourceJar = generateSourceJar(indicator, target, sourceJarPath, psiFile);
        indicator.setText("Attaching source jar");
        attach(sourceJar, libraries);
        callback.setDone();
      }
      catch (Exception e) {
        String msg = "Error while generating sources ";
        LOG.warn(msg, e);
        callback.reject(msg + e.getMessage());
      }
    }
  };
  task.queue();
  return callback;
}
 
Example 7
Source File: CreateBranchModel.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
/**
 * Creates a new branch on the server from an existing branch on the server
 * TODO: remove method if not needed for other create branch flows
 */
public void createBranch() {
    logger.info("CreateBranchModel.createBranch");
    final ModelValidationInfo validationInfo = validate();
    if (validationInfo == null) {
        final String gitRemoteUrl = TfGitHelper.getTfGitRemote(gitRepository).getFirstUrl();
        final Task.Backgroundable createBranchTask = new Task.Backgroundable(project, TfPluginBundle.message(TfPluginBundle.KEY_CREATE_BRANCH_DIALOG_TITLE),
                true, PerformInBackgroundOption.DEAF) {

            @Override
            public void run(@NotNull final ProgressIndicator progressIndicator) {
                progressIndicator.setText(TfPluginBundle.message(TfPluginBundle.KEY_CREATE_BRANCH_DIALOG_TITLE));
                // get context from manager, and store in active context
                final ServerContext context = ServerContextManager.getInstance().getUpdatedContext(
                        gitRemoteUrl, true);

                if (context == null) {
                    VcsNotifier.getInstance(project).notifyError(TfPluginBundle.message(
                                    TfPluginBundle.KEY_CREATE_BRANCH_ERRORS_AUTHENTICATION_FAILED_TITLE),
                            TfPluginBundle.message(TfPluginBundle.KEY_ERRORS_AUTH_NOT_SUCCESSFUL, gitRemoteUrl));
                    return;
                }
                doBranchCreate(context, progressIndicator);
            }
        };
        createBranchTask.queue();
    }
}
 
Example 8
Source File: Generator.java    From r2m-plugin-android with Apache License 2.0 5 votes vote down vote up
private static void displayIndicatorMessage(ProgressIndicator progressIndicator,
                                            String message,
                                            int value)
        throws InterruptedException {
    if (null == progressIndicator) {
        return;
    }
    progressIndicator.setFraction((((double) value) / 100));
    progressIndicator.setText(message);
    Thread.sleep(1000);
}
 
Example 9
Source File: InitializerDownloader.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
void execute(ProgressIndicator indicator) throws IOException {
  File tempFile = createTempFile("spring-assistant-template", ".tmp", true);
  String downloadUrl = builder.safeGetProjectCreationRequest().buildDownloadUrl();
  debug(() -> log.debug("Downloading project from: " + downloadUrl));
  Download download = request(downloadUrl).userAgent(userAgent()).connect(request -> {
    String contentType = request.getConnection().getContentType();
    boolean zip = isNotEmpty(contentType) && contentType.startsWith("application/zip");
    String contentDisposition = request.getConnection().getHeaderField("Content-Disposition");
    String fileName = extractFilenameFromContentDisposition(contentDisposition);
    indicator.setText(fileName);
    request.saveToFile(tempFile, indicator);
    return Download.builder().zip(zip).fileName(fileName).build();
  });
  indicator.setText("Please wait ...");
  File targetExtractionDir = new File(requireNonNull(builder.getContentEntryPath()));
  if (download.zip) {
    extract(tempFile, targetExtractionDir, null);
    markAsExecutable(targetExtractionDir, "gradlew");
    markAsExecutable(targetExtractionDir, "mvnw");
  } else {
    copy(tempFile, new File(targetExtractionDir, download.fileName));
  }

  VirtualFile targetFile =
      LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetExtractionDir);
  getInstance().refresh(false, true, null, targetFile);
}
 
Example 10
Source File: FetchFileContentTask.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
@Override
public final void run(@NotNull final ProgressIndicator indicator) {
    indicator.setText(FETCHING_FILE_CONTENT);
    indicator.setFraction(0.0);
    String fileName = codeInfo.getAbsoluteFileName();
    fileContents = searchUtils.getContentsForFile(fileName);

    //Setting contents so that we can use that for Open in New Tab
    codeInfo.setContents(fileContents);
    indicator.setFraction(1.0);
}
 
Example 11
Source File: CommitHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void delegateCommitToVcsThread(final GeneralCommitProcessor processor) {
  final ProgressIndicator indicator = new DelegatingProgressIndicator();

  final Semaphore endSemaphore = new Semaphore();
  endSemaphore.down();

  ChangeListManagerImpl.getInstanceImpl(myProject).executeOnUpdaterThread(new Runnable() {
    @Override
    public void run() {
      indicator.setText("Performing VCS commit...");
      try {
        ProgressManager.getInstance().runProcess(new Runnable() {
          @Override
          public void run() {
            indicator.checkCanceled();
            generalCommit(processor);
          }
        }, indicator);
      }
      finally {
        endSemaphore.up();
      }
    }
  });

  indicator.setText("Waiting for VCS background tasks to finish...");
  while (!endSemaphore.waitFor(20)) {
    indicator.checkCanceled();
  }
}
 
Example 12
Source File: HTMLExporter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void writeFileImpl(String folder, @NonNls String fileName, CharSequence buf) throws IOException {
  ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  final String fullPath = folder + File.separator + fileName;

  if (indicator != null) {
    ProgressManager.checkCanceled();
    indicator.setText(InspectionsBundle.message("inspection.export.generating.html.for", fullPath));
  }

  FileWriter writer = null;
  try {
    File folderFile = new File(folder);
    folderFile.mkdirs();
    new File(fullPath).getParentFile().mkdirs();
    writer = new FileWriter(fullPath);
    writer.write(buf.toString().toCharArray());
  }
  finally {
    if (writer != null) {
      try {
        writer.close();
      }
      catch (IOException e) {
        //Cannot do anything in case of exception
      }
    }
  }
}
 
Example 13
Source File: DownloadUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void substituteContentLength(@Nullable ProgressIndicator progress, @Nullable String text, int contentLengthInBytes) {
  if (progress != null && text != null) {
    int ind = text.indexOf(CONTENT_LENGTH_TEMPLATE);
    if (ind != -1) {
      String mes = formatContentLength(contentLengthInBytes);
      String newText = text.substring(0, ind) + mes + text.substring(ind + CONTENT_LENGTH_TEMPLATE.length());
      progress.setText(newText);
    }
  }
}
 
Example 14
Source File: ShowImageDuplicatesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void collectAndShowDuplicates(final Project project) {
  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null && !indicator.isCanceled()) {
    indicator.setText("Collecting project images...");
    indicator.setIndeterminate(false);
    final List<VirtualFile> images = new ArrayList<VirtualFile>();
    for (String ext : IMAGE_EXTENSIONS) {
      images.addAll(FilenameIndex.getAllFilesByExt(project, ext));
    }

    final Map<Long, Set<VirtualFile>> duplicates = new HashMap<Long, Set<VirtualFile>>();
    final Map<Long, VirtualFile> all = new HashMap<Long, VirtualFile>();
    for (int i = 0; i < images.size(); i++) {
      indicator.setFraction((double)(i + 1) / (double)images.size());
      final VirtualFile file = images.get(i);
      if (!(file.getFileSystem() instanceof LocalFileSystem)) continue;
      final long length = file.getLength();
      if (all.containsKey(length)) {
        if (!duplicates.containsKey(length)) {
          final HashSet<VirtualFile> files = new HashSet<VirtualFile>();
          files.add(all.get(length));
          duplicates.put(length, files);
        }
        duplicates.get(length).add(file);
      } else {
        all.put(length, file);
      }
      indicator.checkCanceled();
    }
    showResults(project, images, duplicates, all);
  }
}
 
Example 15
Source File: AnalysisScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public int getFileCount() {
  if (myFilesSet == null) initFilesSet();
  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null) { //clear text after building analysis scope set
    indicator.setText("");
    indicator.setText2("");
  }
  return myFilesSet.size();
}
 
Example 16
Source File: ShowLockInfoTask.java    From SVNToolBox with Apache License 2.0 4 votes vote down vote up
@Override
public void run(ProgressIndicator indicator) {
    indicator.setIndeterminate(true);
    //get url
    SvnVcs svn = SvnVcs.getInstance(getProject());
    indicator.setText(getString("configurable.app.svnlock.noinfo.get.file.info") + getFile().getPath());
    Info fileInfo = svn.getInfo(getFile());
    if (fileInfo == null) {
        indicator.stop();
        return;
    }

    //get lock infos
    try {
        indicator.setText(getString("configurable.app.svnlock.noinfo.get.url.info") + fileInfo.getURL());
        Info urlInfo = svn.getInfo(fileInfo.getURL(), Revision.UNDEFINED);
        if (urlInfo == null) {
            indicator.stop();
            return;
        }

        List<String> datas = Lists.newArrayList();
        indicator.setText(getString("configurable.app.svnlock.noinfo.get.lock.info") + fileInfo.getURL());
        Lock lock = urlInfo.getLock();
        if (lock != null) {
            String owner = SvnLockOwnerComponent.getInstance().getOwner(lock.getOwner());
            datas.add(getString("configurable.app.svnlock.owner.label") + FIELD_DELIMITER + owner);
            datas.add(getString("configurable.app.svnlock.comment.label") + FIELD_DELIMITER + lock.getComment());
            datas.add(getString("configurable.app.svnlock.creation.label") + FIELD_DELIMITER + (lock.getCreationDate() != null ? lock.getCreationDate() : EMPTY));
            datas.add(getString("configurable.app.svnlock.expiration.label") + FIELD_DELIMITER + (lock.getExpirationDate() != null ? lock.getExpirationDate() : EMPTY));
          indicator.stop();
          showLockPopupInEdt(datas);
        } else {
          indicator.stop();
          showNoLockNotification(getProject());
        }
    } catch (SvnBindException sbe) {
      indicator.stop();
      LOG.warn("Could not get info for " + getFile(), sbe);
    }
}
 
Example 17
Source File: MigrationsToolWindow.java    From yiistorm with MIT License 4 votes vote down vote up
public void runBackgroundTask(final int Action, Project project) {
    final Task.Backgroundable task = new Task.Backgroundable(project, "Yii migrations", false) {

        @Override
        public String getProcessId() {
            return "Yii migrations";
        }

        @Override
        public DumbModeAction getDumbModeAction() {
            return DumbModeAction.CANCEL;
        }

        public void run(@NotNull final ProgressIndicator indicator) {
            final Task.Backgroundable this_task = this;
            ((ProgressIndicatorEx) indicator).addStateDelegate(new ProgressIndicatorBase() {
                @Override
                public void cancel() {
                    this_task.onCancel();
                }
            });
            switch (Action) {
                case MigrationsToolWindow.MIGRATE_DOWN_BACKGROUND_ACTION:
                    indicator.setText("Migrating 1 down");
                    indicator.setFraction(0.1);
                    MigrationsToolWindow.toolw.migrateDown();
                    indicator.setFraction(0.3);
                    MigrationsToolWindow.toolw.updateNewMigrations(true);
                    indicator.setFraction(0.5);
                    indicator.setText("Updating migrations menu");
                    MigrationsToolWindow.toolw.fillActionMenu();
                    indicator.setFraction(0.8);
                    break;
                case MigrationsToolWindow.ADD_MENUS_BACKGROUND_ACTION:
                    indicator.setText("Updating migrations list");
                    indicator.setFraction(0.1);
                    MigrationsToolWindow.toolw.updateNewMigrations(true);
                    indicator.setFraction(0.5);
                    MigrationsToolWindow.toolw.addMenus();
                    indicator.setFraction(0.8);
                    break;
                case MigrationsToolWindow.UPDATE_MIGRAITIONS_MENUS_BACKGROUND_ACTION:
                    indicator.setText("Updating migrations list");
                    indicator.setFraction(0.1);
                    MigrationsToolWindow.toolw.updateNewMigrations(true);
                    indicator.setFraction(0.5);
                    indicator.setText("Updating migrations menu");
                    MigrationsToolWindow.toolw.fillActionMenu();
                    indicator.setFraction(0.8);
                    break;
                case MigrationsToolWindow.APPLY_MIGRATIONS_BACKGROUND_ACTION:
                    indicator.setText("Applying migrations list");
                    indicator.setFraction(0.1);
                    MigrationsToolWindow.toolw.applyMigrations();
                    indicator.setFraction(0.3);
                    MigrationsToolWindow.toolw.updateNewMigrations(false);
                    indicator.setFraction(0.5);
                    indicator.setText("Updating migrations menu");
                    MigrationsToolWindow.toolw.fillActionMenu();
                    indicator.setFraction(0.8);
                    break;
                case MigrationsToolWindow.CREATE_MIGRATION_BACKGROUND_ACTION:
                    indicator.setText("Creating migration: " + newMigrationDialog.getMigrationName());
                    indicator.setFraction(0.1);
                    MigrationsToolWindow.toolw.createMigrationByName(newMigrationDialog.getMigrationName());
                    indicator.setFraction(0.3);
                    MigrationsToolWindow.toolw.updateNewMigrations(false, true);
                    indicator.setFraction(0.5);
                    indicator.setText("Updating migrations menu");
                    MigrationsToolWindow.toolw.fillActionMenu();
                    indicator.setFraction(0.8);

                    break;
            }

            indicator.stop();
        }

    };
    task.setCancelText("Stop processing").queue();
}
 
Example 18
Source File: RoboVmCompileTask.java    From robovm-idea with GNU General Public License v2.0 4 votes vote down vote up
private boolean compileForIpa(CompileContext context, final CreateIpaAction.IpaConfig ipaConfig) {
    try {
        ProgressIndicator progress = context.getProgressIndicator();
        context.getProgressIndicator().pushState();
        RoboVmPlugin.focusToolWindow(context.getProject());
        progress.setText("Creating IPA");

        RoboVmPlugin.logInfo(context.getProject(), "Creating package in " + ipaConfig.getDestinationDir().getAbsolutePath() + " ...");

        Config.Builder builder = new Config.Builder();
        builder.logger(RoboVmPlugin.getLogger(context.getProject()));
        File moduleBaseDir = new File(ModuleRootManager.getInstance(ipaConfig.getModule()).getContentRoots()[0].getPath());

        // load the robovm.xml file
        loadConfig(context.getProject(), builder, moduleBaseDir, false);
        builder.os(OS.ios);
        builder.archs(ipaConfig.getArchs());
        builder.installDir(ipaConfig.getDestinationDir());
        builder.iosSignIdentity(SigningIdentity.find(SigningIdentity.list(), ipaConfig.getSigningIdentity()));
        if (ipaConfig.getProvisioningProfile() != null) {
            builder.iosProvisioningProfile(ProvisioningProfile.find(ProvisioningProfile.list(), ipaConfig.getProvisioningProfile()));
        }
        configureClassAndSourcepaths(context, builder, ipaConfig.getModule());
        builder.home(RoboVmPlugin.getRoboVmHome());
        Config config = builder.build();

        progress.setFraction(0.5);

        AppCompiler compiler = new AppCompiler(config);
        RoboVmCompilerThread thread = new RoboVmCompilerThread(compiler, progress) {
            protected void doCompile() throws Exception {
                compiler.build();
                compiler.archive();
            }
        };
        thread.compile();

        if(progress.isCanceled()) {
            RoboVmPlugin.logInfo(context.getProject(), "Build canceled");
            return false;
        }

        progress.setFraction(1);
        RoboVmPlugin.logInfo(context.getProject(), "Package successfully created in " + ipaConfig.getDestinationDir().getAbsolutePath());
    } catch(Throwable t) {
        RoboVmPlugin.logErrorThrowable(context.getProject(), "Couldn't create IPA", t, false);
        return false;
    } finally {
        context.getProgressIndicator().popState();
    }
    return true;
}
 
Example 19
Source File: ImportPageModelImpl.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
private boolean setupRemoteOnLocalRepo(final Project project, final GitRepository localRepository,
                                       final com.microsoft.alm.sourcecontrol.webapi.model.GitRepository remoteRepository,
                                       final ServerContext localContext, final ProgressIndicator indicator) {
    //get remotes on local repository
    indicator.setText(TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_REMOTE));
    final Collection<GitRemote> gitRemotes = localRepository.getRemotes();
    final List<String> remoteParams = new ArrayList<String>();

    if (!gitRemotes.isEmpty()) {
        for (GitRemote remote : gitRemotes) {
            if (StringUtils.equalsIgnoreCase(remote.getName(), REMOTE_ORIGIN)) {
                //remote named origin exits, ask user if they want to overwrite it and proceed or cancel
                IdeaHelper.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        final boolean replaceOrigin = IdeaHelper.showConfirmationDialog(project,
                                TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_ORIGIN_EXISTS),
                                TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_DIALOG_TITLE),
                                Icons.VSLogoSmall,
                                TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_UPDATE_ORIGIN),
                                TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_CANCEL));
                        if (replaceOrigin) {
                            remoteParams.add("set-url");
                        }
                    }
                }, true, indicator.getModalityState());
                if (remoteParams.size() == 0) {
                    //user chose to cancel import
                    logger.warn("setupRemoteOnLocalRepo: User chose to cancel import for project: {}, local repo: {}",
                            project.getName(), localRepository.getGitDir().getUrl());
                    notifyImportError(project, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_CANCELED));
                    return false;
                }
                break;
            }
        }
    }

    final String remoteGitUrl = UrlHelper.getCmdLineFriendlyUrl(remoteRepository.getRemoteUrl());
    //update remotes on local repository
    final GitSimpleHandler hRemote = new GitSimpleHandler(project, localRepository.getRoot(), GitCommand.REMOTE);
    hRemote.setSilent(true);
    if (remoteParams.size() == 1) {
        hRemote.addParameters(remoteParams.get(0), REMOTE_ORIGIN, remoteGitUrl);
    } else {
        hRemote.addParameters("add", REMOTE_ORIGIN, remoteGitUrl);
    }

    GitHandlerUtil.runInCurrentThread(hRemote, null, true, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_REMOTE));
    if (hRemote.getExitCode() != 0) {
        logger.error("setupRemoteOnLocalRepo: git remote failed for project: {}, local repo: {}, error: {}, output: {}",
                project.getName(), localRepository.getRoot().getUrl(), hRemote.getStderr(), hRemote.getStdout());
        notifyImportError(project,
                TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_REMOTE_ERROR, remoteGitUrl, hRemote.getStderr()));
        return false;
    }
    return true;
}
 
Example 20
Source File: CrucibleTestConnectionTask.java    From Crucible4IDEA with MIT License 4 votes vote down vote up
@Override
public void run(@NotNull ProgressIndicator indicator) {
  indicator.setText("Connecting...");
  indicator.setFraction(0);
  indicator.setIndeterminate(true);

  final CrucibleTestConnector connector = new CrucibleTestConnector(myProject);
  connector.run();

  while (connector.getConnectionState() == CrucibleTestConnector.ConnectionState.NOT_FINISHED) {
    try {
      if (indicator.isCanceled()) {
        connector.setInterrupted();
        break;
      }
      else {
        Thread.sleep(CHECK_CANCEL_INTERVAL);
      }
    }
    catch (InterruptedException e) {
      LOG.info(e.getMessage());
    }
  }

  CrucibleTestConnector.ConnectionState state = connector.getConnectionState();
  switch (state) {
    case FAILED:
      EventQueue.invokeLater(new Runnable() {
        public void run() {
          Messages.showDialog(myProject, "Reason:  " + connector.getErrorMessage(), "Connection Failed", new String[]{"Ok"}, 0, null);
        }
      });
      break;
    case INTERRUPTED:
      LOG.debug("'Test Connection' canceled");
      break;
    case SUCCEEDED:
      EventQueue.invokeLater(new Runnable() {
        public void run() {
          Messages.showDialog(myProject, "Connected successfully", "Connection OK", new String[]{"Ok"}, 0, null);
        }
      });
      break;
    default: //NOT_FINISHED:
      LOG.warn("Unexpected 'Test Connection' state: "
               + connector.getConnectionState().toString());
  }
}