com.intellij.openapi.externalSystem.model.DataNode Java Examples

The following examples show how to use com.intellij.openapi.externalSystem.model.DataNode. 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: PantsSystemProjectResolver.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private void resolveUsingPantsGoal(
  @NotNull final ExternalSystemTaskId id,
  @NotNull PantsCompileOptionsExecutor executor,
  final ExternalSystemTaskNotificationListener listener,
  @NotNull DataNode<ProjectData> projectDataNode
) {
  final PantsResolver dependenciesResolver = new PantsResolver(executor);
  dependenciesResolver.resolve(
    status -> listener.onStatusChange(new ExternalSystemTaskNotificationEvent(id, status)),
    new ProcessAdapter() {
      @Override
      public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
        listener.onTaskOutput(id, event.getText(), outputType == ProcessOutputTypes.STDOUT);
      }
    }
  );
  dependenciesResolver.addInfoTo(projectDataNode);
}
 
Example #2
Source File: PantsResolver.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
public void addInfoTo(@NotNull DataNode<ProjectData> projectInfoDataNode) {
  if (myProjectInfo == null) return;


  LOG.debug("Amount of targets before modifiers: " + myProjectInfo.getTargets().size());
  for (PantsProjectInfoModifierExtension modifier : PantsProjectInfoModifierExtension.EP_NAME.getExtensions()) {
    modifier.modify(myProjectInfo, myExecutor, LOG);
  }
  LOG.debug("Amount of targets after modifiers: " + myProjectInfo.getTargets().size());

  Optional<BuildGraph> buildGraph = constructBuildGraph(projectInfoDataNode);

  PropertiesComponent.getInstance().setValues(PantsConstants.PANTS_AVAILABLE_TARGETS_KEY, myProjectInfo.getAvailableTargetTypes());
  final Map<String, DataNode<ModuleData>> modules = new HashMap<>();
  for (PantsResolverExtension resolver : PantsResolverExtension.EP_NAME.getExtensions()) {
    resolver.resolve(myProjectInfo, myExecutor, projectInfoDataNode, modules, buildGraph);
  }
  if (LOG.isDebugEnabled()) {
    final int amountOfModules = PantsUtil.findChildren(projectInfoDataNode, ProjectKeys.MODULE).size();
    LOG.debug("Amount of modules created: " + amountOfModules);
  }
}
 
Example #3
Source File: PantsSourceRootsExtension.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void resolve(
  @NotNull ProjectInfo projectInfo,
  @NotNull PantsCompileOptionsExecutor executor,
  @NotNull DataNode<ProjectData> projectDataNode,
  @NotNull Map<String, DataNode<ModuleData>> modules,
  @NotNull Optional<BuildGraph> buildGraph
) {
  for (Map.Entry<String, TargetInfo> entry : projectInfo.getSortedTargets()) {
    final String targetAddress = entry.getKey();
    final TargetInfo targetInfo = entry.getValue();
    if (!modules.containsKey(targetAddress)) {
      continue;
    }
    final DataNode<ModuleData> moduleDataNode = modules.get(targetAddress);

    createContentRoots(moduleDataNode, targetInfo);
  }
  installSyntheticModules(executor, projectDataNode, modules);
}
 
Example #4
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 #5
Source File: PantsModuleDependenciesExtension.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void resolve(
  @NotNull ProjectInfo projectInfo,
  @NotNull PantsCompileOptionsExecutor executor,
  @NotNull DataNode<ProjectData> projectDataNode,
  @NotNull Map<String, DataNode<ModuleData>> modules,
  @NotNull Optional<BuildGraph> buildGraph
) {
  for (Map.Entry<String, TargetInfo> entry : projectInfo.getSortedTargets()) {
    final String mainTarget = entry.getKey();
    final TargetInfo targetInfo = entry.getValue();
    if (!modules.containsKey(mainTarget)) {
      continue;
    }
    final DataNode<ModuleData> moduleDataNode = modules.get(mainTarget);
    for (String target : targetInfo.getTargets()) {
      if (!modules.containsKey(target)) {
        continue;
      }
      addModuleDependency(moduleDataNode, modules.get(target), true);
    }
  }
}
 
