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;
  }
예제 #2
0
  @Override
  public void writeExternal(Element rootElement) throws WriteExternalException {
    LOG.assertTrue(!isDisposed(), "Already disposed!");

    Element element = new Element(ELEMENT);
    if (myName != null) {
      element.setAttribute(LIBRARY_NAME_ATTR, myName);
    }
    if (myKind != null) {
      element.setAttribute(LIBRARY_TYPE_ATTR, myKind.getKindId());
      final Object state = myProperties.getState();
      if (state != null) {
        final Element propertiesElement = XmlSerializer.serialize(state, SERIALIZATION_FILTERS);
        if (propertiesElement != null
            && (!propertiesElement.getContent().isEmpty()
                || !propertiesElement.getAttributes().isEmpty())) {
          element.addContent(propertiesElement.setName(PROPERTIES_ELEMENT));
        }
      }
    }
    ArrayList<OrderRootType> storableRootTypes = new ArrayList<OrderRootType>();
    storableRootTypes.addAll(Arrays.asList(OrderRootType.getAllTypes()));
    if (myKind != null) {
      storableRootTypes.addAll(Arrays.asList(myKind.getAdditionalRootTypes()));
    }
    for (OrderRootType rootType : sortRootTypes(storableRootTypes)) {
      final VirtualFilePointerContainer roots = myRoots.get(rootType);
      if (roots.size() == 0 && rootType.skipWriteIfEmpty()) continue; // compatibility iml/ipr
      final Element rootTypeElement = new Element(rootType.name());
      roots.writeExternal(rootTypeElement, ROOT_PATH_ELEMENT);
      element.addContent(rootTypeElement);
    }
    myJarDirectories.writeExternal(element);
    rootElement.addContent(element);
  }
  @NotNull
  private VirtualFilePointerImpl getOrCreate(
      @NotNull Disposable parentDisposable,
      @Nullable VirtualFilePointerListener listener,
      @NotNull String path,
      @NotNull Pair<VirtualFile, String> fileAndUrl) {
    FilePointerPartNode root = myPointers.get(listener);
    FilePointerPartNode node;
    if (root == null) {
      root = new FilePointerPartNode(path, null, fileAndUrl);
      myPointers.put(listener, root);
      node = root;
    } else {
      node = root.findPointerOrCreate(path, 0, fileAndUrl);
    }

    VirtualFilePointerImpl pointer;
    if (node.leaf == null) {
      pointer = new VirtualFilePointerImpl(listener, parentDisposable, fileAndUrl);
      node.associate(pointer, fileAndUrl);
    } else {
      pointer = node.leaf;
    }
    pointer.myNode.incrementUsageCount(1);

    root.checkConsistency();
    return pointer;
  }
예제 #4
0
 @Override
 @NotNull
 public String[] getUrls(@NotNull OrderRootType rootType) {
   assert !isDisposed();
   final VirtualFilePointerContainer result = myRoots.get(rootType);
   return result.getUrls();
 }
 @Nullable
 public Breakpoint findMasterBreakpoint(@NotNull Breakpoint dependentBreakpoint) {
   XDependentBreakpointManager dependentBreakpointManager =
       ((XBreakpointManagerImpl) getXBreakpointManager()).getDependentBreakpointManager();
   return myBreakpoints.get(
       dependentBreakpointManager.getMasterBreakpoint(dependentBreakpoint.myXBreakpoint));
 }
  @NotNull
  public synchronized List<Breakpoint> getBreakpoints() {
    if (myBreakpointsListForIteration == null) {
      myBreakpointsListForIteration = new ArrayList<Breakpoint>(myBreakpoints.size());

      XBreakpoint<?>[] xBreakpoints =
          ApplicationManager.getApplication()
              .runReadAction(
                  new Computable<XBreakpoint<?>[]>() {
                    public XBreakpoint<?>[] compute() {
                      return getXBreakpointManager().getAllBreakpoints();
                    }
                  });
      for (XBreakpoint<?> xBreakpoint : xBreakpoints) {
        if (isJavaType(xBreakpoint)) {
          Breakpoint breakpoint = myBreakpoints.get(xBreakpoint);
          if (breakpoint == null) {
            breakpoint = createJavaBreakpoint(xBreakpoint);
            myBreakpoints.put(xBreakpoint, breakpoint);
          }
        }
      }

      myBreakpointsListForIteration.addAll(myBreakpoints.values());
    }
    return myBreakpointsListForIteration;
  }
