com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings Java Examples

The following examples show how to use com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings. 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: ExternalSystemApiUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
public static AbstractExternalSystemSettings getSettings(@Nonnull Project project, @Nonnull ProjectSystemId externalSystemId)
        throws IllegalArgumentException {
  ExternalSystemManager<?, ?, ?, ?, ?> manager = getManager(externalSystemId);
  if (manager == null) {
    throw new IllegalArgumentException(String.format("Can't retrieve external system settings for id '%s'. Reason: no such external system is registered",
                                                     externalSystemId.getReadableName()));
  }
  return manager.getSettingsProvider().fun(project);
}
 
Example #2
Source File: AbstractExternalModuleImportProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void executeAndRestoreDefaultProjectSettings(@Nonnull Project project, @Nonnull Runnable task) {
  if (!project.isDefault()) {
    task.run();
    return;
  }

  AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
  Object systemStateToRestore = null;
  if (systemSettings instanceof PersistentStateComponent) {
    systemStateToRestore = ((PersistentStateComponent)systemSettings).getState();
  }
  systemSettings.copyFrom(myControl.getSystemSettings());
  Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings();
  systemSettings.setLinkedProjectsSettings(Collections.singleton(getCurrentExternalProjectSettings()));
  try {
    task.run();
  }
  finally {
    if (systemStateToRestore != null) {
      ((PersistentStateComponent)systemSettings).loadState(systemStateToRestore);
    }
    else {
      systemSettings.setLinkedProjectsSettings(projectSettingsToRestore);
    }
  }
}
 
Example #3
Source File: ProjectRenameAware.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void beAware(@Nonnull Project project) {
  final ExternalSystemFacadeManager facadeManager = ServiceManager.getService(ExternalSystemFacadeManager.class);
  for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
    AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
    //noinspection unchecked
    settings.subscribe(new ExternalSystemSettingsListenerAdapter() {
      @Override
      public void onProjectRenamed(@Nonnull String oldName, @Nonnull String newName) {
        facadeManager.onProjectRename(oldName, newName);
      }
    });
  }
}
 
Example #4
Source File: ExternalSystemAutoImporter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void letTheMagicBegin(@Nonnull Project project) {
  List<MyEntry> autoImportAware = ContainerUtilRt.newArrayList();
  Collection<ExternalSystemManager<?, ?, ?, ?, ?>> managers = ExternalSystemApiUtil.getAllManagers();
  for (ExternalSystemManager<?, ?, ?, ?, ?> manager : managers) {
    AbstractExternalSystemSettings<?, ?, ?> systemSettings = manager.getSettingsProvider().fun(project);
    ExternalSystemAutoImportAware defaultImportAware = createDefault(systemSettings);
    final ExternalSystemAutoImportAware aware;
    if (manager instanceof ExternalSystemAutoImportAware) {
      aware = combine(defaultImportAware, (ExternalSystemAutoImportAware)manager);
    }
    else {
      aware = defaultImportAware;
    }
    autoImportAware.add(new MyEntry(manager.getSystemId(), systemSettings, aware));
  }

  MyEntry[] entries = autoImportAware.toArray(new MyEntry[autoImportAware.size()]);
  ExternalSystemAutoImporter autoImporter = new ExternalSystemAutoImporter(
    project,
    ServiceManager.getService(ProjectDataManager.class),
    entries
  );
  final MessageBus messageBus = project.getMessageBus();
  messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, autoImporter);

  EditorFactory.getInstance().getEventMulticaster().addDocumentListener(autoImporter, project);
}
 
Example #5
Source File: ExternalSystemAutoImporter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static ExternalSystemAutoImportAware createDefault(@Nonnull final AbstractExternalSystemSettings<?, ?, ?> systemSettings) {
  return new ExternalSystemAutoImportAware() {
    @javax.annotation.Nullable
    @Override
    public String getAffectedExternalProjectPath(@Nonnull String changedFileOrDirPath, @Nonnull Project project) {
      return systemSettings.getLinkedProjectSettings(changedFileOrDirPath) == null ? null : changedFileOrDirPath;
    }
  };
}
 
Example #6
Source File: ExternalSystemAutoImporter.java    From consulo with Apache License 2.0 5 votes vote down vote up
MyEntry(@Nonnull ProjectSystemId externalSystemId,
        @Nonnull AbstractExternalSystemSettings<?, ?, ?> systemSettings,
        @Nonnull ExternalSystemAutoImportAware aware)
{
  this.externalSystemId = externalSystemId;
  this.systemSettings = systemSettings;
  this.aware = aware;
}
 
Example #7
Source File: AbstractExternalSystemToolWindowCondition.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean value(Project project) {
  if (project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE) {
    return true;
  }
  ExternalSystemManager<?,?,?,?,?> manager = ExternalSystemApiUtil.getManager(myExternalSystemId);
  if (manager == null) {
    return false;
  }
  AbstractExternalSystemSettings<?, ?,?> settings = manager.getSettingsProvider().fun(project);
  return settings != null && !settings.getLinkedProjectsSettings().isEmpty();
}
 
