com.intellij.openapi.roots.ContentEntry Java Examples
The following examples show how to use
com.intellij.openapi.roots.ContentEntry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentEntriesEditor.java From consulo with Apache License 2.0 | 6 votes |
@Override public void moduleStateChanged() { myEntryToEditorMap.clear(); myEditorsPanel.removeAll(); final ModifiableRootModel model = getModel(); if (model != null) { final ContentEntry[] contentEntries = model.getContentEntries(); if (contentEntries.length > 0) { for (final ContentEntry contentEntry : contentEntries) { addContentEntryPanel(contentEntry); } selectContentEntry(contentEntries[0]); } else { selectContentEntry(null); myRootTreeEditor.setContentEntryEditor(null); } } if(myRootTreeEditor != null) { myRootTreeEditor.update(); } }
Example #2
Source File: OSSPantsScalaExamplesIntegrationTest.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
public void testWelcomeTest() throws Throwable { doImport("examples/tests/scala/org/pantsbuild/example/hello/welcome"); assertFirstSourcePartyModules( "examples_src_resources_org_pantsbuild_example_hello_hello", "examples_src_java_org_pantsbuild_example_hello_greet_greet", "examples_src_scala_org_pantsbuild_example_hello_welcome_welcome", "examples_tests_scala_org_pantsbuild_example_hello_welcome_welcome" ); final ContentEntry[] contentRoots = getContentRoots("examples_tests_scala_org_pantsbuild_example_hello_welcome_welcome"); assertSize(1, contentRoots); final List<SourceFolder> testSourceRoots = contentRoots[0].getSourceFolders(JavaSourceRootType.TEST_SOURCE); assertSize(1, testSourceRoots); assertPantsCompileExecutesAndSucceeds(pantsCompileProject()); findClassAndAssert("org.pantsbuild.example.hello.welcome.WelSpec"); assertScalaLibrary("examples_tests_scala_org_pantsbuild_example_hello_welcome_welcome"); }
Example #3
Source File: ArmaModuleBuilder.java From arma-intellij-plugin with MIT License | 6 votes |
@Override public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException { ContentEntry contentEntry = doAddContentEntry(rootModel); if (contentEntry != null) { final List<Pair<String, String>> sourcePaths = getSourcePaths(); if (sourcePaths != null) { for (final Pair<String, String> sourcePath : sourcePaths) { String first = sourcePath.first; new File(first).mkdirs(); final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first)); if (sourceRoot != null) { contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second); } } } } }
Example #4
Source File: ContentEntryEditor.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public ContentFolder addFolder(@Nonnull final VirtualFile file, ContentFolderTypeProvider contentFolderType) { final ContentEntry contentEntry = getContentEntry(); if (contentEntry != null) { final ContentFolder contentFolder = contentEntry.addFolder(file, contentFolderType); try { return contentFolder; } finally { myEventDispatcher.getMulticaster().folderAdded(this, contentFolder); update(); } } return null; }
Example #5
Source File: JavaSourceFolderProvider.java From intellij with Apache License 2.0 | 6 votes |
@Override public SourceFolder setSourceFolderForLocation( ContentEntry contentEntry, SourceFolder parentFolder, File file, boolean isTestSource) { SourceFolder sourceFolder; if (isResource(parentFolder)) { JavaResourceRootType resourceRootType = isTestSource ? JavaResourceRootType.TEST_RESOURCE : JavaResourceRootType.RESOURCE; sourceFolder = contentEntry.addSourceFolder(UrlUtil.pathToUrl(file.getPath()), resourceRootType); } else { sourceFolder = contentEntry.addSourceFolder(UrlUtil.pathToUrl(file.getPath()), isTestSource); } sourceFolder.setPackagePrefix(derivePackagePrefix(file, parentFolder)); JpsModuleSourceRoot sourceRoot = sourceFolder.getJpsElement(); JpsElement properties = sourceRoot.getProperties(); if (properties instanceof JavaSourceRootProperties) { ((JavaSourceRootProperties) properties).setForGeneratedSources(isGenerated(parentFolder)); } return sourceFolder; }
Example #6
Source File: JavaSourceFolderProvider.java From intellij with Apache License 2.0 | 6 votes |
@Override public ImmutableMap<File, SourceFolder> initializeSourceFolders(ContentEntry contentEntry) { Map<File, SourceFolder> map = new HashMap<>(); BlazeContentEntry javaContentEntry = blazeContentEntries.get(UrlUtil.urlToFile(contentEntry.getUrl())); if (javaContentEntry != null) { for (BlazeSourceDirectory sourceDirectory : javaContentEntry.sources) { File file = sourceDirectory.getDirectory(); if (map.containsKey(file)) { continue; } SourceFolder sourceFolder = addSourceFolderToContentEntry(contentEntry, sourceDirectory); map.put(file, sourceFolder); } } return ImmutableMap.copyOf(map); }
Example #7
Source File: CamelInspectionTestHelper.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
@NotNull @Override protected LightProjectDescriptor getProjectDescriptor() { LanguageLevel languageLevel = LanguageLevel.JDK_1_8; return new DefaultLightProjectDescriptor() { @Override public Sdk getSdk() { String compilerOption = JpsJavaSdkType.complianceOption(languageLevel.toJavaVersion()); return JavaSdk.getInstance().createJdk( "java " + compilerOption, BUILD_MOCK_JDK_DIRECTORY + compilerOption, false ); } @Override public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) { model.getModuleExtension( LanguageLevelModuleExtension.class ).setLanguageLevel( languageLevel ); } }; }
Example #8
Source File: GenerateAction.java From RIBs with Apache License 2.0 | 6 votes |
private static SourceFolder suitableTestSourceFolders(Project project, Module module) { ContentEntry[] contentEntries = ModuleRootManager.getInstance(module).getContentEntries(); for (ContentEntry contentEntry : contentEntries) { List<SourceFolder> testSourceFolders = contentEntry.getSourceFolders(JavaSourceRootType.TEST_SOURCE); for (SourceFolder testSourceFolder : testSourceFolders) { if (testSourceFolder.getFile() != null) { if (!JavaProjectRootsUtil.isInGeneratedCode(testSourceFolder.getFile(), project)) { return testSourceFolder; } } } } return null; }
Example #9
Source File: ModuleOutputPackagingElementImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public Collection<VirtualFile> getSourceRoots(PackagingElementResolvingContext context) { Module module = NamedPointerUtil.get(myModulePointer); if (module == null) { return Collections.emptyList(); } List<VirtualFile> roots = new SmartList<VirtualFile>(); ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module); for (ContentEntry entry : rootModel.getContentEntries()) { for (ContentFolder folder : entry.getFolders(ContentFolderScopes.of(myContentFolderType))) { ContainerUtil.addIfNotNull(folder.getFile(), roots); } } return roots; }
Example #10
Source File: ContentEntriesEditor.java From consulo with Apache License 2.0 | 6 votes |
protected void addContentEntryPanel(final ContentEntry contentEntry) { final ContentEntryEditor contentEntryEditor = createContentEntryEditor(contentEntry); contentEntryEditor.initUI(); contentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener); registerDisposable(new Disposable() { @Override public void dispose() { contentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener); } }); myEntryToEditorMap.put(contentEntry, contentEntryEditor); final JComponent component = contentEntryEditor.getComponent(); component.setBorder(JBUI.Borders.empty()); myEditorsPanel.add(component); }
Example #11
Source File: ExcludeCompilerOutputPolicy.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public VirtualFilePointer[] getExcludeRootsForModule(@Nonnull final ModuleRootLayer moduleRootLayer) { ModuleCompilerPathsManager manager = ModuleCompilerPathsManager.getInstance(moduleRootLayer.getModule()); List<VirtualFilePointer> result = new ArrayList<VirtualFilePointer>(3); if (manager.isInheritedCompilerOutput()) { final VirtualFilePointer compilerOutputPointer = CompilerConfiguration.getInstance(myProject).getCompilerOutputPointer(); for (ContentEntry contentEntry : moduleRootLayer.getContentEntries()) { if (compilerOutputPointer.getUrl().contains(contentEntry.getUrl())) { result.add(compilerOutputPointer); } } } else { if (!manager.isExcludeOutput()) { return VirtualFilePointer.EMPTY_ARRAY; } for (ContentFolderTypeProvider contentFolderType : ContentFolderTypeProvider.filter(ContentFolderScopes.productionAndTest())) { result.add(manager.getCompilerOutputPointer(contentFolderType)); } } return result.isEmpty() ? VirtualFilePointer.EMPTY_ARRAY : result.toArray(new VirtualFilePointer[result.size()]); }
Example #12
Source File: UnmarkRootAction.java From consulo with Apache License 2.0 | 6 votes |
public boolean canUnmark(AnActionEvent e) { Module module = e.getData(LangDataKeys.MODULE); VirtualFile[] vFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (module == null || vFiles == null) { return false; } ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final ContentEntry[] contentEntries = moduleRootManager.getContentEntries(); for (VirtualFile vFile : vFiles) { if (!vFile.isDirectory()) { continue; } for (ContentEntry contentEntry : contentEntries) { for (ContentFolder contentFolder : contentEntry.getFolders(ContentFolderScopes.all())) { if (Comparing.equal(contentFolder.getFile(), vFile)) { return true; } } } } return false; }
Example #13
Source File: ArmaModuleBuilder.java From arma-intellij-plugin with MIT License | 6 votes |
@Override public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException { ContentEntry contentEntry = doAddContentEntry(rootModel); if (contentEntry != null) { final List<Pair<String, String>> sourcePaths = getSourcePaths(); if (sourcePaths != null) { for (final Pair<String, String> sourcePath : sourcePaths) { String first = sourcePath.first; new File(first).mkdirs(); final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first)); if (sourceRoot != null) { contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second); } } } } }
Example #14
Source File: IntegrationTestCase.java From consulo with Apache License 2.0 | 5 votes |
protected void addExcludedDir(final String path) { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { ModuleRootManager rm = ModuleRootManager.getInstance(myModule); ModifiableRootModel m = rm.getModifiableModel(); for (ContentEntry e : m.getContentEntries()) { if (!Comparing.equal(e.getFile(), myRoot)) continue; e.addFolder(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(path)), ExcludedContentFolderTypeProvider.getInstance()); } m.commit(); } }); }
Example #15
Source File: NullModuleDirModuleRootsProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void processFiles(@Nonnull final ModuleRootModel moduleRootModel, @Nonnull final Predicate<ContentFolderTypeProvider> predicate, @Nonnull final Processor<VirtualFile> processor) { moduleRootModel.iterateContentEntries(new Processor<ContentEntry>() { @Override public boolean process(ContentEntry contentEntry) { VirtualFile file = contentEntry.getFile(); return file == null || processor.process(file); } }); }
Example #16
Source File: ContentEntryEditor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void showChangeOptionsDialog(ContentEntry contentEntry, ContentFolder contentFolder) { ContentFolderPropertiesDialog c = new ContentFolderPropertiesDialog(getModel().getProject(), contentFolder); AsyncResult<Boolean> booleanAsyncResult = c.showAndGetOk(); if(booleanAsyncResult.getResult() == Boolean.TRUE) { update(); } }
Example #17
Source File: ContentEntryEditor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void deleteContentEntry() { final String path = FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(myContentEntry.getUrl())); final int answer = Messages.showYesNoDialog(ProjectBundle.message("module.paths.remove.content.prompt", path), ProjectBundle.message("module.paths.remove.content.title"), Messages.getQuestionIcon()); if (answer != 0) { // no return; } myEventDispatcher.getMulticaster().beforeEntryDeleted(this); final ContentEntry entry = getContentEntry(); if (entry != null) { getModel().removeContentEntry(entry); } }
Example #18
Source File: ContentEntryEditor.java From consulo with Apache License 2.0 | 5 votes |
public void removeFolder(@Nonnull final ContentFolder contentFolder) { try { if (contentFolder.isSynthetic()) { return; } final ContentEntry contentEntry = getContentEntry(); if (contentEntry != null) { contentEntry.removeFolder(contentFolder); } } finally { myEventDispatcher.getMulticaster().folderRemoved(this, contentFolder); update(); } }
Example #19
Source File: ContentRootDataService.java From consulo with Apache License 2.0 | 5 votes |
private static void createExcludedRootIfAbsent(@Nonnull ContentEntry entry, @Nonnull ContentRootData.SourceRoot root, @Nonnull String moduleName, @Nonnull Project project) { String rootPath = root.getPath(); for (VirtualFile file : entry.getFolderFiles(ContentFolderScopes.excluded())) { if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(rootPath)) { return; } } LOG.info(String.format("Importing excluded root '%s' for content root '%s' of module '%s'", root, entry.getUrl(), moduleName)); entry.addFolder(toVfsUrl(rootPath), ExcludedContentFolderTypeProvider.getInstance()); ChangeListManager.getInstance(project).addDirectoryToIgnoreImplicitly(rootPath); }
Example #20
Source File: ContentRootDataService.java From consulo with Apache License 2.0 | 5 votes |
private static void createSourceRootIfAbsent(@Nonnull ContentEntry entry, @Nonnull ContentRootData.SourceRoot root, @Nonnull String moduleName, @Nonnull ContentFolderTypeProvider folderTypeProvider, boolean generated, boolean createEmptyContentRootDirectories) { ContentFolder[] folders = entry.getFolders(ContentFolderScopes.of(folderTypeProvider)); for (ContentFolder folder : folders) { VirtualFile file = folder.getFile(); if (file == null) { continue; } if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(root.getPath())) { return; } } LOG.info(String.format("Importing %s for content root '%s' of module '%s'", root, entry.getUrl(), moduleName)); ContentFolder contentFolder = entry.addFolder(toVfsUrl(root.getPath()), folderTypeProvider); /*if (!StringUtil.isEmpty(root.getPackagePrefix())) { sourceFolder.setPackagePrefix(root.getPackagePrefix()); } */ if (generated) { contentFolder.setPropertyValue(GeneratedContentFolderPropertyProvider.IS_GENERATED, Boolean.TRUE); } if (createEmptyContentRootDirectories) { try { VfsUtil.createDirectoryIfMissing(root.getPath()); } catch (IOException e) { LOG.warn(String.format("Unable to create directory for the path: %s", root.getPath()), e); } } }
Example #21
Source File: ContentRootDataService.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static ContentEntry findOrCreateContentRoot(@Nonnull ModifiableRootModel model, @Nonnull String path) { ContentEntry[] entries = model.getContentEntries(); for (ContentEntry entry : entries) { VirtualFile file = entry.getFile(); if (file == null) { continue; } if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(path)) { return entry; } } return model.addContentEntry(toVfsUrl(path)); }
Example #22
Source File: ContentRootPanel.java From consulo with Apache License 2.0 | 5 votes |
public boolean isExcludedOrUnderExcludedDirectory(final VirtualFile file) { final ContentEntry contentEntry = getContentEntry(); for (VirtualFile excludedDir : contentEntry.getFolderFiles(ContentFolderScopes.of(ExcludedContentFolderTypeProvider.getInstance()))) { if (VfsUtilCore.isAncestor(excludedDir, file, false)) { return true; } } return false; }
Example #23
Source File: PantsProjectCacheTest.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
private void cleanUpsourceFolders() { ApplicationManager.getApplication().runWriteAction( () -> { final ModifiableRootModel modifiableRootModel = ModuleRootManager.getInstance(getModule()).getModifiableModel(); for (ContentEntry contentEntry : modifiableRootModel.getContentEntries()) { final SourceFolder[] sourceFolders = contentEntry.getSourceFolders(); for (SourceFolder sourceFolder : sourceFolders) { contentEntry.removeSourceFolder(sourceFolder); } } modifiableRootModel.commit(); } ); }
Example #24
Source File: JavascriptSyncTest.java From intellij with Apache License 2.0 | 5 votes |
@Nullable private static SourceFolder findSourceFolder(ContentEntry entry, VirtualFile file) { for (SourceFolder sourceFolder : entry.getSourceFolders()) { if (file.equals(sourceFolder.getFile())) { return sourceFolder; } } return null; }
Example #25
Source File: ContentEntriesEditor.java From consulo with Apache License 2.0 | 5 votes |
protected List<ContentEntry> addContentEntries(final VirtualFile[] files) { List<ContentEntry> contentEntries = new ArrayList<ContentEntry>(); for (final VirtualFile file : files) { if (isAlreadyAdded(file)) { continue; } final ContentEntry contentEntry = getModel().addContentEntry(file); contentEntries.add(contentEntry); } return contentEntries; }
Example #26
Source File: MultipleJavaClassesTestContextProviderTest.java From intellij with Apache License 2.0 | 5 votes |
@After public final void removeSourceFolder() { ApplicationManager.getApplication() .runWriteAction( () -> { final ModifiableRootModel model = ModuleRootManager.getInstance(testFixture.getModule()).getModifiableModel(); ContentEntry contentEntry = model.getContentEntries()[0]; contentEntry.removeSourceFolder(javaSourceRoot); model.commit(); }); }
Example #27
Source File: MultipleJavaClassesTestContextProviderTest.java From intellij with Apache License 2.0 | 5 votes |
@Before public final void addSourceFolder() { // create a source root so that the package prefixes are correct. VirtualFile pkgRoot = workspace.createDirectory(new WorkspacePath("java")); ApplicationManager.getApplication() .runWriteAction( () -> { final ModifiableRootModel model = ModuleRootManager.getInstance(testFixture.getModule()).getModifiableModel(); ContentEntry contentEntry = model.getContentEntries()[0]; javaSourceRoot = contentEntry.addSourceFolder(pkgRoot, true, ""); model.commit(); }); BlazeProjectDataManager mockProjectDataManager = new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).build()); registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager); registerProjectService( WorkspaceFileFinder.Provider.class, () -> file -> file.getPath().contains("test")); // required for IntelliJ to recognize annotations, JUnit version, etc. workspace.createPsiFile( new WorkspacePath("org/junit/runner/RunWith.java"), "package org.junit.runner;" + "public @interface RunWith {" + " Class<? extends Runner> value();" + "}"); workspace.createPsiFile( new WorkspacePath("org/junit/Test.java"), "package org.junit;", "public @interface Test {}"); workspace.createPsiFile( new WorkspacePath("org/junit/runners/JUnit4.java"), "package org.junit.runners;", "public class JUnit4 {}"); }
Example #28
Source File: MavenImportingTestCase.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
protected void assertContentRoots(String moduleName, String... expectedRoots) { List<String> actual = new ArrayList<>(); for (ContentEntry e : getContentRoots(moduleName)) { actual.add(e.getUrl()); } for (int i = 0; i < expectedRoots.length; i++) { expectedRoots[i] = VfsUtilCore.pathToUrl(expectedRoots[i]); } assertUnorderedPathsAreEqual(actual, Arrays.asList(expectedRoots)); }
Example #29
Source File: JavaSyncTest.java From intellij with Apache License 2.0 | 5 votes |
@Nullable private static SourceFolder findSourceFolder(ContentEntry entry, VirtualFile file) { for (SourceFolder sourceFolder : entry.getSourceFolders()) { if (file.equals(sourceFolder.getFile())) { return sourceFolder; } } return null; }
Example #30
Source File: JavaSyncTest.java From intellij with Apache License 2.0 | 5 votes |
@Test public void testTestSourceRelativePackagePrefixCalculation() { setProjectView( "directories:", " java/com/google", "targets:", " //java/com/google:lib", "test_sources:", " java/com/google/tests/*"); VirtualFile javatestsRoot = workspace.createDirectory(new WorkspacePath("java/com/google/tests")); BlazeSyncParams syncParams = BlazeSyncParams.builder() .setTitle("Full Sync") .setSyncMode(SyncMode.FULL) .setSyncOrigin("test") .setBlazeBuildParams(BlazeBuildParams.fromProject(getProject())) .setAddProjectViewTargets(true) .build(); runBlazeSync(syncParams); errorCollector.assertNoIssues(); ContentEntry root = findContentEntry(javatestsRoot.getParent()); SourceFolder rootSource = findSourceFolder(root, javatestsRoot.getParent()); assertThat(rootSource.isTestSource()).isFalse(); assertThat(rootSource.getPackagePrefix()).isEqualTo("com.google"); SourceFolder childTestSource = findSourceFolder(root, javatestsRoot); assertThat(childTestSource.isTestSource()).isTrue(); assertThat(childTestSource.getPackagePrefix()).isEqualTo("com.google.tests"); }