Search in sources :

Example 6 with ModuleData

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

the class UniquePathModuleValidatorStrategy method fixAndReportFoundIssues.

@Override
void fixAndReportFoundIssues() {
    Set<String> modulePaths = myModulesByPath.keySet();
    for (String modulePath : modulePaths) {
        Collection<Module> modules = myModulesByPath.get(modulePath);
        int moduleCount = modules.size();
        if (moduleCount <= 1) {
            continue;
        }
        StringBuilder msg = new StringBuilder();
        msg.append("The modules [");
        int i = 0;
        Set<String> moduleNames = Sets.newHashSet();
        for (Module module : modules) {
            if (i++ != 0) {
                msg.append(", ");
            }
            String name = module.getName();
            moduleNames.add(name);
            msg.append("'").append(name).append("'");
        }
        msg.append("] point to same directory in the file system.");
        String[] lines = { msg.toString(), "Each module has to have a unique path." };
        SyncMessage message = new SyncMessage(PROJECT_STRUCTURE_ISSUES, ERROR, lines);
        List<DataNode<ModuleData>> modulesToDisplayInDialog = Lists.newArrayList();
        Project project = getProject();
        if (ProjectSubset.getInstance(project).isFeatureEnabled()) {
            DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(project).getCachedProjectData();
            if (projectInfo != null) {
                Collection<DataNode<ModuleData>> cachedModules = findAll(projectInfo, MODULE);
                for (DataNode<ModuleData> moduleNode : cachedModules) {
                    if (moduleNames.contains(moduleNode.getData().getExternalName())) {
                        modulesToDisplayInDialog.add(moduleNode);
                    }
                }
            }
        }
        if (!modulesToDisplayInDialog.isEmpty()) {
            message.add(new AddOrRemoveModulesHyperlink());
        }
        SyncMessages.getInstance(project).report(message);
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 7 with ModuleData

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

the class GradleProjectTaskRunner method addModulesBuildTasks.

private static void addModulesBuildTasks(@Nullable Collection<? extends ProjectTask> projectTasks, @NotNull MultiMap<String, String> cleanTasksMap, @NotNull MultiMap<String, String> buildTasksMap) {
    if (ContainerUtil.isEmpty(projectTasks))
        return;
    final CachedModuleDataFinder moduleDataFinder = new CachedModuleDataFinder();
    for (ProjectTask projectTask : projectTasks) {
        if (!(projectTask instanceof ModuleBuildTask))
            continue;
        ModuleBuildTask moduleBuildTask = (ModuleBuildTask) projectTask;
        Module module = moduleBuildTask.getModule();
        final String rootProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module);
        if (rootProjectPath == null)
            continue;
        final String projectId = ExternalSystemApiUtil.getExternalProjectId(module);
        if (projectId == null)
            continue;
        final String externalProjectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
        if (externalProjectPath == null || StringUtil.endsWith(externalProjectPath, "buildSrc"))
            continue;
        final DataNode<ModuleData> moduleDataNode = moduleDataFinder.findModuleData(module);
        if (moduleDataNode == null)
            continue;
        List<String> gradleTasks = ContainerUtil.mapNotNull(ExternalSystemApiUtil.findAll(moduleDataNode, ProjectKeys.TASK), node -> node.getData().isInherited() ? null : node.getData().getName());
        Collection<String> cleanRootTasks = cleanTasksMap.getModifiable(rootProjectPath);
        Collection<String> buildRootTasks = buildTasksMap.getModifiable(rootProjectPath);
        final String moduleType = ExternalSystemApiUtil.getExternalModuleType(module);
        String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
        if (gradlePath == null)
            continue;
        if (gradlePath.equals(":")) {
            gradlePath = "";
        }
        if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(moduleType)) {
            String sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
            String gradleTask = StringUtil.isEmpty(sourceSetName) || "main".equals(sourceSetName) ? "classes" : sourceSetName + "Classes";
            if (gradleTasks.contains(gradleTask)) {
                if (!moduleBuildTask.isIncrementalBuild()) {
                    cleanRootTasks.add(gradlePath + ":clean" + StringUtil.capitalize(gradleTask));
                }
                buildRootTasks.add(gradlePath + ":" + gradleTask);
            } else if ("main".equals(sourceSetName) || "test".equals(sourceSetName)) {
                if (!moduleBuildTask.isIncrementalBuild()) {
                    cleanRootTasks.add(gradlePath + ":clean");
                }
                buildRootTasks.add(gradlePath + ":build");
            }
        } else {
            if (!moduleBuildTask.isIncrementalBuild()) {
                if (gradleTasks.contains("classes")) {
                    cleanRootTasks.add((StringUtil.equals(rootProjectPath, externalProjectPath) ? ":cleanClasses" : gradlePath + ":cleanClasses"));
                } else if (gradleTasks.contains("clean")) {
                    cleanRootTasks.add((StringUtil.equals(rootProjectPath, externalProjectPath) ? "clean" : gradlePath + ":clean"));
                } else {
                    cleanTasksMap.getModifiable(externalProjectPath).add("clean");
                }
            }
            if (gradleTasks.contains("classes")) {
                buildRootTasks.add((StringUtil.equals(rootProjectPath, externalProjectPath) ? ":classes" : gradlePath + ":classes"));
            } else if (gradleTasks.contains("build")) {
                buildRootTasks.add((StringUtil.equals(rootProjectPath, externalProjectPath) ? "build" : gradlePath + ":build"));
            } else {
                buildTasksMap.getModifiable(externalProjectPath).add("build");
            }
        }
    }
}
Also used : ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) RunConfigurationModule(com.intellij.execution.configurations.RunConfigurationModule)

