Exemplo n.º 1
0
  private void updateWatchedRoots() {
    Set<String> pathsToRemove = new HashSet<String>(myWatchedOutputs.keySet());
    Set<String> toAdd = new HashSet<String>();
    for (Artifact artifact : getArtifacts()) {
      final String path = artifact.getOutputPath();
      if (path != null && path.length() > 0) {
        pathsToRemove.remove(path);
        if (!myWatchedOutputs.containsKey(path)) {
          toAdd.add(path);
        }
      }
    }

    List<LocalFileSystem.WatchRequest> requestsToRemove =
        new ArrayList<LocalFileSystem.WatchRequest>();
    for (String path : pathsToRemove) {
      final LocalFileSystem.WatchRequest request = myWatchedOutputs.remove(path);
      ContainerUtil.addIfNotNull(request, requestsToRemove);
    }

    Set<LocalFileSystem.WatchRequest> newRequests =
        LocalFileSystem.getInstance().replaceWatchedRoots(requestsToRemove, toAdd, null);
    for (LocalFileSystem.WatchRequest request : newRequests) {
      myWatchedOutputs.put(request.getRootPath(), request);
    }
  }
  public static boolean putProxyCredentialsIntoServerFile(
      @NotNull final File configDir,
      @NotNull final String host,
      @NotNull final PasswordAuthentication authentication) {
    final IdeaSVNConfigFile configFile =
        new IdeaSVNConfigFile(new File(configDir, SERVERS_FILE_NAME));
    configFile.updateGroups();

    String groupName = SvnAuthenticationManager.getGroupForHost(host, configFile);
    // no proxy defined in group -> no sense in password
    if (StringUtil.isEmptyOrSpaces(groupName)) return false;
    final Map<String, String> properties = configFile.getAllGroups().get(groupName).getProperties();
    if (StringUtil.isEmptyOrSpaces(properties.get(SvnAuthenticationManager.HTTP_PROXY_HOST)))
      return false;
    if (StringUtil.isEmptyOrSpaces(properties.get(SvnAuthenticationManager.HTTP_PROXY_PORT)))
      return false;

    configFile.setValue(
        groupName, SvnAuthenticationManager.HTTP_PROXY_USERNAME, authentication.getUserName());
    configFile.setValue(
        groupName,
        SvnAuthenticationManager.HTTP_PROXY_PASSWORD,
        String.valueOf(authentication.getPassword()));
    configFile.save();
    return true;
  }
 public void putData(String kind, String realm, Object data) {
   if (data == null) {
     myStorage.remove(kind + "$" + realm);
   } else {
     myStorage.put(kind + "$" + realm, data);
   }
 }
  private void doUpdate(@Nullable Runnable onComplete) {
    try {
      List<Task> issues =
          getIssuesFromRepositories(
              null, myConfig.updateIssuesCount, 0, false, new EmptyProgressIndicator());
      if (issues == null) return;

      synchronized (myIssueCache) {
        myIssueCache.clear();
        for (Task issue : issues) {
          myIssueCache.put(issue.getId(), issue);
        }
      }
      // update local tasks
      synchronized (myTasks) {
        for (Map.Entry<String, LocalTask> entry : myTasks.entrySet()) {
          Task issue = myIssueCache.get(entry.getKey());
          if (issue != null) {
            entry.getValue().updateFromIssue(issue);
          }
        }
      }
    } finally {
      if (onComplete != null) {
        onComplete.run();
      }
      myUpdating = false;
    }
  }
