com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil Java Examples

The following examples show how to use com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil. 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: AttachExternalProjectAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  ProjectSystemId externalSystemId = e.getDataContext().getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId == null) {
    return;
  }

  ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
  if (manager == null) {
    return;
  }

  Project project = e.getDataContext().getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return;
  }

  ImportModuleAction.executeImportAction(project, manager.getExternalProjectDescriptor());
}
 
Example #2
Source File: ExternalSystemAutoImporter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void documentChanged(DocumentEvent event) {
  Document document = event.getDocument();
  FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
  VirtualFile file = fileDocumentManager.getFile(document);
  if (file == null) {
    return;
  }

  String path = ExternalSystemApiUtil.getLocalFileSystemPath(file);
  for (MyEntry entry : myAutoImportAware) {
    if (entry.aware.getAffectedExternalProjectPath(path, myProject) != null) {
      // Document save triggers VFS event but FileDocumentManager might be registered after the current listener, that's why
      // call to 'saveDocument()' might not produce the desired effect. That's why we reschedule document save if necessary.
      scheduleDocumentSave(document);
      return;
    }
  } 
}
 
Example #3
Source File: ModuleDependencyDataService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(@Nonnull Collection<DataNode<ModuleDependencyData>> toImport, @Nonnull Project project, boolean synchronous) {
  Map<DataNode<ModuleData>, List<DataNode<ModuleDependencyData>>> byModule= ExternalSystemApiUtil.groupBy(toImport, MODULE);
  for (Map.Entry<DataNode<ModuleData>, List<DataNode<ModuleDependencyData>>> entry : byModule.entrySet()) {
    Module ideModule = ProjectStructureHelper.findIdeModule(entry.getKey().getData(), project);
    if (ideModule == null) {
      ModuleDataService.getInstance().importData(Collections.singleton(entry.getKey()), project, true);
      ideModule = ProjectStructureHelper.findIdeModule(entry.getKey().getData(), project);
    }
    if (ideModule == null) {
      LOG.warn(String.format(
        "Can't import module dependencies %s. Reason: target module (%s) is not found at the ide and can't be imported",
        entry.getValue(), entry.getKey()
      ));
      continue;
    }
    importData(entry.getValue(), ideModule, synchronous);
  }
}
 
Example #4
Source File: ExternalSystemAutoImporter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void onSuccess(@javax.annotation.Nullable final DataNode<ProjectData> externalProject) {
  if (externalProject != null) {
    ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(myProject) {
      @RequiredUIAccess
      @Override
      public void execute() {
        ProjectRootManagerEx.getInstanceEx(myProject).mergeRootsChangesDuring(new Runnable() {
          @Override
          public void run() {
            myProjectDataManager.importData(externalProject.getKey(), Collections.singleton(externalProject), myProject, true);
          }
        });
      }
    });
  }
}
 
Example #5
Source File: ContentRootDataService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(@Nonnull final Collection<DataNode<ContentRootData>> toImport, @Nonnull final Project project, boolean synchronous) {
  if (toImport.isEmpty()) {
    return;
  }

  Map<DataNode<ModuleData>, List<DataNode<ContentRootData>>> byModule = ExternalSystemApiUtil.groupBy(toImport, ProjectKeys.MODULE);
  for (Map.Entry<DataNode<ModuleData>, List<DataNode<ContentRootData>>> entry : byModule.entrySet()) {
    final Module module = ProjectStructureHelper.findIdeModule(entry.getKey().getData(), project);
    if (module == null) {
      LOG.warn(String.format("Can't import content roots. Reason: target module (%s) is not found at the ide. Content roots: %s", entry.getKey(),
                             entry.getValue()));
      continue;
    }
    importData(entry.getValue(), module, synchronous);
  }
}
 
