Search in sources :

Example 66 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class TLDValidator method validate.

public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    ValidationResult result = new ValidationResult();
    IFile file = (IFile) resource;
    if (file.isAccessible()) {
        // TAGX
        if (fTagXexts.contains(file.getFileExtension()) || fTagXnames.contains(file.getName())) {
            monitor.beginTask("", 4);
            org.eclipse.wst.xml.core.internal.validation.eclipse.Validator xmlValidator = new org.eclipse.wst.xml.core.internal.validation.eclipse.Validator();
            ValidationResult result3 = new MarkupValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            if (monitor.isCanceled())
                return result;
            ValidationResult result2 = xmlValidator.validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            if (monitor.isCanceled())
                return result;
            ValidationResult result1 = new JSPActionValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            List messages = new ArrayList(result1.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(result2.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(result3.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(new JSPDirectiveValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1)).getReporter(new NullProgressMonitor()).getMessages());
            for (int i = 0; i < messages.size(); i++) {
                IMessage message = (IMessage) messages.get(i);
                if (message.getText() != null && message.getText().length() > 0) {
                    ValidatorMessage vmessage = ValidatorMessage.create(message.getText(), resource);
                    if (message.getAttributes() != null) {
                        Map attrs = message.getAttributes();
                        Iterator it = attrs.entrySet().iterator();
                        while (it.hasNext()) {
                            Map.Entry entry = (Map.Entry) it.next();
                            if (!(entry.getValue() instanceof String || entry.getValue() instanceof Integer || entry.getValue() instanceof Boolean)) {
                                it.remove();
                            }
                        }
                        vmessage.setAttributes(attrs);
                    }
                    vmessage.setAttribute(IMarker.LINE_NUMBER, message.getLineNumber());
                    vmessage.setAttribute(IMarker.MESSAGE, message.getText());
                    if (message.getOffset() > -1) {
                        vmessage.setAttribute(IMarker.CHAR_START, message.getOffset());
                        vmessage.setAttribute(IMarker.CHAR_END, message.getOffset() + message.getLength());
                    }
                    int severity = 0;
                    switch(message.getSeverity()) {
                        case IMessage.HIGH_SEVERITY:
                            severity = IMarker.SEVERITY_ERROR;
                            break;
                        case IMessage.NORMAL_SEVERITY:
                            severity = IMarker.SEVERITY_WARNING;
                            break;
                        case IMessage.LOW_SEVERITY:
                            severity = IMarker.SEVERITY_INFO;
                            break;
                    }
                    vmessage.setAttribute(IMarker.SEVERITY, severity);
                    vmessage.setType(MARKER_TYPE);
                    result.add(vmessage);
                }
            }
            monitor.done();
        } else // TLD
        {
            try {
                final IJavaProject javaProject = JavaCore.create(file.getProject());
                if (javaProject.exists()) {
                    IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
                    ProjectScope projectScope = new ProjectScope(file.getProject());
                    if (projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, false)) {
                        scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
                    }
                    Map[] problems = detectProblems(javaProject, file, scopes);
                    for (int i = 0; i < problems.length; i++) {
                        ValidatorMessage message = ValidatorMessage.create(problems[i].get(IMarker.MESSAGE).toString(), resource);
                        message.setType(MARKER_TYPE);
                        message.setAttributes(problems[i]);
                        result.add(message);
                    }
                }
            } catch (Exception e) {
                Logger.logException(e);
            }
        }
    }
    return result;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) ValidationResult(org.eclipse.wst.validation.ValidationResult) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Iterator(java.util.Iterator) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) Map(java.util.Map) MarkupValidator(org.eclipse.wst.xml.core.internal.validation.MarkupValidator) AbstractValidator(org.eclipse.wst.validation.AbstractValidator) MarkupValidator(org.eclipse.wst.xml.core.internal.validation.MarkupValidator)

Example 67 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class TagContentSettingsPropertyPage method createContents.

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(GridDataFactory.fillDefaults());
    composite.setLayout(new GridLayout(2, true));
    Object adapter = getElement().getAdapter(IFile.class);
    if (adapter == null) {
        adapter = getElement().getAdapter(IResource.class);
    }
    if (adapter != null && adapter instanceof IResource) {
        String preferenceKey = TagModelQuery.createPreferenceKey(((IResource) adapter).getFullPath());
        new DefaultScope().getNode(JSPCorePlugin.getDefault().getBundle().getSymbolicName()).put(preferenceKey, fValues[0]);
        ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(((IResource) adapter).getProject()), JSPCorePlugin.getDefault().getBundle().getSymbolicName());
        String[][] entryNamesAndValues = new String[][] { { fDisplayTypes[0], fValues[0] }, { fDisplayTypes[1], fValues[1] } };
        fComboFieldEditor = new ComboFieldEditor(preferenceKey, JSPUIMessages.JSPFContentSettingsPropertyPage_2, entryNamesAndValues, composite);
        fComboFieldEditor.fillIntoGrid(composite, 2);
        fComboFieldEditor.setPreferenceStore(store);
        fComboFieldEditor.load();
        // let the page save for us if needed
        setPreferenceStore(store);
    }
    return composite;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) IResource(org.eclipse.core.resources.IResource) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore)