예제 #7
0
 @Override
 public void moveRootDown(@NotNull String url, @NotNull OrderRootType rootType) {
   assert !isDisposed();
   LOG.assertTrue(isWritable());
   final VirtualFilePointerContainer container = myRoots.get(rootType);
   container.moveDown(url);
 }
예제 #8
0
  @Override
  public void addRoot(@NotNull VirtualFile file, @NotNull OrderRootType rootType) {
    LOG.assertTrue(isWritable());
    assert !isDisposed();

    final VirtualFilePointerContainer container = myRoots.get(rootType);
    container.add(file);
  }
 void removeNode(@NotNull FilePointerPartNode node, VirtualFilePointerListener listener) {
   boolean rootNodeEmpty = node.remove();
   if (rootNodeEmpty) {
     myPointers.remove(listener);
   } else {
     myPointers.get(listener).checkConsistency();
   }
 }
예제 #10
0
 @Override
 public void addJarDirectory(
     @NotNull final VirtualFile file, final boolean recursive, @NotNull OrderRootType rootType) {
   assert !isDisposed();
   LOG.assertTrue(isWritable());
   final VirtualFilePointerContainer container = myRoots.get(rootType);
   container.add(file);
   myJarDirectories.add(rootType, file.getUrl(), recursive);
 }
예제 #11
0
 private String getOutputDir(final Module module) {
   if (myModuleToOutput.containsKey(module)) {
     return myModuleToOutput.get(module);
   }
   final VirtualFile outputDirectory = myCompileContext.getModuleOutputDirectory(module);
   final String out = outputDirectory != null ? outputDirectory.getPath() : null;
   myModuleToOutput.put(module, out);
   return out;
 }
 @NotNull
 private IdentityVirtualFilePointer getOrCreateIdentity(@NotNull String url, VirtualFile found) {
   IdentityVirtualFilePointer pointer = myUrlToIdentity.get(url);
   if (pointer == null) {
     pointer = new IdentityVirtualFilePointer(found, url);
     myUrlToIdentity.put(url, pointer);
   }
   return pointer;
 }
 public void setTreeActionState(Class<? extends TreeAction> action, boolean state) {
   final JCheckBox checkBox = myCheckBoxes.get(action);
   if (checkBox != null) {
     checkBox.setSelected(state);
     for (ActionListener listener : checkBox.getActionListeners()) {
       listener.actionPerformed(new ActionEvent(this, 1, ""));
     }
   }
 }
예제 #14
0
 private void readRoots(Element element) throws InvalidDataException {
   for (OrderRootType rootType : getAllRootTypes()) {
     final Element rootChild = element.getChild(rootType.name());
     if (rootChild == null) {
       continue;
     }
     VirtualFilePointerContainer roots = myRoots.get(rootType);
     roots.readExternal(rootChild, ROOT_PATH_ELEMENT);
   }
 }
  static boolean shouldSkipPlugin(
      final IdeaPluginDescriptor descriptor, IdeaPluginDescriptor[] loaded) {
    final String idString = descriptor.getPluginId().getIdString();
    if (idString.equals(CORE_PLUGIN_ID)) {
      return false;
    }

    //noinspection HardCodedStringLiteral
    final String pluginId = System.getProperty("idea.load.plugins.id");
    if (pluginId == null) {
      if (descriptor instanceof IdeaPluginDescriptorImpl && !descriptor.isEnabled()) return true;

      if (!shouldLoadPlugins()) return true;
    }
    final List<String> pluginIds = pluginId == null ? null : StringUtil.split(pluginId, ",");

    final boolean checkModuleDependencies =
        !ourAvailableModules.isEmpty() && !ourAvailableModules.contains("com.intellij.modules.all");
    if (checkModuleDependencies && !hasModuleDependencies(descriptor)) {
      return true;
    }

    boolean shouldLoad;
    //noinspection HardCodedStringLiteral
    final String loadPluginCategory = System.getProperty("idea.load.plugins.category");
    if (loadPluginCategory != null) {
      shouldLoad = loadPluginCategory.equals(descriptor.getCategory());
    } else {
      if (pluginIds != null) {
        shouldLoad = pluginIds.contains(idString);
        if (!shouldLoad) {
          Map<PluginId, IdeaPluginDescriptor> map = new HashMap<PluginId, IdeaPluginDescriptor>();
          for (final IdeaPluginDescriptor pluginDescriptor : loaded) {
            map.put(pluginDescriptor.getPluginId(), pluginDescriptor);
          }
          addModulesAsDependents(map);
          final IdeaPluginDescriptor descriptorFromProperty = map.get(PluginId.getId(pluginId));
          shouldLoad =
              descriptorFromProperty != null
                  && isDependent(
                      descriptorFromProperty,
                      descriptor.getPluginId(),
                      map,
                      checkModuleDependencies);
        }
      } else {
        shouldLoad = !getDisabledPlugins().contains(idString);
      }
      if (shouldLoad && descriptor instanceof IdeaPluginDescriptorImpl) {
        if (isIncompatible(descriptor)) return true;
      }
    }

    return !shouldLoad;
  }
  public BackgroundableActionEnabledHandler getBackgroundableActionHandler(
      final VcsBackgroundableActions action) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    BackgroundableActionEnabledHandler result = myBackgroundableActionHandlerMap.get(action);
    if (result == null) {
      result = new BackgroundableActionEnabledHandler();
      myBackgroundableActionHandlerMap.put(action, result);
    }
    return result;
  }
    static void registerDisposable(Disposable parentDisposable, VirtualFilePointerImpl pointer) {
      synchronized (ourInstances) {
        DelegatingDisposable result = ourInstances.get(parentDisposable);
        if (result == null) {
          ourInstances.put(parentDisposable, result = new DelegatingDisposable(parentDisposable));
          Disposer.register(parentDisposable, result);
        }

        result.myCounts.put(pointer, result.myCounts.get(pointer) + 1);
      }
    }
