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

The following examples show how to use com.intellij.openapi.externalSystem.model.project.ProjectData. 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: 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 #2
Source File: RemoteExternalSystemProjectResolverImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
@Override
public DataNode<ProjectData> resolveProjectInfo(@Nonnull final ExternalSystemTaskId id,
                                                @Nonnull final String projectPath,
                                                final boolean isPreviewMode,
                                                ExternalSystemExecutionSettings settings)
  throws ExternalSystemException, IllegalArgumentException, IllegalStateException
{
  return execute(id, new Producer<DataNode<ProjectData>>() {
    @javax.annotation.Nullable
    @Override
    public DataNode<ProjectData> produce() {
      return myDelegate.resolveProjectInfo(id, projectPath, isPreviewMode, getSettings(), getNotificationListener());
    }
  });
}
 
Example #3
Source File: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void enableCoeditIfAddToAppDetected(@NotNull Project project) {
  if (isCoeditTransformedProject(project)) {
    return;
  }
  // After a Gradle sync has finished we check the tasks that were run to see if any belong to Flutter.
  Map<ProjectData, MultiMap<String, String>> tasks = getTasksMap(project);
  @NotNull String projectName = project.getName();
  for (ProjectData projectData : tasks.keySet()) {
    MultiMap<String, String> map = tasks.get(projectData);
    Collection<String> col = map.get(FLUTTER_PROJECT_NAME);
    if (col.isEmpty()) {
      col = map.get(""); // Android Studio uses this.
    }
    if (!col.isEmpty()) {
      if (col.parallelStream().anyMatch((x) -> x.startsWith(FLUTTER_TASK_PREFIX))) {
        ApplicationManager.getApplication().invokeLater(() -> enableCoEditing(project));
      }
    }
  }
}
 
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: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void enableCoeditIfAddToAppDetected(@NotNull Project project) {
  if (isCoeditTransformedProject(project)) {
    return;
  }
  // After a Gradle sync has finished we check the tasks that were run to see if any belong to Flutter.
  Map<ProjectData, MultiMap<String, String>> tasks = getTasksMap(project);
  @NotNull String projectName = project.getName();
  for (ProjectData projectData : tasks.keySet()) {
    MultiMap<String, String> map = tasks.get(projectData);
    Collection<String> col = map.get(FLUTTER_PROJECT_NAME);
    if (col.isEmpty()) {
      col = map.get(""); // Android Studio uses this.
    }
    if (!col.isEmpty()) {
      if (col.parallelStream().anyMatch((x) -> x.startsWith(FLUTTER_TASK_PREFIX))) {
        ApplicationManager.getApplication().invokeLater(() -> enableCoEditing(project));
      }
    }
  }
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: PantsPythonSetupDataService.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Computable<Collection<Module>> computeOrphanData(
  @NotNull Collection<DataNode<PythonSetupData>> toImport,
  @NotNull ProjectData projectData,
  @NotNull Project project,
  @NotNull IdeModifiableModelsProvider modelsProvider
) {
  return new Computable<Collection<Module>>() {
    @Override
    public Collection<Module> compute() {
      return Collections.emptyList();
    }
  };
}
 
Example #16
Source File: PantsPythonSetupDataService.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void removeData(
  @NotNull Computable<Collection<Module>> toRemove,
  @NotNull Collection<DataNode<PythonSetupData>> toIgnore,
  @NotNull ProjectData projectData,
  @NotNull Project project,
  @NotNull IdeModifiableModelsProvider modelsProvider
) {

}
 
Example #17
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 #18
Source File: PantsResolver.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private Optional<BuildGraph> constructBuildGraph(@NotNull DataNode<ProjectData> projectInfoDataNode) {
  Optional<BuildGraph> buildGraph;
  if (myExecutor.getOptions().incrementalImportDepth().isPresent()) {
    Optional<VirtualFile> pantsExecutable = PantsUtil.findPantsExecutable(projectInfoDataNode.getData().getLinkedExternalProjectPath());
    SimpleExportResult result = SimpleExportResult.getExportResult(pantsExecutable.get().getPath());
    if (PantsUtil.versionCompare(result.getVersion(), "1.0.9") < 0) {
      throw new PantsException(PantsBundle.message("pants.resolve.incremental.import.unsupported"));
    }
    buildGraph = Optional.of(new BuildGraph(myProjectInfo.getTargets()));
  }
  else {
    buildGraph = Optional.empty();
  }
  return buildGraph;
}
 
Example #19
Source File: AbstractExternalModuleImportProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * The whole import sequence looks like below:
 * <p>
 * <pre>
 * <ol>
 *   <li>Get project view from the gradle tooling api without resolving dependencies (downloading libraries);</li>
 *   <li>Allow to adjust project settings before importing;</li>
 *   <li>Create IJ project and modules;</li>
 *   <li>Ask gradle tooling api to resolve library dependencies (download the if necessary);</li>
 *   <li>Configure libraries used by the gradle project at intellij;</li>
 *   <li>Configure library dependencies;</li>
 * </ol>
 * </pre>
 * <p>
 *
 * @param projectWithResolvedLibraries gradle project with resolved libraries (libraries have already been downloaded and
 *                                     are available at file system under gradle service directory)
 * @param project                      current intellij project which should be configured by libraries and module library
 *                                     dependencies information available at the given gradle project
 */
private void setupLibraries(@Nonnull final DataNode<ProjectData> projectWithResolvedLibraries, final Project project) {
  ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {
    @RequiredUIAccess
    @Override
    public void execute() {
      ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
        @Override
        public void run() {
          if (ExternalSystemApiUtil.isNewProjectConstruction()) {
            // Clean existing libraries (if any).
            LibraryTable projectLibraryTable = ProjectLibraryTable.getInstance(project);
            if (projectLibraryTable == null) {
              LOG.warn("Can't resolve external dependencies of the target gradle project (" + project + "). Reason: project " + "library table is undefined");
              return;
            }
            LibraryTable.ModifiableModel model = projectLibraryTable.getModifiableModel();
            try {
              for (Library library : model.getLibraries()) {
                model.removeLibrary(library);
              }
            }
            finally {
              model.commit();
            }
          }

          // Register libraries.
          myProjectDataManager.importData(Collections.<DataNode<?>>singletonList(projectWithResolvedLibraries), project, false);
        }
      });
    }
  });
}
 
