Skip to main content
summaryrefslogtreecommitdiffstats
blob: 907f88c70dc0e6783868b0e4295beee46be54f31 (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
/*******************************************************************************
 * Copyright (c) 2005 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.internal.registry.osgi;

import java.io.File;
import org.eclipse.core.internal.registry.IRegistryConstants;
import org.eclipse.core.internal.runtime.RuntimeLog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.service.resolver.PlatformAdmin;

/**
 * The registry strategy used by the Equinox extension registry. Adds to the OSGi registry:
 * - Use debug information supplied via .options files
 * - Use Eclipse logging
 * - Use Eclipse platform state for cache validation
 * - Supplied alternative cache location (primarily used with shared installs)
 * 
 * @since org.eclipse.equinox.registry 3.2
 */
public class EquinoxRegistryStrategy extends RegistryStrategyOSGI {

	public static final String PLUGIN_NAME = "org.eclipse.equinox.registry"; //$NON-NLS-1$
	public static final String OPTION_DEBUG = PLUGIN_NAME + "/debug"; //$NON-NLS-1$
	public static final String OPTION_DEBUG_EVENTS = PLUGIN_NAME + "/debug/events"; //$NON-NLS-1$

	private static boolean DEBUG_ECLIPSE_REGISTRY = OSGIUtils.getDefault().getBooleanDebugOption(OPTION_DEBUG, false);
	private static boolean DEBUG_ECLIPSE_EVENTS = OSGIUtils.getDefault().getBooleanDebugOption(OPTION_DEBUG_EVENTS, false);

	public EquinoxRegistryStrategy(File theStorageDir, boolean cacheReadOnly, Object key) {
		super(theStorageDir, cacheReadOnly, key);
	}

	public boolean debug() {
		return DEBUG_ECLIPSE_REGISTRY;
	}

	public boolean debugRegistryEvents() {
		return DEBUG_ECLIPSE_EVENTS;
	}
	
	public final void log(IStatus status) {
		RuntimeLog.log(status);
	}

	public long cacheComputeState() {
		PlatformAdmin admin = OSGIUtils.getDefault().getPlatformAdmin();
		return admin == null ? -1 : admin.getState(false).getTimeStamp();
	}

	// Eclipse extension registry cache can be found in one of the two locations:
	// a) in the local configuration area (standard location passed in by the platform)
	// b) in the shared configuration area (typically, shared install is used) 
	public File cacheAlternativeLocation() {
		// In debug be careful of LocationManager.computeSharedConfigurationLocation
		// and PROP_SHARED_CONFIG_AREA = "osgi.sharedConfiguration.area" - it
		// seems to work differently comparing to stand-alone execution.
		Location currentLocation = OSGIUtils.getDefault().getConfigurationLocation();
		if (currentLocation == null)
			return null;
		Location parentLocation = currentLocation.getParentLocation();
		if (parentLocation == null)
			return null;
		String theRegistryLocation = parentLocation.getURL().getFile() + '/' + IRegistryConstants.RUNTIME_NAME;
		return new File(theRegistryLocation);
	}

}

Back to the top