Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e5f6c450c2ff0d4ed2e108f42bddd10582a41628 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2005, 2009 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
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.core.runtime.internal.adaptor;

import org.eclipse.osgi.storage.bundlefile.BundleEntry;

import java.io.IOException;
import java.io.InputStream;
import java.util.jar.Manifest;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.loader.*;
import org.eclipse.osgi.framework.util.KeyedElement;

public class ClasspathManifest implements KeyedElement {
	public static final Object KEY = new Object();
	public static final int HASHCODE = KEY.hashCode();

	private Manifest manifest;
	private boolean initialized = false;

	public int getKeyHashCode() {
		return HASHCODE;
	}

	public boolean compare(KeyedElement other) {
		return other.getKey() == KEY;
	}

	public Object getKey() {
		return KEY;
	}

	public synchronized Manifest getManifest(ClasspathEntry cpEntry, ClasspathManager loader) {
		if (initialized)
			return manifest;
		if (!hasPackageInfo(cpEntry, loader)) {
			initialized = true;
			manifest = null;
			return manifest;
		}
		BundleEntry mfEntry = cpEntry.getBundleFile().getEntry(org.eclipse.osgi.framework.internal.core.Constants.OSGI_BUNDLE_MANIFEST);
		if (mfEntry != null) {
			InputStream manIn = null;
			try {
				try {
					manIn = mfEntry.getInputStream();
					manifest = new Manifest(manIn);
				} finally {
					if (manIn != null)
						manIn.close();
				}
			} catch (IOException e) {
				// do nothing
			}
		}
		initialized = true;
		return manifest;
	}

	private boolean hasPackageInfo(ClasspathEntry cpEntry, ClasspathManager loader) {
		BaseData bundledata = null;
		if (cpEntry.getBundleFile() == loader.getBaseData().getBundleFile())
			bundledata = loader.getBaseData();
		if (bundledata == null) {
			FragmentClasspath[] fragCPs = loader.getFragmentClasspaths();
			if (fragCPs != null)
				for (int i = 0; i < fragCPs.length; i++)
					if (cpEntry.getBundleFile() == fragCPs[i].getBundleData().getBundleFile()) {
						bundledata = fragCPs[i].getBundleData();
						break;
					}
		}
		if (bundledata == null)
			return true;
		EclipseStorageHook storageHook = (EclipseStorageHook) bundledata.getStorageHook(EclipseStorageHook.KEY);
		return storageHook == null ? true : storageHook.hasPackageInfo();
	}

}

Back to the top