Example 8 with ModuleData

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

the class JavaEEGradleProjectResolverExtension method populateModuleExtraModels.

@Override
public void populateModuleExtraModels(@NotNull IdeaModule gradleModule, @NotNull final DataNode<ModuleData> ideModule) {
    final WebConfiguration webConfiguration = resolverCtx.getExtraProject(gradleModule, WebConfiguration.class);
    final NotNullLazyValue<DataNode<? extends ModuleData>> findTargetModuleNode = new NotNullLazyValue<DataNode<? extends ModuleData>>() {

        @NotNull
        @Override
        protected DataNode<? extends ModuleData> compute() {
            final String mainSourceSetModuleId = ideModule.getData().getId() + ":main";
            DataNode<? extends ModuleData> targetModuleNode = ExternalSystemApiUtil.find(ideModule, GradleSourceSetData.KEY, node -> mainSourceSetModuleId.equals(node.getData().getId()));
            if (targetModuleNode == null) {
                targetModuleNode = ideModule;
            }
            return targetModuleNode;
        }
    };
    if (webConfiguration != null) {
        final List<War> warModels = ContainerUtil.map(webConfiguration.getWarModels(), new Function<WebConfiguration.WarModel, War>() {

            @Override
            public War fun(WebConfiguration.WarModel model) {
                War war = new War(model.getWarName(), model.getWebAppDirName(), model.getWebAppDir());
                war.setWebXml(model.getWebXml());
                war.setWebResources(mapWebResources(model.getWebResources()));
                war.setClasspath(model.getClasspath());
                war.setManifestContent(model.getManifestContent());
                war.setArchivePath(model.getArchivePath());
                return war;
            }
        });
        findTargetModuleNode.getValue().createChild(WebConfigurationModelData.KEY, new WebConfigurationModelData(GradleConstants.SYSTEM_ID, warModels));
    }
    final EarConfiguration earConfiguration = resolverCtx.getExtraProject(gradleModule, EarConfiguration.class);
    if (earConfiguration != null) {
        final List<Ear> warModels = ContainerUtil.map(earConfiguration.getEarModels(), new Function<EarConfiguration.EarModel, Ear>() {

            @Override
            public Ear fun(EarConfiguration.EarModel model) {
                Ear ear = new Ear(model.getEarName(), model.getAppDirName(), model.getLibDirName());
                ear.setManifestContent(model.getManifestContent());
                ear.setDeploymentDescriptor(model.getDeploymentDescriptor());
                ear.setResources(mapEarResources(model.getResources()));
                ear.setArchivePath(model.getArchivePath());
                return ear;
            }
        });
        final Collection<DependencyData> deployDependencies = GradleProjectResolverUtil.getIdeDependencies(resolverCtx, findTargetModuleNode.getValue(), earConfiguration.getDeployDependencies());
        final Collection<DependencyData> earlibDependencies = GradleProjectResolverUtil.getIdeDependencies(resolverCtx, findTargetModuleNode.getValue(), earConfiguration.getEarlibDependencies());
        findTargetModuleNode.getValue().createChild(EarConfigurationModelData.KEY, new EarConfigurationModelData(GradleConstants.SYSTEM_ID, warModels, deployDependencies, earlibDependencies));
    }
    nextResolver.populateModuleExtraModels(gradleModule, ideModule);
}
Also used : DependencyData(com.intellij.openapi.externalSystem.model.project.DependencyData) NotNullLazyValue(com.intellij.openapi.util.NotNullLazyValue) EarConfiguration(org.jetbrains.plugins.gradle.model.ear.EarConfiguration) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) WebConfiguration(org.jetbrains.plugins.gradle.model.web.WebConfiguration)

Example 9 with ModuleData

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

the class GradleArgumentsCompletionProvider method getVariants.