Example 68 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class JSPBatchValidatorTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    String noninteractive = System.getProperty("wtp.autotest.noninteractive");
    if (noninteractive != null)
        wtp_autotest_noninteractive = noninteractive;
    System.setProperty("wtp.autotest.noninteractive", "true");
    if (!getProject().exists()) {
        BundleResourceUtil.createSimpleProject(PROJECT_NAME, null, new String[] { JavaCore.NATURE_ID });
        BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + PROJECT_NAME, "/" + PROJECT_NAME);
    }
    assertTrue("project could not be created", getProject().exists());
    String filePath = "/" + PROJECT_NAME + "/WebContent/header.jspf";
    IFile fragment = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    String qualifier = JSPCorePlugin.getDefault().getBundle().getSymbolicName();
    workspaceScope = new InstanceScope().getNode(qualifier);
    projectScope = new ProjectScope(fragment.getProject()).getNode(qualifier);
    originalWorkspaceValue = workspaceScope.get(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, null);
    Validator[] vs = ValidationFramework.getDefault().getValidators();
    for (int i = 0; i < vs.length; i++) {
        if (!"org.eclipse.jst.jsp.core.JSPBatchValidator".equals(vs[i].getId()) && !"org.eclipse.jst.jsp.core.JSPContentValidator".equals(vs[i].getId())) {
            vs[i].setManualValidation(false);
            vs[i].setBuildValidation(false);
        }
    }
    ValidationFramework.getDefault().saveValidators(vs);
}
Also used : Path(org.eclipse.core.runtime.Path) ProjectScope(org.eclipse.core.resources.ProjectScope) IFile(org.eclipse.core.resources.IFile) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) JSPContentValidator(org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator) JSPValidator(org.eclipse.jst.jsp.core.internal.validation.JSPValidator) Validator(org.eclipse.wst.validation.Validator) JSPJavaValidator(org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator) JSPBatchValidator(org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator)

Example 69 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class NewDTDWizard method applyLineDelimiter.

private String applyLineDelimiter(IFile file, String text) {
    // $NON-NLS-1$
    String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] { new ProjectScope(file.getProject()), new InstanceScope() });
    String convertedText = StringUtils.replace(text, "\r\n", "\n");
    convertedText = StringUtils.replace(convertedText, "\r", "\n");
    convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter);
    return convertedText;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope)

Example 70 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class WorkspaceTaskScanner method init.

private boolean init(IResource resource) {
    IProject project = getProject(resource);
    IPreferencesService preferencesService = Platform.getPreferencesService();
    IScopeContext[] lookupOrder = new IScopeContext[] { new ProjectScope(project), new InstanceScope(), new DefaultScope() };
    boolean proceed = preferencesService.getBoolean(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_ENABLE, false, lookupOrder);
    if (Logger.DEBUG_TASKSPREFS) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println(getClass().getName() + " scan of " + resource.getFullPath() + ":" + proceed);
    }
    if (proceed) {
        String[] tags = StringUtils.unpack(preferencesService.getString(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_TAGS, null, lookupOrder));
        String[] priorities = StringUtils.unpack(preferencesService.getString(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_PRIORITIES, null, lookupOrder));
        String[] currentIgnoreContentTypeIDs = StringUtils.unpack(preferencesService.getString(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_CONTENTTYPES_IGNORED, null, lookupOrder));
        if (Logger.DEBUG_TASKSPREFS) {
            // $NON-NLS-1$
            System.out.print(getClass().getName() + " tags: ");
            for (int i = 0; i < tags.length; i++) {
                if (i > 0) {
                    // $NON-NLS-1$
                    System.out.print(",");
                }
                System.out.print(tags[i]);
            }
            System.out.println();
            // $NON-NLS-1$
            System.out.print(getClass().getName() + " priorities: ");
            for (int i = 0; i < priorities.length; i++) {
                if (i > 0) {
                    // $NON-NLS-1$
                    System.out.print(",");
                }
                System.out.print(priorities[i]);
            }
            System.out.println();
            // $NON-NLS-1$
            System.out.print(getClass().getName() + " ignored content types: ");
            for (int i = 0; i < currentIgnoreContentTypeIDs.length; i++) {
                if (i > 0) {
                    // $NON-NLS-1$
                    System.out.print(",");
                }
                System.out.print(currentIgnoreContentTypeIDs[i]);
            }
            System.out.println();
        }
        fCurrentIgnoreContentTypes = new IContentType[currentIgnoreContentTypeIDs.length];
        IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
        for (int i = 0; i < currentIgnoreContentTypeIDs.length; i++) {
            fCurrentIgnoreContentTypes[i] = contentTypeManager.getContentType(currentIgnoreContentTypeIDs[i]);
        }
        int max = Math.min(tags.length, priorities.length);
        fCurrentTaskTags = new TaskTag[max];
        for (int i = 0; i < max; i++) {
            int priority = TaskTag.PRIORITY_NORMAL;
            try {
                priority = Integer.parseInt(priorities[i]);
            } catch (NumberFormatException e) {
            // default to normal priority
            }
            fCurrentTaskTags[i] = new TaskTag(tags[i], priority);
        }
    }
    return proceed;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) TaskTag(org.eclipse.wst.sse.core.internal.provisional.tasks.TaskTag) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) IProject(org.eclipse.core.resources.IProject) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager)

Aggregations

ProjectScope (org.eclipse.core.resources.ProjectScope)92 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)42 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)31 IProject (org.eclipse.core.resources.IProject)28 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)24 Preferences (org.osgi.service.prefs.Preferences)18 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)17 BackingStoreException (org.osgi.service.prefs.BackingStoreException)17 ScopedPreferenceStore (org.eclipse.ui.preferences.ScopedPreferenceStore)11 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 CoreException (org.eclipse.core.runtime.CoreException)8 IAdaptable (org.eclipse.core.runtime.IAdaptable)5 IPath (org.eclipse.core.runtime.IPath)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Path (org.eclipse.core.runtime.Path)4 Test (org.junit.Test)4 File (java.io.File)3