Example #6
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 #7
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 #8
Source File: PantsMetadataService.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(
  @NotNull final Collection<DataNode<TargetMetadata>> toImport,
  @Nullable ProjectData projectData,
  @NotNull Project project,
  @NotNull IdeModifiableModelsProvider modelsProvider
) {
  // for existing projects. for new projects PantsSettings.defaultSettings will provide the version.
  PantsSettings.getInstance(project).setResolverVersion(PantsResolver.VERSION);
  for (DataNode<TargetMetadata> node : toImport) {
    final TargetMetadata metadata = node.getData();
    final Module module = modelsProvider.findIdeModule(metadata.getModuleName());
    if (module != null) {
      module.setOption(PantsConstants.PANTS_LIBRARY_EXCLUDES_KEY, PantsUtil.dehydrateTargetAddresses(metadata.getLibraryExcludes()));
      module.setOption(PantsConstants.PANTS_TARGET_ADDRESSES_KEY, PantsUtil.dehydrateTargetAddresses(metadata.getTargetAddresses()));
      module.setOption(PantsConstants.PANTS_TARGET_ADDRESS_INFOS_KEY, gson.toJson(metadata.getTargetAddressInfoSet()));
      module.setOption(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH, Paths.get(projectData.getLinkedExternalProjectPath()).normalize().toString());
      ExternalSystemModulePropertyManager.getInstance(module).setExternalModuleType(PantsConstants.PANTS_TARGET_MODULE_TYPE);
    }
  }
}
 
Example #9
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 #10
Source File: ProjectDataManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> void importData(@Nonnull Key<T> key, @Nonnull Collection<DataNode<T>> nodes, @Nonnull Project project, boolean synchronous) {
  ensureTheDataIsReadyToUse(nodes);
  List<ProjectDataService<?, ?>> services = myServices.getValue().get(key);
  if (services == null) {
    LOG.warn(String.format(
      "Can't import data nodes '%s'. Reason: no service is registered for key %s. Available services for %s",
      nodes, key, myServices.getValue().keySet()
    ));
  }
  else {
    for (ProjectDataService<?, ?> service : services) {
      ((ProjectDataService<T, ?>)service).importData(nodes, project, synchronous);
    }
  }

  Collection<DataNode<?>> children = ContainerUtilRt.newArrayList();
  for (DataNode<T> node : nodes) {
    children.addAll(node.getChildren());
  }
  importData(children, project, synchronous);
}
 
Example #11
Source File: ProjectDataManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> void ensureTheDataIsReadyToUse(@Nonnull Collection<DataNode<T>> nodes) {
  Map<Key<?>, List<ProjectDataService<?, ?>>> servicesByKey = myServices.getValue();
  Stack<DataNode<T>> toProcess = ContainerUtil.newStack(nodes);
  while (!toProcess.isEmpty()) {
    DataNode<T> node = toProcess.pop();
    List<ProjectDataService<?, ?>> services = servicesByKey.get(node.getKey());
    if (services != null) {
      for (ProjectDataService<?, ?> service : services) {
        node.prepareData(service.getClass().getClassLoader());
      }
    }

    for (DataNode<?> dataNode : node.getChildren()) {
      toProcess.push((DataNode<T>)dataNode);
    }
  }
}
 
Example #12
Source File: ProjectDataServiceImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(@Nonnull Collection<DataNode<ProjectData>> toImport, @Nonnull Project project, boolean synchronous) {
  if (toImport.size() != 1) {
    throw new IllegalArgumentException(String.format("Expected to get a single project but got %d: %s", toImport.size(), toImport));
  }
  DataNode<ProjectData> node = toImport.iterator().next();
  ProjectData projectData = node.getData();
  
  if (!ExternalSystemApiUtil.isNewProjectConstruction() && !ExternalSystemUtil.isOneToOneMapping(project, node)) {
    return;
  }
  
  if (!project.getName().equals(projectData.getInternalName())) {
    renameProject(projectData.getInternalName(), projectData.getOwner(), project, synchronous);
  }
}
 
