Search in sources :

Example 46 with ContentEntry

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

the class CucumberJavaTestUtil method createCucumberJava8ProjectDescriptor.

public static DefaultLightProjectDescriptor createCucumberJava8ProjectDescriptor() {
    return new DefaultLightProjectDescriptor() {

        @Override
        public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
            attachCucumberLibraries(module, model);
            LanguageLevelModuleExtension extension = model.getModuleExtension(LanguageLevelModuleExtension.class);
            if (extension != null) {
                extension.setLanguageLevel(LanguageLevel.JDK_1_8);
            }
            VirtualFile sourceRoot = VirtualFileManager.getInstance().refreshAndFindFileByUrl("temp:///src");
            if (sourceRoot != null) {
                contentEntry.removeSourceFolder(contentEntry.getSourceFolders()[0]);
                contentEntry.addSourceFolder(sourceRoot, true);
            }
        }
    };
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) DefaultLightProjectDescriptor(com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor) Module(com.intellij.openapi.module.Module) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with ContentEntry

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

the class FlexModuleBuilder method setupRootModel.

public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
    final ContentEntry contentEntry = doAddContentEntry(modifiableRootModel);
    if (contentEntry == null)
        return;
    final VirtualFile sourceRoot = createSourceRoot(contentEntry);
    final Module module = modifiableRootModel.getModule();
    final FlexProjectConfigurationEditor currentFlexEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
    final boolean needToCommitFlexEditor = currentFlexEditor == null;
    final FlexProjectConfigurationEditor flexConfigEditor;
    flexConfigEditor = currentFlexEditor != null ? currentFlexEditor : FlexProjectConfigurationEditor.createEditor(module.getProject(), Collections.singletonMap(module, modifiableRootModel), null, null);
    final ModifiableFlexBuildConfiguration[] configurations = flexConfigEditor.getConfigurations(module);
    assert configurations.length == 1;
    final ModifiableFlexBuildConfiguration bc = configurations[0];
    setupBC(modifiableRootModel, bc);
    if (bc.getOutputType() == OutputType.Application) {
        createRunConfiguration(module, bc);
    }
    if (sourceRoot != null && myCreateSampleApp && myFlexSdk != null) {
        try {
            final boolean flex4 = !FlexSdkUtils.isAirSdkWithoutFlex(myFlexSdk) && StringUtil.compareVersionNumbers(myFlexSdk.getVersionString(), "4") >= 0;
            FlexUtils.createSampleApp(module.getProject(), sourceRoot, mySampleAppName, myTargetPlatform, flex4);
        } catch (IOException ex) {
            throw new ConfigurationException(ex.getMessage());
        }
    }
    if (myCreateHtmlWrapperTemplate && myFlexSdk != null) {
        final String path = VfsUtilCore.urlToPath(contentEntry.getUrl()) + "/" + CreateHtmlWrapperTemplateDialog.HTML_TEMPLATE_FOLDER_NAME;
        if (CreateHtmlWrapperTemplateDialog.createHtmlWrapperTemplate(module.getProject(), myFlexSdk, path, myEnableHistory, myCheckPlayerVersion, myExpressInstall)) {
            bc.setUseHtmlWrapper(true);
            bc.setWrapperTemplatePath(path);
        }
    }
    if (needToCommitFlexEditor) {
        flexConfigEditor.commit();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ContentEntry(com.intellij.openapi.roots.ContentEntry) IOException(java.io.IOException) Module(com.intellij.openapi.module.Module) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)

Example 48 with ContentEntry

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

the class DartWorkflowTest method testPackagesFolderExclusion.

