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

The following examples show how to use com.intellij.openapi.externalSystem.model.ProjectKeys. 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 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: PythonRequirementsResolver.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private DataNode<ModuleData> createRequirementsModule(
  @NotNull DataNode<ProjectData> projectDataNode,
  @NotNull PythonSetup pythonSetup,
  @NotNull PantsCompileOptionsExecutor executor
) {
  final String moduleName = "python_requirements";
  final ModuleData moduleData = new ModuleData(
    moduleName,
    PantsConstants.SYSTEM_ID,
    ModuleTypeId.JAVA_MODULE,
    moduleName,
    projectDataNode.getData().getIdeProjectFileDirectoryPath() + "/" + moduleName,
    new File(executor.getBuildRoot(), moduleName).getAbsolutePath()
  );

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

  final File chroot = new File(pythonSetup.getDefaultInterpreterInfo().getChroot());
  for (File dep : FileUtil.notNullize(new File(chroot, ".deps").listFiles())) {
    if (!dep.isDirectory()) {
      continue;
    }
    final ContentRootData contentRoot = new ContentRootData(PantsConstants.SYSTEM_ID, dep.getAbsolutePath());
    contentRoot.storePath(ExternalSystemSourceType.SOURCE, dep.getAbsolutePath());
    moduleDataNode.createChild(ProjectKeys.CONTENT_ROOT, contentRoot);
  }

  return moduleDataNode;
}
 
Example #12
Source File: PythonRequirementsResolver.java    From intellij-pants-plugin with Apache License 2.0 5 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
) {
  final PythonSetup pythonSetup = projectInfo.getPythonSetup();
  if (pythonSetup == null) {
    LOG.warn("Current version of Pants doesn't provide information about Python setup. Please upgrade!");
    return;
  }

  final DataNode<ModuleData> requirementsModuleDataNode = createRequirementsModule(projectDataNode, pythonSetup, executor);
  requirementsModuleDataNode.createChild(
    PythonSetupData.KEY,
    new PythonSetupData(requirementsModuleDataNode.getData(), pythonSetup.getDefaultInterpreterInfo())
  );

  for (Map.Entry<String, TargetInfo> targetInfoEntry : projectInfo.getSortedTargets()) {
    final String targetName = targetInfoEntry.getKey();
    final TargetInfo targetInfo = targetInfoEntry.getValue();
    final DataNode<ModuleData> moduleDataNode = modules.get(targetName);
    if (targetInfo.isPythonTarget() && moduleDataNode != null) {
      final ModuleDependencyData moduleDependencyData = new ModuleDependencyData(
        moduleDataNode.getData(),
        requirementsModuleDataNode.getData()
      );
      moduleDependencyData.setExported(true);
      moduleDataNode.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData);
      moduleDataNode.createChild(
        PythonSetupData.KEY,
        new PythonSetupData(moduleDataNode.getData(), pythonSetup.getDefaultInterpreterInfo())
      );
    }
  }
}
 
Example #13
Source File: PythonPexResolver.java    From intellij-pants-plugin with Apache License 2.0 5 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
) {
  final Optional<VirtualFile> buildRoot = PantsUtil.findBuildRoot(projectDataNode.getData().getLinkedExternalProjectPath());
  final Optional<VirtualFile> bootstrappedPants =  buildRoot.map(file -> file.findChild(PantsConstants.PANTS_PEX));
  final Optional<VirtualFile> pexFile = bootstrappedPants.flatMap(file -> findSpecificPexVersionInHomeDirectory(buildRoot));
  if (pexFile.isPresent()) {
    final LibraryData libraryData = new LibraryData(PantsConstants.SYSTEM_ID, PantsConstants.PANTS_LIBRARY_NAME);
    libraryData.addPath(LibraryPathType.BINARY, pexFile.get().getPath());
    projectDataNode.createChild(ProjectKeys.LIBRARY, libraryData);

    for (DataNode<ModuleData> moduleDataNode : modules.values()) {
      final LibraryDependencyData library = new LibraryDependencyData(
        moduleDataNode.getData(),
        libraryData,
        LibraryLevel.PROJECT
      );
      library.setExported(false);
      moduleDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, library);
    }
  }
}
 