Example #13
Source File: PantsSystemProjectResolver.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private static void clearPantsModules(@NotNull Project project, String projectPath, DataNode<ProjectData> projectDataNode) {
  Runnable clearModules = () -> {
    Set<String> importedModules = projectDataNode.getChildren().stream()
      .map(node -> node.getData(ProjectKeys.MODULE))
      .filter(Objects::nonNull)
      .map(ModuleData::getInternalName)
      .collect(Collectors.toSet());

    Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
      boolean hasPantsProjectPath = Objects.equals(module.getOptionValue(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH), Paths.get(projectPath).normalize().toString());
      boolean isNotBeingImported = !importedModules.contains(module.getName());
      if (hasPantsProjectPath && isNotBeingImported) {
        ModuleManager.getInstance(project).disposeModule(module);
      }
    }
  };

  Application application = ApplicationManager.getApplication();
  application.invokeAndWait(() -> application.runWriteAction(clearModules));
}
 
Example #14
Source File: ModuleDataService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredUIAccess
private Collection<DataNode<ModuleData>> filterExistingModules(@Nonnull Collection<DataNode<ModuleData>> modules, @Nonnull Project project) {
  Collection<DataNode<ModuleData>> result = ContainerUtilRt.newArrayList();
  for (DataNode<ModuleData> node : modules) {
    ModuleData moduleData = node.getData();
    Module module = ProjectStructureHelper.findIdeModule(moduleData, project);
    if (module == null) {
      result.add(node);
    }
    else {
      setModuleOptions(module, null, node);
    }
  }
  return result;
}
 
Example #15
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 #16
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 #17
Source File: ExternalSystemApiUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@javax.annotation.Nullable
public static <T> DataNode<T> find(@Nonnull DataNode<?> node, @Nonnull Key<T> key, BooleanFunction<DataNode<T>> predicate) {
  for (DataNode<?> child : node.getChildren()) {
    if (key.equals(child.getKey()) && predicate.fun((DataNode<T>)child)) {
      return (DataNode<T>)child;
    }
  }
  return null;
}
 
