use of com.intellij.util.indexing.FileContent in project intellij-community by JetBrains.
the class FrameworkDetectionProcessor method collectSuitableFiles.
private void collectSuitableFiles(@NotNull VirtualFile file) {
try {
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
// Since this code is invoked from New Project Wizard it's very possible that VFS isn't loaded to memory yet, so we need to do it
// manually, otherwise refresh will do nothing
myProgressIndicator.checkCanceled();
return true;
}
});
file.refresh(false, true);
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
myProgressIndicator.checkCanceled();
if (!myProcessedFiles.add(file)) {
return false;
}
if (!file.isDirectory()) {
final FileType fileType = file.getFileType();
if (myDetectorsByFileType.containsKey(fileType)) {
myProgressIndicator.setText2(file.getPresentableUrl());
try {
final FileContent fileContent = new FileContentImpl(file, file.contentsToByteArray(false));
for (FrameworkDetectorData detector : myDetectorsByFileType.get(fileType)) {
if (detector.myFilePattern.accepts(fileContent)) {
detector.mySuitableFiles.add(file);
}
}
} catch (IOException e) {
LOG.info(e);
}
}
}
return true;
}
});
} catch (ProcessCanceledException ignored) {
}
}
use of com.intellij.util.indexing.FileContent in project intellij-community by JetBrains.
the class PlatformIdTableBuilding method getTodoIndexer.
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType) fileType).isSameFileType()) {
SubstitutedFileType sft = (SubstitutedFileType) fileType;
extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
} else {
extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
}
if (extIndexer != null) {
return extIndexer;
}
if (fileType instanceof LanguageFileType) {
final Language lang = ((LanguageFileType) fileType).getLanguage();
final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
if (commentTokens != null) {
return new TokenSetTodoIndexer(commentTokens, virtualFile);
}
}
if (fileType instanceof CustomSyntaxTableFileType) {
return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
}
return null;
}
use of com.intellij.util.indexing.FileContent in project intellij-plugins by JetBrains.
the class FacetDetectionTest method testDetectNoFacet.
@Test
public void testDetectNoFacet() {
ElementPattern<FileContent> filter = new OsmorcFrameworkDetector().createSuitableFilePattern();
VirtualFile manifestFile = myTempDirFixture.getFile("t1/src/META-INF/MANIFEST.MF");
assertThat(filter.accepts(FileContentImpl.createByFile(manifestFile)), equalTo(false));
}
use of com.intellij.util.indexing.FileContent 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();
}
}
use of com.intellij.util.indexing.FileContent 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();
}
}
Aggregations