Search in sources :

Example 31 with ModifiableRootModel

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

the class FacetDetectionTest method testDetectBundlorFacet.

@Test
public void testDetectBundlorFacet() {
    ModuleManager moduleManager = ModuleManager.getInstance(myFixture.getProject());
    Module t2 = moduleManager.findModuleByName("t2");
    assertNotNull(t2);
    OsmorcFrameworkDetector detector = new OsmorcFrameworkDetector();
    ElementPattern<FileContent> filter = detector.createSuitableFilePattern();
    VirtualFile manifestFile = myTempDirFixture.getFile("t2/src/META-INF/template.mf");
    assertThat(filter.accepts(FileContentImpl.createByFile(manifestFile)), equalTo(true));
    OsmorcFacetConfiguration facetConfiguration = detector.createConfiguration(Collections.singletonList(manifestFile));
    assertNotNull(facetConfiguration);
    assertThat(facetConfiguration.getManifestLocation(), equalTo(manifestFile.getPath()));
    assertThat(facetConfiguration.isUseProjectDefaultManifestFileLocation(), equalTo(false));
    OsmorcFacet facet = OsmorcFacetType.getInstance().createFacet(t2, "OSGi", facetConfiguration, null);
    ModifiableRootModel model = ModuleRootManager.getInstance(t2).getModifiableModel();
    try {
        detector.setupFacet(facet, model);
        assertThat(facetConfiguration.getManifestLocation(), equalTo(""));
        assertThat(facetConfiguration.getBundlorFileLocation(), equalTo("src/META-INF/template.mf"));
        assertThat(facetConfiguration.isUseBundlorFile(), equalTo(true));
    } finally {
        model.dispose();
    }
}
Also used : FileContent(com.intellij.util.indexing.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 32 with ModifiableRootModel

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

the class FacetDetectionTest method testDetectFacet.

@Test
public void testDetectFacet() {
    Module t0 = ModuleManager.getInstance(myFixture.getProject()).findModuleByName("t0");
    assertNotNull(t0);
    OsmorcFrameworkDetector detector = new OsmorcFrameworkDetector();
    ElementPattern<FileContent> filter = detector.createSuitableFilePattern();
    VirtualFile manifestFile = myTempDirFixture.getFile("t0/src/META-INF/MANIFEST.MF");
    assertThat(filter.accepts(FileContentImpl.createByFile(manifestFile)), equalTo(true));
    OsmorcFacetConfiguration facetConfiguration = detector.createConfiguration(Collections.singletonList(manifestFile));
    assertNotNull(facetConfiguration);
    assertThat(facetConfiguration.getManifestLocation(), equalTo(manifestFile.getPath()));
    assertThat(facetConfiguration.isUseProjectDefaultManifestFileLocation(), equalTo(false));
    OsmorcFacet facet = OsmorcFacetType.getInstance().createFacet(t0, "OSGi", facetConfiguration, null);
    ModifiableRootModel model = ModuleRootManager.getInstance(t0).getModifiableModel();
    try {
        detector.setupFacet(facet, model);
        assertThat(facetConfiguration.getManifestLocation(), equalTo("src/META-INF/MANIFEST.MF"));
    } finally {
        model.dispose();
    }
}
Also used : FileContent(com.intellij.util.indexing.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 33 with ModifiableRootModel

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

the class DartProjectGenerator method generateProject.

@Override
public final void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, @NotNull final DartProjectWizardData data, @NotNull final Module module) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModifiableRootModel modifiableModel = ModifiableModelsProvider.SERVICE.getInstance().getModuleModifiableModel(module);
        DartModuleBuilder.setupProject(modifiableModel, baseDir, data);
        ModifiableModelsProvider.SERVICE.getInstance().commitModuleModifiableModel(modifiableModel);
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel)

Example 34 with ModifiableRootModel

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

the class VFSUtilTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final File dir = createTempDirectory();
    updateRoots(new Updater() {

        @Override
        public void update(ModifiableRootModel modifiableModel) {
            myContentRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
            try {
                VirtualFile src = myContentRoot.createChildDirectory(this, "src");
                myContentEntry = modifiableModel.addContentEntry(myContentRoot);
                myContentEntry.addSourceFolder(src, false);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    ProjectRootManager rootManager = ProjectRootManager.getInstance(getProject());
    myContentRoot = rootManager.getContentRoots()[0];
    mySourceRoot = rootManager.getContentSourceRoots()[0];
    VFSUtil._setProject(getProject());
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VFile(jetbrains.communicator.core.vfs.VFile) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager)

Example 35 with ModifiableRootModel

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

the class VFSUtilTest method updateRoots.

private void updateRoots(final Updater updater) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(getModule()).getModifiableModel();
            updater.update(modifiableModel);
            modifiableModel.commit();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel)

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