public void testPackagesFolderExclusion() throws Exception {
    try {
        final String rootUrl = ModuleRootManager.getInstance(myModule).getContentEntries()[0].getUrl();
        myFixture.addFileToProject("dir1/pubspec.yaml", "name: project1");
        myFixture.addFileToProject("dir1/lib/foo.txt", "");
        myFixture.addFileToProject("dir1/someFolder/lib/foo.dart", "");
        final VirtualFile pubspec2 = myFixture.addFileToProject("dir2/pubspec.yaml", "name: project2\n" + "dependencies:\n" + "  project1:\n" + "    path: ../dir1").getVirtualFile();
        myFixture.addFileToProject("dir2/.pub/foo.txt", "");
        myFixture.addFileToProject("dir2/bin/foo.dart", "");
        myFixture.addFileToProject("dir2/bin/sub/foo.dart", "");
        myFixture.addFileToProject("dir2/lib/foo.dart", "");
        myFixture.addFileToProject("dir2/lib/sub/foo.dart", "");
        myFixture.addFileToProject("dir2/benchmark/foo.dart", "");
        myFixture.addFileToProject("dir2/benchmark/sub/foo.dart", "");
        myFixture.addFileToProject("dir2/test/foo.dart", "");
        myFixture.addFileToProject("dir2/test/sub/foo.dart", "");
        myFixture.addFileToProject("dir2/tool/foo.dart", "");
        myFixture.addFileToProject("dir2/tool/sub/foo.dart", "");
        myFixture.addFileToProject("dir2/web/foo.dart", "");
        myFixture.addFileToProject("dir2/web/sub/foo.dart", "");
        myFixture.addFileToProject("dir2/build/foo.dart", "");
        myFixture.addFileToProject("dir2/build/sub/foo.dart", "");
        final VirtualFile pubspec3 = myFixture.addFileToProject("dir2/example/pubspec.yaml", "name: project3\n" + "dependencies:\n" + "  project2:\n" + "    path: ..\n" + "  outside_project:\n" + "    path: ../../dir1/someFolder").getVirtualFile();
        myFixture.addFileToProject("dir2/example/lib/foo.dart", "");
        myFixture.addFileToProject("dir2/example/lib/sub/foo.dart", "");
        myFixture.addFileToProject("dir2/example/web/foo.dart", "");
        myFixture.addFileToProject("dir2/example/web/sub/foo.dart", "");
        ApplicationManager.getApplication().runWriteAction(() -> {
            final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
            final ContentEntry contentEntry = model.getContentEntries()[0];
            contentEntry.addExcludeFolder(rootUrl + "/dir1/someFolder");
            contentEntry.addExcludeFolder(rootUrl + "/dir1/packages/project1");
            contentEntry.addExcludeFolder(rootUrl + "/dir1/web/packages");
            contentEntry.addExcludeFolder(rootUrl + "/dir2/packages/oldProject2Name");
            contentEntry.addExcludeFolder(rootUrl + "/dir2/someFolder");
            contentEntry.addExcludeFolder(rootUrl + "/dir2/packages");
            contentEntry.addExcludeFolder(rootUrl + "/dir2/web/packages");
            contentEntry.addExcludeFolder(rootUrl + "/dir2/lib/someFolder");
            contentEntry.addExcludeFolder(rootUrl + "/dir2/example/nonexistent/packages");
            contentEntry.addExcludeFolder(rootUrl + "/dir2/example/packages/oldProject3Name");
            model.commit();
        });
        DartProjectComponent.excludeBuildAndPackagesFolders(myModule, pubspec2);
        assertSameElements(ModuleRootManager.getInstance(myModule).getContentEntries()[0].getExcludeFolderUrls(), rootUrl + "/dir1/someFolder", rootUrl + "/dir1/packages/project1", rootUrl + "/dir1/web/packages", rootUrl + "/dir2/.pub", rootUrl + "/dir2/build", rootUrl + "/dir2/someFolder", rootUrl + "/dir2/lib/someFolder", rootUrl + "/dir2/example/packages/oldProject3Name");
        DartProjectComponent.excludeBuildAndPackagesFolders(myModule, pubspec3);
        assertSameElements(ModuleRootManager.getInstance(myModule).getContentEntries()[0].getExcludeFolderUrls(), rootUrl + "/dir1/someFolder", rootUrl + "/dir1/packages/project1", rootUrl + "/dir1/web/packages", rootUrl + "/dir2/.pub", rootUrl + "/dir2/build", rootUrl + "/dir2/someFolder", rootUrl + "/dir2/lib/someFolder", rootUrl + "/dir2/example/.pub", rootUrl + "/dir2/example/build");
    } finally {
        DartTestUtils.resetModuleRoots(myModule);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 49 with ContentEntry

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

the class MxmlTest method testResolveResourceIfNameIsAmbiguous.

public void testResolveResourceIfNameIsAmbiguous() throws Exception {
    moduleInitializer = (model, file, libs1) -> {
        final VirtualFile localesDir = DesignerTests.getFile("locales");
        final ContentEntry localesContentEntry = model.addContentEntry(localesDir);
        //noinspection ConstantConditions
        localesContentEntry.addSourceFolder(localesDir.findChild("en_US"), false);
        //localesContentEntry.addSourceFolder(localesDir.findChild("ru_RU"), false);
        return null;
    };
    testFile("ResourceDirective.mxml");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 50 with ContentEntry

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

the class GradleSyncIntegrationTest method testJarsFolderInExplodedAarIsExcluded.

// https://code.google.com/p/android/issues/detail?id=227931
public void testJarsFolderInExplodedAarIsExcluded() throws Exception {
    loadSimpleApplication();
    Module appModule = myModules.getAppModule();
    AndroidModuleModel androidModel = AndroidModuleModel.get(appModule);
    assertNotNull(androidModel);
    Collection<SyncIssue> issues = androidModel.getSyncIssues();
    assertThat(issues).isEmpty();
    AndroidPluginInfo pluginInfo = AndroidPluginInfo.find(getProject());
    assertNotNull(pluginInfo);
    assertEquals(pluginInfo.getPluginGeneration(), ORIGINAL);
    GradleVersion pluginVersion = pluginInfo.getPluginVersion();
    assertNotNull(pluginVersion);
    if (pluginVersion.compareIgnoringQualifiers("2.3.0") >= 0) {
        // it is not inside the project.
        return;
    }
    ProjectLibraries libraries = new ProjectLibraries(getProject());
    Library appCompat = libraries.findMatchingLibrary("appcompat-v7.*");
    assertNotNull(appCompat);
    File jarsFolderPath = null;
    for (String url : appCompat.getUrls(CLASSES)) {
        if (url.startsWith(JAR_PROTOCOL_PREFIX)) {
            File jarPath = getJarFromJarUrl(url);
            assertNotNull(jarPath);
            jarsFolderPath = jarPath.getParentFile();
            break;
        }
    }
    assertNotNull(jarsFolderPath);
    ContentEntry[] contentEntries = ModuleRootManager.getInstance(appModule).getContentEntries();
    assertThat(contentEntries).hasLength(1);
    ContentEntry contentEntry = contentEntries[0];
    List<String> excludeFolderUrls = contentEntry.getExcludeFolderUrls();
    assertThat(excludeFolderUrls).contains(pathToIdeaUrl(jarsFolderPath));
}
Also used : SyncIssue(com.android.builder.model.SyncIssue) ProjectLibraries(com.android.tools.idea.gradle.ProjectLibraries) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) ContentEntry(com.intellij.openapi.roots.ContentEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) FileUtil.writeToFile(com.intellij.openapi.util.io.FileUtil.writeToFile) File(java.io.File)

Aggregations

ContentEntry (com.intellij.openapi.roots.ContentEntry)61 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)27 Module (com.intellij.openapi.module.Module)17 File (java.io.File)16 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)11 SourceFolder (com.intellij.openapi.roots.SourceFolder)7 NotNull (org.jetbrains.annotations.NotNull)7 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)4 IOException (java.io.IOException)4 Nullable (org.jetbrains.annotations.Nullable)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 Project (com.intellij.openapi.project.Project)3 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)3 JavaModuleContentRoot (com.android.tools.idea.gradle.model.java.JavaModuleContentRoot)2 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)2 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 PsiFile (com.intellij.psi.PsiFile)2 ArrayList (java.util.ArrayList)2