예제 #18
0
  public String getAttributeValue(String qname) { // todo ?
    Map<String, String> map = myAttributeValueMap;
    while (map == null) {
      getAttributes();
      map = myAttributeValueMap;

      if (map == null) {
        myAttributes = null;
      }
    }
    return map.get(qname);
  }
예제 #19
0
 @Override
 public boolean removeRoot(@NotNull String url, @NotNull OrderRootType rootType) {
   assert !isDisposed();
   LOG.assertTrue(isWritable());
   final VirtualFilePointerContainer container = myRoots.get(rootType);
   final VirtualFilePointer byUrl = container.findByUrl(url);
   if (byUrl != null) {
     container.remove(byUrl);
     myJarDirectories.remove(rootType, url);
     return true;
   }
   return false;
 }
  @Override
  public void writeExternal(Element element) throws WriteExternalException {
    final CodeStyleSettings parentSettings = new CodeStyleSettings();
    DefaultJDOMExternalizer.writeExternal(
        this, element, new DifferenceFilter<CodeStyleSettings>(this, parentSettings));
    List<CustomCodeStyleSettings> customSettings =
        new ArrayList<CustomCodeStyleSettings>(getCustomSettingsValues());

    Collections.sort(
        customSettings,
        new Comparator<CustomCodeStyleSettings>() {
          @Override
          public int compare(final CustomCodeStyleSettings o1, final CustomCodeStyleSettings o2) {
            return o1.getTagName().compareTo(o2.getTagName());
          }
        });

    for (final CustomCodeStyleSettings settings : customSettings) {
      final CustomCodeStyleSettings parentCustomSettings =
          parentSettings.getCustomSettings(settings.getClass());
      if (parentCustomSettings == null) {
        throw new WriteExternalException("Custom settings are null for " + settings.getClass());
      }
      settings.writeExternal(element, parentCustomSettings);
    }

    final FileType[] fileTypes =
        myAdditionalIndentOptions
            .keySet()
            .toArray(new FileType[myAdditionalIndentOptions.keySet().size()]);
    Arrays.sort(
        fileTypes,
        new Comparator<FileType>() {
          @Override
          public int compare(final FileType o1, final FileType o2) {
            return o1.getDefaultExtension().compareTo(o2.getDefaultExtension());
          }
        });

    for (FileType fileType : fileTypes) {
      final IndentOptions indentOptions = myAdditionalIndentOptions.get(fileType);
      Element additionalIndentOptions = new Element(ADDITIONAL_INDENT_OPTIONS);
      indentOptions.serialize(additionalIndentOptions, getDefaultIndentOptions(fileType));
      additionalIndentOptions.setAttribute(FILETYPE, fileType.getDefaultExtension());
      if (!additionalIndentOptions.getChildren().isEmpty()) {
        element.addContent(additionalIndentOptions);
      }
    }

    myCommonSettingsManager.writeExternal(element);
  }