Example #6
Source File: ContentRootData.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Ask to remember that directory at the given path contains sources of the given type.
 *
 * @param type           target sources type
 * @param path           target source directory path
 * @param packagePrefix  target source directory package prefix
 * @throws IllegalArgumentException   if given path points to the directory that is not located
 *                                    under the {@link #getRootPath() content root}
 */
public void storePath(@Nonnull ExternalSystemSourceType type, @Nonnull String path, @javax.annotation.Nullable String packagePrefix) throws IllegalArgumentException {
  if (FileUtil.isAncestor(new File(getRootPath()), new File(path), false)) {
    Collection<SourceRoot> paths = myData.get(type);
    if (paths == null) {
      myData.put(type, paths = new TreeSet<SourceRoot>(SourceRootComparator.INSTANCE));
    }
    paths.add(new SourceRoot(
            ExternalSystemApiUtil.toCanonicalPath(path),
            StringUtil.nullize(packagePrefix, true)
    ));
    return;
  }
  if (!ExternalSystemSourceType.EXCLUDED.equals(type)) { // There are external systems which mark output directory as 'excluded' path.
    // We don't need to bother if it's outside a module content root then.
    throw new IllegalArgumentException(String.format(
            "Can't register given path of type '%s' because it's out of content root.%nContent root: '%s'%nGiven path: '%s'",
            type, getRootPath(), new File(path).getAbsolutePath()
    ));
  }
}
 
Example #7
Source File: ModuleDataService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void removeData(@Nonnull final Collection<? extends Module> modules, @Nonnull final Project project, boolean synchronous) {
  if (modules.isEmpty()) {
    return;
  }
  ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(project) {
    @RequiredUIAccess
    @Override
    @RequiredWriteAction
    public void execute() {
      ModuleManager moduleManager = ModuleManager.getInstance(project);

      for (Module module : modules) {
        if (module.isDisposed()) continue;
        moduleManager.disposeModule(module);
      }
    }
  });
}
 
Example #8
Source File: LibraryDataService.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void importLibrary(@Nonnull final String libraryName, @Nonnull final Map<OrderRootType, Collection<File>> libraryFiles, @Nonnull final Project project, boolean synchronous) {
  ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(project) {
    @RequiredUIAccess
    @Override
    public void execute() {
      // Is assumed to be called from the EDT.
      final LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
      final LibraryTable.ModifiableModel projectLibraryModel = libraryTable.getModifiableModel();
      final Library intellijLibrary;
      try {
        intellijLibrary = projectLibraryModel.createLibrary(libraryName);
      }
      finally {
        projectLibraryModel.commit();
      }
      final Library.ModifiableModel libraryModel = intellijLibrary.getModifiableModel();
      try {
        registerPaths(libraryFiles, libraryModel, libraryName);
      }
      finally {
        libraryModel.commit();
      }
    }
  });
}
 
Example #9
Source File: LibraryDependencyDataService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(@Nonnull Collection<DataNode<LibraryDependencyData>> toImport, @Nonnull Project project, boolean synchronous) {
  if (toImport.isEmpty()) {
    return;
  }

  Map<DataNode<ModuleData>, List<DataNode<LibraryDependencyData>>> byModule = ExternalSystemApiUtil.groupBy(toImport, MODULE);
  for (Map.Entry<DataNode<ModuleData>, List<DataNode<LibraryDependencyData>>> entry : byModule.entrySet()) {
    Module module = ProjectStructureHelper.findIdeModule(entry.getKey().getData(), project);
    if (module == null) {
      ModuleDataService.getInstance().importData(Collections.singleton(entry.getKey()), project, true);
      module = ProjectStructureHelper.findIdeModule(entry.getKey().getData(), project);
      if (module == null) {
        LOG.warn(String.format("Can't import library dependencies %s. Reason: target module (%s) is not found at the ide and can't be imported", entry.getValue(), entry.getKey()));
        continue;
      }
    }
    importData(entry.getValue(), module, synchronous);
  }
}
 
Example #10
Source File: PantsResolverTestBase.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
public void assertSourceRoot(String moduleName, final String path) {
  final DataNode<ModuleData> moduleNode = findModule(moduleName);
  assertModuleExists(moduleName, moduleNode);
  final Collection<DataNode<ContentRootData>> contentRoots = ExternalSystemApiUtil.findAll(moduleNode, ProjectKeys.CONTENT_ROOT);
  assertFalse(String.format("No content root for module %s", moduleName), contentRoots.isEmpty());
  for (DataNode<ContentRootData> contentRoot : contentRoots) {
    final ContentRootData contentRootData = contentRoot.getData();
    for (PantsSourceType type : PantsSourceType.values()) {
      for (ContentRootData.SourceRoot sourceRoot : contentRootData.getPaths(type.toExternalSystemSourceType())) {
        final File expectedFile = new File(new File(""), path);
        if (StringUtil.equalsIgnoreCase(expectedFile.getPath(), sourceRoot.getPath())) {
          return;
        }
      }
    }
  }
  fail(String.format("Source root %s is not found for %s!", path, moduleName));
}
 
