Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 240724 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Chris Aniszczyk <zx@code9.com> - bug 240724
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.osgi.tests.eclipseadaptor;
12
package org.eclipse.osgi.tests.eclipseadaptor;
12
13
Lines 18-23 Link Here
18
		TestSuite suite = new TestSuite(AllTests.class.getName());
19
		TestSuite suite = new TestSuite(AllTests.class.getName());
19
		suite.addTest(EnvironmentInfoTest.suite());
20
		suite.addTest(EnvironmentInfoTest.suite());
20
		suite.addTest(FilePathTest.suite());
21
		suite.addTest(FilePathTest.suite());
22
		suite.addTest(ExecutionEnvironmentTest.suite());
21
		return suite;
23
		return suite;
22
	}
24
	}
23
}
25
}
(-)src/org/eclipse/osgi/tests/eclipseadaptor/ExecutionEnvironmentTest.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Code 9 Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Code 9 Corporation - initial API and implementation
10
 *     Chris Aniszczyk <zx@code9.com> - bug 240724
11
 *******************************************************************************/
12
package org.eclipse.osgi.tests.eclipseadaptor;
13
14
import junit.framework.*;
15
import org.eclipse.osgi.service.environment.ExecutionEnvironment;
16
import org.eclipse.osgi.service.environment.ExecutionEnvironmentService;
17
import org.eclipse.osgi.tests.OSGiTestsActivator;
18
import org.osgi.framework.ServiceReference;
19
20
public class ExecutionEnvironmentTest extends TestCase {
21
22
	public static Test suite() {
23
		return new TestSuite(ExecutionEnvironmentTest.class);
24
	}
25
26
	public ExecutionEnvironmentTest(String name) {
27
		super(name);
28
	}
29
30
	public void testExecutionEnvironments() {
31
		ServiceReference reference = null;
32
		reference = OSGiTestsActivator.getContext().getServiceReference(ExecutionEnvironmentService.class.getName());
33
		assertNotNull(reference);
34
35
		ExecutionEnvironmentService eeService = (ExecutionEnvironmentService) OSGiTestsActivator.getContext().getService(reference);
36
		assertNotNull(eeService);
37
38
		ExecutionEnvironment[] environments = eeService.getExecutionEnvironments();
39
		assertNotNull(environments);
40
41
		ExecutionEnvironment env1 = eeService.getExecutionEnvironment("CDC-1.1/Foundation-1.1"); //$NON-NLS-1$
42
		assertNotNull(env1);
43
44
		// TODO add more tests
45
	}
46
}
(-)core/framework/org/eclipse/osgi/framework/internal/core/SystemBundleActivator.java (-12 / +14 lines)
Lines 14-19 Link Here
14
import java.util.Dictionary;
14
import java.util.Dictionary;
15
import java.util.Hashtable;
15
import java.util.Hashtable;
16
import org.eclipse.osgi.framework.debug.FrameworkDebugOptions;
16
import org.eclipse.osgi.framework.debug.FrameworkDebugOptions;
17
import org.eclipse.osgi.service.environment.ExecutionEnvironmentService;
17
import org.osgi.framework.*;
18
import org.osgi.framework.*;
18
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
19
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
19
20
Lines 22-41 Link Here
22
 */
23
 */
