Search in sources :

Example 36 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.

the class Flexmojos3GenerateConfigTask method updateMainClass.

public static void updateMainClass(final Module module, final VirtualFile configFile) {
    // Project Structure open
    if (FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor() != null)
        return;
    try {
        final String mainClassPath = FlexUtils.findXMLElement(configFile.getInputStream(), "<flex-config><file-specs><path-element>");
        final VirtualFile mainClassFile = mainClassPath == null ? null : LocalFileSystem.getInstance().findFileByPath(mainClassPath);
        if (mainClassFile == null || mainClassFile.isDirectory())
            return;
        final VirtualFile sourceRoot = ProjectRootManager.getInstance(module.getProject()).getFileIndex().getSourceRootForFile(mainClassFile);
        final String relativePath = sourceRoot == null ? null : VfsUtilCore.getRelativePath(mainClassFile, sourceRoot, '/');
        final String mainClass = relativePath == null ? mainClassFile.getNameWithoutExtension() : FileUtil.getNameWithoutExtension(relativePath).replace('/', '.');
        final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
        final LibraryTable.ModifiableModel librariesModel = ProjectLibraryTable.getInstance(module.getProject()).getModifiableModel();
        final FlexProjectConfigurationEditor flexEditor = FlexProjectConfigurationEditor.createEditor(module.getProject(), Collections.singletonMap(module, modifiableModel), librariesModel, null);
        final ModifiableFlexBuildConfiguration[] bcs = flexEditor.getConfigurations(module);
        final ModifiableFlexBuildConfiguration mainBC = ContainerUtil.find(bcs, bc -> bc.getOutputType() == OutputType.Application && module.getName().equals(bc.getName()));
        if (mainBC != null) {
            mainBC.setMainClass(mainClass);
        }
        flexEditor.commit();
        Disposer.dispose(librariesModel);
        modifiableModel.dispose();
    } catch (IOException ignore) {
    /**/
    } catch (ConfigurationException ignore) {
    /**/
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ConfigurationException(com.intellij.openapi.options.ConfigurationException) IOException(java.io.IOException) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)

Example 37 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.

the class FlashBuilderImporter method commit.

public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
    //FlexModuleBuilder.setupResourceFilePatterns(project);
    final boolean needToCommit = model == null;
    final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
    final List<String> paths = getList();
    final boolean isArchive = paths.size() == 1 && FlashBuilderProjectFinder.hasArchiveExtension(paths.get(0));
    final List<String> dotProjectPaths = getDotProjectPaths(project);
    final List<FlashBuilderProject> flashBuilderProjects = FlashBuilderProjectLoadUtil.loadProjects(dotProjectPaths, isArchive);
    final Map<FlashBuilderProject, ModifiableRootModel> flashBuilderProjectToModifiableModelMap = new THashMap<>();
    final Map<Module, ModifiableRootModel> moduleToModifiableModelMap = new THashMap<>();
    final Set<String> moduleNames = new THashSet<>(flashBuilderProjects.size());
    final FlexProjectConfigurationEditor currentFlexEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
    assert needToCommit == (currentFlexEditor == null);
    for (FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
        final String moduleName = makeUnique(flashBuilderProject.getName(), moduleNames);
        moduleNames.add(moduleName);
        final String moduleFilePath = flashBuilderProject.getProjectRootPath() + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
        if (LocalFileSystem.getInstance().findFileByPath(moduleFilePath) != null) {
            ApplicationManager.getApplication().runWriteAction(() -> ModuleBuilder.deleteModuleFile(moduleFilePath));
        }
        final Module module = moduleModel.newModule(moduleFilePath, FlexModuleType.getInstance().getId());
        final ModifiableRootModel rootModel = currentFlexEditor != null ? currentFlexEditor.getModifiableRootModel(module) : ModuleRootManager.getInstance(module).getModifiableModel();
        flashBuilderProjectToModifiableModelMap.put(flashBuilderProject, rootModel);
        moduleToModifiableModelMap.put(module, rootModel);
    }
    final FlexProjectConfigurationEditor flexConfigEditor = currentFlexEditor != null ? currentFlexEditor : FlexProjectConfigurationEditor.createEditor(project, moduleToModifiableModelMap, null, null);
    final FlashBuilderSdkFinder sdkFinder = new FlashBuilderSdkFinder(project, getParameters().myInitiallySelectedPath, flashBuilderProjects);
    final FlashBuilderModuleImporter flashBuilderModuleImporter = new FlashBuilderModuleImporter(project, flexConfigEditor, flashBuilderProjects, sdkFinder);
    for (final FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
        flashBuilderModuleImporter.setupModule(flashBuilderProjectToModifiableModelMap.get(flashBuilderProject), flashBuilderProject);
    }
    if (needToCommit) {
        try {
            flexConfigEditor.commit();
        } catch (ConfigurationException e) {
            Logger.getInstance(FlashBuilderImporter.class).error(e);
        }
        ApplicationManager.getApplication().runWriteAction(() -> {
            ModifiableModelCommitter.multiCommit(moduleToModifiableModelMap.values(), moduleModel);
        });
    }
    return new ArrayList<>(moduleToModifiableModelMap.keySet());
}
Also used : THashSet(gnu.trove.THashSet) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) THashMap(gnu.trove.THashMap) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module)

