Search in sources :

Example 31 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.

the class GradleModuleWizardStep method updateComponents.

private void updateComponents() {
    final boolean isAddToVisible = myParentProjectForm.isVisible();
    myInheritGroupIdCheckBox.setVisible(isAddToVisible);
    myInheritVersionCheckBox.setVisible(isAddToVisible);
    myParentProjectForm.updateComponents();
    ProjectData parentProject = myParentProjectForm.getParentProject();
    if (parentProject == null) {
        myContext.putUserData(ExternalModuleSettingsStep.SKIP_STEP_KEY, Boolean.FALSE);
        myGroupIdField.setEnabled(true);
        myVersionField.setEnabled(true);
        myInheritGroupIdCheckBox.setEnabled(false);
        myInheritVersionCheckBox.setEnabled(false);
        setTestIfEmpty(myArtifactIdField, myBuilder.getName());
        setTestIfEmpty(myGroupIdField, "");
        setTestIfEmpty(myVersionField, DEFAULT_VERSION);
    } else {
        myContext.putUserData(ExternalModuleSettingsStep.SKIP_STEP_KEY, Boolean.TRUE);
        myGroupIdField.setEnabled(!myInheritGroupIdCheckBox.isSelected());
        myVersionField.setEnabled(!myInheritVersionCheckBox.isSelected());
        if (myInheritGroupIdCheckBox.isSelected() || myGroupIdField.getText().equals(myInheritedGroupId)) {
            myGroupIdField.setText(parentProject.getGroup());
        }
        if (myInheritVersionCheckBox.isSelected() || myVersionField.getText().equals(myInheritedVersion)) {
            myVersionField.setText(parentProject.getVersion());
        }
        myInheritedGroupId = myGroupIdField.getText();
        myInheritedVersion = myVersionField.getText();
        myInheritGroupIdCheckBox.setEnabled(true);
        myInheritVersionCheckBox.setEnabled(true);
    }
}
Also used : ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 32 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.

the class GradleModuleWizardStep method updateDataModel.

@Override
public void updateDataModel() {
    myContext.setProjectBuilder(myBuilder);
    ProjectData parentProject = myParentProjectForm.getParentProject();
    myBuilder.setParentProject(parentProject);
    myBuilder.setProjectId(new ProjectId(myGroupIdField.getText(), myArtifactIdField.getText(), myVersionField.getText()));
    myBuilder.setInheritGroupId(myInheritGroupIdCheckBox.isSelected());
    myBuilder.setInheritVersion(myInheritVersionCheckBox.isSelected());
    if (StringUtil.isNotEmpty(myBuilder.getProjectId().getArtifactId())) {
        myContext.setProjectName(myBuilder.getProjectId().getArtifactId());
    }
    if (parentProject != null) {
        myContext.setProjectFileDirectory(parentProject.getLinkedExternalProjectPath() + '/' + myContext.getProjectName());
    } else {
        if (myProjectOrNull != null) {
            myContext.setProjectFileDirectory(myProjectOrNull.getBaseDir().getPath() + '/' + myContext.getProjectName());
        }
    }
}
Also used : ProjectId(com.intellij.openapi.externalSystem.model.project.ProjectId) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 33 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.

the class GradleModuleWizardStep method updateStep.

@Override
public void updateStep() {
    ProjectData parentProject = myParentProjectForm.getParentProject();
    ProjectId projectId = myBuilder.getProjectId();
    if (projectId == null) {
        setTestIfEmpty(myArtifactIdField, myBuilder.getName());
        setTestIfEmpty(myGroupIdField, parentProject == null ? myBuilder.getName() : parentProject.getGroup());
        setTestIfEmpty(myVersionField, parentProject == null ? DEFAULT_VERSION : parentProject.getVersion());
    } else {
        setTestIfEmpty(myArtifactIdField, projectId.getArtifactId());
        setTestIfEmpty(myGroupIdField, projectId.getGroupId());
        setTestIfEmpty(myVersionField, projectId.getVersion());
    }
    myInheritGroupIdCheckBox.setSelected(myBuilder.isInheritGroupId());
    myInheritVersionCheckBox.setSelected(myBuilder.isInheritVersion());
    updateComponents();
}
Also used : ProjectId(com.intellij.openapi.externalSystem.model.project.ProjectId) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 34 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project kotlin by JetBrains.