Exemplo n.º 5
0
  private static void patchGtkDefaults(UIDefaults defaults) {
    if (!UIUtil.isUnderGTKLookAndFeel()) return;

    Map<String, Icon> map =
        ContainerUtil.newHashMap(
            Arrays.asList(
                "OptionPane.errorIcon",
                "OptionPane.informationIcon",
                "OptionPane.warningIcon",
                "OptionPane.questionIcon"),
            Arrays.asList(
                AllIcons.General.ErrorDialog,
                AllIcons.General.InformationDialog,
                AllIcons.General.WarningDialog,
                AllIcons.General.QuestionDialog));
    // GTK+ L&F keeps icons hidden in style
    SynthStyle style = SynthLookAndFeel.getStyle(new JOptionPane(""), Region.DESKTOP_ICON);
    for (String key : map.keySet()) {
      if (defaults.get(key) != null) continue;

      Object icon = style == null ? null : style.get(null, key);
      defaults.put(key, icon instanceof Icon ? icon : map.get(key));
    }

    Color fg = defaults.getColor("Label.foreground");
    Color bg = defaults.getColor("Label.background");
    if (fg != null && bg != null) {
      defaults.put("Label.disabledForeground", UIUtil.mix(fg, bg, 0.5));
    }
  }
 @Override
 public void removeTask(LocalTask task) {
   if (task.isDefault()) return;
   if (myActiveTask.equals(task)) {
     activateTask(myTasks.get(LocalTaskImpl.DEFAULT_TASK_ID), true);
   }
   myTasks.remove(task.getId());
   myDispatcher.getMulticaster().taskRemoved(task);
   myContextManager.removeContext(task);
 }
  public <T extends TaskRepository> void setRepositories(List<T> repositories) {

    Set<TaskRepository> set = new HashSet<TaskRepository>(myRepositories);
    set.removeAll(repositories);
    myBadRepositories.removeAll(set); // remove all changed reps
    myIssueCache.clear();

    myRepositories.clear();
    myRepositories.addAll(repositories);

    reps:
    for (T repository : repositories) {
      if (repository.isShared() && repository.getUrl() != null) {
        List<TaskProjectConfiguration.SharedServer> servers = getProjectConfiguration().servers;
        TaskRepositoryType type = repository.getRepositoryType();
        for (TaskProjectConfiguration.SharedServer server : servers) {
          if (repository.getUrl().equals(server.url) && type.getName().equals(server.type)) {
            continue reps;
          }
        }
        TaskProjectConfiguration.SharedServer server = new TaskProjectConfiguration.SharedServer();
        server.type = type.getName();
        server.url = repository.getUrl();
        servers.add(server);
      }
    }
  }
 public void updateIssues(final @Nullable Runnable onComplete) {
   TaskRepository first =
       ContainerUtil.find(
           getAllRepositories(),
           new Condition<TaskRepository>() {
             public boolean value(TaskRepository repository) {
               return repository.isConfigured();
             }
           });
   if (first == null) {
     myIssueCache.clear();
     if (onComplete != null) {
       onComplete.run();
     }
     return;
   }
   myUpdating = true;
   if (ApplicationManager.getApplication().isUnitTestMode()) {
     doUpdate(onComplete);
   } else {
     ApplicationManager.getApplication()
         .executeOnPooledThread(
             new Runnable() {
               public void run() {
                 doUpdate(onComplete);
               }
             });
   }
 }
 public void setHighlightingSettingForRoot(
     @NotNull PsiElement root, @NotNull FileHighlightingSetting setting) {
   final PsiFile containingFile = root.getContainingFile();
   final VirtualFile virtualFile = containingFile.getVirtualFile();
   if (virtualFile == null) return;
   FileHighlightingSetting[] defaults = myHighlightSettings.get(virtualFile);
   int rootIndex = PsiUtilBase.getRootIndex(root);
   if (defaults != null && rootIndex >= defaults.length) defaults = null;
   if (defaults == null) defaults = getDefaults(containingFile);
   defaults[rootIndex] = setting;
   boolean toRemove = true;
   for (FileHighlightingSetting aDefault : defaults) {
     if (aDefault != FileHighlightingSetting.NONE) toRemove = false;
   }
   if (toRemove) {
     myHighlightSettings.remove(virtualFile);
   } else {
     myHighlightSettings.put(virtualFile, defaults);
   }
 }
 @Override
 public List<Task> getCachedIssues(final boolean withClosed) {
   return ContainerUtil.filter(
       myIssueCache.values(),
       new Condition<Task>() {
         @Override
         public boolean value(final Task task) {
           return withClosed || !task.isClosed();
         }
       });
 }
  @NotNull
  public FileHighlightingSetting getHighlightingSettingForRoot(@NotNull PsiElement root) {
    final PsiFile containingFile = root.getContainingFile();
    final VirtualFile virtualFile = containingFile.getVirtualFile();
    FileHighlightingSetting[] fileHighlightingSettings = myHighlightSettings.get(virtualFile);
    final int index = PsiUtilBase.getRootIndex(root);

    if (fileHighlightingSettings == null || fileHighlightingSettings.length <= index) {
      return getDefaultHighlightingSetting(root.getProject(), virtualFile);
    }
    return fileHighlightingSettings[index];
  }
  @SuppressWarnings({"unchecked"})
  public void loadState(Config config) {
    XmlSerializerUtil.copyBean(config, myConfig);
    myTasks.clear();
    for (LocalTaskImpl task : config.tasks) {
      addTask(task);
    }

    myRepositories.clear();
    Element element = config.servers;
    List<TaskRepository> repositories = loadRepositories(element);
    myRepositories.addAll(repositories);
  }
 @Override
 public List<LocalTask> getLocalTasks(final boolean withClosed) {
   synchronized (myTasks) {
     return ContainerUtil.filter(
         myTasks.values(),
         new Condition<LocalTask>() {
           @Override
           public boolean value(final LocalTask task) {
             return withClosed || !isLocallyClosed(task);
           }
         });
   }
 }
  public static void putProxyIntoServersFile(
      final File configDir, final String host, final Proxy proxyInfo) {
    final IdeaSVNConfigFile configFile =
        new IdeaSVNConfigFile(new File(configDir, SERVERS_FILE_NAME));
    configFile.updateGroups();

    String groupName = SvnAuthenticationManager.getGroupForHost(host, configFile);

    if (StringUtil.isEmptyOrSpaces(groupName)) {
      groupName = host;
      final Map<String, ProxyGroup> groups = configFile.getAllGroups();
      while (StringUtil.isEmptyOrSpaces(groupName) || groups.containsKey(groupName)) {
        groupName += "1";
      }
    }

    final HashMap<String, String> map = new HashMap<String, String>();
    final InetSocketAddress address = ((InetSocketAddress) proxyInfo.address());
    map.put(SvnAuthenticationManager.HTTP_PROXY_HOST, address.getHostName());
    map.put(SvnAuthenticationManager.HTTP_PROXY_PORT, String.valueOf(address.getPort()));
    configFile.addGroup(groupName, host + "*", map);
    configFile.save();
  }
 @SuppressWarnings({"unchecked"})
 @NotNull
 public Config getState() {
   myConfig.tasks =
       ContainerUtil.map(
           myTasks.values(),
           new Function<Task, LocalTaskImpl>() {
             public LocalTaskImpl fun(Task task) {
               return new LocalTaskImpl(task);
             }
           });
   myConfig.servers = XmlSerializer.serialize(getAllRepositories());
   return myConfig;
 }