Example #18
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 #19
Source File: ToolWindowTaskService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void processData(@Nonnull Collection<DataNode<TaskData>> nodes,
                           @Nonnull Project project,
                           @Nullable final ExternalSystemTasksTreeModel model)
{
  if (nodes.isEmpty()) {
    return;
  }
  ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
  ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
  assert manager != null;

  Map<ExternalConfigPathAware, List<DataNode<TaskData>>> grouped = ExternalSystemApiUtil.groupBy(nodes, TASK_HOLDER_RETRIEVAL_STRATEGY);
  Map<String, Collection<ExternalTaskPojo>> data = ContainerUtilRt.newHashMap();
  for (Map.Entry<ExternalConfigPathAware, List<DataNode<TaskData>>> entry : grouped.entrySet()) {
    data.put(entry.getKey().getLinkedExternalProjectPath(), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
  }

  AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
  Map<String, Collection<ExternalTaskPojo>> availableTasks = ContainerUtilRt.newHashMap(settings.getAvailableTasks());
  availableTasks.putAll(data);
  settings.setAvailableTasks(availableTasks);

  if (model != null) {
    ExternalSystemUiUtil.apply(settings, model);
  }
}
 
Example #20
Source File: ToolWindowModuleService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void processData(@Nonnull final Collection<DataNode<ModuleData>> nodes,
                           @Nonnull Project project,
                           @javax.annotation.Nullable final ExternalSystemTasksTreeModel model)
{
  if (nodes.isEmpty()) {
    return;
  }
  ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
  ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
  assert manager != null;

  final Map<DataNode<ProjectData>, List<DataNode<ModuleData>>> grouped = ExternalSystemApiUtil.groupBy(nodes, ProjectKeys.PROJECT);
  Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> data = ContainerUtilRt.newHashMap();
  for (Map.Entry<DataNode<ProjectData>, List<DataNode<ModuleData>>> entry : grouped.entrySet()) {
    data.put(ExternalProjectPojo.from(entry.getKey().getData()), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
  }

  AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
  Set<String> pathsToForget = detectRenamedProjects(data, settings.getAvailableProjects());
  if (!pathsToForget.isEmpty()) {
    settings.forgetExternalProjects(pathsToForget);
  }
  Map<ExternalProjectPojo,Collection<ExternalProjectPojo>> projects = ContainerUtilRt.newHashMap(settings.getAvailableProjects());
  projects.putAll(data);
  settings.setAvailableProjects(projects);
}
 
Example #21
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 #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: PantsResolverTestBase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
protected DataNode<ProjectData> getProjectNode() {
  if (myProjectNode == null) {
    myProjectNode = createProjectNode();
  }
  return myProjectNode;
}
 
Example #24
Source File: ExternalSystemApiUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <K, V> Map<DataNode<K>, List<DataNode<V>>> groupBy(@Nonnull Collection<DataNode<V>> nodes, @Nonnull final Key<K> key) {
  return groupBy(nodes, new NullableFunction<DataNode<V>, DataNode<K>>() {
    @Nullable
    @Override
    public DataNode<K> fun(DataNode<V> node) {
      return node.getDataNode(key);
    }
  });
}
 
Example #25
Source File: PantsResolverTestBase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private DataNode<ModuleData> findModule(final String moduleName) {
  final Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(getProjectNode(), ProjectKeys.MODULE);
  return moduleNodes.stream()
    .filter(node -> StringUtil.equalsIgnoreCase(moduleName, node.getData().getExternalName()))
    .findFirst()
    .orElse(null);
}
 
Example #26
Source File: ExternalSystemImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected void ignoreData(BooleanFunction<DataNode<?>> booleanFunction, final boolean ignored) {
  final ExternalProjectInfo externalProjectInfo = ProjectDataManagerImpl.getInstance().getExternalProjectData(
    myProject, getExternalSystemId(), getCurrentExternalProjectSettings().getExternalProjectPath());
  assertNotNull(externalProjectInfo);

  final DataNode<ProjectData> projectDataNode = externalProjectInfo.getExternalProjectStructure();
  assertNotNull(projectDataNode);

  final Collection<DataNode<?>> nodes = ExternalSystemApiUtil.findAllRecursively(projectDataNode, booleanFunction);
  for (DataNode<?> node : nodes) {
    ExternalSystemApiUtil.visit(node, dataNode -> dataNode.setIgnored(ignored));
  }
  ServiceManager.getService(ProjectDataManager.class).importData(projectDataNode, myProject, true);
}
 
Example #27
Source File: PantsResolverTestBase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public void assertContentRoots(String moduleName, String... roots) {
  final DataNode<ModuleData> moduleNode = findModule(moduleName);
  assertModuleExists(moduleName, moduleNode);
  final Collection<DataNode<ContentRootData>> contentRoots = ExternalSystemApiUtil.findAll(moduleNode, ProjectKeys.CONTENT_ROOT);
  final List<String> actualRootPaths = contentRoots.stream().map(s -> s.getData().getRootPath()).collect(Collectors.toList());
  List<String> expected = Arrays.asList(roots);
  Collections.sort(expected);
  Collections.sort(actualRootPaths);
  assertEquals("Content roots", expected, actualRootPaths);
}
 
Example #28
Source File: PantsResolverTestBase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public void assertNoContentRoot(String moduleName) {
  final DataNode<ModuleData> moduleNode = findModule(moduleName);
  assertModuleExists(moduleName, moduleNode);
  final Collection<DataNode<ContentRootData>> contentRoots = ExternalSystemApiUtil.findAll(moduleNode, ProjectKeys.CONTENT_ROOT);
  for (DataNode<ContentRootData> contentRoot : contentRoots) {
    assertNull(
      String
        .format("Content root %s is defined for module %s", contentRoot.getData().getRootPath(), moduleName),
      contentRoot
    );
  }
}
 
Example #29
Source File: PantsResolverTestBase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
protected DataNode<ProjectData> createProjectNode() {
  final PantsResolver dependenciesResolver = new PantsResolver(PantsCompileOptionsExecutor.createMock());
  dependenciesResolver.setProjectInfo(getProjectInfo());
  final ProjectData projectData = new ProjectData(
    PantsConstants.SYSTEM_ID, "test-project", "path/to/fake/project", "path/to/fake/project/BUILD"
  );
  final DataNode<ProjectData> dataNode = new DataNode<>(ProjectKeys.PROJECT, projectData, null);
  dependenciesResolver.addInfoTo(dataNode);
  return dataNode;
}
 
Example #30
Source File: PantsResolverTestBase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public DataNode<LibraryDependencyData> findLibraryDependency(String moduleName, final String libraryId) {
  final DataNode<ModuleData> moduleNode = findModule(moduleName);
  return ExternalSystemApiUtil.findAll(moduleNode, ProjectKeys.LIBRARY_DEPENDENCY)
    .stream()
    .filter(node -> StringUtil.equalsIgnoreCase(libraryId, node.getData().getExternalName()))
    .findFirst()
    .orElse(null);
}