the class ExternalSystemImportingTestCase method doImportProject.

private void doImportProject() {
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
    ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
    projectSettings.setExternalProjectPath(getProjectPath());
    @SuppressWarnings("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();
    ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(myProject, getExternalSystemId()).use(ProgressExecutionMode.MODAL_SYNC).callback(new ExternalProjectRefreshCallback() {

        @Override
        public void onSuccess(@Nullable 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));
        }
    }).forceWhenUptodate());
    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);
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) Couple(com.intellij.openapi.util.Couple) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 35 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project android by JetBrains.

the class ProjectSubset method findAndIncludeModuleContainingSourceFile.

/**
   * Finds and includes the module that contains the given file.
   * <p>
   * When using the "Project Subset" feature it is possible that the user knows which file she wants to edit but not the module where
   * such file is. This method tries to find the module that includes the given file in the folders that it marked as "source", either
   * production or test code.
   * </p>
   * <p>
   * The search is based on the Gradle models for both Android and Java modules. If the search finds more than one module that might contain
   * the file, the IDE will display a dialog where the user can see the potential matches and choose the module to include in the project.
   * </p>
   *
   * @param virtualFile the given file.
   */
public void findAndIncludeModuleContainingSourceFile(@NotNull VirtualFile virtualFile) {
    DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(myProject).getCachedProjectData();
    if (projectInfo == null) {
        return;
    }
    Collection<DataNode<ModuleData>> moduleInfos = findAll(projectInfo, MODULE);
    if (!moduleInfos.isEmpty()) {
        File file = virtualToIoFile(virtualFile);
        new Task.Modal(myProject, "Looking up Module", false) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                List<ModuleSearchResult> results = Lists.newArrayList();
                String[] storedSelection = getSelection();
                Set<String> selection = storedSelection != null ? Sets.newHashSet(storedSelection) : Sets.newHashSet();
                List<DataNode<ModuleData>> selectedModules = Lists.newArrayList();
                int doneCount = 0;
                for (DataNode<ModuleData> moduleNode : moduleInfos) {
                    indicator.setFraction(++doneCount / moduleInfos.size());
                    ModuleData module = moduleNode.getData();
                    String name = module.getExternalName();
                    boolean selected = selection.contains(name);
                    if (selected) {
                        // This module is already included in the project. We need to mark it as "selected" so when we are done searching we don't
                        // exclude it by accident.
                        selectedModules.add(moduleNode);
                    }
                    ModuleSearchResult result = containsSourceFile(moduleNode, file, selected);
                    if (result != null) {
                        // Even though the module is already included, we add it to the search results, because the module might not be the one that
                        // actually contains the file, and the user might need to exclude it in the case that the module that contains the file has
                        // the same path as the already-included module.
                        results.add(result);
                    }
                }
                int resultCount = results.size();
                if (resultCount == 0) {
                    // Nothing found.
                    invokeLaterIfNeeded(() -> {
                        String text = String.format("Unable to find a module containing the file '%1$s' in a source directory.", file.getName());
                        AndroidGradleNotification notification = AndroidGradleNotification.getInstance(ProjectSubset.this.myProject);
                        notification.showBalloon(MODULE_LOOKUP_MESSAGE_TITLE, text, ERROR);
                    });
                } else if (resultCount == 1) {
                    // If there is one result,just apply it.
                    addResultAndPopulateProject(results.get(0), projectInfo, selectedModules, file);
                } else {
                    // We need to let user decide which modules to include.
                    showModuleSelectionDialog(results, projectInfo, selectedModules, file);
                }
            }
        }.queue();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Aggregations

ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)40 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)13 DataNode (com.intellij.openapi.externalSystem.model.DataNode)12 Project (com.intellij.openapi.project.Project)8 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)4 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)4 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MultiMap (com.intellij.util.containers.MultiMap)4 NotNull (org.jetbrains.annotations.NotNull)4 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)3 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)3 Module (com.intellij.openapi.module.Module)3 Task (com.intellij.openapi.progress.Task)3 DataNodeCaches (com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches)2 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)2 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)2