Example #11
Source File: AbstractToolWindowService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(@Nonnull final Collection<DataNode<T>> toImport, @Nonnull final Project project, boolean synchronous) {
  if (toImport.isEmpty()) {
    return;
  }
  ExternalSystemApiUtil.executeOnEdt(false, new Runnable() {
    @Override
    public void run() {
      ExternalSystemTasksTreeModel model = ExternalSystemUtil.getToolWindowElement(ExternalSystemTasksTreeModel.class,
                                                                                   project,
                                                                                   ExternalSystemDataKeys.ALL_TASKS_MODEL,
                                                                                   toImport.iterator().next().getData().getOwner());
      processData(toImport, project, model);
    }
  });
}
 
Example #12
Source File: ExternalSystemFacadeManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
private RemoteExternalSystemFacade doCreateFacade(@Nonnull IntegrationKey key, @Nonnull Project project,
                                                  @Nonnull ExternalSystemCommunicationManager communicationManager) throws Exception {
  final RemoteExternalSystemFacade facade = communicationManager.acquire(project.getName(), key.getExternalSystemId());
  if (facade == null) {
    throw new IllegalStateException("Can't obtain facade to working with external api at the remote process. Project: " + project);
  }
  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      myFacadeWrappers.clear();
      myRemoteFacades.clear();
    }
  });
  final RemoteExternalSystemFacade result = new ExternalSystemFacadeWrapper(facade, myProgressManager);
  ExternalSystemExecutionSettings settings
    = ExternalSystemApiUtil.getExecutionSettings(project, key.getExternalProjectConfigPath(), key.getExternalSystemId());
  Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings> newPair = Pair.create(result, settings);
  myRemoteFacades.put(key, newPair);
  result.applySettings(newPair.second);
  return result;
}
 
Example #13
Source File: ExternalSystemFacadeManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean prepare(@Nonnull ExternalSystemCommunicationManager communicationManager,
                        @Nonnull Project project, @Nonnull IntegrationKey key,
                        @Nonnull Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings> pair)
{
   if (!communicationManager.isAlive(pair.first)) {
    return false;
  }
  try {
    ExternalSystemExecutionSettings currentSettings
      = ExternalSystemApiUtil.getExecutionSettings(project, key.getExternalProjectConfigPath(), key.getExternalSystemId());
    if (!currentSettings.equals(pair.second)) {
      pair.first.applySettings(currentSettings);
      myRemoteFacades.put(key, Pair.create(pair.first, currentSettings));
    }
    return true;
  }
  catch (RemoteException e) {
    return false;
  }
}
 
Example #14
Source File: ExternalSystemExecuteTaskTask.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void doExecute() throws Exception {
  final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class);
  ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(getIdeProject(),
                                                                                        getExternalProjectPath(),
                                                                                        getExternalSystemId());
  RemoteExternalSystemFacade facade = manager.getFacade(getIdeProject(), getExternalProjectPath(), getExternalSystemId());
  RemoteExternalSystemTaskManager taskManager = facade.getTaskManager();
  List<String> taskNames = ContainerUtilRt.map2List(myTasksToExecute, MAPPER);

  final List<String> vmOptions = parseCmdParameters(myVmOptions);
  final List<String> scriptParametersList = parseCmdParameters(myScriptParameters);

  taskManager.executeTasks(getId(), taskNames, getExternalProjectPath(), settings, vmOptions, scriptParametersList, myDebuggerSetup);
}
 
Example #15
Source File: ExternalSystemResolveProjectTask.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void doExecute() throws Exception {
  final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class);
  Project ideProject = getIdeProject();
  RemoteExternalSystemProjectResolver resolver = manager.getFacade(ideProject, myProjectPath, getExternalSystemId()).getResolver();
  ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(ideProject, myProjectPath, getExternalSystemId());

  DataNode<ProjectData> project = resolver.resolveProjectInfo(getId(), myProjectPath, myIsPreviewMode, settings);

  if (project == null) {
    return;
  }
  myExternalProject.set(project);
}
 
