// TODO we should only validate versions that we have a match
private void validateImportPackage(IProgressMonitor monitor) {
        IHeader header = getHeader(Constants.IMPORT_PACKAGE);
        if (header == null)
            return;
        BundleDescription desc = fModel.getBundleDescription();
        if (desc == null) {
            ManifestElement[] elements = header.getElements();
            for (int i = 0; i < elements.length; i++) {
                validateSpecificationVersionAttribute(header, elements[i]);
                validateImportPackageVersion(header, elements[i]);
            }
            return;
        }
        boolean hasUnresolved = false;
        VersionConstraint[] constraints = desc.getContainingState().getStateHelper().getUnsatisfiedConstraints(desc);
        for (int i = 0; i < constraints.length; i++) {
            if (constraints[i] instanceof ImportPackageSpecification) {
                hasUnresolved = true;
                break;
            }
        }
        HashMap<String, ExportPackageDescription> exported = getAvailableExportedPackages(desc.getContainingState());
        ImportPackageSpecification[] imports = desc.getImportPackages();
        if (desc.hasDynamicImports()) {
            List<ImportPackageSpecification> staticImportsList = new ArrayList();
            for (int i = 0; i < imports.length; ++i) {
                if (!imports[i].getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_DYNAMIC))
                    staticImportsList.add(imports[i]);
            }
            imports = staticImportsList.toArray(new ImportPackageSpecification[staticImportsList.size()]);
        }
        ManifestElement[] elements = header.getElements();
        int index = 0;
        for (int i = 0; i < elements.length; i++) {
            checkCanceled(monitor);
            validateSpecificationVersionAttribute(header, elements[i]);
            validateResolutionDirective(header, elements[i]);
            // TODO we should only validate versions that we have a match
            validateImportPackageVersion(header, elements[i]);
            if (!hasUnresolved)
                continue;
            int length = elements[i].getValueComponents().length;
            for (int j = 0; j < length; j++) {
                ImportPackageSpecification importSpec = imports[index++];
                String name = importSpec.getName();
                if (//$NON-NLS-1$ //$NON-NLS-2$
                name.equals("java") || name.startsWith("java.")) {
                    IHeader jreHeader = getHeader(ICoreConstants.ECLIPSE_JREBUNDLE);
                    if (jreHeader == null || !"true".equals(//$NON-NLS-1$
                    jreHeader.getValue())) {
                        report(PDECoreMessages.BundleErrorReporter_importNoJRE, getPackageLine(header, elements[i]), CompilerFlags.ERROR, PDEMarkerFactory.M_JAVA_PACKAGE__PORTED, PDEMarkerFactory.CAT_FATAL);
                        continue;
                    }
                }
                if (importSpec.isResolved() || !isCheckUnresolvedImports())
                    continue;
                boolean optional = isOptional(elements[i]);
                int severity = getRequireBundleSeverity(elements[i], optional);
                ExportPackageDescription export = exported.get(name);
                if (export != null) {
                    if (export.getSupplier().isResolved()) {
                        Version version = export.getVersion();
                        org.eclipse.osgi.service.resolver.VersionRange range = importSpec.getVersionRange();
                        if (range != null && !range.isIncluded(version)) {
                            report(NLS.bind(PDECoreMessages.BundleErrorReporter_unsatisfiedConstraint, importSpec.toString()), getPackageLine(header, elements[i]), severity, PDEMarkerFactory.CAT_FATAL);
                        }
                    } else {
                        report(NLS.bind(PDECoreMessages.BundleErrorReporter_unresolvedExporter, new String[] { export.getSupplier().getSymbolicName(), name }), getPackageLine(header, elements[i]), severity, PDEMarkerFactory.CAT_OTHER);
                    }
                } else {
                    IMarker marker = report(NLS.bind(PDECoreMessages.BundleErrorReporter_PackageNotExported, name), getPackageLine(header, elements[i]), severity, PDEMarkerFactory.M_IMPORT_PKG_NOT_AVAILABLE, PDEMarkerFactory.CAT_FATAL);
                    try {
                        if (marker != null) {
                            //$NON-NLS-1$
                            marker.setAttribute(//$NON-NLS-1$
                            "packageName", //$NON-NLS-1$
                            name);
                            if (optional)
                                //$NON-NLS-1$
                                marker.setAttribute(//$NON-NLS-1$
                                "optional", //$NON-NLS-1$
                                true);
                        }
                    } catch (CoreException e) {
                    }
                }
            }
        }
    }
validateSpecificationVersionAttribute(header, elements[i]);
validateResolutionDirective(header, elements[i]);
// TODO we should only validate versions that we have a match
validateImportPackageVersion(header, elements[i]);
if (!hasUnresolved)
staticImportsList.add(imports[i]);
}
imports = staticImportsList.toArray(new ImportPackageSpecification[staticImportsList.size()]);
}
ManifestElement[] elements = header.getElements();
int index = 0;
for (int i = 0; i < elements.length; i++) {
checkCanceled(monitor);
validateSpecificationVersionAttribute(header, elements[i]);
validateResolutionDirective(header, elements[i]);
// TODO we should only validate versions that we have a match
validateImportPackageVersion(header, elements[i]);
if (!hasUnresolved)
continue;
int length = elements[i].getValueComponents().length;
for (int j = 0; j < length; j++) {
ImportPackageSpecification importSpec = imports[index++];
String name = importSpec.getName();
if (//$NON-NLS-1$ //$NON-NLS-2$
name.equals("java") || name.startsWith("java.")) {
IHeader jreHeader = getHeader(ICoreConstants.ECLIPSE_JREBUNDLE);
hasUnresolved = true;
break;
}
}
HashMap<String, ExportPackageDescription> exported = getAvailableExportedPackages(desc.getContainingState());
ImportPackageSpecification[] imports = desc.getImportPackages();
if (desc.hasDynamicImports()) {
List<ImportPackageSpecification> staticImportsList = new ArrayList();
for (int i = 0; i < imports.length; ++i) {
if (!imports[i].getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_DYNAMIC))
staticImportsList.add(imports[i]);
}
imports = staticImportsList.toArray(new ImportPackageSpecification[staticImportsList.size()]);
}
ManifestElement[] elements = header.getElements();
int index = 0;
for (int i = 0; i < elements.length; i++) {
checkCanceled(monitor);
validateSpecificationVersionAttribute(header, elements[i]);
validateResolutionDirective(header, elements[i]);
// TODO we should only validate versions that we have a match
validateImportPackageVersion(header, elements[i]);
if (!hasUnresolved)
continue;
int length = elements[i].getValueComponents().length;
for (int j = 0; j < length; j++) {
ImportPackageSpecification importSpec = imports[index++];
String name = importSpec.getName();
if (//$NON-NLS-1$ //$NON-NLS-2$
name.equals("java") || name.startsWith("java.")) {
IHeader jreHeader = getHeader(ICoreConstants.ECLIPSE_JREBUNDLE);
if (jreHeader == null || !"true".equals(//$NON-NLS-1$
jreHeader.getValue())) {
report(PDECoreMessages.BundleErrorReporter_importNoJRE, getPackageLine(header, elements[i]), CompilerFlags.ERROR, PDEMarkerFactory.M_JAVA_PACKAGE__PORTED, PDEMarkerFactory.CAT_FATAL);
continue;
}
}
if (importSpec.isResolved() || !isCheckUnresolvedImports())
continue;
boolean optional = isOptional(elements[i]);
int severity = getRequireBundleSeverity(elements[i], optional);