com.intellij.openapi.externalSystem.model.project.ModuleData Java Examples

The following examples show how to use com.intellij.openapi.externalSystem.model.project.ModuleData. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: ModuleDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void syncPaths(@Nonnull Module module, @Nonnull ModuleData data) {
  ModuleCompilerPathsManager compilerPathsManager = ModuleCompilerPathsManager.getInstance(module);
  compilerPathsManager.setInheritedCompilerOutput(data.isInheritProjectCompileOutputPath());
  if (!data.isInheritProjectCompileOutputPath()) {
    String compileOutputPath = data.getCompileOutputPath(ExternalSystemSourceType.SOURCE);
    if (compileOutputPath != null) {
      compilerPathsManager.setCompilerOutputUrl(ProductionContentFolderTypeProvider.getInstance(), VfsUtilCore.pathToUrl(compileOutputPath));
    }
    String testCompileOutputPath = data.getCompileOutputPath(ExternalSystemSourceType.TEST);
    if (testCompileOutputPath != null) {
      compilerPathsManager.setCompilerOutputUrl(TestContentFolderTypeProvider.getInstance(), VfsUtilCore.pathToUrl(testCompileOutputPath));
    }
  }
}
 
Example #12
Source File: PythonSetupDataTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private PythonSetupData newData() {
  PythonInterpreterInfo info = new PythonInterpreterInfo();
  ModuleData moduleData = new ModuleData("id", PantsConstants.SYSTEM_ID, "module", "name", "path", "path");
  info.setBinary("binary");
  info.setChroot("chroot");
  return new PythonSetupData(moduleData, info);
}
 
Example #13
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 #14
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);
}
 
Example #15
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 #16
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 #17
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
  if (externalProject == null) {
    return;
  }
  Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(externalProject, ProjectKeys.MODULE);
  for (DataNode<ModuleData> node : moduleNodes) {
    myExternalModulePaths.add(node.getData().getLinkedExternalProjectPath());
  }
  ExternalSystemApiUtil.executeProjectChangeAction(true, 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);
        }
      });

      processOrphanProjectLibraries();
    }
  });
  if (--myCounter[0] <= 0) {
    processOrphanModules();
  }
}
 
Example #18
Source File: PantsSystemProjectResolver.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private boolean containsContentRoot(@NotNull DataNode<ProjectData> projectDataNode, @NotNull String path) {
  for (DataNode<ModuleData> moduleDataNode : ExternalSystemApiUtil.findAll(projectDataNode, ProjectKeys.MODULE)) {
    for (DataNode<ContentRootData> contentRootDataNode : ExternalSystemApiUtil.findAll(moduleDataNode, ProjectKeys.CONTENT_ROOT)) {
      final ContentRootData contentRootData = contentRootDataNode.getData();
      if (FileUtil.isAncestor(contentRootData.getRootPath(), path, false)) {
        return true;
      }
    }
  }

  return false;
}
 
Example #19
Source File: GradleReindexingProjectDataService.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Override
public void onSuccessImport(@NotNull Collection<DataNode<ModuleData>> imported,
    @Nullable ProjectData projectData, @NotNull Project project,
    @NotNull IdeModelsProvider modelsProvider) {
  if (projectData != null) {
    debug(() -> log.debug(
        "Gradle dependencies are updated for project, will trigger indexing via dumbservice for project "
            + project.getName()));
    DumbService.getInstance(project).smartInvokeLater(() -> {
      log.debug("Will attempt to trigger indexing for project " + project.getName());
      SuggestionService service = ServiceManager.getService(project, SuggestionService.class);

      try {
        Module[] validModules = stream(modelsProvider.getModules()).filter(module -> {
          String externalRootProjectPath = getExternalRootProjectPath(module);
          return externalRootProjectPath != null && externalRootProjectPath
              .equals(projectData.getLinkedExternalProjectPath());
        }).toArray(Module[]::new);

        if (validModules.length > 0) {
          service.reindex(project, validModules);
        } else {
          debug(() -> log.debug(
              "None of the modules " + moduleNamesAsStrCommaDelimited(modelsProvider.getModules(),
                  true) + " are relevant for indexing, skipping for project " + project
                  .getName()));
        }
      } catch (Throwable e) {
        log.error("Error occurred while indexing project " + project.getName() + " & modules "
            + moduleNamesAsStrCommaDelimited(modelsProvider.getModules(), false), e);
      }
    });
  }
}
 