protected List<LookupElement> getVariants(@NotNull final DataNode<ProjectData> projectDataNode, @NotNull final String modulePath) {
    final DataNode<ModuleData> moduleDataNode = findModuleDataNode(projectDataNode, modulePath);
    if (moduleDataNode == null) {
        return Collections.emptyList();
    }
    final ModuleData moduleData = moduleDataNode.getData();
    final boolean isRoot = projectDataNode.getData().getLinkedExternalProjectPath().equals(moduleData.getLinkedExternalProjectPath());
    final Collection<DataNode<TaskData>> tasks = ExternalSystemApiUtil.getChildren(moduleDataNode, ProjectKeys.TASK);
    List<LookupElement> elements = ContainerUtil.newArrayListWithCapacity(tasks.size());
    for (DataNode<TaskData> taskDataNode : tasks) {
        final TaskData taskData = taskDataNode.getData();
        elements.add(LookupElementBuilder.create(taskData.getName()).withIcon(ExternalSystemIcons.Task));
        if (!taskData.isInherited()) {
            elements.add(LookupElementBuilder.create((isRoot ? ':' : moduleData.getId() + ':') + taskData.getName()).withIcon(ExternalSystemIcons.Task));
        }
    }
    return elements;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) LookupElement(com.intellij.codeInsight.lookup.LookupElement) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

Example 10 with ModuleData

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

the class ProjectDataManager method importData.

@SuppressWarnings("unchecked")
public void importData(@NotNull Collection<DataNode<?>> nodes, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider, boolean synchronous) {
    if (project.isDisposed())
        return;
    MultiMap<Key<?>, DataNode<?>> grouped = ExternalSystemApiUtil.recursiveGroup(nodes);
    for (Key<?> key : myServices.getValue().keySet()) {
        if (!grouped.containsKey(key)) {
            grouped.put(key, Collections.<DataNode<?>>emptyList());
        }
    }
    final Collection<DataNode<?>> projects = grouped.get(ProjectKeys.PROJECT);
    // only one project(can be multi-module project) expected for per single import
    assert projects.size() == 1 || projects.isEmpty();
    final DataNode<ProjectData> projectNode = (DataNode<ProjectData>) ContainerUtil.getFirstItem(projects);
    final ProjectData projectData;
    ProjectSystemId projectSystemId;
    if (projectNode != null) {
        projectData = projectNode.getData();
        projectSystemId = projectNode.getData().getOwner();
        ExternalProjectsDataStorage.getInstance(project).saveInclusionSettings(projectNode);
    } else {
        projectData = null;
        DataNode<ModuleData> aModuleNode = (DataNode<ModuleData>) ContainerUtil.getFirstItem(grouped.get(ProjectKeys.MODULE));
        projectSystemId = aModuleNode != null ? aModuleNode.getData().getOwner() : null;
    }
    if (projectSystemId != null) {
        ExternalSystemUtil.scheduleExternalViewStructureUpdate(project, projectSystemId);
    }
    List<Runnable> onSuccessImportTasks = ContainerUtil.newSmartList();
    try {
        final Set<Map.Entry<Key<?>, Collection<DataNode<?>>>> entries = grouped.entrySet();
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null) {
            indicator.setIndeterminate(false);
        }
        final int size = entries.size();
        int count = 0;
        List<Runnable> postImportTasks = ContainerUtil.newSmartList();
        for (Map.Entry<Key<?>, Collection<DataNode<?>>> entry : entries) {
            if (indicator != null) {
                String message = ExternalSystemBundle.message("progress.update.text", projectSystemId != null ? projectSystemId.getReadableName() : "", "Refresh " + getReadableText(entry.getKey()));
                indicator.setText(message);
                indicator.setFraction((double) count++ / size);
            }
            doImportData(entry.getKey(), entry.getValue(), projectData, project, modelsProvider, postImportTasks, onSuccessImportTasks);
        }
        for (Runnable postImportTask : postImportTasks) {
            postImportTask.run();
        }
        commit(modelsProvider, project, synchronous, "Imported data");
        if (indicator != null) {
            indicator.setIndeterminate(true);
        }
    } catch (Throwable t) {
        dispose(modelsProvider, project, synchronous);
        ExceptionUtil.rethrowAllAsUnchecked(t);
    }
    for (Runnable onSuccessImportTask : ContainerUtil.reverse(onSuccessImportTasks)) {
        onSuccessImportTask.run();
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) MultiMap(com.intellij.util.containers.MultiMap) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Aggregations

ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)36 DataNode (com.intellij.openapi.externalSystem.model.DataNode)22 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)13 Module (com.intellij.openapi.module.Module)9 NotNull (org.jetbrains.annotations.NotNull)6 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)5 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)4 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)3 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)2 SourceFileContainerInfo (com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo)2 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)2 ModuleDependencyData (com.intellij.openapi.externalSystem.model.project.ModuleDependencyData)2 AbstractExternalSystemLocalSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings)2 ProjectNode (com.intellij.openapi.externalSystem.view.ProjectNode)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 Variant (com.android.builder.model.Variant)1