Example #20
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 #21
Source File: RemoteExternalSystemProjectResolver.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public DataNode<ProjectData> resolveProjectInfo(@Nonnull ExternalSystemTaskId id,
                                                @Nonnull String projectPath,
                                                boolean isPreviewMode,
                                                @javax.annotation.Nullable ExternalSystemExecutionSettings settings)
  throws ExternalSystemException, IllegalArgumentException, IllegalStateException
{
  return null;
}
 
Example #22
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 #23
Source File: PantsMetadataService.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void removeData(
  @NotNull Computable<Collection<Module>> toRemove,
  @NotNull Collection<DataNode<TargetMetadata>> toIgnore,
  @NotNull ProjectData projectData,
  @NotNull Project project,
  @NotNull IdeModifiableModelsProvider modelsProvider
) {
  for (Module module : toRemove.compute()) {
    module.clearOption(PantsConstants.PANTS_TARGET_ADDRESSES_KEY);
  }
}
 
Example #24
Source File: PantsMetadataService.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Computable<Collection<Module>> computeOrphanData(
  @NotNull Collection<DataNode<TargetMetadata>> toImport,
  @NotNull ProjectData projectData,
  @NotNull Project project,
  @NotNull IdeModifiableModelsProvider modelsProvider
) {
  return Collections::emptyList;
}
 
Example #25
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 #26
Source File: QuarkusProjectDataService.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void importData(@NotNull Collection<DataNode<LibraryDependencyData>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    for(DataNode<LibraryDependencyData> libraryNode : toImport) {
        String name = libraryNode.getData().getExternalName();
        if (name.startsWith("io.quarkus:")) {
            Module module = modelsProvider.findIdeModule(libraryNode.getData().getOwnerModule());
            if (module != null) {
                ensureQuarkusFacet(module, modelsProvider, libraryNode.getData().getOwner());
            }
        }

    }
}
 
Example #27
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 #28
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 #29
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 #30
Source File: PantsSystemProjectResolver.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public DataNode<ProjectData> resolveProjectInfo(
  @NotNull ExternalSystemTaskId id,
  @NotNull String projectPath,
  boolean isPreviewMode,
  @Nullable PantsExecutionSettings settings,
  @NotNull ExternalSystemTaskNotificationListener listener
) throws ExternalSystemException, IllegalArgumentException, IllegalStateException {
  if (projectPath.startsWith(".pants.d")) {
    return null;
  }

  checkForDifferentPantsExecutables(id, projectPath);
  final PantsCompileOptionsExecutor executor = PantsCompileOptionsExecutor.create(projectPath, settings);
  task2executor.put(id, executor);

  final DataNode<ProjectData> projectDataNode =
    resolveProjectInfoImpl(id, executor, listener, settings, isPreviewMode);

  // We do not want to repeatedly force switching to 'Project Files Tree' view if
  // user decides to use import dep as jar and wants to use the more focused 'Project' view.
  if (!settings.isImportSourceDepsAsJars()) {
    doViewSwitch(id, projectPath);
  }
  task2executor.remove(id);
  // Removing the existing modules right before returning to minimize the time user observes
  // that the old modules are gone.
  Optional.ofNullable(id.findProject()).ifPresent(p -> clearPantsModules(p, projectPath, projectDataNode));
  return projectDataNode;
}