Example #20
Source File: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@SuppressWarnings("DuplicatedCode")
private static Map<ProjectData, MultiMap<String, String>> getTasksMap(Project project) {
  Map<ProjectData, MultiMap<String, String>> tasks = new LinkedHashMap<>();
  for (GradleProjectSettings setting : GradleSettings.getInstance(project).getLinkedProjectsSettings()) {
    final ExternalProjectInfo projectData =
      ProjectDataManager.getInstance().getExternalProjectData(project, GradleConstants.SYSTEM_ID, setting.getExternalProjectPath());
    if (projectData == null || projectData.getExternalProjectStructure() == null) continue;

    MultiMap<String, String> projectTasks = MultiMap.createOrderedSet();
    for (DataNode<ModuleData> moduleDataNode : getChildren(projectData.getExternalProjectStructure(), ProjectKeys.MODULE)) {
      String gradlePath;
      String moduleId = moduleDataNode.getData().getId();
      if (moduleId.charAt(0) != ':') {
        int colonIndex = moduleId.indexOf(':');
        gradlePath = colonIndex > 0 ? moduleId.substring(colonIndex) : ":";
      }
      else {
        gradlePath = moduleId;
      }
      for (DataNode<TaskData> node : getChildren(moduleDataNode, ProjectKeys.TASK)) {
        TaskData taskData = node.getData();
        String taskName = taskData.getName();
        if (isNotEmpty(taskName)) {
          String taskPathPrefix = ":".equals(gradlePath) || taskName.startsWith(gradlePath) ? "" : (gradlePath + ':');
          projectTasks.putValue(taskPathPrefix, taskName);
        }
      }
    }
    tasks.put(projectData.getExternalProjectStructure().getData(), projectTasks);
  }
  return tasks;
}
 
Example #21
Source File: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@SuppressWarnings("DuplicatedCode")
private static Map<ProjectData, MultiMap<String, String>> getTasksMap(Project project) {
  Map<ProjectData, MultiMap<String, String>> tasks = new LinkedHashMap<>();
  for (GradleProjectSettings setting : GradleSettings.getInstance(project).getLinkedProjectsSettings()) {
    final ExternalProjectInfo projectData =
      ProjectDataManager.getInstance().getExternalProjectData(project, GradleConstants.SYSTEM_ID, setting.getExternalProjectPath());
    if (projectData == null || projectData.getExternalProjectStructure() == null) continue;

    MultiMap<String, String> projectTasks = MultiMap.createOrderedSet();
    for (DataNode<ModuleData> moduleDataNode : getChildren(projectData.getExternalProjectStructure(), ProjectKeys.MODULE)) {
      String gradlePath;
      String moduleId = moduleDataNode.getData().getId();
      if (moduleId.charAt(0) != ':') {
        int colonIndex = moduleId.indexOf(':');
        gradlePath = colonIndex > 0 ? moduleId.substring(colonIndex) : ":";
      }
      else {
        gradlePath = moduleId;
      }
      for (DataNode<TaskData> node : getChildren(moduleDataNode, ProjectKeys.TASK)) {
        TaskData taskData = node.getData();
        String taskName = taskData.getName();
        if (isNotEmpty(taskName)) {
          String taskPathPrefix = ":".equals(gradlePath) || taskName.startsWith(gradlePath) ? "" : (gradlePath + ':');
          projectTasks.putValue(taskPathPrefix, taskName);
        }
      }
    }
    tasks.put(projectData.getExternalProjectStructure().getData(), projectTasks);
  }
  return tasks;
}
 