Example #16
Source File: ExternalActionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static MyInfo getProcessingInfo(@Nonnull DataContext context) {
  ExternalProjectPojo externalProject = context.getData(ExternalSystemDataKeys.SELECTED_PROJECT);
  if (externalProject == null) {
    return MyInfo.EMPTY;
  }

  ProjectSystemId externalSystemId = context.getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId == null) {
    return MyInfo.EMPTY;
  }

  Project ideProject = context.getData(CommonDataKeys.PROJECT);
  if (ideProject == null) {
    return MyInfo.EMPTY;
  }

  AbstractExternalSystemSettings<?, ?, ?> settings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId);
  ExternalProjectSettings externalProjectSettings = settings.getLinkedProjectSettings(externalProject.getPath());
  AbstractExternalSystemLocalSettings localSettings = ExternalSystemApiUtil.getLocalSettings(ideProject, externalSystemId);

  return new MyInfo(externalProjectSettings == null ? null : settings,
                    localSettings == null ? null : localSettings,
                    externalProjectSettings == null ? null : externalProject,
                    ideProject,
                    externalSystemId);
}
 
Example #17
Source File: ExternalSystemRecentTaskListModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Asks current model to remove all 'recent task info' entries which point to tasks from external project with the given path.
 * 
 * @param externalProjectPath  target external project's path
 */
public void forgetTasksFrom(@Nonnull String externalProjectPath) {
  for (int i = size() - 1; i >= 0; i--) {
    Object e = getElementAt(i);
    if (e instanceof ExternalTaskExecutionInfo) {
      String path = ((ExternalTaskExecutionInfo)e).getSettings().getExternalProjectPath();
      if (externalProjectPath.equals(path)
          || externalProjectPath.equals(ExternalSystemApiUtil.getRootProjectPath(path, myExternalSystemId, myProject)))
      {
        removeElementAt(i);
      }
    }
  }
  ensureSize(ExternalSystemConstants.RECENT_TASKS_NUMBER);
}
 
Example #18
Source File: AbstractExternalSystemToolWindowCondition.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean value(Project project) {
  if (project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE) {
    return true;
  }
  ExternalSystemManager<?,?,?,?,?> manager = ExternalSystemApiUtil.getManager(myExternalSystemId);
  if (manager == null) {
    return false;
  }
  AbstractExternalSystemSettings<?, ?,?> settings = manager.getSettingsProvider().fun(project);
  return settings != null && !settings.getLinkedProjectsSettings().isEmpty();
}
 
Example #19
Source File: ContentRootDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static ContentEntry findOrCreateContentRoot(@Nonnull ModifiableRootModel model, @Nonnull String path) {
  ContentEntry[] entries = model.getContentEntries();

  for (ContentEntry entry : entries) {
    VirtualFile file = entry.getFile();
    if (file == null) {
      continue;
    }
    if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(path)) {
      return entry;
    }
  }
  return model.addContentEntry(toVfsUrl(path));
}
 
Example #20
Source File: ContentRootDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void createSourceRootIfAbsent(@Nonnull ContentEntry entry,
                                             @Nonnull ContentRootData.SourceRoot root,
                                             @Nonnull String moduleName,
                                             @Nonnull ContentFolderTypeProvider folderTypeProvider,
                                             boolean generated,
                                             boolean createEmptyContentRootDirectories) {
  ContentFolder[] folders = entry.getFolders(ContentFolderScopes.of(folderTypeProvider));
  for (ContentFolder folder : folders) {
    VirtualFile file = folder.getFile();
    if (file == null) {
      continue;
    }
    if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(root.getPath())) {
      return;
    }
  }
  LOG.info(String.format("Importing %s for content root '%s' of module '%s'", root, entry.getUrl(), moduleName));
  ContentFolder contentFolder = entry.addFolder(toVfsUrl(root.getPath()), folderTypeProvider);
  /*if (!StringUtil.isEmpty(root.getPackagePrefix())) {
    sourceFolder.setPackagePrefix(root.getPackagePrefix());
  } */
  if (generated) {
    contentFolder.setPropertyValue(GeneratedContentFolderPropertyProvider.IS_GENERATED, Boolean.TRUE);
  }
  if (createEmptyContentRootDirectories) {
    try {
      VfsUtil.createDirectoryIfMissing(root.getPath());
    }
    catch (IOException e) {
      LOG.warn(String.format("Unable to create directory for the path: %s", root.getPath()), e);
    }
  }
}
 
