Search in sources :

Example 1 with IFileTaskScanner

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();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) IContentType(org.eclipse.core.runtime.content.IContentType) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IFileTaskScanner(org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with IFileTaskScanner

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;
}
Also used : IFileTaskScanner(org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 3 with IFileTaskScanner

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;
}
Also used : ArrayList(java.util.ArrayList) IContentType(org.eclipse.core.runtime.content.IContentType) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IFileTaskScanner(org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner) CoreException(org.eclipse.core.runtime.CoreException) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 IFileTaskScanner (org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner)3 CoreException (org.eclipse.core.runtime.CoreException)2 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 IContentType (org.eclipse.core.runtime.content.IContentType)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)1