Search in sources :

Example 46 with ModifiableRootModel

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

the class RubyMotionFacetConfigurator method configure.

public static void configure(VirtualFile baseDir, Module module) {
    final RubyMotionFacet existingFacet = RubyMotionFacet.getInstance(module);
    if (existingFacet != null) {
        return;
    }
    FacetManager facetManager = FacetManager.getInstance(module);
    final ModifiableFacetModel model = facetManager.createModifiableModel();
    RubyMotionFacetType facetType = RubyMotionFacetType.getInstance();
    RubyMotionFacetConfiguration configuration = ProjectFacetManager.getInstance(module.getProject()).createDefaultConfiguration(facetType);
    //configuration.setProjectRootPath(baseDir.getPath());
    VirtualFile testFolder = baseDir.findChild("spec");
    final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    if (testFolder != null) {
        //configuration.setTestPath(testFolder.getPath());
        addTestSources(testFolder, rootModel);
    }
    VirtualFile libFolder = baseDir.findChild("app");
    if (libFolder != null) {
    //configuration.setLibPath(libFolder.getPath());
    }
    RubyMotionFacet.updateMotionLibrary(rootModel);
    IdeaInternalUtil.runInsideWriteAction(new ActionRunner.InterruptibleRunnable() {

        public void run() throws Exception {
            rootModel.commit();
        }
    });
    RubyMotionFacet facet = facetManager.createFacet(facetType, facetType.getDefaultFacetName(), configuration, null);
    model.addFacet(facet);
    new WriteAction() {

        protected void run(@NotNull final Result result) throws Throwable {
            model.commit();
        }
    }.execute();
    RubyMotionUtilExt.createMotionRunConfiguration(module);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionRunner(com.intellij.util.ActionRunner) WriteAction(com.intellij.openapi.application.WriteAction) RubyMotionFacetType(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacetType) RubyMotionFacetConfiguration(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacetConfiguration) Result(com.intellij.openapi.application.Result) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) RubyMotionFacet(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacet) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) FacetManager(com.intellij.facet.FacetManager)

Example 47 with ModifiableRootModel

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

the class AndroidEclipseNatureImporter method doImport.

@Override
public void doImport(@NotNull Project project, @NotNull List<Module> modules) {
    for (Module module : modules) {
        final VirtualFile contentRoot = chooseMainContentRoot(module);
        if (contentRoot == null) {
            AndroidUtils.reportImportErrorToEventLog("Cannot find content root containing " + SdkConstants.FN_ANDROID_MANIFEST_XML + " file", module.getName(), project);
            continue;
        }
        final AndroidFacet facet = AndroidUtils.addAndroidFacetInWriteAction(module, contentRoot, false);
        final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
        AndroidFrameworkDetector.doImportSdkAndFacetConfiguration(facet, modifiableModel);
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            @Override
            public void run() {
                modifiableModel.commit();
            }
        });
    }
    ImportDependenciesUtil.doImportDependencies(project, modules, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 48 with ModifiableRootModel

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

the class NewProjectImportGradleSyncListener method createTopLevelModule.

@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    File projectRootDir = getBaseDirPath(project);
    VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
    if (contentRoot != null) {
        File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
        Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
        // This prevents the balloon "Unsupported Modules detected".
        ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        model.addContentEntry(contentRoot);
        if (IdeInfo.getInstance().isAndroidStudio()) {
            // If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
            // users will update build.gradle files to fix Gradle sync.)
            // See: https://code.google.com/p/android/issues/detail?id=194621
            Sdk jdk = IdeSdks.getInstance().getJdk();
            if (jdk != null) {
                model.setSdk(jdk);
            }
        }
        model.commit();
        FacetManager facetManager = FacetManager.getInstance(module);
        ModifiableFacetModel facetModel = facetManager.createModifiableModel();
        try {
            GradleFacet gradleFacet = GradleFacet.getInstance(module);
            if (gradleFacet == null) {
                // Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
                gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
                facetModel.addFacet(gradleFacet);
            }
            gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
            // Add "android" facet to avoid the balloon "Android Framework detected".
            AndroidFacet androidFacet = AndroidFacet.getInstance(module);
            if (androidFacet == null) {
                androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
                facetModel.addFacet(androidFacet);
            }
            // This is what actually stops Studio from showing the balloon.
            androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
        } finally {
            facetModel.commit();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) Sdk(com.intellij.openapi.projectRoots.Sdk) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 49 with ModifiableRootModel

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

the class PostProjectBuildTasksExecutor method excludeOutputFolders.

private static void excludeOutputFolders(@NotNull AndroidFacet facet) {
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel == null) {
        return;
    }
    File buildFolderPath = androidModel.getAndroidProject().getBuildFolder();
    if (!buildFolderPath.isDirectory()) {
        return;
    }
    Module module = facet.getModule();
    if (module.getProject().isDisposed()) {
        return;
    }
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
    try {
        ContentEntry[] contentEntries = rootModel.getContentEntries();
        ContentEntry parent = findParentContentEntry(buildFolderPath, contentEntries);
        if (parent == null) {
            rootModel.dispose();
            return;
        }
        List<File> excludedFolderPaths = androidModel.getExcludedFolderPaths();
        for (File folderPath : excludedFolderPaths) {
            parent.addExcludeFolder(pathToIdeaUrl(folderPath));
        }
    } finally {
        if (!rootModel.isDisposed()) {
            rootModel.commit();
        }
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) FilePaths.findParentContentEntry(com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 50 with ModifiableRootModel

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

the class ProjectStructureCleanupStep method cleanUpProject.

@Override
public void cleanUpProject(@NotNull Project project, @NotNull IdeModifiableModelsProvider ideModifiableModelsProvider, @Nullable ProgressIndicator indicator) {
    Set<Sdk> androidSdks = new HashSet<>();
    for (Module module : ideModifiableModelsProvider.getModules()) {
        ModifiableRootModel rootModel = ideModifiableModelsProvider.getModifiableRootModel(module);
        adjustInterModuleDependencies(module, ideModifiableModelsProvider);
        Sdk sdk = rootModel.getSdk();
        if (sdk != null) {
            if (myAndroidSdks.isAndroidSdk(sdk)) {
                androidSdks.add(sdk);
            }
            continue;
        }
        NativeAndroidProject nativeAndroidProject = getNativeAndroidProject(module);
        if (nativeAndroidProject != null) {
            // Native modules does not need any jdk entry.
            continue;
        }
        Sdk jdk = IdeSdks.getInstance().getJdk();
        rootModel.setSdk(jdk);
    }
    for (Sdk sdk : androidSdks) {
        myAndroidSdks.refreshLibrariesIn(sdk);
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) GradleUtil.getNativeAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) HashSet(java.util.HashSet)

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