예제 #21
0
  private ProgressIndicatorEx removeFromMaps(@NotNull InlineProgressIndicator progress) {
    final ProgressIndicatorEx original = myInline2Original.get(progress);

    myInline2Original.remove(progress);

    myOriginal2Inlines.remove(original, progress);
    if (myOriginal2Inlines.get(original) == null) {
      final int originalIndex = myOriginals.indexOf(original);
      myOriginals.remove(originalIndex);
      myInfos.remove(originalIndex);
    }

    return original;
  }
  @Override
  public void after(@NotNull final List<? extends VFileEvent> events) {
    incModificationCount();

    for (FilePointerPartNode node : myPointersToUpdateUrl) {
      synchronized (this) {
        VirtualFilePointerImpl pointer = node.leaf;
        String urlBefore = pointer.getUrlNoUpdate();
        Pair<VirtualFile, String> after = node.update();
        String urlAfter = after.second;
        if (URL_COMPARATOR.compare(urlBefore, urlAfter) != 0) {
          // url has changed, reinsert
          FilePointerPartNode root = myPointers.get(pointer.getListener());
          int useCount = node.useCount;
          node.remove();
          FilePointerPartNode newNode =
              root.findPointerOrCreate(VfsUtilCore.urlToPath(urlAfter), 0, after);
          VirtualFilePointerImpl existingPointer = newNode.leaf;
          if (existingPointer != null) {
            // can happen when e.g. file renamed to the existing file
            // merge two pointers
            pointer.myNode = newNode;
          } else {
            newNode.associate(pointer, after);
          }
          newNode.incrementUsageCount(useCount);
        }
      }
    }

    VirtualFilePointer[] pointersToFireArray = toPointers(myPointersToFire);
    for (VirtualFilePointer pointer : pointersToFireArray) {
      ((VirtualFilePointerImpl) pointer).myNode.update();
    }

    for (EventDescriptor event : myEvents) {
      event.fireAfter();
    }

    if (pointersToFireArray.length != 0) {
      myBus.syncPublisher(VirtualFilePointerListener.TOPIC).validityChanged(pointersToFireArray);
    }

    myPointersToUpdateUrl = Collections.emptyList();
    myEvents = Collections.emptyList();
    myPointersToFire = Collections.emptyList();
    for (FilePointerPartNode root : myPointers.values()) {
      root.checkConsistency();
    }
  }
  /**
   * If the file type has an associated language and language indent options are defined, returns
   * these options. Otherwise attempts to find indent options from <code>
   * FileTypeIndentOptionsProvider</code>. If none are found, other indent options are returned.
   *
   * @param fileType The file type to search indent options for.
   * @return File type indent options or <code>OTHER_INDENT_OPTIONS</code>.
   * @see FileTypeIndentOptionsProvider
   * @see LanguageCodeStyleSettingsProvider
   */
  public IndentOptions getIndentOptions(@Nullable FileType fileType) {
    IndentOptions indentOptions = getLanguageIndentOptions(fileType);
    if (indentOptions != null) return indentOptions;

    if (USE_SAME_INDENTS || fileType == null) return OTHER_INDENT_OPTIONS;

    if (!myLoadedAdditionalIndentOptions) {
      loadAdditionalIndentOptions();
    }
    indentOptions = myAdditionalIndentOptions.get(fileType);
    if (indentOptions != null) return indentOptions;

    return OTHER_INDENT_OPTIONS;
  }
예제 #24
0
 private VirtualFile getTempDir(Module module) throws IOException {
   VirtualFile tempDir = myModuleToTempDirMap.get(module);
   if (tempDir == null) {
     final String projectName = myProject.getName();
     final String moduleName = module.getName();
     File tempDirectory = FileUtil.createTempDirectory(projectName, moduleName);
     tempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory);
     if (tempDir == null) {
       LOG.error("Cannot locate temp directory " + tempDirectory.getPath());
     }
     myModuleToTempDirMap.put(module, tempDir);
   }
   return tempDir;
 }
예제 #25
0
 private LibraryImpl(
     @NotNull LibraryImpl from, LibraryImpl newSource, ModifiableRootModel rootModel) {
   this(from.myLibraryTable, rootModel, newSource, from.myName, from.myKind);
   assert !from.isDisposed();
   if (from.myKind != null && from.myProperties != null) {
     myProperties = myKind.createDefaultProperties();
     //noinspection unchecked
     myProperties.loadState(from.myProperties.getState());
   }
   for (OrderRootType rootType : getAllRootTypes()) {
     final VirtualFilePointerContainer thisContainer = myRoots.get(rootType);
     final VirtualFilePointerContainer thatContainer = from.myRoots.get(rootType);
     thisContainer.addAll(thatContainer);
   }
   myJarDirectories.copyFrom(from.myJarDirectories);
 }