Example #21
Source File: ContentRootDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void createExcludedRootIfAbsent(@Nonnull ContentEntry entry,
                                               @Nonnull ContentRootData.SourceRoot root,
                                               @Nonnull String moduleName,
                                               @Nonnull Project project) {
  String rootPath = root.getPath();
  for (VirtualFile file : entry.getFolderFiles(ContentFolderScopes.excluded())) {
    if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(rootPath)) {
      return;
    }
  }
  LOG.info(String.format("Importing excluded root '%s' for content root '%s' of module '%s'", root, entry.getUrl(), moduleName));
  entry.addFolder(toVfsUrl(rootPath), ExcludedContentFolderTypeProvider.getInstance());
  ChangeListManager.getInstance(project).addDirectoryToIgnoreImplicitly(rootPath);
}
 
Example #22
Source File: ProjectDataManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> void importData(@Nonnull Collection<DataNode<?>> nodes, @Nonnull Project project, boolean synchronous) {
  Map<Key<?>, List<DataNode<?>>> grouped = ExternalSystemApiUtil.group(nodes);
  for (Map.Entry<Key<?>, List<DataNode<?>>> entry : grouped.entrySet()) {
    // Simple class cast makes ide happy but compiler fails.
    Collection<DataNode<T>> dummy = ContainerUtilRt.newArrayList();
    for (DataNode<?> node : entry.getValue()) {
      dummy.add((DataNode<T>)node);
    }
    importData((Key<T>)entry.getKey(), dummy, project, synchronous);
  }
}
 
Example #23
Source File: ModuleDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void importData(@Nonnull final Collection<DataNode<ModuleData>> toImport, @Nonnull final Project project, final boolean synchronous) {
  if (toImport.isEmpty()) {
    return;
  }
  if (!project.isInitialized()) {
    myFuture = AppExecutorUtil.getAppScheduledExecutorService()
            .schedule(new ImportModulesTask(project, toImport, synchronous), PROJECT_INITIALISATION_DELAY_MS, TimeUnit.MILLISECONDS);
    return;
  }
  ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(project) {
    @RequiredUIAccess
    @Override
    public void execute() {
      final Collection<DataNode<ModuleData>> toCreate = filterExistingModules(toImport, project);
      if (!toCreate.isEmpty()) {
        createModules(toCreate, project);
      }
      for (DataNode<ModuleData> node : toImport) {
        Module module = ProjectStructureHelper.findIdeModule(node.getData(), project);
        if (module != null) {
          syncPaths(module, node.getData());
        }
      }
    }
  });
}
 
Example #24
Source File: ExternalSystemFacadeManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Nonnull
private RemoteExternalSystemFacade doGetFacade(@Nonnull IntegrationKey key, @Nonnull Project project) throws Exception {
  final boolean currentInProcess = ExternalSystemApiUtil.isInProcessMode(key.getExternalSystemId());
  final ExternalSystemCommunicationManager myCommunicationManager = currentInProcess ? myInProcessCommunicationManager : myRemoteCommunicationManager;
  
  ExternalSystemManager manager = ExternalSystemApiUtil.getManager(key.getExternalSystemId());
  if (project.isDisposed() || manager == null) {
    return RemoteExternalSystemFacade.NULL_OBJECT;
  }
  Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings> pair = myRemoteFacades.get(key);
  if (pair != null && prepare(myCommunicationManager, project, key, pair)) {
    return pair.first;
  }
  
  myLock.lock();
  try {
    pair = myRemoteFacades.get(key);
    if (pair != null && prepare(myCommunicationManager, project, key, pair)) {
      return pair.first;
    }
    if (pair != null) {
      myFacadeWrappers.clear();
      myRemoteFacades.clear();
    }
    return doCreateFacade(key, project, myCommunicationManager);
  }
  finally {
    myLock.unlock();
  }
}
 
Example #25
Source File: AbstractDependencyDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setScope(@Nonnull final DependencyScope scope, @Nonnull final ExportableOrderEntry dependency, boolean synchronous) {
  ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(dependency.getOwnerModule()) {
    @RequiredUIAccess
    @Override
    public void execute() {
      doForDependency(dependency, new Consumer<ExportableOrderEntry>() {
        @Override
        public void consume(ExportableOrderEntry entry) {
          entry.setScope(scope);
        }
      });
    }
  });
}
 
