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 207505 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/osgi/tests/bundles/BundleTests.java (+1 lines)
Lines 16-21 Link Here
16
public class BundleTests {
16
public class BundleTests {
17
	public static Test suite() {
17
	public static Test suite() {
18
		TestSuite suite = new TestSuite(BundleTests.class.getName());
18
		TestSuite suite = new TestSuite(BundleTests.class.getName());
19
		suite.addTest(PackageAdminBundleTests.suite());
19
		suite.addTest(PlatformAdminBundleTests.suite());
20
		suite.addTest(PlatformAdminBundleTests.suite());
20
		suite.addTest(ExtensionBundleTests.suite());
21
		suite.addTest(ExtensionBundleTests.suite());
21
		suite.addTest(ClassLoadingBundleTests.suite());
22
		suite.addTest(ClassLoadingBundleTests.suite());
(-)src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java (+113 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.osgi.tests.bundles;
12
13
import java.util.ArrayList;
14
import junit.framework.Test;
15
import junit.framework.TestSuite;
16
import org.eclipse.osgi.tests.OSGiTestsActivator;
17
import org.osgi.framework.*;
18
19
public class PackageAdminBundleTests extends AbstractBundleTests {
20
	public class TestListener implements SynchronousBundleListener {
21
		ArrayList events = new ArrayList();
22
23
		public synchronized void bundleChanged(BundleEvent event) {
24
			events.add(event);
25
		}
26
27
		public synchronized BundleEvent[] getEvents() {
28
			try {
29
				return (BundleEvent[]) events.toArray(new BundleEvent[0]);
30
			} finally {
31
				events.clear();
32
			}
33
		}
34
	}
35
36
	public static Test suite() {
37
		return new TestSuite(PackageAdminBundleTests.class);
38
	}
39
40
	public void testBundleEvents01() throws Exception {
41
		Bundle chainTest = installer.installBundle("chain.test");
42
		Bundle chainTestA = installer.installBundle("chain.test.a");
43
		Bundle chainTestB = installer.installBundle("chain.test.b");
44
		Bundle chainTestC = installer.installBundle("chain.test.c");
45
		Bundle chainTestD = installer.installBundle("chain.test.d");
46
		Bundle[] resolveBundles = new Bundle[] {chainTestC, chainTestA, chainTestB, chainTest, chainTestD};
47
		Bundle[] dependencyOrder = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
48
		TestListener testListener = new TestListener();
49
		OSGiTestsActivator.getContext().addBundleListener(testListener);
50
		try {
51
			installer.resolveBundles(resolveBundles);
52
			BundleEvent[] events = testListener.getEvents();
53
			assertEquals("Event count", 10, events.length);
54
			int j = 0;
55
			for (int i = dependencyOrder.length - 1; i >= 0; i--, j++) {
56
				assertTrue("Resolved Event Bundle: " + dependencyOrder[i].getSymbolicName(), dependencyOrder[i] == events[j].getBundle());
57
				assertEquals("Expecting Resolved event", BundleEvent.RESOLVED, events[j].getType());
58
			}
59
			j = 5;
60
			for (int i = dependencyOrder.length - 1; i >= 0; i--, j++) {
61
				assertTrue("Lazy Starting Bundle: " + dependencyOrder[i].getSymbolicName(), dependencyOrder[i] == events[j].getBundle());
62
				assertEquals("Expecting Lazy Starting event", BundleEvent.LAZY_ACTIVATION, events[j].getType());
63
			}
64
		} finally {
65
			OSGiTestsActivator.getContext().removeBundleListener(testListener);
66
		}
67
	}
68
69
	public void testBundleEvents02() throws Exception {
70
		Bundle chainTest = installer.installBundle("chain.test");
71
		Bundle chainTestA = installer.installBundle("chain.test.a");
72
		Bundle chainTestB = installer.installBundle("chain.test.b");
73
		Bundle chainTestC = installer.installBundle("chain.test.c");
74
		Bundle chainTestD = installer.installBundle("chain.test.d");
75
		Bundle[] resolveBundles = new Bundle[] {chainTestC, chainTestA, chainTestB, chainTest, chainTestD};
76
		Bundle[] dependencyOrder = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
77
		TestListener testListener = new TestListener();
78
		OSGiTestsActivator.getContext().addBundleListener(testListener);
79
		try {
80
			installer.resolveBundles(resolveBundles);
81
			BundleEvent[] events = testListener.getEvents();
82
			// throw away the events.  This was already tested
83
			installer.refreshPackages(resolveBundles);
84
			events = testListener.getEvents();
85
			assertEquals("Event count", 25, events.length);
86
			int j = 0;
87
			for (int i = 0; i < dependencyOrder.length; i++, j += 2) {
88
				assertTrue("Stopping Event Bundle: " + dependencyOrder[i].getSymbolicName(), dependencyOrder[i] == events[j].getBundle());
89
				assertEquals("Expecting Stopping event", BundleEvent.STOPPING, events[j].getType());
90
				assertTrue("Stopped Event Bundle: " + dependencyOrder[i].getSymbolicName(), dependencyOrder[i] == events[j + 1].getBundle());
91
				assertEquals("Expecting Stopping event", BundleEvent.STOPPED, events[j + 1].getType());
92
			}
93
			j = 10;
94
			for (int i = 0; i < dependencyOrder.length; i++, j++) {
95
				assertTrue("Unresolved Event Bundle: " + dependencyOrder[i].getSymbolicName(), dependencyOrder[i] == events[j].getBundle());
96
				assertEquals("Expecting Unresolved event", BundleEvent.UNRESOLVED, events[j].getType());
97
			}
98
			j = 15;
99
			for (int i = dependencyOrder.length - 1; i >= 0; i--, j++) {
100
				assertTrue("Resolved Event Bundle: " + dependencyOrder[i].getSymbolicName(), dependencyOrder[i] == events[j].getBundle());
101
				assertEquals("Expecting Resolved event", BundleEvent.RESOLVED, events[j].getType());
102
			}
103
			j = 20;
104
			for (int i = dependencyOrder.length - 1; i >= 0; i--, j++) {
105
				assertTrue("Lazy Starting Event Bundle: " + dependencyOrder[i].getSymbolicName(), dependencyOrder[i] == events[j].getBundle());
106
				assertEquals("Expecting Lazy Starting event", BundleEvent.LAZY_ACTIVATION, events[j].getType());
107
			}
108
109
		} finally {
110
			OSGiTestsActivator.getContext().removeBundleListener(testListener);
111
		}
112
	}
113
}
(-)core/framework/org/eclipse/osgi/framework/internal/core/PackageAdminImpl.java (-11 / +8 lines)
Lines 337-344 Link Here
337
		return bundle;
337
		return bundle;
338
	}
338
	}
339
339
340
	private AbstractBundle[] applyDeltas(BundleDelta[] bundleDeltas) throws BundleException {
340
	private void applyDeltas(BundleDelta[] bundleDeltas) throws BundleException {
341
		ArrayList results = new ArrayList(bundleDeltas.length);
342
		for (int i = 0; i < bundleDeltas.length; i++) {
341
		for (int i = 0; i < bundleDeltas.length; i++) {
343
			int type = bundleDeltas[i].getType();
342
			int type = bundleDeltas[i].getType();
344
			if ((type & (BundleDelta.REMOVAL_PENDING | BundleDelta.REMOVAL_COMPLETE)) != 0)
343
			if ((type & (BundleDelta.REMOVAL_PENDING | BundleDelta.REMOVAL_COMPLETE)) != 0)
Lines 354-364 Link Here
354
						} catch (BundleException e) {
353
						} catch (BundleException e) {
355
							framework.publishFrameworkEvent(FrameworkEvent.ERROR, bundle, e);
354
							framework.publishFrameworkEvent(FrameworkEvent.ERROR, bundle, e);
356
						}
355
						}
357
					results.add(bundle);
358
				}
356
				}
359
			}
357
			}
360
		}