Exemplo n.º 16
0
  @Override
  public void loadState(final Element element) {
    String className = null;
    Element lafElement = element.getChild(ELEMENT_LAF);
    if (lafElement != null) {
      className = lafElement.getAttributeValue(ATTRIBUTE_CLASS_NAME);
      if (className != null && ourLafClassesAliases.containsKey(className)) {
        className = ourLafClassesAliases.get(className);
      }
    }

    UIManager.LookAndFeelInfo laf = findLaf(className);
    // If LAF is undefined (wrong class name or something else) we have set default LAF anyway.
    if (laf == null) {
      laf = getDefaultLaf();
    }

    if (myCurrentLaf != null && !laf.getClassName().equals(myCurrentLaf.getClassName())) {
      setCurrentLookAndFeel(laf);
      updateUI();
    }

    myCurrentLaf = laf;
  }
  @Override
  public Element getState() {
    final Element element = new Element("state");
    for (Map.Entry<VirtualFile, FileHighlightingSetting[]> entry : myHighlightSettings.entrySet()) {
      final Element child = new Element(SETTING_TAG);

      final VirtualFile vFile = entry.getKey();
      if (!vFile.isValid()) continue;
      child.setAttribute(FILE_ATT, vFile.getUrl());
      for (int i = 0; i < entry.getValue().length; i++) {
        final FileHighlightingSetting fileHighlightingSetting = entry.getValue()[i];
        child.setAttribute(ROOT_ATT_PREFIX + i, fileHighlightingSetting.toString());
      }
      element.addContent(child);
    }
    return element;
  }
 @Override
 public List<Task> getIssues(
     @Nullable String query,
     int max,
     long since,
     boolean forceRequest,
     final boolean withClosed,
     @NotNull final ProgressIndicator cancelled) {
   List<Task> tasks = getIssuesFromRepositories(query, max, since, forceRequest, cancelled);
   if (tasks == null) return getCachedIssues(withClosed);
   myIssueCache.putAll(ContainerUtil.newMapFromValues(tasks.iterator(), KEY_CONVERTOR));
   return ContainerUtil.filter(
       tasks,
       new Condition<Task>() {
         @Override
         public boolean value(final Task task) {
           return withClosed || !task.isClosed();
         }
       });
 }
 @Override
 public void loadState(Element element) {
   List children = element.getChildren(SETTING_TAG);
   for (final Object aChildren : children) {
     final Element child = (Element) aChildren;
     final String url = child.getAttributeValue(FILE_ATT);
     if (url == null) continue;
     final VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl(url);
     if (fileByUrl != null) {
       final List<FileHighlightingSetting> settings = new ArrayList<FileHighlightingSetting>();
       int index = 0;
       while (child.getAttributeValue(ROOT_ATT_PREFIX + index) != null) {
         final String attributeValue = child.getAttributeValue(ROOT_ATT_PREFIX + index++);
         settings.add(Enum.valueOf(FileHighlightingSetting.class, attributeValue));
       }
       myHighlightSettings.put(
           fileByUrl, settings.toArray(new FileHighlightingSetting[settings.size()]));
     }
   }
 }
