use of com.intellij.framework.detection.FrameworkDetector in project intellij-community by JetBrains.
the class FrameworkDetectionIndex method getIndexer.
@NotNull
@Override
public DataIndexer<Integer, Void, FileContent> getIndexer() {
final MultiMap<FileType, Pair<ElementPattern<FileContent>, Integer>> detectors = new MultiMap<>();
FrameworkDetectorRegistry registry = FrameworkDetectorRegistry.getInstance();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
detectors.putValue(detector.getFileType(), Pair.create(detector.createSuitableFilePattern(), registry.getDetectorId(detector)));
}
return new DataIndexer<Integer, Void, FileContent>() {
@NotNull
@Override
public Map<Integer, Void> map(@NotNull FileContent inputData) {
final FileType fileType = inputData.getFileType();
if (!detectors.containsKey(fileType)) {
return Collections.emptyMap();
}
Map<Integer, Void> result = null;
for (Pair<ElementPattern<FileContent>, Integer> pair : detectors.get(fileType)) {
if (pair.getFirst().accepts(inputData)) {
if (LOG.isDebugEnabled()) {
LOG.debug(inputData.getFile() + " accepted by detector " + pair.getSecond());
}
if (result == null) {
result = new HashMap<>();
}
myDispatcher.getMulticaster().fileUpdated(inputData.getFile(), pair.getSecond());
result.put(pair.getSecond(), null);
}
}
return result != null ? result : Collections.<Integer, Void>emptyMap();
}
};
}
use of com.intellij.framework.detection.FrameworkDetector in project intellij-community by JetBrains.
the class FrameworkDetectionManager method runDetector.
private List<? extends DetectedFrameworkDescription> runDetector(Integer detectorId, FileBasedIndex index, DetectionExcludesConfiguration excludesConfiguration, final boolean processNewFilesOnly) {
Collection<VirtualFile> acceptedFiles = index.getContainingFiles(FrameworkDetectionIndex.NAME, detectorId, GlobalSearchScope.projectScope(myProject));
final Collection<VirtualFile> filesToProcess;
if (processNewFilesOnly) {
filesToProcess = myDetectedFrameworksData.retainNewFiles(detectorId, acceptedFiles);
} else {
filesToProcess = new ArrayList<>(acceptedFiles);
}
FrameworkDetector detector = FrameworkDetectorRegistry.getInstance().getDetectorById(detectorId);
if (detector == null) {
LOG.info("Framework detector not found by id " + detectorId);
return Collections.emptyList();
}
((DetectionExcludesConfigurationImpl) excludesConfiguration).removeExcluded(filesToProcess, detector.getFrameworkType());
if (LOG.isDebugEnabled()) {
LOG.debug("Detector '" + detector.getDetectorId() + "': " + acceptedFiles.size() + " accepted files, " + filesToProcess.size() + " files to process");
}
final List<? extends DetectedFrameworkDescription> frameworks;
if (!filesToProcess.isEmpty()) {
frameworks = detector.detect(filesToProcess, new FrameworkDetectionContextImpl(myProject));
} else {
frameworks = Collections.emptyList();
}
return frameworks;
}
use of com.intellij.framework.detection.FrameworkDetector in project intellij-community by JetBrains.
the class FrameworkDetectorRegistryImpl method loadDetectors.
private void loadDetectors() {
Map<String, FrameworkDetector> newDetectors = new HashMap<>();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
newDetectors.put(detector.getDetectorId(), detector);
}
myDetectorIds = new TObjectIntHashMap<>();
final File file = getDetectorsRegistryFile();
int maxId = REGISTRY_VERSION;
if (file.exists()) {
LOG.debug("loading framework detectors registry from " + file.getAbsolutePath());
List<String> unknownIds = new ArrayList<>();
boolean versionChanged = false;
try {
DataInputStream input = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
try {
input.readInt();
myDetectorsVersion = input.readInt();
int size = input.readInt();
while (size-- > REGISTRY_VERSION) {
final String stringId = input.readUTF();
int intId = input.readInt();
maxId = Math.max(maxId, intId);
final int version = input.readInt();
final FrameworkDetector detector = newDetectors.remove(stringId);
if (detector != null) {
if (version != detector.getDetectorVersion()) {
LOG.info("Version of framework detector '" + stringId + "' changed: " + version + " -> " + detector.getDetectorVersion());
versionChanged = true;
}
myDetectorIds.put(stringId, intId);
} else {
unknownIds.add(stringId);
}
}
} finally {
input.close();
}
} catch (IOException e) {
LOG.info(e);
}
if (!unknownIds.isEmpty()) {
LOG.debug("Unknown framework detectors: " + unknownIds);
}
if (versionChanged || !newDetectors.isEmpty()) {
if (!newDetectors.isEmpty()) {
LOG.info("New framework detectors: " + newDetectors.keySet());
}
myDetectorsVersion++;
LOG.info("Framework detection index version changed to " + myDetectorsVersion);
}
}
int nextId = maxId + 1;
for (String newDetector : newDetectors.keySet()) {
myDetectorIds.put(newDetector, nextId++);
}
myDetectorById = new TIntObjectHashMap<>();
myDetectorsByFileType = new MultiMap<>();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
final int id = myDetectorIds.get(detector.getDetectorId());
myDetectorsByFileType.putValue(detector.getFileType(), id);
myDetectorById.put(id, detector);
LOG.debug("'" + detector.getDetectorId() + "' framework detector: id = " + id);
}
}
use of com.intellij.framework.detection.FrameworkDetector in project intellij-community by JetBrains.
the class FrameworkDetectorRegistryImpl method saveDetectors.
private void saveDetectors() {
final File file = getDetectorsRegistryFile();
FileUtil.createIfDoesntExist(file);
try {
DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
try {
output.writeInt(REGISTRY_VERSION);
output.writeInt(myDetectorsVersion);
final FrameworkDetector[] detectors = FrameworkDetector.EP_NAME.getExtensions();
output.writeInt(detectors.length);
for (FrameworkDetector detector : detectors) {
output.writeUTF(detector.getDetectorId());
output.writeInt(myDetectorIds.get(detector.getDetectorId()));
output.writeInt(detector.getDetectorVersion());
}
} finally {
output.close();
}
} catch (IOException e) {
LOG.info(e);
}
}
Aggregations