358
		}
361
		return (AbstractBundle[]) (results.size() == 0 ? null : results.toArray(new AbstractBundle[results.size()]));
362
	}
359
	}
363
360
364
	private AbstractBundle[] processDelta(BundleDelta[] bundleDeltas, boolean refreshPackages) {
361
	private AbstractBundle[] processDelta(BundleDelta[] bundleDeltas, boolean refreshPackages) {
Lines 378-384 Link Here
378
		// then sort by dependency order
375
		// then sort by dependency order
379
		StartLevelManager.sortByDependency(refresh);
376
		StartLevelManager.sortByDependency(refresh);
380
		boolean[] previouslyResolved = new boolean[refresh.length];
377
		boolean[] previouslyResolved = new boolean[refresh.length];
381
		AbstractBundle[] resolved = null;
382
		try {
378
		try {
383
			try {
379
			try {
384
				if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {
380
				if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {
Lines 415-425 Link Here
415
				}
411
				}
416
412
417
				synchronized (framework.bundles) {
413
				synchronized (framework.bundles) {
418
					for (int i = 0; i < refresh.length; i++)
414
					for (int i = refresh.length - 1; i >= 0; i--)
419
						refresh[i].refresh();
415
						refresh[i].refresh();
420
				}
416
				}
421
				// send out unresolved events outside synch block (defect #80610)
417
				// send out unresolved events outside synch block (defect #80610)
422
				for (int i = 0; i < refresh.length; i++) {
418
				// send out unresolved events in reverse dependency order (defect #207505)
419
				for (int i = refresh.length - 1; i >= 0; i--) {
423
					// send out unresolved events
420
					// send out unresolved events
424
					if (previouslyResolved[i])
421
					if (previouslyResolved[i])
425
						framework.publishBundleEvent(BundleEvent.UNRESOLVED, refresh[i]);
422
						framework.publishBundleEvent(BundleEvent.UNRESOLVED, refresh[i]);
Lines 432-438 Link Here
432
					Debug.println("refreshPackages: applying deltas to bundles"); //$NON-NLS-1$
429
					Debug.println("refreshPackages: applying deltas to bundles"); //$NON-NLS-1$
433
				}
430
				}
434
				synchronized (framework.bundles) {
431
				synchronized (framework.bundles) {
435
					resolved = applyDeltas(bundleDeltas);
432
					applyDeltas(bundleDeltas);
436
				}
433
				}
437
434
438
			} finally {
435
			} finally {
Lines 475-483 Link Here
475
		// send out any resolved.  This must be done after the state change locks have been release.
472
		// send out any resolved.  This must be done after the state change locks have been release.
476
		if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN)
473
		if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN)
477
			Debug.println("refreshPackages: send out RESOLVED events"); //$NON-NLS-1$
474
			Debug.println("refreshPackages: send out RESOLVED events"); //$NON-NLS-1$
478
		if (resolved != null)
475
		for (int i = 0; i < refresh.length; i++)
479
			for (int i = 0; i < resolved.length; i++)
476
			if (refresh[i].isResolved())
480
				framework.publishBundleEvent(BundleEvent.RESOLVED, resolved[i]);
477
				framework.publishBundleEvent(BundleEvent.RESOLVED, refresh[i]);
481
478
482
		return refresh;
479
		return refresh;
483
	}
480
	}

Return to bug 207505