Example #22
Source File: PantsModuleDependenciesExtension.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private void addModuleDependency(DataNode<ModuleData> moduleDataNode, DataNode<ModuleData> submoduleDataNode, boolean exported) {
  final List<ModuleDependencyData> subModuleDeps = PantsUtil.findChildren(submoduleDataNode, ProjectKeys.MODULE_DEPENDENCY);
  for (ModuleDependencyData dep : subModuleDeps) {
    if (dep.getTarget().equals(moduleDataNode.getData())) {
      return;
    }
  }
  final ModuleDependencyData moduleDependencyData = new ModuleDependencyData(
    moduleDataNode.getData(),
    submoduleDataNode.getData()
  );
  moduleDependencyData.setExported(exported);
  moduleDataNode.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData);
}
 
Example #23
Source File: PantsSourceRootsExtension.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private void createContentRoots(@NotNull DataNode<ModuleData> moduleDataNode, @NotNull final TargetInfo targetInfo) {
  final Set<ContentRoot> roots = targetInfo.getRoots();
  if (roots.isEmpty()) {
    return;
  }

  for (String baseRoot : findBaseRoots(targetInfo, roots)) {
    final ContentRootData contentRoot = new ContentRootData(PantsConstants.SYSTEM_ID, baseRoot);
    moduleDataNode.createChild(ProjectKeys.CONTENT_ROOT, contentRoot);

    for (ContentRoot sourceRoot : roots) {
      final String sourceRootPathToAdd = getSourceRootRegardingTargetType(targetInfo, sourceRoot);
      if (FileUtil.isAncestor(baseRoot, sourceRootPathToAdd, false)) {
        try {
          contentRoot.storePath(
            targetInfo.getSourcesType().toExternalSystemSourceType(),
            sourceRootPathToAdd,
            doNotSupportPackagePrefixes(targetInfo) ? null : sourceRoot.getPackagePrefix()
          );
        }
        catch (IllegalArgumentException e) {
          LOG.warn(e);
          // todo(fkorotkov): log and investigate exceptions from ContentRootData.storePath(ContentRootData.java:94)
        }
      }
    }
  }
}
 
Example #24
Source File: PantsCreateModulesExtension.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private DataNode<ModuleData> createModuleData(
  @NotNull DataNode<ProjectData> projectInfoDataNode,
  @NotNull String targetName,
  @NotNull TargetInfo targetInfo,
  @NotNull PantsCompileOptionsExecutor executor
) {
  final String moduleName = PantsUtil.getCanonicalModuleName(targetName);

  final ModuleData moduleData = new ModuleData(
    targetName,
    PantsConstants.SYSTEM_ID,
    ModuleTypeId.JAVA_MODULE,
    moduleName,
    projectInfoDataNode.getData().getIdeProjectFileDirectoryPath() + "/" + moduleName,
    new File(executor.getBuildRoot(), targetName).getAbsolutePath()
  );

  final DataNode<ModuleData> moduleDataNode = projectInfoDataNode.createChild(ProjectKeys.MODULE, moduleData);

  DataNode<ProjectSdkData> sdk = ExternalSystemApiUtil.find(projectInfoDataNode, ProjectSdkData.KEY);
  if(sdk != null){
    ModuleSdkData moduleSdk = new ModuleSdkData(sdk.getData().getSdkName());
    moduleDataNode.createChild(ModuleSdkData.KEY, moduleSdk);
  }

  final TargetMetadata metadata = new TargetMetadata(PantsConstants.SYSTEM_ID, moduleName);
  metadata.setTargetAddresses(ContainerUtil.map(targetInfo.getAddressInfos(), TargetAddressInfo::getTargetAddress));
  metadata.setTargetAddressInfoSet(targetInfo.getAddressInfos());
  metadata.setLibraryExcludes(targetInfo.getExcludes());
  moduleDataNode.createChild(TargetMetadata.KEY, metadata);

  return moduleDataNode;
}
 