Example #8
Source File: ExternalActionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static MyInfo getProcessingInfo(@Nonnull DataContext context) {
  ExternalProjectPojo externalProject = context.getData(ExternalSystemDataKeys.SELECTED_PROJECT);
  if (externalProject == null) {
    return MyInfo.EMPTY;
  }

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

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

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

  return new MyInfo(externalProjectSettings == null ? null : settings,
                    localSettings == null ? null : localSettings,
                    externalProjectSettings == null ? null : externalProject,
                    ideProject,
                    externalSystemId);
}
 
Example #9
Source File: ExternalActionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
MyInfo(@Nullable AbstractExternalSystemSettings<?, ?, ?> settings,
       @Nullable AbstractExternalSystemLocalSettings localSettings,
       @javax.annotation.Nullable ExternalProjectPojo externalProject,
       @javax.annotation.Nullable Project ideProject,
       @Nullable ProjectSystemId externalSystemId)
{
  this.settings = settings;
  this.localSettings = localSettings;
  this.externalProject = externalProject;
  this.ideProject = ideProject;
  this.externalSystemId = externalSystemId;
}
 
Example #10
Source File: ExternalSystemImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
private void doImportProject() {
  AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
  final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
  projectSettings.setExternalProjectPath(getProjectPath());
  //noinspection unchecked
  Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
  projects.remove(projectSettings);
  projects.add(projectSettings);
  //noinspection unchecked
  systemSettings.setLinkedProjectsSettings(projects);

  final Ref<Couple<String>> error = Ref.create();
  ImportSpec importSpec = createImportSpec();
  if (importSpec.getCallback() == null) {
    importSpec = new ImportSpecBuilder(importSpec).callback(new ExternalProjectRefreshCallback() {
      @Override
      public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
        if (externalProject == null) {
          System.err.println("Got null External project after import");
          return;
        }
        ServiceManager.getService(ProjectDataManager.class).importData(externalProject, myProject, true);
        System.out.println("External project was successfully imported");
      }

      @Override
      public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
        error.set(Couple.of(errorMessage, errorDetails));
      }
    }).build();
  }

  ExternalSystemProgressNotificationManager notificationManager =
    ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
  ExternalSystemTaskNotificationListenerAdapter listener = new ExternalSystemTaskNotificationListenerAdapter() {
    @Override
    public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
      if (StringUtil.isEmptyOrSpaces(text)) return;
      (stdOut ? System.out : System.err).print(text);
    }
  };
  notificationManager.addNotificationListener(listener);
  try {
    ExternalSystemUtil.refreshProjects(importSpec);
  }
  finally {
    notificationManager.removeNotificationListener(listener);
  }

  if (!error.isNull()) {
    String failureMsg = "Import failed: " + error.get().first;
    if (StringUtil.isNotEmpty(error.get().second)) {
      failureMsg += "\nError details: \n" + error.get().second;
    }
    fail(failureMsg);
  }
}
 
Example #11
Source File: AbstractExternalModuleImportProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull ExternalModuleImportContext<C> context, @Nonnull final Project project, @Nonnull ModifiableModuleModel model, @Nonnull Consumer<Module> newModuleConsumer) {
  project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);
  final DataNode<ProjectData> externalProjectNode = getExternalProjectNode();
  if (externalProjectNode != null) {
    beforeCommit(externalProjectNode, project);
  }

  StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
    @SuppressWarnings("unchecked")
    @Override
    public void run() {
      AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
      final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
      Set<ExternalProjectSettings> projects = ContainerUtilRt.<ExternalProjectSettings>newHashSet(systemSettings.getLinkedProjectsSettings());
      // add current importing project settings to linked projects settings or replace if similar already exist
      projects.remove(projectSettings);
      projects.add(projectSettings);

      systemSettings.copyFrom(myControl.getSystemSettings());
      systemSettings.setLinkedProjectsSettings(projects);

      if (externalProjectNode != null) {
        ExternalSystemUtil.ensureToolWindowInitialized(project, myExternalSystemId);
        ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {
          @RequiredUIAccess
          @Override
          public void execute() {
            ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
              @Override
              public void run() {
                myProjectDataManager.importData(externalProjectNode.getKey(), Collections.singleton(externalProjectNode), project, true);
                myExternalProjectNode = null;
              }
            });
          }
        });

        final Runnable resolveDependenciesTask = new Runnable() {
          @Override
          public void run() {
            String progressText = ExternalSystemBundle.message("progress.resolve.libraries", myExternalSystemId.getReadableName());
            ProgressManager.getInstance().run(new Task.Backgroundable(project, progressText, false) {
              @Override
              public void run(@Nonnull final ProgressIndicator indicator) {
                if (project.isDisposed()) return;
                ExternalSystemResolveProjectTask task = new ExternalSystemResolveProjectTask(myExternalSystemId, project, projectSettings.getExternalProjectPath(), false);
                task.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
                DataNode<ProjectData> projectWithResolvedLibraries = task.getExternalProject();
                if (projectWithResolvedLibraries == null) {
                  return;
                }

                setupLibraries(projectWithResolvedLibraries, project);
              }
            });
          }
        };
        UIUtil.invokeLaterIfNeeded(resolveDependenciesTask);
      }
    }
  });
}
 
