public ExtensionsErrorReporter(IFile file) { super(file); fModel = MonitorRegistry.findModel(file.getProject()); try { if (fModel != null && fModel.getUnderlyingResource() != null) fBuildModel = ClasspathUtilCore.getBuild(fModel); } catch (CoreException e) { } }
public void validateContent(IProgressMonitor monitor) { Element element = getDocumentRoot(); if (element == null) return; String elementName = element.getNodeName(); if (!"plugin".equals(elementName) && !"fragment".equals(elementName)) { // $NON-NLS-1$ //$NON-NLS-2$ reportIllegalElement(element, CompilerFlags.ERROR); } else { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED); if (severity != CompilerFlags.IGNORE) { NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { reportUnusedAttribute(element, attrs.item(i).getNodeName(), severity); } } NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (monitor.isCanceled()) break; Element child = (Element) children.item(i); String name = child.getNodeName(); if (name.equals("extension")) { // $NON-NLS-1$ validateExtension(child); } else if (name.equals("extension-point")) { // $NON-NLS-1$ validateExtensionPoint(child); } else { if (!name.equals("runtime") && !name.equals("requires")) { // $NON-NLS-1$ //$NON-NLS-2$ severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); if (severity != CompilerFlags.IGNORE) reportIllegalElement(child, severity); } else { severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED); if (severity != CompilerFlags.IGNORE) reportUnusedElement(child, severity); } } } IExtensions extensions = fModel.getExtensions(); if (extensions != null && extensions.getExtensions().length == 0 && extensions.getExtensionPoints().length == 0) report( MDECoreMessages.Builders_Manifest_useless_file, -1, IMarker.SEVERITY_WARNING, MDEMarkerFactory.P_USELESS_FILE, MDEMarkerFactory.CAT_OTHER); } }
protected void validateJavaAttribute(Element element, Attr attr) { String value = attr.getValue(); IJavaProject javaProject = JavaCore.create(fFile.getProject()); // be careful: people have the option to use the format: // fullqualifiedName:staticMethod int index = value.indexOf(":"); // $NON-NLS-1$ if (index != -1) value = value.substring(0, index); // assume we're on the classpath already boolean onClasspath = true; int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_CLASS); if (severity != CompilerFlags.IGNORE && javaProject.isOpen()) { onClasspath = PDEJavaHelper.isOnClasspath(value, javaProject); if (!onClasspath) { report( NLS.bind( MDECoreMessages.Builders_Manifest_class, (new String[] {value, attr.getName()})), getLine(element, attr.getName()), severity, MDEMarkerFactory.P_UNKNOWN_CLASS, element, attr.getName() + F_ATT_VALUE_PREFIX + attr.getValue(), MDEMarkerFactory.CAT_FATAL); } } severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DISCOURAGED_CLASS); if (severity != CompilerFlags.IGNORE && javaProject.isOpen()) { BundleDescription desc = fModel.getBundleDescription(); if (desc == null) return; // only check if we're discouraged if there is something on the classpath if (onClasspath && PDEJavaHelper.isDiscouraged(value, javaProject, desc)) { report( NLS.bind( MDECoreMessages.Builders_Manifest_discouragedClass, (new String[] {value, attr.getName()})), getLine(element, attr.getName()), severity, MDEMarkerFactory.M_DISCOURAGED_CLASS, element, attr.getName() + F_ATT_VALUE_PREFIX + attr.getValue(), MDEMarkerFactory.CAT_OTHER); } } }
private void validateInternalExtensionAttribute(Element element, ISchemaElement schemaElement) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_INTERNAL); if (severity == CompilerFlags.IGNORE) return; if (schemaElement instanceof ISchemaRootElement) { ISchemaRootElement rootElement = (ISchemaRootElement) schemaElement; String epid = schemaElement.getSchema().getPluginId(); String pid = fModel.getMonitorBase().getId(); if (epid == null || pid == null) return; if (rootElement.isInternal() && !epid.equals(pid)) { String point = element.getAttribute("point"); // $NON-NLS-1$ if (point == null) return; // should never come to this... report( NLS.bind(MDECoreMessages.Builders_Manifest_internal_rootElement, point), getLine(element, "point"), severity, MDEMarkerFactory.CAT_DEPRECATION); // $NON-NLS-1$ } } }
private boolean resourceExists(String location) { String bundleJar = null; IPath path = new Path(location); if ("platform:".equals(path.getDevice()) && path.segmentCount() > 2) { // $NON-NLS-1$ if ("plugin".equals(path.segment(0))) { // $NON-NLS-1$ String id = path.segment(1); IMonitorModelBase model = MonitorRegistry.findModel(id); if (model != null && model.isEnabled()) { path = path.setDevice(null).removeFirstSegments(2); String bundleLocation = model.getInstallLocation(); if (bundleLocation.endsWith(".jar")) { // $NON-NLS-1$ bundleJar = bundleLocation; } else { path = new Path(model.getInstallLocation()).append(path); } location = path.toString(); } } } else if (path.getDevice() == null && path.segmentCount() > 3 && "platform:".equals(path.segment(0))) { // $NON-NLS-1$ if ("plugin".equals(path.segment(1))) { // $NON-NLS-1$ String id = path.segment(2); IMonitorModelBase model = MonitorRegistry.findModel(id); if (model != null && model.isEnabled()) { path = path.removeFirstSegments(3); String bundleLocation = model.getInstallLocation(); if (bundleLocation.endsWith(".jar")) { // $NON-NLS-1$ bundleJar = bundleLocation; } else { path = new Path(model.getInstallLocation()).append(path); } location = path.toString(); } } } ArrayList paths = new ArrayList(); if (location.indexOf("$nl$") != -1) { // $NON-NLS-1$ StringTokenizer tokenizer = new StringTokenizer(TargetPlatform.getNL(), "_"); // $NON-NLS-1$ String language = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null; String country = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null; if (language != null && country != null) paths.add( location.replaceAll( "\\$nl\\$", "nl" + IPath.SEPARATOR + language + IPath.SEPARATOR + country)); //$NON-NLS-1$ //$NON-NLS-2$ if (language != null) paths.add( location.replaceAll( "\\$nl\\$", "nl" + IPath.SEPARATOR + language)); // $NON-NLS-1$ //$NON-NLS-2$ paths.add(location.replaceAll("\\$nl\\$", "")); // $NON-NLS-1$ //$NON-NLS-2$ } else { paths.add(location); } for (int i = 0; i < paths.size(); i++) { if (bundleJar == null) { IPath currPath = new Path(paths.get(i).toString()); if (currPath.isAbsolute() && currPath.toFile().exists()) return true; if (PDEProject.getBundleRoot(fFile.getProject()).findMember(currPath) != null) return true; if (fBuildModel != null && fBuildModel.getEntry("source." + paths.get(i)) != null) // $NON-NLS-1$ return true; } else { if (CoreUtility.jarContainsResource(new File(bundleJar), paths.get(i).toString(), false)) return true; } } return false; }