Example #26
Source File: AbstractDependencyDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setExported(final boolean exported, @Nonnull final ExportableOrderEntry dependency, boolean synchronous) {
  ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(dependency.getOwnerModule()) {
    @RequiredUIAccess
    @Override
    public void execute() {
      doForDependency(dependency, new Consumer<ExportableOrderEntry>() {
        @Override
        public void consume(ExportableOrderEntry entry) {
          entry.setExported(exported);
        }
      });
    }
  });
}
 
Example #27
Source File: AbstractDependencyDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void removeData(@Nonnull Collection<? extends ExportableOrderEntry> toRemove, @Nonnull final Module module, boolean synchronous) {
  if (toRemove.isEmpty()) {
    return;
  }
  for (final ExportableOrderEntry dependency : toRemove) {
    ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(dependency.getOwnerModule()) {
      @RequiredUIAccess
      @Override
      public void execute() {
        ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel();
        try {
          // The thing is that intellij created order entry objects every time new modifiable model is created,
          // that's why we can't use target dependency object as is but need to get a reference to the current
          // entry object from the model instead.
          for (OrderEntry entry : moduleRootModel.getOrderEntries()) {
            if (entry instanceof ExportableOrderEntry) {
              ExportableOrderEntry orderEntry = (ExportableOrderEntry)entry;
              if (orderEntry.getPresentableName().equals(dependency.getPresentableName()) &&
                  orderEntry.getScope().equals(dependency.getScope())) {
                moduleRootModel.removeOrderEntry(entry);
                break;
              }
            }
            else if (entry.getPresentableName().equals(dependency.getPresentableName())) {
              moduleRootModel.removeOrderEntry(entry);
              break;
            }
          }
        }
        finally {
          moduleRootModel.commit();
        }
      }
    });
  }
}
 
Example #28
Source File: LibraryDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void removeData(@Nonnull final Collection<? extends Library> libraries, @Nonnull final Project project, boolean synchronous) {
  if (libraries.isEmpty()) {
    return;
  }
  ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(project) {
    @RequiredUIAccess
    @Override
    public void execute() {
      final LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
      final LibraryTable.ModifiableModel model = libraryTable.getModifiableModel();
      try {
        for (Library library : libraries) {
          String libraryName = library.getName();
          if (libraryName != null) {
            Library libraryToRemove = model.getLibraryByName(libraryName);
            if (libraryToRemove != null) {
              model.removeLibrary(libraryToRemove);
            }
          }
        }
      }
      finally {
        model.commit();
      }
    }
  });
}
 
Example #29
Source File: LibraryDependencyDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void importMissingProjectLibraries(@Nonnull Module module, @Nonnull Collection<DataNode<LibraryDependencyData>> nodesToImport, boolean synchronous) {
  LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
  List<DataNode<LibraryData>> librariesToImport = ContainerUtilRt.newArrayList();
  for (DataNode<LibraryDependencyData> dataNode : nodesToImport) {
    final LibraryDependencyData dependencyData = dataNode.getData();
    if (dependencyData.getLevel() != LibraryLevel.PROJECT) {
      continue;
    }
    final Library library = libraryTable.getLibraryByName(dependencyData.getInternalName());
    if (library == null) {
      DataNode<ProjectData> projectNode = dataNode.getDataNode(ProjectKeys.PROJECT);
      if (projectNode != null) {
        DataNode<LibraryData> libraryNode = ExternalSystemApiUtil.find(projectNode, ProjectKeys.LIBRARY, new BooleanFunction<DataNode<LibraryData>>() {
          @Override
          public boolean fun(DataNode<LibraryData> node) {
            return node.getData().equals(dependencyData.getTarget());
          }
        });
        if (libraryNode != null) {
          librariesToImport.add(libraryNode);
        }
      }
    }
  }
  if (!librariesToImport.isEmpty()) {
    LibraryDataService.getInstance().importData(librariesToImport, module.getProject(), synchronous);
  }
}
 
Example #30
Source File: ProjectStructureHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Library findIdeLibrary(@Nonnull final LibraryData libraryData, @Nonnull Project ideProject) {
  final LibraryTable libraryTable = ProjectLibraryTable.getInstance(ideProject);
  for (Library ideLibrary : libraryTable.getLibraries()) {
    if (ExternalSystemApiUtil.isRelated(ideLibrary, libraryData)) return ideLibrary;
  }
  return null;
}