Example #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
Source File: LibraryDataService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<LibraryData> getTargetDataKey() {
  return ProjectKeys.LIBRARY;
}
 
Example #21
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 #22
Source File: ModuleDataService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
private static void setModuleOptions(@Nonnull final Module module,
                                     @javax.annotation.Nullable final ModifiableRootModel originalModel,
                                     @Nonnull final DataNode<ModuleData> moduleDataNode) {

  ModuleData moduleData = moduleDataNode.getData();
  module.putUserData(MODULE_DATA_KEY, moduleData);

  final ProjectData projectData = moduleDataNode.getData(ProjectKeys.PROJECT);
  if (projectData == null) {
    throw new IllegalArgumentException("projectData is null");
  }

  ModifiableRootModel otherModel = originalModel == null ? ModuleRootManager.getInstance(module).getModifiableModel() : originalModel;

  // remove prev. extension
  ExternalSystemMutableModuleExtension<?> oldExtension = otherModel.getExtension(ExternalSystemMutableModuleExtension.class);
  if (oldExtension != null) {
    oldExtension.setEnabled(false);
    oldExtension.removeAllOptions();
  }

  ExternalSystemMutableModuleExtension<?> newExtension = otherModel.getExtensionWithoutCheck(projectData.getOwner().getId());
  if (newExtension == null) {
    LOG.error("ModuleExtension is not registered for externalSystem: " + projectData.getOwner().getId());
    return;
  }

  newExtension.setEnabled(true);
  newExtension.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, moduleData.getOwner().toString());
  newExtension.setOption(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY, moduleData.getLinkedExternalProjectPath());
  newExtension.setOption(ExternalSystemConstants.LINKED_PROJECT_ID_KEY, moduleData.getId());
  if (moduleData.getGroup() != null) {
    newExtension.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_MODULE_GROUP_KEY, moduleData.getGroup());
  }
  if (moduleData.getVersion() != null) {
    newExtension.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_MODULE_VERSION_KEY, moduleData.getVersion());
  }

  newExtension.setOption(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY, projectData.getLinkedExternalProjectPath());

  if (originalModel == null) {
    WriteAction.run(otherModel::commit);
  }
}
 
Example #23
Source File: LibraryDependencyDataService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<LibraryDependencyData> getTargetDataKey() {
  return ProjectKeys.LIBRARY_DEPENDENCY;
}
 
Example #24
Source File: ToolWindowTaskService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ExternalConfigPathAware fun(DataNode<TaskData> node) {
  ModuleData moduleData = node.getData(ProjectKeys.MODULE);
  return moduleData == null ? node.getData(ProjectKeys.PROJECT) : moduleData;
}
 
Example #25
Source File: ToolWindowTaskService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<TaskData> getTargetDataKey() {
  return ProjectKeys.TASK;
}
 
Example #26
Source File: QuarkusProjectDataService.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@NotNull
@Override
public Key<LibraryDependencyData> getTargetDataKey() {
    return ProjectKeys.LIBRARY_DEPENDENCY;
}
 
Example #27
Source File: ModuleDataService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<ModuleData> getTargetDataKey() {
  return ProjectKeys.MODULE;
}
 
Example #28
Source File: ProjectDataServiceImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<ProjectData> getTargetDataKey() {
  return ProjectKeys.PROJECT;
}
 
Example #29
Source File: ContentRootDataService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<ContentRootData> getTargetDataKey() {
  return ProjectKeys.CONTENT_ROOT;
}
 
Example #30
Source File: ModuleDependencyDataService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<ModuleDependencyData> getTargetDataKey() {
  return ProjectKeys.MODULE_DEPENDENCY;
}