Example #25
Source File: PantsResolverExtension.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
void resolve(
  @NotNull ProjectInfo projectInfo,
  @NotNull PantsCompileOptionsExecutor executor,
  @NotNull DataNode<ProjectData> projectDataNode,
  @NotNull Map<String, DataNode<ModuleData>> modules,
  @NotNull Optional<BuildGraph> buildGraph
);
 
Example #26
Source File: ModuleDataService.java    From consulo with Apache License 2.0 4 votes vote down vote up
ImportModulesTask(@Nonnull Project project, @Nonnull Collection<DataNode<ModuleData>> modules, boolean synchronous) {
  myProject = project;
  myModules = modules;
  mySynchronous = synchronous;
}
 
Example #27
Source File: PythonSetupData.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
@PropertyMapping({"myOwnerModuleData", "interpreterInfo"})
public PythonSetupData(ModuleData ownerModuleData, @NotNull PythonInterpreterInfo interpreterInfo) {
  super(PantsConstants.SYSTEM_ID);
  myOwnerModuleData = ownerModuleData;
  myInterpreterInfo = interpreterInfo;
}
 
Example #28
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Allows to answer if given ide project has 1-1 mapping with the given external project, i.e. the ide project has been
 * imported from external system and no other external projects have been added.
 * <p>
 * This might be necessary in a situation when project-level setting is changed (e.g. project name). We don't want to rename
 * ide project if it doesn't completely corresponds to the given ide project then.
 *
 * @param ideProject      target ide project
 * @param externalProject target external project
 * @return <code>true</code> if given ide project has 1-1 mapping to the given external project;
 * <code>false</code> otherwise
 */
public static boolean isOneToOneMapping(@Nonnull Project ideProject, @Nonnull DataNode<ProjectData> externalProject) {
  String linkedExternalProjectPath = null;
  for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
    ProjectSystemId externalSystemId = manager.getSystemId();
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId);
    Collection projectsSettings = systemSettings.getLinkedProjectsSettings();
    int linkedProjectsNumber = projectsSettings.size();
    if (linkedProjectsNumber > 1) {
      // More than one external project of the same external system type is linked to the given ide project.
      return false;
    }
    else if (linkedProjectsNumber == 1) {
      if (linkedExternalProjectPath == null) {
        // More than one external project of different external system types is linked to the current ide project.
        linkedExternalProjectPath = ((ExternalProjectSettings)projectsSettings.iterator().next()).getExternalProjectPath();
      }
      else {
        return false;
      }
    }
  }

  ProjectData projectData = externalProject.getData();
  if (linkedExternalProjectPath != null && !linkedExternalProjectPath.equals(projectData.getLinkedExternalProjectPath())) {
    // New external project is being linked.
    return false;
  }

  Set<String> externalModulePaths = ContainerUtilRt.newHashSet();
  for (DataNode<ModuleData> moduleNode : ExternalSystemApiUtil.findAll(externalProject, ProjectKeys.MODULE)) {
    externalModulePaths.add(moduleNode.getData().getLinkedExternalProjectPath());
  }
  externalModulePaths.remove(linkedExternalProjectPath);

  for (Module module : ModuleManager.getInstance(ideProject).getModules()) {
    String path = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.LINKED_PROJECT_PATH_KEY);
    if (!StringUtil.isEmpty(path) && !externalModulePaths.remove(path)) {
      return false;
    }
  }
  return externalModulePaths.isEmpty();
}
 
Example #29
Source File: ToolWindowModuleService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<ModuleData> getTargetDataKey() {
  return ProjectKeys.MODULE;
}
 
Example #30
Source File: ToolWindowModuleService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ExternalProjectPojo fun(DataNode<ModuleData> node) {
  return ExternalProjectPojo.from(node.getData());
}