Bug 377510 - Resolver gives false positives on conflicting constraints
from a fragment
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
index d42750d..4e165e1 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
@@ -3655,6 +3655,49 @@
 		assertEquals("2.4", 1, wiresE.size());
 	}
 
+	public void testEEBug377510() throws BundleException {
+		State state = buildEmptyState();
+		int bundleID = 0;
+		Hashtable manifest = new Hashtable();
+
+		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
+		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.osgi"); //$NON-NLS-1$
+		BundleDescription systemBundle = state.getFactory().createBundleDescription(state, manifest, "org.eclipse.osgi", bundleID++); //$NON-NLS-1$
+		state.addBundle(systemBundle);
+
+		List bundles = new ArrayList();
+		manifest.clear();
+		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
+		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A"); //$NON-NLS-1$
+		manifest.put(Constants.IMPORT_PACKAGE, "test");
+		manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "JavaSE-1.6"); //$NON-NLS-1$
+		BundleDescription a = state.getFactory().createBundleDescription(state, manifest, "A", bundleID++); //$NON-NLS-1$
+		bundles.add(a);
+		state.addBundle(a);
+
+		manifest.clear();
+		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
+		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A.FRAG"); //$NON-NLS-1$
+		manifest.put(Constants.FRAGMENT_HOST, "A");
+		manifest.put(Constants.IMPORT_PACKAGE, "test");
+		manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.5"); //$NON-NLS-1$
+		BundleDescription aFrag = state.getFactory().createBundleDescription(state, manifest, "A.FRAG", bundleID++); //$NON-NLS-1$
+		bundles.add(aFrag);
+		state.addBundle(aFrag);
+
+		Dictionary[] props = new Dictionary[] {new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable()};
+		props[0].put("org.osgi.framework.executionenvironment", "J2SE-1.5");
+		props[0].put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "test");
+		props[1].put("org.osgi.framework.executionenvironment", "J2SE-1.5, JavaSE-1.6");
+		props[1].put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "test");
+		state.setPlatformProperties(props);
+
+		state.resolve();
+
+		assertTrue("host not resolved", a.isResolved());
+		assertTrue("fragment not resolved", aFrag.isResolved());
+	}
+
 	public void testBug338697() throws BundleException, IOException {
 		State state = buildEmptyState();
 		int bundleID = 0;
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java
index 0e6f865..544ae47 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java
@@ -448,7 +448,7 @@
 		for (int i = 0; i < newImports.length; i++) {
 			ResolverImport hostImport = getImport(newImports[i].getName());
 			ResolverExport resolvedExport = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier());
-			if ((resolvedExport == null && isResolved()) || (resolvedExport != null && !newImports[i].isSatisfiedBy(resolvedExport.getExportPackageDescription()))) {
+			if (importPackageConflict(resolvedExport, newImports[i])) {
 				result = true;
 				resolver.getState().addResolverError(fragment, ResolverError.FRAGMENT_CONFLICT, newImports[i].toString(), newImports[i]);
 			}
@@ -474,6 +474,12 @@
 		return result;
 	}
 
+	private boolean importPackageConflict(ResolverExport resolvedExport, ImportPackageSpecification newImport) {
+		if (resolvedExport == null)
+			return isResolved();
+		return !((ImportPackageSpecificationImpl) newImport).isSatisfiedBy(resolvedExport.getExportPackageDescription(), false);
+	}
+
 	private void setNewFragmentExports(boolean newFragmentExports) {
 		this.newFragmentExports = newFragmentExports;
 	}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java
index 83a14b1..8d7a437 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -95,6 +95,10 @@
 	}
 
 	public boolean isSatisfiedBy(BaseDescription supplier) {
+		return isSatisfiedBy(supplier, true);
+	}
+
+	public boolean isSatisfiedBy(BaseDescription supplier, boolean checkEE) {
 		if (!(supplier instanceof ExportPackageDescription))
 			return false;
 		ExportPackageDescriptionImpl pkgDes = (ExportPackageDescriptionImpl) supplier;
@@ -152,6 +156,8 @@
 		if (!hasMandatoryAttributes(mandatory))
 			return false;
 		// finally check the ee index
+		if (!checkEE)
+			return true;
 		if (((BundleDescriptionImpl) getBundle()).getEquinoxEE() < 0)
 			return true;
 		int eeIndex = ((Integer) pkgDes.getDirective(ExportPackageDescriptionImpl.EQUINOX_EE)).intValue();