use of org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner in project webtools.sourceediting by eclipse.
the class WorkspaceTaskScanner method scanFile.
void scanFile(IProject project, TaskTag[] taskTags, IFile file, IProgressMonitor monitor) {
if (monitor.isCanceled())
return;
// 3 "stages"
// $NON-NLS-1$
monitor.beginTask("", 8);
monitor.subTask(file.getFullPath().toString().substring(1));
final List markerAttributes = new ArrayList();
IContentType[] types = detectContentTypes(file);
Set markerTypes = new HashSet(3);
// Always included for safety and migration
markerTypes.add(DEFAULT_MARKER_TYPE);
monitor.worked(1);
IFileTaskScanner[] fileScanners = null;
IFileTaskScanner[] ignoredFileScanners = null;
if (types != null) {
if (fCurrentIgnoreContentTypes.length == 0) {
fileScanners = registry.getFileTaskScanners(types);
} else {
List validTypes = new ArrayList();
// obtain a filtered list of delegates
for (int i = 0; i < types.length; i++) {
boolean ignoreContentType = false;
for (int j = 0; j < fCurrentIgnoreContentTypes.length; j++) {
ignoreContentType = ignoreContentType || types[i].isKindOf(fCurrentIgnoreContentTypes[j]);
}
if (!ignoreContentType) {
validTypes.add(types[i]);
} else {
ignoredFileScanners = registry.getFileTaskScanners(new IContentType[] { types[i] });
}
}
fileScanners = registry.getFileTaskScanners((IContentType[]) validTypes.toArray(new IContentType[validTypes.size()]));
}
monitor.worked(1);
if (ignoredFileScanners != null && ignoredFileScanners.length > 0) {
for (int i = 0; i < ignoredFileScanners.length; i++) markerTypes.add(ignoredFileScanners[i].getMarkerType());
}
if (fileScanners.length > 0) {
IProgressMonitor scannerMonitor = new SubProgressMonitor(monitor, 3, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
// $NON-NLS-1$
scannerMonitor.beginTask("", fileScanners.length);
for (int j = 0; fileScanners != null && j < fileScanners.length; j++) {
if (monitor.isCanceled())
continue;
try {
if (!fActiveScanners.contains(fileScanners[j]) && !monitor.isCanceled()) {
fileScanners[j].startup(file.getProject());
fActiveScanners.add(fileScanners[j]);
}
markerTypes.add(fileScanners[j].getMarkerType());
Map[] taskMarkerAttributes = fileScanners[j].scan(file, taskTags, new SubProgressMonitor(scannerMonitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
/*
* TODO: pool the marker results so there's only one
* operation creating them
*/
for (int i = 0; i < taskMarkerAttributes.length; i++) {
if (!taskMarkerAttributes[i].containsKey(IMarker.TASK)) {
taskMarkerAttributes[i].put(IMarker.TASK, fileScanners[j].getMarkerType());
}
taskMarkerAttributes[i].put(IMarker.SOURCE_ID, fileScanners[j].getClass().getName());
markerAttributes.add(taskMarkerAttributes[i]);
}
} catch (Exception e) {
Logger.logException(file.getFullPath().toString(), e);
}
}
scannerMonitor.done();
}
} else {
monitor.worked(4);
}
if (monitor.isCanceled())
return;
// only update markers if we ran a scanner on this file
if (fileScanners != null && fileScanners.length > 0 || ignoredFileScanners != null && ignoredFileScanners.length > 0) {
IProgressMonitor markerUpdateMonitor = new SubProgressMonitor(monitor, 3, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
if (markerAttributes != null) {
replaceTaskMarkers(file, (String[]) markerTypes.toArray(new String[markerTypes.size()]), (Map[]) markerAttributes.toArray(new Map[markerAttributes.size()]), markerUpdateMonitor);
}
} else {
monitor.worked(3);
}
monitor.done();
}
use of org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner in project webtools.sourceediting by eclipse.
the class FileTaskScannerRegistryReader method getFileTaskScanners.
IFileTaskScanner[] getFileTaskScanners(IContentType[] contentTypes) {
if (fScannerElements == null) {
readRegistry();
}
List scannerInfos = new ArrayList(1);
for (int i = 0; i < contentTypes.length; i++) {
ScannerInfo[] scannerInfosForContentType = (ScannerInfo[]) fScannerInfos.get(contentTypes[i].getId());
if (scannerInfosForContentType == null) {
scannerInfosForContentType = loadScanners(contentTypes[i]);
}
// only add non-duplicate scanners
for (int j = 0; j < scannerInfosForContentType.length; j++) {
if (!scannerInfos.contains(scannerInfosForContentType[j])) {
scannerInfos.add(scannerInfosForContentType[j]);
}
}
}
IFileTaskScanner[] scanners = new IFileTaskScanner[scannerInfos.size()];
for (int i = 0; i < scanners.length; i++) {
scanners[i] = ((ScannerInfo) scannerInfos.get(i)).getScanner();
}
return scanners;
}
use of org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner in project webtools.sourceediting by eclipse.
the class FileTaskScannerRegistryReader method loadScanners.
private ScannerInfo[] loadScanners(IContentType contentType) {
List elements = new ArrayList(0);
ScannerInfo[] scannerInfos = null;
IConfigurationElement[] delegateElements = fScannerElements;
if (contentType != null) {
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
for (int j = 0; j < delegateElements.length; j++) {
if (!delegateElements[j].getName().equals(NAME_SCANNER))
continue;
String[] supportedContentTypeIds = StringUtils.unpack(delegateElements[j].getAttribute(ATT_CONTENT_TYPES));
IContentType[] supportedContentTypes = new IContentType[supportedContentTypeIds.length];
for (int k = 0; k < supportedContentTypeIds.length; k++) {
supportedContentTypes[k] = contentTypeManager.getContentType(supportedContentTypeIds[k].trim());
}
for (int k = 0; k < supportedContentTypeIds.length; k++) {
// allow subtypes to be returned as well
if (supportedContentTypes[k] != null && contentType.isKindOf(supportedContentTypes[k])) {
elements.add(delegateElements[j]);
}
}
}
// instantiate and save the scanners
List scannerInfoList = new ArrayList(elements.size());
for (int i = 0; i < elements.size(); i++) {
try {
IFileTaskScanner scanner = (IFileTaskScanner) ((IConfigurationElement) elements.get(i)).createExecutableExtension(ATT_CLASS);
if (scanner != null) {
scannerInfoList.add(new ScannerInfo(((IConfigurationElement) elements.get(i)).getAttribute(ATT_ID), scanner));
}
} catch (CoreException e) {
// $NON-NLS-1$
Logger.logException("Non-fatal exception creating task scanner for " + contentType.getId(), e);
}
}
scannerInfos = (ScannerInfo[]) scannerInfoList.toArray(new ScannerInfo[scannerInfoList.size()]);
fScannerInfos.put(contentType.getId(), scannerInfos);
if (Logger.DEBUG_TASKSREGISTRY) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("Created " + scannerInfos.length + " task scanner for " + contentType.getId());
}
}
return scannerInfos;
}
Aggregations