예제 #26
0
  @Override
  public List<String> getInvalidRootUrls(OrderRootType type) {
    if (myDisposed) return Collections.emptyList();

    final List<VirtualFilePointer> pointers = myRoots.get(type).getList();
    List<String> invalidPaths = null;
    for (VirtualFilePointer pointer : pointers) {
      if (!pointer.isValid()) {
        if (invalidPaths == null) {
          invalidPaths = new SmartList<String>();
        }
        invalidPaths.add(pointer.getUrl());
      }
    }
    return invalidPaths == null ? Collections.<String>emptyList() : invalidPaths;
  }
예제 #27
0
 @Override
 @NotNull
 public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
   assert !isDisposed();
   final List<VirtualFile> expanded = new ArrayList<VirtualFile>();
   for (VirtualFile file : myRoots.get(rootType).getFiles()) {
     if (file.isDirectory()) {
       if (myJarDirectories.contains(rootType, file.getUrl())) {
         collectJarFiles(file, expanded, myJarDirectories.isRecursive(rootType, file.getUrl()));
         continue;
       }
     }
     expanded.add(file);
   }
   return VfsUtilCore.toVirtualFileArray(expanded);
 }
  static ClassLoader[] getParentLoaders(
      Map<PluginId, ? extends IdeaPluginDescriptor> idToDescriptorMap, PluginId[] pluginIds) {
    if (isUnitTestMode()) return new ClassLoader[0];
    final List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
    for (final PluginId id : pluginIds) {
      IdeaPluginDescriptor pluginDescriptor = idToDescriptorMap.get(id);
      if (pluginDescriptor == null) {
        continue; // Might be an optional dependency
      }

      final ClassLoader loader = pluginDescriptor.getPluginClassLoader();
      if (loader == null) {
        getLogger().error("Plugin class loader should be initialized for plugin " + id);
      }
      classLoaders.add(loader);
    }
    return classLoaders.toArray(new ClassLoader[classLoaders.size()]);
  }
  public void addEntryPoint(RefElement newEntryPoint, boolean isPersistent) {
    if (!newEntryPoint.isValid()) return;
    if (newEntryPoint instanceof RefClass) {
      RefClass refClass = (RefClass) newEntryPoint;

      if (refClass.isAnonymous()) {
        // Anonymous class cannot be an entry point.
        return;
      }

      ArrayList<RefMethod> refConstructors = refClass.getConstructors();
      if (refConstructors.size() == 1) {
        addEntryPoint(refConstructors.get(0), isPersistent);
        return;
      } else if (refConstructors.size() > 1) {
        // Many constructors here. Need to ask user which ones are used
        for (int i = 0; i < refConstructors.size(); i++) {
          addEntryPoint((RefMethod) ((ArrayList) refConstructors).get(i), isPersistent);
        }

        return;
      }
    }

    if (isPersistent) {
      myTemporaryEntryPoints.add(newEntryPoint);
      ((RefElementImpl) newEntryPoint).setEntry(true);
    } else {
      if (myPersistentEntryPoints.get(newEntryPoint.getExternalName()) == null) {
        final SmartRefElementPointerImpl entry =
            new SmartRefElementPointerImpl(newEntryPoint, true);
        myPersistentEntryPoints.put(entry.getFQName(), entry);
        ((RefElementImpl) newEntryPoint).setEntry(true);
        ((RefElementImpl) newEntryPoint).setPermanentEntry(true);
        if (entry.isPersistent()) { // do save entry points
          final EntryPointsManagerImpl entryPointsManager =
              getInstance(newEntryPoint.getElement().getProject());
          if (this != entryPointsManager) {
            entryPointsManager.addEntryPoint(newEntryPoint, true);
          }
        }
      }
    }
  }
 /**
  * Schedules action to be executed when all documents are committed.
  *
  * @return true if action has been run immediately, or false if action was scheduled for execution
  *     later.
  */
 @Override
 public boolean performWhenAllCommitted(@NotNull final Runnable action) {
   ApplicationManager.getApplication().assertIsDispatchThread();
   assert !myProject.isDisposed() : "Already disposed: " + myProject;
   if (myUncommittedDocuments.isEmpty()) {
     action.run();
     return true;
   }
   CompositeRunnable actions =
       (CompositeRunnable) actionsWhenAllDocumentsAreCommitted.get(PERFORM_ALWAYS_KEY);
   if (actions == null) {
     actions = new CompositeRunnable();
     actionsWhenAllDocumentsAreCommitted.put(PERFORM_ALWAYS_KEY, actions);
   }
   actions.add(action);
   myDocumentCommitProcessor.log(
       "PDI: added performWhenAllCommitted", null, false, action, myUncommittedDocuments);
   return false;
 }