Example 38 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class CompilerOutputModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    File mainClassesFolder = null;
    File testClassesFolder = null;
    ExtIdeaCompilerOutput compilerOutput = javaModuleModel.getCompilerOutput();
    if (compilerOutput == null) {
        File buildFolderPath = javaModuleModel.getBuildFolderPath();
        if (buildFolderPath != null) {
            mainClassesFolder = new File(buildFolderPath, join(CLASSES_FOLDER_NAME, "main"));
            testClassesFolder = new File(buildFolderPath, join(CLASSES_FOLDER_NAME, "test"));
        }
    } else {
        mainClassesFolder = compilerOutput.getMainClassesDir();
        testClassesFolder = compilerOutput.getTestClassesDir();
    }
    if (mainClassesFolder != null) {
        // This folder is null for modules that are just folders containing other modules. This type of modules are later on removed by
        // PostProjectSyncTaskExecutor.
        ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
        myCompilerSettingsSetup.setOutputPaths(moduleModel, mainClassesFolder, testClassesFolder);
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ExtIdeaCompilerOutput(org.jetbrains.plugins.gradle.model.ExtIdeaCompilerOutput) File(java.io.File)

Example 39 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class ContentRootsModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    JavaContentEntriesSetup setup = new JavaContentEntriesSetup(javaModuleModel, moduleModel);
    List<ContentEntry> contentEntries = findContentEntries(moduleModel, javaModuleModel);
    setup.execute(contentEntries);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 40 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class DependenciesModuleSetupStep method updateDependency.

private static void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JavaModuleDependency dependency) {
    DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
    String moduleName = dependency.getModuleName();
    Module found = null;
    for (Module m : modelsProvider.getModules()) {
        if (moduleName.equals(m.getName())) {
            found = m;
        }
    }
    ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
    if (found != null) {
        AndroidFacet androidFacet = findFacet(found, modelsProvider, AndroidFacet.ID);
        if (androidFacet == null) {
            ModuleOrderEntry entry = moduleModel.addModuleOrderEntry(found);
            entry.setExported(true);
        } else {
            // If it depends on an android module, we should skip that.
            setupErrors.addInvalidModuleDependency(moduleModel.getModule(), found.getName(), "Java modules cannot depend on Android modules");
        }
        return;
    }
    setupErrors.addMissingModule(moduleName, module.getName(), null);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) DependencySetupErrors(com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)102 Module (com.intellij.openapi.module.Module)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 ContentEntry (com.intellij.openapi.roots.ContentEntry)27 File (java.io.File)18 Library (com.intellij.openapi.roots.libraries.Library)15 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)14 ModuleManager (com.intellij.openapi.module.ModuleManager)8 Sdk (com.intellij.openapi.projectRoots.Sdk)8 IOException (java.io.IOException)8 NotNull (org.jetbrains.annotations.NotNull)8 OrderEntry (com.intellij.openapi.roots.OrderEntry)7 Project (com.intellij.openapi.project.Project)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Nullable (org.jetbrains.annotations.Nullable)6 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)5 ConfigurationException (com.intellij.openapi.options.ConfigurationException)5 THashMap (gnu.trove.THashMap)5 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)4 AccessToken (com.intellij.openapi.application.AccessToken)4