23
24
24
public class SystemBundleActivator implements BundleActivator {
25
public class SystemBundleActivator implements BundleActivator {
25
	protected BundleContext context;
26
	private BundleContext context;
26
	protected SystemBundle bundle;
27
	private Framework framework;
27
	protected Framework framework;
28
	private ServiceRegistration packageAdmin;
28
	protected ServiceRegistration packageAdmin;
29
	private ServiceRegistration securityAdmin;
29
	protected ServiceRegistration securityAdmin;
30
	private ServiceRegistration startLevel;
30
	protected ServiceRegistration startLevel;
31
	private ServiceRegistration debugOptions;
31
	protected ServiceRegistration debugOptions;
32
	private ServiceRegistration eeService;
32
33
33
	public SystemBundleActivator() {
34
	public SystemBundleActivator() {
34
	}
35
	}
35
36
36
	public void start(BundleContext context) throws Exception {
37
	public void start(BundleContext context) throws Exception {
37
		this.context = context;
38
		this.context = context;
38
		bundle = (SystemBundle) context.getBundle();
39
		SystemBundle bundle = (SystemBundle) context.getBundle();
39
		framework = bundle.framework;
40
		framework = bundle.framework;
40
41
41
		if (framework.packageAdmin != null)
42
		if (framework.packageAdmin != null)
Lines 48-53 Link Here
48
		if ((dbgOptions = FrameworkDebugOptions.getDefault()) != null)
49
		if ((dbgOptions = FrameworkDebugOptions.getDefault()) != null)
49
			debugOptions = register(new String[] {org.eclipse.osgi.service.debug.DebugOptions.class.getName()}, dbgOptions);
50
			debugOptions = register(new String[] {org.eclipse.osgi.service.debug.DebugOptions.class.getName()}, dbgOptions);
50
51
52
		eeService = register(new String[] {ExecutionEnvironmentService.class.getName()}, new ExecutionEnvironmentServiceImpl(bundle));
51
		// Always call the adaptor.frameworkStart() at the end of this method.
53
		// Always call the adaptor.frameworkStart() at the end of this method.
52
		framework.adaptor.frameworkStart(context);
54
		framework.adaptor.frameworkStart(context);
53
		// attempt to resolve all bundles
55
		// attempt to resolve all bundles
Lines 70-78 Link Here
70
			startLevel.unregister();
72
			startLevel.unregister();
71
		if (debugOptions != null)
73
		if (debugOptions != null)
72
			debugOptions.unregister();
74
			debugOptions.unregister();
73
75
		if (eeService != null)
76
			eeService.unregister();
74
		framework = null;
77
		framework = null;
75
		bundle = null;
76
		this.context = null;
78
		this.context = null;
77
	}
79
	}
78
80
Lines 82-91 Link Here
82
	 */
84
	 */
83
	protected ServiceRegistration register(String[] names, Object service) {
85
	protected ServiceRegistration register(String[] names, Object service) {
84
		Hashtable properties = new Hashtable(7);
86
		Hashtable properties = new Hashtable(7);
85
		Dictionary headers = bundle.getHeaders();
87
		Dictionary headers = context.getBundle().getHeaders();
86
		properties.put(Constants.SERVICE_VENDOR, headers.get(Constants.BUNDLE_VENDOR));
88
		properties.put(Constants.SERVICE_VENDOR, headers.get(Constants.BUNDLE_VENDOR));
87
		properties.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
89
		properties.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
88
		properties.put(Constants.SERVICE_PID, bundle.getBundleId() + "." + service.getClass().getName()); //$NON-NLS-1$
90
		properties.put(Constants.SERVICE_PID, context.getBundle().getBundleId() + "." + service.getClass().getName()); //$NON-NLS-1$
89
		return context.registerService(names, service, properties);
91
		return context.registerService(names, service, properties);
90
	}
92
	}
91
93
(-)supplement/src/org/eclipse/osgi/service/environment/ExecutionEnvironment.java (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Code 9 Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Chris Aniszczyk <zx@code9.com> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.osgi.service.environment;
12
13
/**
14
 * An execution environment describes the VM which the 
15
 * framework can run in.  Execution environments describe 
16
 * the packages available from the VM and the other 
17
 * execution environments which are supported by the 
18
 * execution environment (subsets of the execution environment). 
19
 * 
20
 * @since 3.5
21
 * @noimplement This interface is not intended to be implemented by clients.
22
 */
23
// TODO Consider making this a concrete class instead of an interface.
24
public interface ExecutionEnvironment {
25
26
	/**
27
	 * The unique and primary name of the execution environment profile
28
	 * 
29
	 * @since 3.5
30
	 */
31
	public String getName();
32
33
	/**
34
	 * A comma separated list of export package descriptions that specify
35
	 * the packages available from this execution environment.
36
	 * 
37
	 * @see {@link org.osgi.framework.Constants#FRAMEWORK_SYSTEMPACKAGES}
38
	 */
39
	public String getSystemPackages();
40
41
	/**
42
	 * A comma separated list of environment names supported by this 
43
	 * execution environment.
44
	 * @see {@link org.osgi.framework.Constants#FRAMEWORK_EXECUTIONENVIRONMENT}
45
	 */
46
	public String getSupportedEnvironments();
47
48
}
(-)supplement/src/org/eclipse/osgi/service/environment/ExecutionEnvironmentService.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Code 9 Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Chris Aniszczyk <zx@code9.com> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.osgi.service.environment;
12
13
/**
14
 * The profile service is used to register, unregister and acquire profiles.
15
 * 
16
 * <p>
17
 * Profiles available by default:
18
 * <ul>
19
 * 	<li>OSGi/Minimum-1.0</li>
20
 * 	<li>OSGi/Minimum-1.1</li>
21
 *  <li>CDC-1.0/Foundation-1.0</li>
22
 *  <li>CDC-1.1/Foundation-1.1</li>
23
 *  <li>JRE-1.1</li>
24
 *  <li>J2SE-1.2</li>
25
 *  <li>J2SE-1.3</li>
26
 *  <li>J2SE-1.4</li>
27
 *  <li>J2SE-1.5</li>
28
 *  <li>JavaSE-1.6</li>
29
 * </p>
30
 * 
31
 * <p>
32
 * This interface is not intended to be implemented by clients.
33
 * </p>
34
 * 
35
 * @since 3.5
36
 * @noimplement This interface is not intended to be implemented by clients.
37
 */
38
public interface ExecutionEnvironmentService {
39
	/**
40
	 * Get an execution environment profile.
41
	 * 
42
	 * @param name the unique name of the execution environment
43
	 * 
44
	 * @return A <code>ExecutionEnvironment</code> for the given unique name.
45
	 * A value of <code>null</code> is returned if the execution environment 
46
	 * does not exist.
47
	 */
48
	public ExecutionEnvironment getExecutionEnvironment(String name);
49
50
	/**
51
	 * Acquire the list of all available execution environment profiles
52
	 * 
53
	 * @param name the unique name of the profile
54
	 * 
55
	 * @return A list of <code>ExecutionEnvironment</code> available.  An 
56
	 * empty array is returned if no execution environments are available.
57
	 */
58
	public ExecutionEnvironment[] getExecutionEnvironments();
59
60
}
(-)core/framework/org/eclipse/osgi/framework/internal/core/ExecutionEnvironmentServiceImpl.java (+90 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Code 9 Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Chris Aniszczyk <zx@code9.com> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.osgi.framework.internal.core;
12
13
import java.io.*;
14
import java.net.URL;
15
import java.util.*;
16
import org.eclipse.osgi.service.environment.ExecutionEnvironment;
17
import org.eclipse.osgi.service.environment.ExecutionEnvironmentService;
18
import org.osgi.framework.Bundle;
19
20
public class ExecutionEnvironmentServiceImpl implements ExecutionEnvironmentService {
21
22
	private final static String PROFILE_EXT = ".profile";
23
	private final Bundle systemBundle;
24
	private Map profileMap;
25
26
	/** This constructor is called by the Framework */
27
	protected ExecutionEnvironmentServiceImpl(Bundle systemBundle) {
28
		this.systemBundle = systemBundle;
29
	}
30
31
	public synchronized ExecutionEnvironment getExecutionEnvironment(String name) {
32
		return (ExecutionEnvironment) getProfiles().get(name);
33
	}
34
35
	public synchronized ExecutionEnvironment[] getExecutionEnvironments() {
36
		return (ExecutionEnvironment[]) getProfiles().values().toArray(new ExecutionEnvironment[profileMap.size()]);
37
	}
38
39
	// @GuardedBy(this)
40
	private Map getProfiles() {
41
		if (profileMap == null)
42
			profileMap = new HashMap(7);
43
		discoverProfiles(profileMap);
44
		return profileMap;
45
	}
46
47
	private void discoverProfiles(Map profiles) {
48
		Enumeration frameworkEntries = systemBundle.getEntryPaths("/"); //$NON-NLS-1$
49
		if (frameworkEntries != null)
50
			while (frameworkEntries.hasMoreElements()) {
51
				String path = (String) frameworkEntries.nextElement();
52
				if (path.endsWith(PROFILE_EXT)) {
53
					URL profile = systemBundle.getEntry(path);
54
					ExecutionEnvironment ee = loadEE(profile);
55
					if (ee != null)
56
						profiles.put(ee.getName(), ee);
57
				}
58
			}
59
		Enumeration fragmentEntries = systemBundle.findEntries("profiles", "*.profile", false); //$NON-NLS-1$ //$NON-NLS-2$
60
		if (fragmentEntries != null)
61
			while (fragmentEntries.hasMoreElements()) {
62
				URL profile = (URL) fragmentEntries.nextElement();
63
				ExecutionEnvironment ee = loadEE(profile);
64
				if (ee != null)
65
					profiles.put(ee.getName(), ee);
66
			}
67
	}
68
69
	private ExecutionEnvironment loadEE(URL profile) {
70
		InputStream in = null;
71
		try {
72
			Properties properties = new Properties();
73
			in = profile.openStream();
74
			properties.load(new BufferedInputStream(in));
75
			// time to create profiles!
76
			return new ExecutionEnvironmentImpl(properties);
77
		} catch (IOException ex) {
78
			// TODO consider logging or throwing...
79
			return null;
80
		} finally {
81
			if (in != null)
82
				try {
83
					in.close();
84
				} catch (IOException ee) {
85
					// do nothing
86
				}
87
		}
88
	}
89
90
}
(-)core/framework/org/eclipse/osgi/framework/internal/core/ExecutionEnvironmentImpl.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Code 9 Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Chris Aniszczyk <zx@code9.com> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.osgi.framework.internal.core;
12
13
import java.util.Properties;
14
import org.eclipse.osgi.service.environment.ExecutionEnvironment;
15
16
public class ExecutionEnvironmentImpl implements ExecutionEnvironment {
17
18
	private final String name;
19
	private final String environments;
20
	private final String packages;
21
22
	public ExecutionEnvironmentImpl(Properties properties) {
23
		this.name = properties.getProperty(Constants.OSGI_JAVA_PROFILE_NAME);
24
		this.environments = properties.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
25
		this.packages = properties.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
26
	}
27
28
	public String getName() {
29
		return name;
30
	}
31
32
	public String getSupportedEnvironments() {
33
		return environments;
34
	}
35
36
	public String getSystemPackages() {
37
		return packages;
38
	}
39
40
	public String toString() {
41
		return name;
42
	}
43
44
}

Return to bug 240724