Exemplo n.º 20
0
 static {
   ourLafClassesAliases.put("idea.dark.laf.classname", DarculaLookAndFeelInfo.CLASS_NAME);
 }
 public UpdateRootInfo getUpdateRootInfo(File file, final SvnVcs svnVcs) {
   if (!myUpdateRootInfos.containsKey(file)) {
     myUpdateRootInfos.put(file, new UpdateRootInfo(file, svnVcs));
   }
   return myUpdateRootInfos.get(file);
 }
 public MergeRootInfo getMergeRootInfo(final File file, final SvnVcs svnVcs) {
   if (!myMergeRootInfos.containsKey(file)) {
     myMergeRootInfos.put(file, new MergeRootInfo(file, svnVcs));
   }
   return myMergeRootInfos.get(file);
 }
 public Object getData(String kind, String realm) {
   return myStorage.get(kind + "$" + realm);
 }
 @Nullable
 @Override
 public LocalTask findTask(String id) {
   return myTasks.get(id);
 }
 public void clear() {
   myStorage.clear();
 }
 private void addTask(LocalTaskImpl task) {
   myTasks.put(task.getId(), task);
   myDispatcher.getMulticaster().taskAdded(task);
 }
Exemplo n.º 27
0
 @Override
 public void disposeComponent() {
   LocalFileSystem.getInstance().removeWatchedRoots(myWatchedOutputs.values());
 }