Skip to main content
summaryrefslogtreecommitdiffstats
blob: 71e7bf352b49697130dc93e49ad99d1de9e3a472 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
 *  Copyright (c) 2010  Oracle. 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 http://www.eclipse.org/legal/epl-v10.html
 *  
 *  Contributors: 
 *  	Oracle - initial API and implementation
 *******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.libval;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jpt.common.core.libval.LibraryValidator;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
import org.eclipse.jpt.jpa.core.internal.libprov.JpaOsgiBundlesLibraryProviderInstallOperationConfig;
import org.eclipse.jst.common.project.facet.core.libprov.osgi.BundleReference;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;

public abstract class AbstractOsgiBundlesLibraryValidator
		implements LibraryValidator {
	
	protected IStatus validate(
			JpaOsgiBundlesLibraryProviderInstallOperationConfig config, 
			Map<String, VersionRange[]> bundleVersionRanges) {
		
		Map<String, Bundle> bundles = new HashMap<String, Bundle>();
		
		for (BundleReference bundleRef : config.getBundleReferences()) {
			for (String bundleName : bundleVersionRanges.keySet()) {
				// if we've gotten here, the bundle references are resolvable
				if (bundleRef.getBundle().getSymbolicName().equals(bundleName)) {
					bundles.put(bundleName, bundleRef.getBundle());
				}
			}
		}
		
		for (String bundleName : bundleVersionRanges.keySet()) {
			if (bundles.get(bundleName) == null) {
				String message 
						= NLS.bind(JptCoreMessages.OSGI_BUNDLES_LIBRARY_VALIDATOR__BUNDLE_NOT_FOUND, bundleName);
				return new Status(IStatus.ERROR, JptJpaCorePlugin.PLUGIN_ID, message);
			}
		}
		
		for (String bundleName : bundleVersionRanges.keySet()) {
			Bundle bundle = bundles.get(bundleName);
			for (VersionRange versionRange : bundleVersionRanges.get(bundleName)) {
				if (! versionRange.isIncluded(bundle.getVersion())) {
					String message 
							= NLS.bind(JptCoreMessages.OSGI_BUNDLES_LIBRARY_VALIDATOR__IMPROPER_BUNDLE_VERSION, bundleName);
					return new Status(IStatus.ERROR, JptJpaCorePlugin.PLUGIN_ID, message);
				}
			}
		}
		
		return Status.OK_STATUS;
	}
}

Back to the top