Example #12
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Asks to refresh all external projects of the target external system linked to the given ide project based on provided spec
 *
 * @param specBuilder import specification builder
 */
public static void refreshProjects(@Nonnull final ImportSpecBuilder specBuilder) {
  ImportSpec spec = specBuilder.build();

  ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(spec.getExternalSystemId());
  if (manager == null) {
    return;
  }
  AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(spec.getProject());
  final Collection<? extends ExternalProjectSettings> projectsSettings = settings.getLinkedProjectsSettings();
  if (projectsSettings.isEmpty()) {
    return;
  }

  final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
  final int[] counter = new int[1];

  ExternalProjectRefreshCallback callback =
          new MyMultiExternalProjectRefreshCallback(spec.getProject(), projectDataManager, counter, spec.getExternalSystemId());

  Map<String, Long> modificationStamps = manager.getLocalSettingsProvider().fun(spec.getProject()).getExternalConfigModificationStamps();
  Set<String> toRefresh = ContainerUtilRt.newHashSet();
  for (ExternalProjectSettings setting : projectsSettings) {

    // don't refresh project when auto-import is disabled if such behavior needed (e.g. on project opening when auto-import is disabled)
    if (!setting.isUseAutoImport() && spec.isWhenAutoImportEnabled()) continue;

    if (spec.isForceWhenUptodate()) {
      toRefresh.add(setting.getExternalProjectPath());
    }
    else {
      Long oldModificationStamp = modificationStamps.get(setting.getExternalProjectPath());
      long currentModificationStamp = getTimeStamp(setting, spec.getExternalSystemId());
      if (oldModificationStamp == null || oldModificationStamp < currentModificationStamp) {
        toRefresh.add(setting.getExternalProjectPath());
      }
    }
  }

  if (!toRefresh.isEmpty()) {
    ExternalSystemNotificationManager.getInstance(spec.getProject()).clearNotifications(null, NotificationSource.PROJECT_SYNC, spec.getExternalSystemId());

    counter[0] = toRefresh.size();
    for (String path : toRefresh) {
      refreshProject(spec.getProject(), spec.getExternalSystemId(), path, callback, false, spec.getProgressExecutionMode());
    }
  }
}
 
Example #13
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 #14
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Tries to obtain external project info implied by the given settings and link that external project to the given ide project.
 *
 * @param externalSystemId        target external system
 * @param projectSettings         settings of the external project to link
 * @param project                 target ide project to link external project to
 * @param executionResultCallback it might take a while to resolve external project info, that's why it's possible to provide
 *                                a callback to be notified on processing result. It receives <code>true</code> if an external
 *                                project has been successfully linked to the given ide project;
 *                                <code>false</code> otherwise (note that corresponding notification with error details is expected
 *                                to be shown to the end-user then)
 * @param isPreviewMode           flag which identifies if missing external project binaries should be downloaded
 * @param progressExecutionMode   identifies how progress bar will be represented for the current processing
 */
@SuppressWarnings("UnusedDeclaration")
public static void linkExternalProject(@Nonnull final ProjectSystemId externalSystemId,
                                       @Nonnull final ExternalProjectSettings projectSettings,
                                       @Nonnull final Project project,
                                       @Nullable final Consumer<Boolean> executionResultCallback,
                                       boolean isPreviewMode,
                                       @Nonnull final ProgressExecutionMode progressExecutionMode) {
  ExternalProjectRefreshCallback callback = new ExternalProjectRefreshCallback() {
    @SuppressWarnings("unchecked")
    @Override
    public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
      if (externalProject == null) {
        if (executionResultCallback != null) {
          executionResultCallback.consume(false);
        }
        return;
      }
      AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, externalSystemId);
      Set<ExternalProjectSettings> projects = ContainerUtilRt.<ExternalProjectSettings>newHashSet(systemSettings.getLinkedProjectsSettings());
      projects.add(projectSettings);
      systemSettings.setLinkedProjectsSettings(projects);
      ensureToolWindowInitialized(project, externalSystemId);
      ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {
        @RequiredUIAccess
        @Override
        public void execute() {
          ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
            @Override
            public void run() {
              ProjectDataManager dataManager = ServiceManager.getService(ProjectDataManager.class);
              dataManager.importData(externalProject.getKey(), Collections.singleton(externalProject), project, true);
            }
          });
        }
      });
      if (executionResultCallback != null) {
        executionResultCallback.consume(true);
      }
    }

    @Override
    public void onFailure(@Nonnull String errorMessage, @Nullable String errorDetails) {
      if (executionResultCallback != null) {
        executionResultCallback.consume(false);
      }
    }
  };
  refreshProject(project, externalSystemId, projectSettings.getExternalProjectPath(), callback, isPreviewMode, progressExecutionMode);
}