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

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/region/hook/RegionResolverHookTests.java (+32 lines)
Lines 403-408 Link Here
403
		}
403
		}
404
404
405
		@Override
405
		@Override
406
		public BundleRevision getResource() {
407
			return getRevision();
408
		}
409
410
		@Override
406
		public BundleRevision getRevision() {
411
		public BundleRevision getRevision() {
407
			return new StubBundleRevision(bundle(this.bundleSymbolicName));
412
			return new StubBundleRevision(bundle(this.bundleSymbolicName));
408
		}
413
		}
Lines 481-486 Link Here
481
		}
486
		}
482
487
483
		@Override
488
		@Override
489
		public BundleRevision getResource() {
490
			return getRevision();
491
		}
492
493
		@Override
484
		public BundleRevision getRevision() {
494
		public BundleRevision getRevision() {
485
			return new StubBundleRevision(bundle(this.bundleSymbolicName));
495
			return new StubBundleRevision(bundle(this.bundleSymbolicName));
486
		}
496
		}
Lines 543-548 Link Here
543
		}
553
		}
544
554
545
		@Override
555
		@Override
556
		public BundleRevision getResource() {
557
			return getRevision();
558
		}
559
560
		@Override
546
		public BundleRevision getRevision() {
561
		public BundleRevision getRevision() {
547
			return this.bundleRevision;
562
			return this.bundleRevision;
548
		}
563
		}
Lines 552-557 Link Here
552
			throw new UnsupportedOperationException();
567
			throw new UnsupportedOperationException();
553
		}
568
		}
554
569
570
		@Override
571
		public boolean matches(Capability capability) {
572
			if (!(capability instanceof BundleCapability))
573
				return false;
574
			return matches((BundleCapability) capability);
575
		}
555
	}
576
	}
556
577
557
	final class StubBundleRevision implements BundleRevision {
578
	final class StubBundleRevision implements BundleRevision {
Lines 597-602 Link Here
597
			throw new UnsupportedOperationException();
618
			throw new UnsupportedOperationException();
598
		}
619
		}
599
620
621
		@SuppressWarnings({"cast", "unchecked", "rawtypes"})
622
		@Override
623
		public List<Capability> getCapabilities(String namespace) {
624
			return (List<Capability>) (List) getDeclaredCapabilities(namespace);
625
		}
626
627
		@SuppressWarnings({"cast", "unchecked", "rawtypes"})
628
		@Override
629
		public List<Requirement> getRequirements(String namespace) {
630
			return (List<Requirement>) (List) getDeclaredRequirements(namespace);
631
		}
600
	}
632
	}
601
633
602
}
634
}
(-).settings/.api_filters (+55 lines)
Lines 989-994 Link Here
989
<message_argument value="org.osgi.framework.wiring.BundleCapability"/>
989
<message_argument value="org.osgi.framework.wiring.BundleCapability"/>
990
</message_arguments>
990
</message_arguments>
991
</filter>
991
</filter>
992
<filter comment="Ignore osgi API." id="1211105284">
993
<message_arguments>
994
<message_argument value="getResource()"/>
995
</message_arguments>
996
</filter>
992
</resource>
997
</resource>
993
<resource path="osgi/src/org/osgi/framework/wiring/BundleRequirement.java" type="org.osgi.framework.wiring.BundleRequirement">
998
<resource path="osgi/src/org/osgi/framework/wiring/BundleRequirement.java" type="org.osgi.framework.wiring.BundleRequirement">
994
<filter comment="Ignore OSGi API" id="1110441988">
999
<filter comment="Ignore OSGi API" id="1110441988">
Lines 996-1001 Link Here
996
<message_argument value="org.osgi.framework.wiring.BundleRequirement"/>
1001
<message_argument value="org.osgi.framework.wiring.BundleRequirement"/>
997
</message_arguments>
1002
</message_arguments>
998
</filter>
1003
</filter>
1004
<filter comment="Ignore osgi API." id="1211105284">
1005
<message_arguments>
1006
<message_argument value="getResource()"/>
1007
</message_arguments>
1008
</filter>
999
</resource>
1009
</resource>
1000
<resource path="osgi/src/org/osgi/framework/wiring/BundleRevision.java" type="org.osgi.framework.wiring.BundleRevision">
1010
<resource path="osgi/src/org/osgi/framework/wiring/BundleRevision.java" type="org.osgi.framework.wiring.BundleRevision">
1001
<filter comment="Ignore OSGi API" id="1110441988">
1011
<filter comment="Ignore OSGi API" id="1110441988">
Lines 1017-1022 Link Here
1017
<message_argument value="org.osgi.framework.wiring.BundleWire"/>
1027
<message_argument value="org.osgi.framework.wiring.BundleWire"/>
1018
</message_arguments>
1028
</message_arguments>
1019
</filter>
1029
</filter>
1030
<filter comment="Ignore osgi API." id="1211105284">
1031
<message_arguments>
1032
<message_argument value="getProvider()"/>
1033
</message_arguments>
1034
</filter>
1035
<filter comment="Ignore osgi API." id="1211105284">
1036
<message_arguments>
1037
<message_argument value="getRequirer()"/>
1038
</message_arguments>
1039
</filter>
1020
</resource>
1040
</resource>
1021
<resource path="osgi/src/org/osgi/framework/wiring/BundleWiring.java" type="org.osgi.framework.wiring.BundleWiring">
1041
<resource path="osgi/src/org/osgi/framework/wiring/BundleWiring.java" type="org.osgi.framework.wiring.BundleWiring">
1022
<filter comment="Ignore OSGi API" id="1110441988">
1042
<filter comment="Ignore OSGi API" id="1110441988">
Lines 1025-1030 Link Here
1025
</message_arguments>
1045
</message_arguments>
1026
</filter>
1046
</filter>
1027
</resource>
1047
</resource>
1048
<resource path="osgi/src/org/osgi/framework/wiring/Capability.java" type="org.osgi.framework.wiring.Capability">
1049
<filter comment="Ignore osgi API." id="1110441988">
1050
<message_arguments>
1051
<message_argument value="org.osgi.framework.wiring.Capability"/>
1052
</message_arguments>
1053
</filter>
1054
</resource>
1028
<resource path="osgi/src/org/osgi/framework/wiring/FrameworkWiring.java" type="org.osgi.framework.wiring.FrameworkWiring">
1055
<resource path="osgi/src/org/osgi/framework/wiring/FrameworkWiring.java" type="org.osgi.framework.wiring.FrameworkWiring">
1029
<filter comment="Ignore OSGi API" id="1110441988">
1056
<filter comment="Ignore OSGi API" id="1110441988">
1030
<message_arguments>
1057
<message_arguments>
Lines 1032-1037 Link Here
1032
</message_arguments>
1059
</message_arguments>
1033
</filter>
1060
</filter>
1034
</resource>
1061
</resource>
1062
<resource path="osgi/src/org/osgi/framework/wiring/Requirement.java" type="org.osgi.framework.wiring.Requirement">
1063
<filter comment="Ignore osgi API." id="1110441988">
1064
<message_arguments>
1065
<message_argument value="org.osgi.framework.wiring.Requirement"/>
1066
</message_arguments>
1067
</filter>
1068
</resource>
1069
<resource path="osgi/src/org/osgi/framework/wiring/Resource.java" type="org.osgi.framework.wiring.Resource">
1070
<filter comment="Ignore osgi API." id="1110441988">
1071
<message_arguments>
1072
<message_argument value="org.osgi.framework.wiring.Resource"/>
1073
</message_arguments>
1074
</filter>
1075
</resource>
1076
<resource path="osgi/src/org/osgi/framework/wiring/ResourceConstants.java" type="org.osgi.framework.wiring.ResourceConstants">
1077
<filter comment="Ignore osgi API." id="1110441988">
1078
<message_arguments>
1079
<message_argument value="org.osgi.framework.wiring.ResourceConstants"/>
1080
</message_arguments>
1081
</filter>
1082
</resource>
1083
<resource path="osgi/src/org/osgi/framework/wiring/Wire.java" type="org.osgi.framework.wiring.Wire">
1084
<filter comment="Ignore osgi API." id="1110441988">
1085
<message_arguments>
1086
<message_argument value="org.osgi.framework.wiring.Wire"/>
1087
</message_arguments>
1088
</filter>
1089
</resource>
1035
<resource path="osgi/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java" type="org.osgi.service.condpermadmin.ConditionalPermissionAdmin">
1090
<resource path="osgi/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java" type="org.osgi.service.condpermadmin.ConditionalPermissionAdmin">
1036
<filter comment="Ignore OSGi API" id="403853384">
1091
<filter comment="Ignore OSGi API" id="403853384">
1037
<message_arguments>
1092
<message_arguments>
(-)META-INF/MANIFEST.MF (-2 / +2 lines)
Lines 25-31 Link Here
25
 org.osgi.framework.hooks.service; version="1.1",
25
 org.osgi.framework.hooks.service; version="1.1",
26
 org.osgi.framework.hooks.weaving; version="1.0",
26
 org.osgi.framework.hooks.weaving; version="1.0",
27
 org.osgi.framework.startlevel; version="1.0",
27
 org.osgi.framework.startlevel; version="1.0",
28
 org.osgi.framework.wiring; version="1.0",
28
 org.osgi.framework.wiring; version="1.1",
29
 org.osgi.service.condpermadmin;version="1.1.1",
29
 org.osgi.service.condpermadmin;version="1.1.1",
30
 org.osgi.service.framework; version="1.0"; x-internal:=true,
30
 org.osgi.service.framework; version="1.0"; x-internal:=true,
31
 org.osgi.service.log; version="1.3",
31
 org.osgi.service.log; version="1.3",
Lines 75-81 Link Here
75
Bundle-Description: %systemBundle
75
Bundle-Description: %systemBundle
76
Bundle-Copyright: %copyright
76
Bundle-Copyright: %copyright
77
Bundle-Vendor: %eclipse.org
77
Bundle-Vendor: %eclipse.org
78
Bundle-Version: 3.7.100.qualifier
78
Bundle-Version: 3.8.0.qualifier
79
Bundle-Localization: systembundle
79
Bundle-Localization: systembundle
80
Bundle-DocUrl: http://www.eclipse.org
80
Bundle-DocUrl: http://www.eclipse.org
81
Eclipse-ExtensibleAPI: true
81
Eclipse-ExtensibleAPI: true
(-)osgi/src/org/osgi/framework/wiring/BundleCapability.java (-2 / +5 lines)
Lines 18-32 Link Here
18
18
19
import java.util.Map;
19
import java.util.Map;
20
20
21
21
/**
22
/**
22
 * A capability that has been declared from a {@link BundleRevision bundle
23
 * A capability that has been declared from a {@link BundleRevision bundle
23
 * revision}.
24
 * revision}.
24
 * 
25
 * 
25
 * @ThreadSafe
26
 * @ThreadSafe
26
 * @noimplement
27
 * @noimplement
27
 * @version $Id: 0fde13c3228af1aa97872b37ccf0aa6e23123b11 $
28
 * @version $Id: 6bbc1e645f927531d40fb245c95f5d26ad189db3 $
28
 */
29
 */
29
public interface BundleCapability {
30
public interface BundleCapability extends Capability{
30
	/**
31
	/**
31
	 * Returns the name space of this capability.
32
	 * Returns the name space of this capability.
32
	 * 
33
	 * 
Lines 58-61 Link Here
58
	 * @return The bundle revision declaring this capability.
59
	 * @return The bundle revision declaring this capability.
59
	 */
60
	 */
60
	BundleRevision getRevision();
61
	BundleRevision getRevision();
62
63
	BundleRevision getResource();
61
}
64
}
(-)osgi/src/org/osgi/framework/wiring/BundleRequirement.java (-2 / +8 lines)
Lines 18-32 Link Here
18
18
19
import java.util.Map;
19
import java.util.Map;
20
20
21
21
/**
22
/**
22
 * A requirement that has been declared from a {@link BundleRevision bundle
23
 * A requirement that has been declared from a {@link BundleRevision bundle
23
 * revision}.
24
 * revision}.
24
 * 
25
 * 
25
 * @ThreadSafe
26
 * @ThreadSafe
26
 * @noimplement
27
 * @noimplement
27
 * @version $Id: 659132c1fac7526240df377ead0e1bc8d4af2e77 $
28
 * @version $Id: 3ee254a3c0d5516b56affaa66544c892f3d522cb $
28
 */
29
 */
29
public interface BundleRequirement {
30
public interface BundleRequirement extends Requirement{
30
	/**
31
	/**
31
	 * Returns the name space of this requirement.
32
	 * Returns the name space of this requirement.
32
	 * 
33
	 * 
Lines 60-65 Link Here
60
	BundleRevision getRevision();
61
	BundleRevision getRevision();
61
62
62
	/**
63
	/**
64
	 * {@inheritDoc}
65
	 */
66
	BundleRevision getResource();
67
68
	/**
63
	 * Returns whether the specified capability matches this requirement.
69
	 * Returns whether the specified capability matches this requirement.
64
	 * 
70
	 * 
65
	 * @param capability The capability to match to this requirement.
71
	 * @param capability The capability to match to this requirement.
(-)osgi/src/org/osgi/framework/wiring/BundleRevision.java (-5 / +5 lines)
Lines 47-55 Link Here
47
 * 
47
 * 
48
 * @ThreadSafe
48
 * @ThreadSafe
49
 * @noimplement
49
 * @noimplement
50
 * @version $Id: 139b3046ebd46c48b03dda8d36f2f9d79e2e616d $
50
 * @version $Id: 2eb450f15fc9d4fe1b611dc55e2238b972b4c486 $
51
 */
51
 */
52
public interface BundleRevision extends BundleReference {
52
public interface BundleRevision extends BundleReference, Resource {
53
	/**
53
	/**
54
	 * Returns the symbolic name for this bundle revision.
54
	 * Returns the symbolic name for this bundle revision.
55
	 * 
55
	 * 
Lines 137-143 Link Here
137
	 * package wires required by a bundle wiring may change as the bundle wiring
137
	 * package wires required by a bundle wiring may change as the bundle wiring
138
	 * may dynamically import additional packages.
138
	 * may dynamically import additional packages.
139
	 */
139
	 */
140
	String	PACKAGE_NAMESPACE	= "osgi.wiring.package";
140
	String	PACKAGE_NAMESPACE	= ResourceConstants.WIRING_PACKAGE_NAMESPACE;
141
141
142
	/**
142
	/**
143
	 * Name space for bundle capabilities and requirements.
143
	 * Name space for bundle capabilities and requirements.
Lines 175-181 Link Here
175
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
175
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
176
	 * {@literal <} 2) must not provide a bundle capability.
176
	 * {@literal <} 2) must not provide a bundle capability.
177
	 */
177
	 */
178
	String	BUNDLE_NAMESPACE	= "osgi.wiring.bundle";
178
	String	BUNDLE_NAMESPACE	= ResourceConstants.WIRING_BUNDLE_NAMESPACE;
179
179
180
	/**
180
	/**
181
	 * Name space for host capabilities and requirements.
181
	 * Name space for host capabilities and requirements.
Lines 216-222 Link Here
216
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
216
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
217
	 * {@literal <} 2) must not provide a host capability.
217
	 * {@literal <} 2) must not provide a host capability.
218
	 */
218
	 */
219
	String	HOST_NAMESPACE		= "osgi.wiring.host";
219
	String	HOST_NAMESPACE		= ResourceConstants.WIRING_HOST_NAMESPACE;
220
220
221
	/**
221
	/**
222
	 * Returns the special types of this bundle revision. The bundle revision
222
	 * Returns the special types of this bundle revision. The bundle revision
(-)osgi/src/org/osgi/framework/wiring/BundleWire.java (-2 / +13 lines)
Lines 16-29 Link Here
16
16
17
package org.osgi.framework.wiring;
17
package org.osgi.framework.wiring;
18
18
19
19
/**
20
/**
20
 * A wire connecting a {@link BundleCapability} to a {@link BundleRequirement}.
21
 * A wire connecting a {@link BundleCapability} to a {@link BundleRequirement}.
21
 * 
22
 * 
22
 * @ThreadSafe
23
 * @ThreadSafe
23
 * @noimplement
24
 * @noimplement
24
 * @version $Id: 4f936a84065762ec3267a44f86ae01b0150e44ce $
25
 * @version $Id: aca8642cea91995d0b178129cba1131ed327c7e7 $
25
 */
26
 */
26
public interface BundleWire {
27
public interface BundleWire extends Wire {
27
	/**
28
	/**
28
	 * Returns the {@link BundleCapability} for this wire.
29
	 * Returns the {@link BundleCapability} for this wire.
29
	 * 
30
	 * 
Lines 69-72 Link Here
69
	 *         returned.
70
	 *         returned.
70
	 */
71
	 */
71
	BundleWiring getRequirerWiring();
72
	BundleWiring getRequirerWiring();
73
74
	/**
75
	 * {@inheritDoc}
76
	 */
77
	BundleRevision getProvider();
78
79
	/**
80
	 * {@inheritDoc}
81
	 */
82
	BundleRevision getRequirer();
72
}
83
}
(-)osgi/src/org/osgi/framework/wiring/BundleWiring.java (-2 / +9 lines)
Lines 83-91 Link Here
83
	 * <p>
83
	 * <p>
84
	 * A bundle wiring for a non-fragment revision provides a subset of the
84
	 * A bundle wiring for a non-fragment revision provides a subset of the
85
	 * declared capabilities from the bundle revision and all attached fragment
85
	 * declared capabilities from the bundle revision and all attached fragment
86
	 * revisions. Not all declared capabilities may be provided since some may
86
	 * revisions<sup>&#8224;</sup>. Not all declared capabilities may be provided since some may
87
	 * be discarded. For example, if a package is declared to be exported and
87
	 * be discarded. For example, if a package is declared to be exported and
88
	 * import, only one is selected and the other is discarded.
88
	 * import, only one is selected and the other is discarded.
89
	 * <p>
90
	 * A bundle wiring for a fragment revision with a symbolic name must 
91
	 * provide exactly one {@link ResourceConstants#IDENTITY_NAMESPACE identity} capability.
92
	 * <p>
93
	 * &#8224; The {@link ResourceConstants#IDENTITY_NAMESPACE identity} capability
94
	 * provided by attached fragment revisions must not be included in the capabilities of the 
95
	 * host bundle wiring.
89
	 * 
96
	 * 
90
	 * @param namespace The name space of the capabilities to return or
97
	 * @param namespace The name space of the capabilities to return or
91
	 *        {@code null} to return the capabilities from all name spaces.
98
	 *        {@code null} to return the capabilities from all name spaces.
Lines 95-101 Link Here
95
	 *         {@link #isInUse() in use}, {@code null} will be returned. For a
102
	 *         {@link #isInUse() in use}, {@code null} will be returned. For a
96
	 *         given name space, the list contains the wires in the order the
103
	 *         given name space, the list contains the wires in the order the
97
	 *         capabilities were specified in the manifests of the
104
	 *         capabilities were specified in the manifests of the
98
	 *         {@link #getRevision() bundle revision} and the attached fragments
105
	 *         {@link #getRevision() bundle revision} and the attached fragments<sup>&#8224;</sup>
99
	 *         of this bundle wiring. There is no ordering defined between
106
	 *         of this bundle wiring. There is no ordering defined between
100
	 *         capabilities in different name spaces.
107
	 *         capabilities in different name spaces.
101
	 */
108
	 */
(-)osgi/src/org/osgi/framework/wiring/Capability.java (+83 lines)
Added Link Here
1
/*
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
package org.osgi.framework.wiring;
18
19
import java.util.Map;
20
21
/**
22
 * A capability that has been declared from a {@link Resource}.
23
 * 
24
 * @ThreadSafe
25
 * @Immutable
26
 * @version $Id: a37df4f0d0a54593fab0a3ddec451f0b1342d4f3 $
27
 */
28
public interface Capability {
29
30
	/**
31
	 * Returns the name space of this capability.
32
	 * 
33
	 * @return The name space of this capability.
34
	 */
35
	String getNamespace();
36
37
	/**
38
	 * Returns the directives of this capability. Only the following list of
39
	 * directives have semantic meaning in the returned {@link Map map} of
40
	 * directives:
41
	 * <ul>
42
	 * <li> {@link ResourceConstants#CAPABILITY_EFFECTIVE_DIRECTIVE effective}
43
	 * <li> {@link ResourceConstants#CAPABILITY_USES_DIRECTIVE uses}
44
	 * <li> {@link ResourceConstants#CAPABILITY_MANDATORY_DIRECTIVE mandatory} -
45
	 * only recognized for the
46
	 * {@link ResourceConstants#WIRING_BUNDLE_NAMESPACE osgi.wiring.bundle} and
47
	 * {@link ResourceConstants#WIRING_PACKAGE_NAMESPACE osgi.wiring.package}
48
	 * name spaces.
49
	 * <li> {@link ResourceConstants#CAPABILITY_EXCLUDE_DIRECTIVE exclude} -
50
	 * only recognized for the
51
	 * {@link ResourceConstants#WIRING_PACKAGE_NAMESPACE osgi.wiring.package}
52
	 * name space.
53
	 * <li> {@link ResourceConstants#CAPABILITY_INCLUDE_DIRECTIVE include} -
54
	 * only recognized for the
55
	 * {@link ResourceConstants#WIRING_PACKAGE_NAMESPACE osgi.wiring.package}
56
	 * name space.
57
	 * </ul>
58
	 * All other directive are considered extra user defined information that
59
	 * has no semantic meaning. OSGi Alliance reserves the right to extend the
60
	 * set of directives which have semantic meaning.
61
	 * 
62
	 * @return An unmodifiable map of directive names to directive values for
63
	 *         this capability, or an empty map if this capability has no
64
	 *         directives.
65
	 */
66
	Map<String, String> getDirectives();
67
68
	/**
69
	 * Returns the attributes of this capability.
70
	 * 
71
	 * @return An unmodifiable map of attribute names to attribute values for
72
	 *         this capability, or an empty map if this capability has no
73
	 *         attributes.
74
	 */
75
	Map<String, Object> getAttributes();
76
77
	/**
78
	 * The resource that declares this capability.
79
	 * 
80
	 * @return the resource
81
	 */
82
	Resource getResource();
83
}
(-)osgi/src/org/osgi/framework/wiring/Requirement.java (+107 lines)
Added Link Here
1
/*
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
package org.osgi.framework.wiring;
18
19
import java.util.Map;
20
21
import org.osgi.framework.Constants;
22
23
/**
24
 * A requirement that has been declared from a {@link Resource} .
25
 * 
26
 * @ThreadSafe
27
 * @Immutable
28
 * 
29
 * @version $Id: a085f0fb285b6a0d72203440ffdb1c9e6a236f49 $
30
 */
31
public interface Requirement {
32
	/**
33
	 * Returns the name space of this requirement.
34
	 * 
35
	 * @return The name space of this requirement.
36
	 */
37
	String getNamespace();
38
39
	/**
40
	 * Returns the directives of this requirement. Only the following list of
41
	 * directives have semantic meaning in the returned {@link Map map} of
42
	 * directives:
43
	 * <ul>
44
	 * <li> {@link ResourceConstants#REQUIREMENT_EFFECTIVE_DIRECTIVE effective}
45
	 * <li> {@link ResourceConstants#REQUIREMENT_FILTER_DIRECTIVE filter}
46
	 * <li> {@link ResourceConstants#REQUIREMENT_CARDINALITY_DIRECTIVE
47
	 * cardinality}
48
	 * <li> {@link ResourceConstants#REQUIREMENT_RESOLUTION_DIRECTIVE resolution}
49
	 * <li> {@link ResourceConstants#REQUIREMENT_VISIBILITY_DIRECTIVE visibility}
50
	 * - only recognized for the
51
	 * {@link ResourceConstants#WIRING_BUNDLE_NAMESPACE osgi.wiring.bundle} name
52
	 * space.
53
	 * </ul>
54
	 * All other directive are considered extra user defined information that
55
	 * has no semantic meaning. OSGi Alliance reserves the right to extend the
56
	 * set of directives which have semantic meaning.
57
	 * 
58
	 * @return An unmodifiable map of directive names to directive values for
59
	 *         this requirement, or an empty map if this requirement has no
60
	 *         directives.
61
	 */
62
	Map<String, String> getDirectives();
63
64
	/**
65
	 * Returns the attributes of this requirement. Requirement attributes have
66
	 * no semantic meaning and are considered extra user defined information.
67
	 * 
68
	 * @return An unmodifiable map of attribute names to attribute values for
69
	 *         this requirement, or an empty map if this requirement has no
70
	 *         attributes.
71
	 */
72
	Map<String, Object> getAttributes();
73
74
	/**
75
	 * Returns the resource declaring this requirement. If there is no resource
76
	 * declaring this requirement, {@code null} is returned.
77
	 * 
78
	 * @return The resource declaring this requirement, if any.
79
	 */
80
	Resource getResource();
81
82
	/**
83
	 * Returns whether the specified capability matches this requirement. A
84
	 * capability matches this requirement when all of the following are true:
85
	 * <ul>
86
	 * <li>The specified capability has the same {@link #getNamespace() name
87
	 * space} as this requirement.
88
	 * <li>The filter specified by the {@link Constants#FILTER_DIRECTIVE filter}
89
	 * directive of this requirement matches the
90
	 * {@link Capability#getAttributes() attributes of the specified capability}.
91
	 * <li>The {@link #getDirectives() requirement directives} and the
92
	 * {@link Capability#getDirectives() capability directives} that apply to
93
	 * the name space are satisfied.
94
	 * </ul>
95
	 * 
96
	 * 
97
	 * @param capability
98
	 *            The capability to match to this requirement.
99
	 * @return {@code true} if the specified capability matches this this
100
	 *         requirement. {@link #getNamespace() name space} as this
101
	 *         requirement and the filter for this requirement matches the
102
	 *         {@link BundleCapability#getAttributes() attributes of the
103
	 *         specified capability}; {@code false} otherwise.
104
	 */
105
	// TODO much debate on the placement and need for this method.
106
	boolean matches(Capability capability);
107
}
(-)osgi/src/org/osgi/framework/wiring/Resource.java (+42 lines)
Added Link Here
1
package org.osgi.framework.wiring;
2
3
import java.util.List;
4
5
6
/**
7
 * A resource is the representation of a uniquely identified and typed data.
8
 * 
9
 * A resources can be wired together via capabilities and requirements.
10
 * 
11
 * @ThreadSafe
12
 * @Immutable
13
 *  
14
 * @version $Id: ab65b58b724ec74515bb8c5bad355658efc2460d $
15
 */
16
public interface Resource {
17
	/**
18
	 * Returns the capabilities declared by this resource.
19
	 * 
20
	 * @param namespace
21
	 *            The name space of the declared capabilities to return or
22
	 *            {@code null} to return the declared capabilities from all name
23
	 *            spaces.
24
	 * @return A list containing a snapshot of the declared {@link Capability}s,
25
	 *         or an empty list if this resource declares no capabilities in the
26
	 *         specified name space.
27
	 */
28
	List<Capability> getCapabilities(String namespace);
29
30
	/**
31
	 * Returns the requirements declared by this bundle resource.
32
	 * 
33
	 * @param namespace
34
	 *            The name space of the declared requirements to return or
35
	 *            {@code null} to return the declared requirements from all name
36
	 *            spaces.
37
	 * @return A list containing a snapshot of the declared {@link Requirement}
38
	 *         s, or an empty list if this resource declares no requirements in
39
	 *         the specified name space.
40
	 */
41
	List<Requirement> getRequirements(String namespace);
42
}
(-)osgi/src/org/osgi/framework/wiring/ResourceConstants.java (+372 lines)
Added Link Here
1
/*
2
 * Copyright (c) OSGi Alliance (2011). All Rights Reserved.
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package org.osgi.framework.wiring;
17
18
import org.osgi.framework.Constants;
19
import org.osgi.framework.Version;
20
21
/**
22
 * Defines standard names for the attributes, directives and name spaces for
23
 * resources, capabilities and requirements.
24
 * 
25
 * <p>
26
 * The values associated with these keys are of type {@code String}, unless
27
 * otherwise indicated.
28
 * 
29
 * @version $Id$
30
 */
31
public final class ResourceConstants {
32
33
	private ResourceConstants() {
34
		// keep others from creating objects of this type.
35
	}
36
37
	/**
38
	 * Name space for the identity capability.  Each {@link Resource resource} 
39
	 * provides exactly one<sup>&#8224;</sup> identity capability that can be 
40
	 * used to identify the resource.
41
	 * 
42
	 * For identity capability attributes the following applies:
43
	 * <ul>
44
	 * <li>The
45
	 * <q>osgi.identity</q> attribute contains the symbolic name of the
46
	 * resource.
47
	 * <li>The {@link #IDENTITY_VERSION_ATTRIBUTE version} attribute contains
48
	 * the {@link Version} of the resource.
49
	 * <li>The {@link #IDENTITY_TYPE_ATTRIBUTE type} attribute contains the
50
	 * resource type.
51
	 * </ul>
52
	 * <p>
53
	 * A resource with a symbolic name 
54
	 * {@link Resource#getCapabilities(String) provides} exactly one 
55
	 * <sup>&#8224;</sup> identity
56
	 * {@link Resource#getCapabilities(String) capability}.
57
	 * <p>
58
	 * For a {@link BundleRevision revision} with a symbolic name the 
59
	 * {@link BundleWiring wiring} for the revision
60
	 * {@link BundleWiring#getCapabilities(String) provides} exactly
61
	 * one<sup>&#8224;</sup> identity capability. 
62
	 * <p>
63
	 * &#8224; A resource with no symbolic name must not provide an identity
64
	 * capability.
65
	 */
66
	public static final String IDENTITY_NAMESPACE = "osgi.identity";
67
68
	/**
69
	 * An {@link #IDENTITY_NAMESPACE identity} capability attribute identifying the
70
	 * {@link Version version} of the resource.  This attribute must be set to a value of
71
	 * type {@link Version}.  If the resource has no version then the value 
72
	 * {@link Version#emptyVersion 0.0.0} must be used for the attribute.
73
	 */
74
	public static final String IDENTITY_VERSION_ATTRIBUTE = Constants.VERSION_ATTRIBUTE;
75
76
	/**
77
	 * An {@link #IDENTITY_NAMESPACE identity} capability attribute identifying the
78
	 * resource type.  This attribute must be set to a value of type {@link String}.
79
	 * if the resource has no type then the value 
80
	 * {@link ResourceConstants#IDENTITY_TYPE_UNKNOWN unknown} must be used for the
81
	 * attribute.
82
	 */
83
	public static final String IDENTITY_TYPE_ATTRIBUTE = "type";
84
85
	/**
86
	 * An {@link #IDENTITY_NAMESPACE identity} capability {@link #IDENTITY_TYPE_ATTRIBUTE type}
87
	 * attribute value identifying the resource type as an OSGi bundle.
88
	 */
89
	public static final String IDENTITY_TYPE_BUNDLE = "osgi.bundle";
90
91
	/**
92
	 * An {@link #IDENTITY_NAMESPACE identity} capability {@link #IDENTITY_TYPE_ATTRIBUTE type}
93
	 * attribute value identifying the resource type as an OSGi fragment.
94
	 */
95
	public static final String IDENTITY_TYPE_FRAGMENT = "osgi.fragment";
96
97
	/**
98
	 * An {@link #IDENTITY_NAMESPACE identity} capability {@link #IDENTITY_TYPE_ATTRIBUTE type}
99
	 * attribute value identifying the resource type as unknown.
100
	 */
101
	public static final String IDENTITY_TYPE_UNKNOWN = "unknown";
102
103
	/**
104
	 * An {@link #IDENTITY_NAMESPACE identity} capability {@link Requirement#getDirectives() directive}
105
	 * identifying if the resource is a singleton.  A {@link String} value of &quot;true&quot; indicates
106
	 * the resource is a singleton; any other value or <code>null</code> indicates the resource is not a 
107
	 * singleton.
108
	 */
109
	public static final String IDENTITY_SINGLETON_DIRECTIVE = Constants.SINGLETON_DIRECTIVE;
110
111
	/**
112
	 * Name space for package capabilities and requirements.
113
	 * 
114
	 * For capability attributes the following applies:
115
	 * <ul>
116
	 * <li>The
117
	 * <q>osgi.wiring.package</q> attribute contains the name of the package.
118
	 * <li>The {@link Constants#VERSION_ATTRIBUTE version} attribute contains
119
	 * the the {@link Version} of the package if one is specified or
120
	 * {@link Version#emptyVersion} if not specified.
121
	 * <li>The {@link Constants#BUNDLE_SYMBOLICNAME_ATTRIBUTE
122
	 * bundle-symbolic-name} attribute contains the symbolic name of the
123
	 * resource providing the package if one is specified.
124
	 * <li>The {@link Constants#BUNDLE_VERSION_ATTRIBUTE bundle-version}
125
	 * attribute contains the {@link Version} of resource providing the package
126
	 * if one is specified or {@link Version#emptyVersion} if not specified.
127
	 * <li>All other attributes are of type {@link String} and are used as
128
	 * arbitrary matching attributes for the capability.
129
	 * </ul>
130
	 * <p>
131
	 * A resource provides zero or more package
132
	 * {@link Resource#getCapabilities(String) capabilities} (this is, exported
133
	 * packages) and requires zero or more package
134
	 * {@link Resource#getRequirements(String) requirements} (that is, imported
135
	 * packages).
136
	 */
137
	public static final String WIRING_PACKAGE_NAMESPACE = "osgi.wiring.package";
138
139
	/**
140
	 * Name space for bundle capabilities and requirements.
141
	 * 
142
	 * For capability attributes the following applies:
143
	 * <ul>
144
	 * <li>The
145
	 * <q>osgi.wiring.bundle</q> attribute contains the symbolic name of the
146
	 * bundle.
147
	 * <li>The {@link Constants#BUNDLE_VERSION_ATTRIBUTE bundle-version}
148
	 * attribute contains the {@link Version} of the bundle if one is specified
149
	 * or {@link Version#emptyVersion} if not specified.
150
	 * <li>All other attributes are of type {@link String} and are used as
151
	 * arbitrary matching attributes for the capability.
152
	 * </ul>
153
	 * <p>
154
	 * A non-fragment resource with the {@link #IDENTITY_TYPE_BUNDLE
155
	 * osgi.bundle} type {@link #IDENTITY_TYPE_ATTRIBUTE identity} provides 
156
	 * exactly one <sup>&#8224;</sup> bundle
157
	 * {@link Resource#getCapabilities(String) capability} (that is, the bundle
158
	 * can be required by another bundle). A fragment resource with the 
159
	 * {@link #IDENTITY_TYPE_FRAGMENT osgi.fragment} type 
160
	 * {@link #IDENTITY_TYPE_ATTRIBUTE identity} must not declare
161
	 * a bundle capability. A resource requires zero or more bundle
162
	 * {@link Resource#getRequirements(String) requirements} (that is, required
163
	 * bundles).
164
	 * <p>
165
	 * &#8224; A resource with no symbolic name must not provide a bundle
166
	 * capability.
167
	 */
168
	public static final String WIRING_BUNDLE_NAMESPACE = "osgi.wiring.bundle";
169
170
	/**
171
	 * Name space for host capabilities and requirements.
172
	 * 
173
	 * For capability attributes the following applies:
174
	 * <ul>
175
	 * <li>The
176
	 * <q>osgi.wiring.host</q> attribute contains the symbolic name of the
177
	 * bundle.
178
	 * <li>The {@link Constants#BUNDLE_VERSION_ATTRIBUTE bundle-version}
179
	 * attribute contains the {@link Version} of the bundle if one is specified
180
	 * or {@link Version#emptyVersion} if not specified.
181
	 * <li>All other attributes are of type {@link String} and are used as
182
	 * arbitrary matching attributes for the capability.
183
	 * </ul>
184
	 * <p>
185
	 * <p>
186
	 * A non-fragment resource with the with the {@link #IDENTITY_TYPE_BUNDLE
187
	 * osgi.bundle} type {@link #IDENTITY_TYPE_ATTRIBUTE identity} provides 
188
	 * zero or one <sup>&#8224;</sup> host
189
	 * {@link Resource#getCapabilities(String) capabilities}. 
190
	 * A fragment resource with the 
191
	 * {@link #IDENTITY_TYPE_FRAGMENT osgi.fragment} type 
192
	 * {@link #IDENTITY_TYPE_ATTRIBUTE identity} must not declare
193
	 * a host capability and must 
194
	 * {@link Resource#getRequirements(String) declare} exactly one host
195
	 * requirement.
196
	 * <p>
197
	 * &#8224; A resource with no bundle symbolic name must not provide a host
198
	 * capability.
199
	 */
200
	public static final String WIRING_HOST_NAMESPACE = "osgi.wiring.host";
201
202
	/**
203
	 * A requirement {@link Requirement#getDirectives() directive} used to
204
	 * specify a capability filter. This filter is used to match against a
205
	 * capability's {@link Capability#getAttributes() attributes}.
206
	 */
207
	public final static String REQUIREMENT_FILTER_DIRECTIVE = Constants.FILTER_DIRECTIVE;
208
209
	/**
210
	 * A requirement {@link Requirement#getDirectives() directive} used to
211
	 * specify the resolution type for a requirement. The default value is
212
	 * {@link #REQUIREMENT_RESOLUTION_MANDATORY mandatory}.
213
	 * 
214
	 * @see #REQUIREMENT_RESOLUTION_MANDATORY mandatory
215
	 * @see #REQUIREMENT_RESOLUTION_OPTIONAL optional
216
	 */
217
	public final static String REQUIREMENT_RESOLUTION_DIRECTIVE = Constants.RESOLUTION_DIRECTIVE;
218
	/**
219
	 * A directive value identifying a mandatory
220
	 * {@link Resource#getRequirements(String) requirement} resolution type. A
221
	 * mandatory resolution type indicates that the requirement must be resolved
222
	 * when the {@link Resource resource} is resolved. If such requirement
223
	 * cannot be resolved, the resource fails to resolve.
224
	 * 
225
	 * @see #REQUIREMENT_RESOLUTION_DIRECTIVE
226
	 */
227
	public final static String REQUIREMENT_RESOLUTION_MANDATORY = Constants.RESOLUTION_MANDATORY;
228
229
	/**
230
	 * A directive value identifying an optional
231
	 * {@link Resource#getRequirements(String) requirement} resolution type. An
232
	 * optional resolution type indicates that the requirement is optional and
233
	 * the {@link Resource resource} may be resolved without requirement being
234
	 * resolved.
235
	 * 
236
	 * @see #REQUIREMENT_RESOLUTION_DIRECTIVE
237
	 */
238
	public final static String REQUIREMENT_RESOLUTION_OPTIONAL = Constants.RESOLUTION_OPTIONAL;
239
240
	/**
241
	 * A requirement {@link Requirement#getDirectives() directive} used to
242
	 * specify the effective time for the requirement. The default value is
243
	 * {@link #EFFECTIVE_RESOLVE resolve}.
244
	 * 
245
	 * @see #EFFECTIVE_RESOLVE resolve
246
	 * @see #EFFECTIVE_ACTIVE active
247
	 */
248
	public final static String REQUIREMENT_EFFECTIVE_DIRECTIVE = Constants.EFFECTIVE_DIRECTIVE;
249
250
	/**
251
	 * A directive value identifying a {@link #CAPABILITY_EFFECTIVE_DIRECTIVE
252
	 * capability} or {@link #REQUIREMENT_EFFECTIVE_DIRECTIVE requirement} that
253
	 * is effective at resolve time. Capabilities and requirements with an
254
	 * effective time of resolve are the only capabilities which are processed
255
	 * while resolving a resource.
256
	 * 
257
	 * @see #REQUIREMENT_EFFECTIVE_DIRECTIVE
258
	 * @see #CAPABILITY_EFFECTIVE_DIRECTIVE
259
	 */
260
	public final static String EFFECTIVE_RESOLVE = Constants.EFFECTIVE_RESOLVE;
261
262
	/**
263
	 * A directive value identifying a {@link #CAPABILITY_EFFECTIVE_DIRECTIVE
264
	 * capability} or {@link #REQUIREMENT_EFFECTIVE_DIRECTIVE requirement} that
265
	 * is effective at active time. Capabilities and requirements with an
266
	 * effective time of active are ignored while resolving a resource.
267
	 * 
268
	 * @see #REQUIREMENT_EFFECTIVE_DIRECTIVE
269
	 * @see #CAPABILITY_EFFECTIVE_DIRECTIVE
270
	 */
271
	public final static String EFFECTIVE_ACTIVE = Constants.EFFECTIVE_ACTIVE;
272
273
	/**
274
	 * A requirement {@link Requirement#getDirectives() directive} used to
275
	 * specify the visibility type for a requirement. The default value is
276
	 * {@link #REQUIREMENT_VISIBILITY_PRIVATE private}. This directive must only
277
	 * be used for requirements with the require
278
	 * {@link #WIRING_BUNDLE_NAMESPACE bundle} name space.
279
	 * 
280
	 * @see #REQUIREMENT_VISIBILITY_PRIVATE private
281
	 * @see #REQUIREMENT_VISIBILITY_REEXPORT reexport
282
	 */
283
	public final static String REQUIREMENT_VISIBILITY_DIRECTIVE = Constants.VISIBILITY_DIRECTIVE;
284
285
	/**
286
	 * A directive value identifying a private
287
	 * {@link #REQUIREMENT_VISIBILITY_DIRECTIVE visibility} type. A private
288
	 * visibility type indicates that any {@link #WIRING_PACKAGE_NAMESPACE
289
	 * packages} that are exported by the required
290
	 * {@link #WIRING_BUNDLE_NAMESPACE bundle} are not made visible on the
291
	 * export signature of the requiring {@link #WIRING_BUNDLE_NAMESPACE bundle}
292
	 * .
293
	 * 
294
	 * @see #REQUIREMENT_VISIBILITY_DIRECTIVE
295
	 */
296
	public final static String REQUIREMENT_VISIBILITY_PRIVATE = Constants.VISIBILITY_PRIVATE;
297
298
	/**
299
	 * A directive value identifying a reexport
300
	 * {@link #REQUIREMENT_VISIBILITY_DIRECTIVE visibility} type. A reexport
301
	 * visibility type indicates any {@link #WIRING_PACKAGE_NAMESPACE packages}
302
	 * that are exported by the required {@link #WIRING_BUNDLE_NAMESPACE bundle}
303
	 * are re-exported by the requiring {@link #WIRING_BUNDLE_NAMESPACE bundle}.
304
	 */
305
	public final static String REQUIREMENT_VISIBILITY_REEXPORT = Constants.VISIBILITY_REEXPORT;
306
	
307
	/**
308
	 * A requirement {@link Requirement#getDirectives() directive} used to
309
	 * specify the cardinality for a requirement. The default value is
310
	 * {@link #REQUIREMENT_CARDINALITY_SINGULAR singular}.
311
	 * 
312
	 * @see #REQUIREMENT_CARDINALITY_MULTIPLE multiple
313
	 * @see #REQUIREMENT_CARDINALITY_SINGULAR singular
314
	 */
315
	public final static String REQUIREMENT_CARDINALITY_DIRECTIVE = "cardinality";
316
	  
317
	/**
318
	 * A directive value identifying a multiple
319
	 * {@link #REQUIREMENT_CARDINALITY_DIRECTIVE cardinality} type.
320
	 */
321
	public final static String REQUIREMENT_CARDINALITY_MULTIPLE = "multiple";
322
	  
323
	/**
324
	 * A directive value identifying a singular
325
	 * {@link #REQUIREMENT_CARDINALITY_DIRECTIVE cardinality} type.
326
	 */
327
	public final static String REQUIREMENT_CARDINALITY_SINGULAR = "singular";
328
329
330
	/**
331
	 * A capability {@link Capability#getDirectives() directive} used to specify
332
	 * the comma separated list of {@link #WIRING_PACKAGE_NAMESPACE package}
333
	 * names a capability uses.
334
	 */
335
	public final static String CAPABILITY_USES_DIRECTIVE = Constants.USES_DIRECTIVE;
336
337
	/**
338
	 * A capability {@link Capability#getDirectives() directive} used to specify
339
	 * the effective time for the capability. The default value is
340
	 * {@link #EFFECTIVE_RESOLVE resolve}.
341
	 * 
342
	 * @see #EFFECTIVE_RESOLVE resolve
343
	 * @see #EFFECTIVE_ACTIVE active
344
	 */
345
	public final static String CAPABILITY_EFFECTIVE_DIRECTIVE = Constants.EFFECTIVE_DIRECTIVE;
346
347
	/**
348
	 * A capability {@link Capability#getDirectives() directive} used to specify
349
	 * the comma separated list of mandatory attributes which must be specified
350
	 * in the {@link #REQUIREMENT_FILTER_DIRECTIVE filter} of a requirement in
351
	 * order for the capability to match the requirement. This directive must
352
	 * only be used for capabilities with the {@link #WIRING_PACKAGE_NAMESPACE
353
	 * package} name space.
354
	 */
355
	public final static String CAPABILITY_MANDATORY_DIRECTIVE = "mandatory";
356
357
	/**
358
	 * A capability {@link Capability#getDirectives() directive} used to specify
359
	 * the comma separated list of classes which must be allowed to be exported.
360
	 * This directive must only be used for capabilities with the
361
	 * {@link #WIRING_PACKAGE_NAMESPACE package} name space.
362
	 */
363
	public final static String CAPABILITY_INCLUDE_DIRECTIVE = "include";
364
365
	/**
366
	 * A capability {@link Capability#getDirectives() directive} used to specify
367
	 * the comma separated list of classes which must not be allowed to be
368
	 * exported. This directive must only be used for capabilities with the
369
	 * {@link #WIRING_PACKAGE_NAMESPACE package} name space.
370
	 */
371
	public final static String CAPABILITY_EXCLUDE_DIRECTIVE = "exclude";	
372
}
(-)osgi/src/org/osgi/framework/wiring/Wire.java (+58 lines)
Added Link Here
1
/*
2
 * Copyright (c) OSGi Alliance (2011). All Rights Reserved.
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
package org.osgi.framework.wiring;
18
19
/**
20
 * A wire connecting a {@link Capability} to a {@link Requirement}.
21
 * 
22
 * @ThreadSafe
23
 * @Immutable
24
 * @version $Id: ca06f75ac2d214182c5e5112f84334efd9d083fd $
25
 */
26
public interface Wire {
27
	/**
28
	 * Returns the {@link Capability} for this wire.
29
	 * 
30
	 * @return The {@link Capability} for this wire.
31
	 */
32
	Capability getCapability();
33
34
	/**
35
	 * Return the {@link Requirement} for this wire.
36
	 * 
37
	 * @return The {@link Requirement} for this wire.
38
	 */
39
	Requirement getRequirement();
40
41
	/**
42
	 * Return the providing {@link Resource resource} of the {@link #getCapability() capability}.
43
	 * <p>
44
	 * The resource returned may differ from the resource referenced by the {@link #getCapability()
45
	 * capability}.
46
	 * @return the providing {@link Resource resource}.
47
	 */
48
	Resource getProvider();
49
50
	/**
51
	 * Return the requiring {@link Resource resource} of the {@link #getRequirement() requirement}.
52
	 * <p>
53
	 * The resource returned my differ from the resource referenced by the {@link #getRequirement()
54
	 * requirement}
55
	 * @return the requiring {@link Resource resource}.
56
	 */
57
	Resource getRequirer();
58
}
(-)resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java (-6 / +20 lines)
Lines 16-21 Link Here
16
import org.eclipse.osgi.internal.resolver.GenericDescriptionImpl;
16
import org.eclipse.osgi.internal.resolver.GenericDescriptionImpl;
17
import org.eclipse.osgi.service.resolver.*;
17
import org.eclipse.osgi.service.resolver.*;
18
import org.osgi.framework.Constants;
18
import org.osgi.framework.Constants;
19
import org.osgi.framework.wiring.ResourceConstants;
19
20
20
/*
21
/*
21
 * A companion to BundleDescription from the state used while resolving.
22
 * A companion to BundleDescription from the state used while resolving.
Lines 62-68 Link Here
62
			imports = new ResolverImport[0];
63
			imports = new ResolverImport[0];
63
			requires = new BundleConstraint[0];
64
			requires = new BundleConstraint[0];
64
			genericReqiures = new GenericConstraint[0];
65
			genericReqiures = new GenericConstraint[0];
65
			genericCapabilities = new GenericCapability[0];
66
			GenericDescription[] capabilities = getBundleDescription().getGenericCapabilities();
67
			GenericCapability identity = null;
68
			for (GenericDescription capability : capabilities) {
69
				if (ResourceConstants.IDENTITY_NAMESPACE.equals(capability.getType())) {
70
					identity = new GenericCapability(this, capability);
71
					break;
72
				}
73
			}
74
75
			genericCapabilities = identity == null ? new GenericCapability[0] : new GenericCapability[] {identity};
66
			return;
76
			return;
67
		}
77
		}
68
78
Lines 311-318 Link Here
311
			return; // do not allow fragments with conflicting constraints
321
			return; // do not allow fragments with conflicting constraints
312
		if (isResolved() && newExports.length > 0)
322
		if (isResolved() && newExports.length > 0)
313
			fragment.setNewFragmentExports(true);
323
			fragment.setNewFragmentExports(true);
314
		if (isResolved() && newGenericCapabilities.length > 0)
315
			fragment.setNewFragmentCapabilities(true);
316
324
317
		initFragments();
325
		initFragments();
318
		// need to make sure there is not already another version of this fragment 
326
		// need to make sure there is not already another version of this fragment 
Lines 371-380 Link Here
371
		List<GenericCapability> hostCapabilities = new ArrayList<GenericCapability>(newGenericCapabilities.length);
379
		List<GenericCapability> hostCapabilities = new ArrayList<GenericCapability>(newGenericCapabilities.length);
372
		if (newGenericCapabilities.length > 0 && dynamicAttach) {
380
		if (newGenericCapabilities.length > 0 && dynamicAttach) {
373
			for (GenericDescription capability : newGenericCapabilities) {
381
			for (GenericDescription capability : newGenericCapabilities) {
374
				GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
382
				if (!ResourceConstants.IDENTITY_NAMESPACE.equals(capability.getType())) {
375
				hostCapabilities.add(new GenericCapability(this, hostCapabililty));
383
					GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
384
					hostCapabilities.add(new GenericCapability(this, hostCapabililty));
385
				}
386
			}
387
			if (hostCapabilities.size() > 0) {
388
				fragmentGenericCapabilities.put(fragment.bundleID, hostCapabilities);
389
				if (isResolved())
390
					fragment.setNewFragmentCapabilities(true);
376
			}
391
			}
377
			fragmentGenericCapabilities.put(fragment.bundleID, hostCapabilities);
378
		}
392
		}
379
		if (dynamicAttach) {
393
		if (dynamicAttach) {
380
			resolver.getResolverExports().put(hostExports.toArray(new ResolverExport[hostExports.size()]));
394
			resolver.getResolverExports().put(hostExports.toArray(new ResolverExport[hostExports.size()]));
(-)resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java (-9 / +20 lines)
Lines 1333-1339 Link Here
1333
		if (namespace == null)
1333
		if (namespace == null)
1334
			capabilities = Collections.EMPTY_LIST;
1334
			capabilities = Collections.EMPTY_LIST;
1335
		else
1335
		else
1336
			capabilities = name == null || "*".equals(name) ? namespace.getAllValues() : namespace.get(name); //$NON-NLS-1$
1336
			capabilities = name == null || name.indexOf('*') >= 0 ? namespace.getAllValues() : namespace.get(name);
1337
		List<GenericCapability> candidates = new ArrayList<GenericCapability>(capabilities);
1337
		List<GenericCapability> candidates = new ArrayList<GenericCapability>(capabilities);
1338
		List<BundleCapability> genCapabilities = new ArrayList<BundleCapability>(candidates.size());
1338
		List<BundleCapability> genCapabilities = new ArrayList<BundleCapability>(candidates.size());
1339
		// Must remove candidates that do not match before calling hooks.
1339
		// Must remove candidates that do not match before calling hooks.
Lines 1359-1372 Link Here
1359
				result = true; // Wired to ourselves
1359
				result = true; // Wired to ourselves
1360
				continue;
1360
				continue;
1361
			}
1361
			}
1362
			ResolverBundle supplier = capability.getResolverBundle();
1362
			VersionSupplier[] capabilityHosts = capability.getResolverBundle().isFragment() ? capability.getResolverBundle().getHost().getPossibleSuppliers() : new ResolverBundle[] {capability.getResolverBundle()};
1363
			// if in dev mode then allow a constraint to resolve to an unresolved bundle
1363
			boolean foundResolvedMatch = false;
1364
			if (supplier.getState() == ResolverBundle.RESOLVED || (resolveBundle(supplier, cycle) || developmentMode)) {
1364
			for (int i = 0; capabilityHosts != null && i < capabilityHosts.length; i++) {
1365
				// Check cyclic dependencies
1365
				ResolverBundle capabilitySupplier = capabilityHosts[i].getResolverBundle();
1366
				if (supplier.getState() == ResolverBundle.RESOLVING)
1366
				if (capabilitySupplier == constraint.getBundle()) {
1367
					if (!cycle.contains(supplier))
1367
					// the capability is from a fragment attached to this host do not recursively resolve the host again
1368
						cycle.add(supplier);
1368
					foundResolvedMatch = true;
1369
			} else {
1369
					continue;
1370
				}
1371
				// if in dev mode then allow a constraint to resolve to an unresolved bundle
1372
				if (capabilitySupplier.getState() == ResolverBundle.RESOLVED || (resolveBundle(capabilitySupplier, cycle) || developmentMode)) {
1373
					foundResolvedMatch |= !capability.getResolverBundle().isFragment() ? true : capability.getResolverBundle().getHost().getPossibleSuppliers() != null;
1374
					// Check cyclic dependencies
1375
					if (capabilitySupplier.getState() == ResolverBundle.RESOLVING)
1376
						if (!cycle.contains(capabilitySupplier))
1377
							cycle.add(capabilitySupplier);
1378
				}
1379
			}
1380
			if (!foundResolvedMatch) {
1370
				constraint.removePossibleSupplier(capability);
1381
				constraint.removePossibleSupplier(capability);
1371
				continue; // constraint hasn't resolved
1382
				continue; // constraint hasn't resolved
1372
			}
1383
			}
(-)resolver/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java (+4 lines)
Lines 156-160 Link Here
156
		public String toString() {
156
		public String toString() {
157
			return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false) + BaseDescriptionImpl.toString(getDirectives(), true);
157
			return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false) + BaseDescriptionImpl.toString(getDirectives(), true);
158
		}
158
		}
159
160
		public BundleRevision getResource() {
161
			return getRevision();
162
		}
159
	}
163
	}
160
}
164
}
(-)resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java (-9 / +26 lines)
Lines 1031-1036 Link Here
1031
		public String toString() {
1031
		public String toString() {
1032
			return getRequirement() + " -> " + getCapability(); //$NON-NLS-1$
1032
			return getRequirement() + " -> " + getCapability(); //$NON-NLS-1$
1033
		}
1033
		}
1034
1035
		public BundleRevision getProvider() {
1036
			return provider.getRevision();
1037
		}
1038
1039
		public BundleRevision getRequirer() {
1040
			return requirer.getRevision();
1041
		}
1034
	}
1042
	}
1035
1043
1036
	// Note that description wiring are identity equality based
1044
	// Note that description wiring are identity equality based
Lines 1056-1066 Link Here
1056
		public List<BundleCapability> getCapabilities(String namespace) {
1064
		public List<BundleCapability> getCapabilities(String namespace) {
1057
			if (!isInUse())
1065
			if (!isInUse())
1058
				return null;
1066
				return null;
1059
			@SuppressWarnings("unchecked")
1067
			List<BundleCapability> result = new ArrayList<BundleCapability>();
1060
			List<BundleCapability> result = Collections.EMPTY_LIST;
1068
			GenericDescription[] genericCapabilities = getSelectedGenericCapabilities();
1069
			for (GenericDescription capabilitiy : genericCapabilities) {
1070
				if (namespace == null || namespace.equals(capabilitiy.getType()))
1071
					result.add(capabilitiy.getCapability());
1072
			}
1061
			if (host != null)
1073
			if (host != null)
1062
				return result;
1074
				return result;
1063
			result = new ArrayList<BundleCapability>();
1064
			if (getSymbolicName() != null) {
1075
			if (getSymbolicName() != null) {
1065
				if (namespace == null || BundleRevision.BUNDLE_NAMESPACE.equals(namespace)) {
1076
				if (namespace == null || BundleRevision.BUNDLE_NAMESPACE.equals(namespace)) {
1066
					result.add(BundleDescriptionImpl.this.getCapability());
1077
					result.add(BundleDescriptionImpl.this.getCapability());
Lines 1074-1084 Link Here
1074
				for (ExportPackageDescription exportPkg : exports)
1085
				for (ExportPackageDescription exportPkg : exports)
1075
					result.add(exportPkg.getCapability());
1086
					result.add(exportPkg.getCapability());
1076
			}
1087
			}
1077
			GenericDescription[] genericCapabilities = getSelectedGenericCapabilities();
1078
			for (GenericDescription capabilitiy : genericCapabilities) {
1079
				if (namespace == null || namespace.equals(capabilitiy.getType()))
1080
					result.add(capabilitiy.getCapability());
1081
			}
1082
			return result;
1088
			return result;
1083
		}
1089
		}
1084
1090
Lines 1093-1099 Link Here
1093
					requirements.add(wire.getRequirement());
1099
					requirements.add(wire.getRequirement());
1094
			}
1100
			}
1095
			// get dynamic imports
1101
			// get dynamic imports
1096
			if (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
1102
			if (getHost() == null && (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace))) {
1103
				// TODO need to handle fragments that add dynamic imports
1097
				if (hasDynamicImports()) {
1104
				if (hasDynamicImports()) {
1098
					ImportPackageSpecification[] imports = getImportPackages();
1105
					ImportPackageSpecification[] imports = getImportPackages();
1099
					for (ImportPackageSpecification impPackage : imports) {
1106
					for (ImportPackageSpecification impPackage : imports) {
Lines 1230-1233 Link Here
1230
			return BundleDescriptionImpl.this.toString();
1237
			return BundleDescriptionImpl.this.toString();
1231
		}
1238
		}
1232
	}
1239
	}
1240
1241
	@SuppressWarnings({"cast", "unchecked", "rawtypes"})
1242
	public List<Capability> getCapabilities(String namespace) {
1243
		return (List<Capability>) (List) getDeclaredCapabilities(namespace);
1244
	}
1245
1246
	@SuppressWarnings({"cast", "unchecked", "rawtypes"})
1247
	public List<Requirement> getRequirements(String namespace) {
1248
		return (List<Requirement>) (List) getDeclaredRequirements(namespace);
1249
	}
1233
}
1250
}
(-)resolver/src/org/eclipse/osgi/internal/resolver/BundleSpecificationImpl.java (-3 / +11 lines)
Lines 91-97 Link Here
91
			}
91
			}
92
		}
92
		}
93
		String[] mandatory = (String[]) candidate.getDirective(Constants.MANDATORY_DIRECTIVE);
93
		String[] mandatory = (String[]) candidate.getDirective(Constants.MANDATORY_DIRECTIVE);
94
		if (!hasMandatoryAttributes(mandatory))
95
			return false;
96
		if (getName() != null && getName().equals(candidate.getSymbolicName()) && (getVersionRange() == null || getVersionRange().isIncluded(candidate.getVersion())))
97
			return true;
98
		return false;
99
	}
100
101
	@Override
102
	protected boolean hasMandatoryAttributes(String[] mandatory) {
94
		if (mandatory != null) {
103
		if (mandatory != null) {
104
			Map<String, ?> requiredAttrs = getAttributes();
95
			for (String key : mandatory) {
105
			for (String key : mandatory) {
96
				if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(key))
106
				if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(key))
97
					continue; // has a default value of 0.0.0
107
					continue; // has a default value of 0.0.0
Lines 99-107 Link Here
99
					return false;
109
					return false;
100
			}
110
			}
101
		}
111
		}
102
		if (getName() != null && getName().equals(candidate.getSymbolicName()) && (getVersionRange() == null || getVersionRange().isIncluded(candidate.getVersion())))
112
		return true;
103
			return true;
104
		return false;
105
	}
113
	}
106
114
107
	public String toString() {
115
	public String toString() {
(-)resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java (+5 lines)
Lines 57-62 Link Here
57
		return matchingFilter == null || matchingFilter.match(candidate.getAttributes());
57
		return matchingFilter == null || matchingFilter.match(candidate.getAttributes());
58
	}
58
	}
59
59
60
	@Override
61
	protected boolean hasMandatoryAttributes(String[] mandatory) {
62
		return true;
63
	}
64
60
	public String toString() {
65
	public String toString() {
61
		StringBuffer sb = new StringBuffer();
66
		StringBuffer sb = new StringBuffer();
62
		sb.append(Constants.REQUIRE_CAPABILITY).append(": ").append(getType()); //$NON-NLS-1$
67
		sb.append(Constants.REQUIRE_CAPABILITY).append(": ").append(getType()); //$NON-NLS-1$
(-)resolver/src/org/eclipse/osgi/internal/resolver/HostSpecificationImpl.java (-8 / +16 lines)
Lines 69-82 Link Here
69
			}
69
			}
70
		}
70
		}
71
		String[] mandatory = (String[]) candidate.getDirective(Constants.MANDATORY_DIRECTIVE);
71
		String[] mandatory = (String[]) candidate.getDirective(Constants.MANDATORY_DIRECTIVE);
72
		if (mandatory != null) {
72
		if (!hasMandatoryAttributes(mandatory))
73
			for (String key : mandatory) {
73
			return false;
74
				if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(key))
75
					continue; // has a default value of 0.0.0
76
				if (requiredAttrs == null || requiredAttrs.get(key) == null)
77
					return false;
78
			}
79
		}
80
		if (getName() != null && getName().equals(candidate.getSymbolicName()) && (getVersionRange() == null || getVersionRange().isIncluded(candidate.getVersion())))
74
		if (getName() != null && getName().equals(candidate.getSymbolicName()) && (getVersionRange() == null || getVersionRange().isIncluded(candidate.getVersion())))
81
			return true;
75
			return true;
82
		return false;
76
		return false;
Lines 88-93 Link Here
88
		}
82
		}
89
	}
83
	}
90
84
85
	@Override
86
	protected boolean hasMandatoryAttributes(String[] mandatory) {
87
		if (mandatory != null) {
88
			Map<String, ?> requiredAttrs = getAttributes();
89
			for (String key : mandatory) {
90
				if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(key))
91
					continue; // has a default value of 0.0.0
92
				if (requiredAttrs == null || requiredAttrs.get(key) == null)
93
					return false;
94
			}
95
		}
96
		return true;
97
	}
98
91
	public boolean isResolved() {
99
	public boolean isResolved() {
92
		synchronized (this.monitor) {
100
		synchronized (this.monitor) {
93
			return hosts != null && hosts.length > 0;
101
			return hosts != null && hosts.length > 0;
(-)resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java (-6 / +14 lines)
Lines 149-158 Link Here
149
			}
149
			}
150
		}
150
		}
151
		String[] mandatory = (String[]) pkgDes.getDirective(Constants.MANDATORY_DIRECTIVE);
151
		String[] mandatory = (String[]) pkgDes.getDirective(Constants.MANDATORY_DIRECTIVE);
152
		if (!hasMandatoryAttributes(mandatory))
153
			return false;
154
		// finally check the ee index
155
		if (((BundleDescriptionImpl) getBundle()).getEquinoxEE() < 0)
156
			return true;
157
		int eeIndex = ((Integer) pkgDes.getDirective(ExportPackageDescriptionImpl.EQUINOX_EE)).intValue();
158
		return eeIndex < 0 || eeIndex == ((BundleDescriptionImpl) getBundle()).getEquinoxEE();
159
	}
160
161
	@Override
162
	protected boolean hasMandatoryAttributes(String[] mandatory) {
152
		if (mandatory != null) {
163
		if (mandatory != null) {
164
			Map<String, ?> importAttrs = getAttributes();
153
			for (int i = 0; i < mandatory.length; i++) {
165
			for (int i = 0; i < mandatory.length; i++) {
154
				if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(mandatory[i])) {
166
				if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(mandatory[i])) {
155
					if (exporterSymbolicName == null)
167
					if (getBundleSymbolicName() == null)
156
						return false;
168
						return false;
157
				} else if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(mandatory[i])) {
169
				} else if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(mandatory[i])) {
158
					if (bundleVersionRange == null)
170
					if (bundleVersionRange == null)
Lines 168-178 Link Here
168
				}
180
				}
169
			}
181
			}
170
		}
182
		}
171
		// finally check the ee index
183
		return true;
172
		if (((BundleDescriptionImpl) getBundle()).getEquinoxEE() < 0)
173
			return true;
174
		int eeIndex = ((Integer) pkgDes.getDirective(ExportPackageDescriptionImpl.EQUINOX_EE)).intValue();
175
		return eeIndex < 0 || eeIndex == ((BundleDescriptionImpl) getBundle()).getEquinoxEE();
176
	}
184
	}
177
185
178
	protected void setBundleSymbolicName(String symbolicName) {
186
	protected void setBundleSymbolicName(String symbolicName) {
(-)resolver/src/org/eclipse/osgi/internal/resolver/NativeCodeSpecificationImpl.java (+5 lines)
Lines 145-150 Link Here
145
		return match;
145
		return match;
146
	}
146
	}
147
147
148
	@Override
149
	protected boolean hasMandatoryAttributes(String[] mandatory) {
150
		return true;
151
	}
152
148
	public String toString() {
153
	public String toString() {
149
		StringBuffer sb = new StringBuffer();
154
		StringBuffer sb = new StringBuffer();
150
		NativeCodeDescription[] suppliers = getPossibleSuppliers();
155
		NativeCodeDescription[] suppliers = getPossibleSuppliers();
(-)resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java (-5 / +46 lines)
Lines 19-24 Link Here
19
import org.eclipse.osgi.util.ManifestElement;
19
import org.eclipse.osgi.util.ManifestElement;
20
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.osgi.util.NLS;
21
import org.osgi.framework.*;
21
import org.osgi.framework.*;
22
import org.osgi.framework.wiring.ResourceConstants;
22
23
23
/**
24
/**
24
 * This class builds bundle description objects from manifests
25
 * This class builds bundle description objects from manifests
Lines 118-124 Link Here
118
		result.setGenericRequires(createGenericRequires(genericRequires, osgiRequires));
119
		result.setGenericRequires(createGenericRequires(genericRequires, osgiRequires));
119
		ManifestElement[] genericCapabilities = getGenericCapabilities(manifest, genericAliases);
120
		ManifestElement[] genericCapabilities = getGenericCapabilities(manifest, genericAliases);
120
		ManifestElement[] osgiCapabilities = ManifestElement.parseHeader(Constants.PROVIDE_CAPABILITY, manifest.get(Constants.PROVIDE_CAPABILITY));
121
		ManifestElement[] osgiCapabilities = ManifestElement.parseHeader(Constants.PROVIDE_CAPABILITY, manifest.get(Constants.PROVIDE_CAPABILITY));
121
		result.setGenericCapabilities(createGenericCapabilities(genericCapabilities, osgiCapabilities));
122
		result.setGenericCapabilities(createGenericCapabilities(genericCapabilities, osgiCapabilities, result));
122
		ManifestElement[] nativeCode = ManifestElement.parseHeader(Constants.BUNDLE_NATIVECODE, manifest.get(Constants.BUNDLE_NATIVECODE));
123
		ManifestElement[] nativeCode = ManifestElement.parseHeader(Constants.BUNDLE_NATIVECODE, manifest.get(Constants.BUNDLE_NATIVECODE));
123
		result.setNativeCodeSpecification(createNativeCode(nativeCode));
124
		result.setNativeCodeSpecification(createNativeCode(nativeCode));
124
		return result;
125
		return result;
Lines 554-566 Link Here
554
		return results;
555
		return results;
555
	}
556
	}
556
557
557
	private static GenericDescription[] createGenericCapabilities(ManifestElement[] equinoxCapabilities, ManifestElement[] osgiCapabilities) {
558
	private static GenericDescription[] createGenericCapabilities(ManifestElement[] equinoxCapabilities, ManifestElement[] osgiCapabilities, BundleDescription description) throws BundleException {
558
		List<GenericDescription> result = createEquinoxCapabilities(equinoxCapabilities);
559
		List<GenericDescription> result = createEquinoxCapabilities(equinoxCapabilities);
559
		result = createOSGiCapabilities(osgiCapabilities, result);
560
		result = createOSGiCapabilities(osgiCapabilities, result, description);
560
		return result == null ? null : result.toArray(new GenericDescription[result.size()]);
561
		return result == null ? null : result.toArray(new GenericDescription[result.size()]);
561
	}
562
	}
562
563
563
	static List<GenericDescription> createOSGiCapabilities(ManifestElement[] osgiCapabilities, List<GenericDescription> result) {
564
	private static List<GenericDescription> createOSGiCapabilities(ManifestElement[] osgiCapabilities, List<GenericDescription> result, BundleDescription description) throws BundleException {
565
		if (result == null)
566
			result = new ArrayList<GenericDescription>(osgiCapabilities == null ? 1 : osgiCapabilities.length + 1);
567
		// Always have an osgi.identity capability if there is a symbolic name.
568
		GenericDescription osgiIdentity = createOsgiIdentityCapability(description);
569
		if (osgiIdentity != null)
570
			// always add the capability to the front
571
			result.add(0, osgiIdentity);
572
		return createOSGiCapabilities(osgiCapabilities, result);
573
	}
574
575
	static List<GenericDescription> createOSGiCapabilities(ManifestElement[] osgiCapabilities, List<GenericDescription> result) throws BundleException {
564
		if (osgiCapabilities == null)
576
		if (osgiCapabilities == null)
565
			return result;
577
			return result;
566
		if (result == null)
578
		if (result == null)
Lines 570-577 Link Here
570
			String[] namespaces = element.getValueComponents();
582
			String[] namespaces = element.getValueComponents();
571
			types: for (String namespace : namespaces) {
583
			types: for (String namespace : namespaces) {
572
				String effective = element.getDirective(Constants.EFFECTIVE_DIRECTIVE);
584
				String effective = element.getDirective(Constants.EFFECTIVE_DIRECTIVE);
585
				// Any declared osgi.identity capability with an effective directive value of "resolve" will be overridden.
573
				if (effective != null && !Constants.EFFECTIVE_RESOLVE.equals(effective))
586
				if (effective != null && !Constants.EFFECTIVE_RESOLVE.equals(effective))
574
					break types; // ignore any namespace that is not effective at resolve time.
587
					break types; // ignore any namespace that is not effective at resolve time.
588
				if (ResourceConstants.IDENTITY_NAMESPACE.equals(namespace))
589
					throw new BundleException("A bundle is not allowed to define a capability in the " + ResourceConstants.IDENTITY_NAMESPACE + " name space."); //$NON-NLS-1$ //$NON-NLS-2$
590
575
				GenericDescriptionImpl desc = new GenericDescriptionImpl();
591
				GenericDescriptionImpl desc = new GenericDescriptionImpl();
576
				desc.setType(namespace);
592
				desc.setType(namespace);
577
				Map<String, Object> mapAttrs = getAttributes(element, new String[0]);
593
				Map<String, Object> mapAttrs = getAttributes(element, new String[0]);
Lines 591-597 Link Here
591
		return result;
607
		return result;
592
	}
608
	}
593
609
594
	private static List<GenericDescription> createEquinoxCapabilities(ManifestElement[] equinoxCapabilities) {
610
	private static List<GenericDescription> createEquinoxCapabilities(ManifestElement[] equinoxCapabilities) throws BundleException {
595
		if (equinoxCapabilities == null)
611
		if (equinoxCapabilities == null)
596
			return null;
612
			return null;
597
		ArrayList<GenericDescription> results = new ArrayList<GenericDescription>(equinoxCapabilities.length);
613
		ArrayList<GenericDescription> results = new ArrayList<GenericDescription>(equinoxCapabilities.length);
Lines 604-609 Link Here
604
				if (colonIdx > 0) {
620
				if (colonIdx > 0) {
605
					name = genericNames[j].substring(0, colonIdx);
621
					name = genericNames[j].substring(0, colonIdx);
606
					desc.setType(genericNames[j].substring(colonIdx + 1));
622
					desc.setType(genericNames[j].substring(colonIdx + 1));
623
					if (ResourceConstants.IDENTITY_NAMESPACE.equals(desc.getType()))
624
						throw new BundleException("A bundle is not allowed to define a capability in the " + ResourceConstants.IDENTITY_NAMESPACE + " name space."); //$NON-NLS-1$ //$NON-NLS-2$
607
				}
625
				}
608
				Map<String, Object> mapAttrs = getAttributes(equinoxCapabilities[i], new String[] {Constants.VERSION_ATTRIBUTE});
626
				Map<String, Object> mapAttrs = getAttributes(equinoxCapabilities[i], new String[] {Constants.VERSION_ATTRIBUTE});
609
				Dictionary<String, Object> attrs = mapAttrs == null ? new Hashtable<String, Object>() : new Hashtable<String, Object>(mapAttrs);
627
				Dictionary<String, Object> attrs = mapAttrs == null ? new Hashtable<String, Object>() : new Hashtable<String, Object>(mapAttrs);
Lines 748-751 Link Here
748
			throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_EXTENSION_ERROR, hostName), BundleException.MANIFEST_ERROR); //$NON-NLS-1$
766
			throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_EXTENSION_ERROR, hostName), BundleException.MANIFEST_ERROR); //$NON-NLS-1$
749
		}
767
		}
750
	}
768
	}
769
770
	private static GenericDescription createOsgiIdentityCapability(BundleDescription description) {
771
		if (description.getSymbolicName() == null)
772
			return null;
773
		GenericDescriptionImpl result = new GenericDescriptionImpl();
774
		result.setType(ResourceConstants.IDENTITY_NAMESPACE);
775
		Dictionary<String, Object> attributes = new Hashtable<String, Object>(description.getDeclaredAttributes());
776
		// remove osgi.wiring.bundle and bundle-version attributes
777
		attributes.remove(ResourceConstants.WIRING_BUNDLE_NAMESPACE);
778
		attributes.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
779
		attributes.put(ResourceConstants.IDENTITY_NAMESPACE, description.getSymbolicName());
780
		attributes.put(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE, description.getHost() == null ? ResourceConstants.IDENTITY_TYPE_BUNDLE : ResourceConstants.IDENTITY_TYPE_FRAGMENT);
781
		attributes.put(ResourceConstants.IDENTITY_VERSION_ATTRIBUTE, description.getVersion());
782
		result.setAttributes(attributes);
783
		Map<String, String> directives = new HashMap<String, String>(description.getDeclaredDirectives());
784
		// remove defaults directive values
785
		if (!description.isSingleton())
786
			directives.remove(Constants.SINGLETON_DIRECTIVE);
787
		if (description.attachFragments() && description.dynamicFragments())
788
			directives.remove(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE);
789
		result.setDirectives(directives);
790
		return result;
791
	}
751
}
792
}
(-)resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java (-1 / +5 lines)
Lines 871-877 Link Here
871
	}
871
	}
872
872
873
	private void addSystemCapabilities(List<GenericDescription> capabilities, ManifestElement[] elements) {
873
	private void addSystemCapabilities(List<GenericDescription> capabilities, ManifestElement[] elements) {
874
		StateBuilder.createOSGiCapabilities(elements, capabilities);
874
		try {
875
			StateBuilder.createOSGiCapabilities(elements, capabilities);
876
		} catch (BundleException e) {
877
			throw new RuntimeException("Unexpected exception adding system capabilities.", e); //$NON-NLS-1$
878
		}
875
	}
879
	}
876
880
877
	@SuppressWarnings("rawtypes")
881
	@SuppressWarnings("rawtypes")
(-)resolver/src/org/eclipse/osgi/internal/resolver/VersionConstraintImpl.java (-1 / +24 lines)
Lines 17-23 Link Here
17
import org.eclipse.osgi.framework.internal.core.Constants;
17
import org.eclipse.osgi.framework.internal.core.Constants;
18
import org.eclipse.osgi.internal.resolver.BaseDescriptionImpl.BaseCapability;
18
import org.eclipse.osgi.internal.resolver.BaseDescriptionImpl.BaseCapability;
19
import org.eclipse.osgi.service.resolver.*;
19
import org.eclipse.osgi.service.resolver.*;
20
import org.osgi.framework.Version;
20
import org.eclipse.osgi.util.ManifestElement;
21
import org.osgi.framework.*;
21
import org.osgi.framework.wiring.*;
22
import org.osgi.framework.wiring.*;
22
23
23
abstract class VersionConstraintImpl implements VersionConstraint {
24
abstract class VersionConstraintImpl implements VersionConstraint {
Lines 101-106 Link Here
101
102
102
	protected abstract Map<String, Object> getInteralAttributes();
103
	protected abstract Map<String, Object> getInteralAttributes();
103
104
105
	protected abstract boolean hasMandatoryAttributes(String[] mandatory);
106
104
	public BundleRequirement getRequirement() {
107
	public BundleRequirement getRequirement() {
105
		String namespace = getInternalNameSpace();
108
		String namespace = getInternalNameSpace();
106
		if (namespace == null)
109
		if (namespace == null)
Lines 156-161 Link Here
156
		public String toString() {
159
		public String toString() {
157
			return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false) + BaseDescriptionImpl.toString(getDirectives(), true);
160
			return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false) + BaseDescriptionImpl.toString(getDirectives(), true);
158
		}
161
		}
162
163
		public boolean matches(Capability capability) {
164
			if (capability instanceof BundleCapability)
165
				return matches((BundleCapability) capability);
166
			// now we must do the generic thing
167
			if (!namespace.equals(capability.getNamespace()))
168
				return false;
169
			String filterSpec = getDirectives().get(ResourceConstants.REQUIREMENT_FILTER_DIRECTIVE);
170
			try {
171
				if (filterSpec != null && !FrameworkUtil.createFilter(filterSpec).matches(capability.getAttributes()))
172
					return false;
173
			} catch (InvalidSyntaxException e) {
174
				return false;
175
			}
176
			return hasMandatoryAttributes(ManifestElement.getArrayFromList(capability.getDirectives().get(ResourceConstants.CAPABILITY_MANDATORY_DIRECTIVE)));
177
		}
178
179
		public BundleRevision getResource() {
180
			return getRevision();
181
		}
159
	}
182
	}
160
183
161
	static StringBuffer addFilterAttributes(StringBuffer filter, Map<String, ?> attributes) {
184
	static StringBuffer addFilterAttributes(StringBuffer filter, Map<String, ?> attributes) {
(-).classpath (+7 lines)
Lines 111-116 Link Here
111
	<classpathentry kind="src" output="bundle_tests/test.bug306181b" path="bundles_src/test.bug306181b"/>
111
	<classpathentry kind="src" output="bundle_tests/test.bug306181b" path="bundles_src/test.bug306181b"/>
112
	<classpathentry kind="src" output="bundle_tests/test.logging.a" path="bundles_src/test.logging.a"/>
112
	<classpathentry kind="src" output="bundle_tests/test.logging.a" path="bundles_src/test.logging.a"/>
113
	<classpathentry kind="src" output="bundle_tests/console.test" path="bundles_src/console.test"/>
113
	<classpathentry kind="src" output="bundle_tests/console.test" path="bundles_src/console.test"/>
114
	<classpathentry kind="src" output="bundle_tests/resource.tb1" path="bundles_src/resource.tb1"/>
115
	<classpathentry kind="src" output="bundle_tests/resource.tb2" path="bundles_src/resource.tb2"/>
116
	<classpathentry kind="src" output="bundle_tests/resource.tf1" path="bundles_src/resource.tf1"/>
117
	<classpathentry kind="src" output="bundle_tests/resource.tf2" path="bundles_src/resource.tf2"/>
118
	<classpathentry kind="src" output="bundle_tests/resource.tb3" path="bundles_src/resource.tb3"/>
119
	<classpathentry kind="src" output="bundle_tests/resource.tb4" path="bundles_src/resource.tb4"/>
120
	<classpathentry kind="src" output="bundle_tests/resource.tb5" path="bundles_src/resource.tb5"/>
114
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
121
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
115
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
122
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
116
	<classpathentry kind="output" path="bin"/>
123
	<classpathentry kind="output" path="bin"/>
(-)bundles_src/resource.tb1/META-INF/MANIFEST.MF (+4 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-SymbolicName: resource.tb1; singleton:="true"; dir1:="d1"; dir2:="d2"; attr1="a1"; attr2="a2"
4
Bundle-Version: 1.0.0
(-)bundles_src/resource.tb2/META-INF/MANIFEST.MF (+3 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 1
3
(-)bundles_src/resource.tb3/META-INF/MANIFEST.MF (+9 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-SymbolicName: resource.tb3
4
Bundle-Version: 1.0.0
5
Require-Capability: osgi.identity;
6
 filter:=(&(osgi.identity=resource.tb1)(version=1.0.0)(type=osgi.bundle)),
7
 osgi.identity;
8
 filter:=(&(osgi.identity=resource.tf1)(version=1.0.0)(type=osgi.fragment))
9
(-)bundles_src/resource.tb4/META-INF/MANIFEST.MF (+5 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-SymbolicName: resource.tb4
4
Bundle-Version: 1.0.0
5
(-)bundles_src/resource.tb5/META-INF/MANIFEST.MF (+11 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-SymbolicName: resource.tb5
4
Bundle-Version: 1.0.0
5
Require-Capability: 
6
 capability.1,
7
 capability.1;b=a,
8
 capability.1;b=a;bar=foo;filter:=(a=b),
9
 capability.1;a=b;filter:=(a=c),
10
 capability.2;bar=foo;y=x;filter:=(&(foo=bar));mandatory:="foo,x"
11
(-)bundles_src/resource.tf1/META-INF/MANIFEST.MF (+8 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-SymbolicName: resource.tf1
4
Bundle-Version: 1.0.0
5
Fragment-Host: resource.tb1
6
Require-Capability: osgi.identity;
7
 filter:=(&(osgi.identity=resource.tb4)(version=1.0.0)(type=osgi.bundle))
8
(-)bundles_src/resource.tf2/META-INF/MANIFEST.MF (+4 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 1
3
Fragment-Host: resource.tb1
4
(-)src/org/eclipse/osgi/tests/AutomatedTests.java (+1 lines)
Lines 63-68 Link Here
63
		suite.addTest(AllCompositeTests.suite());
63
		suite.addTest(AllCompositeTests.suite());
64
		suite.addTest(org.eclipse.osgi.tests.securityadmin.AllSecurityAdminTests.suite());
64
		suite.addTest(org.eclipse.osgi.tests.securityadmin.AllSecurityAdminTests.suite());
65
		suite.addTest(AllConsoleTests.suite());
65
		suite.addTest(AllConsoleTests.suite());
66
		suite.addTest(org.eclipse.osgi.tests.resource.AllTests.suite());
66
		return suite;
67
		return suite;
67
	}
68
	}
68
}
69
}
(-)src/org/eclipse/osgi/tests/resource/AbstractResourceTest.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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.resource;
12
13
import org.eclipse.osgi.tests.OSGiTest;
14
import org.eclipse.osgi.tests.OSGiTestsActivator;
15
import org.eclipse.osgi.tests.bundles.BundleInstaller;
16
import org.osgi.framework.InvalidSyntaxException;
17
18
public abstract class AbstractResourceTest extends OSGiTest {
19
	protected BundleInstaller installer;
20
21
	public AbstractResourceTest() {
22
		super();
23
	}
24
25
	public AbstractResourceTest(String name) {
26
		super(name);
27
	}
28
29
	protected void setUp() throws Exception {
30
		super.setUp();
31
		try {
32
			installer = new BundleInstaller("bundle_tests", OSGiTestsActivator.getContext()); //$NON-NLS-1$
33
		} catch (InvalidSyntaxException e) {
34
			fail("Failed to create bundle installer", e); //$NON-NLS-1$
35
		}
36
	}
37
38
	protected void tearDown() throws Exception {
39
		installer.shutdown();
40
		super.tearDown();
41
	}
42
}
(-)src/org/eclipse/osgi/tests/resource/AllTests.java (+22 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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.resource;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
public class AllTests {
17
	public static Test suite() {
18
		TestSuite suite = new TestSuite(AllTests.class.getName());
19
		suite.addTest(BasicTest.suite());
20
		return suite;
21
	}
22
}
(-)src/org/eclipse/osgi/tests/resource/BasicTest.java (+539 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 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.resource;
12
13
import java.util.*;
14
import java.util.Map.Entry;
15
import junit.framework.*;
16
import org.osgi.framework.Bundle;
17
import org.osgi.framework.Version;
18
import org.osgi.framework.wiring.*;
19
20
public class BasicTest extends AbstractResourceTest {
21
	private interface CapabilityProvider {
22
		List getCapabilities(String namespace);
23
	}
24
25
	static class BasicCapability implements Capability {
26
		private final Map attributes;
27
		private final Map directives;
28
		private final String namespace;
29
30
		public BasicCapability(String namespace) {
31
			this(namespace, Collections.EMPTY_MAP);
32
		}
33
34
		public BasicCapability(String namespace, Map attributes) {
35
			this(namespace, attributes, Collections.EMPTY_MAP);
36
		}
37
38
		public BasicCapability(String namespace, Map attributes, Map directives) {
39
			this.namespace = namespace;
40
			this.attributes = attributes;
41
			this.directives = directives;
42
		}
43
44
		public String getNamespace() {
45
			return namespace;
46
		}
47
48
		public Map getDirectives() {
49
			return directives;
50
		}
51
52
		public Map getAttributes() {
53
			return attributes;
54
		}
55
56
		public Resource getResource() {
57
			return null;
58
		}
59
	}
60
61
	private Bundle tb1;
62
	private Bundle tb2;
63
	private Bundle tb3;
64
	private Bundle tb4;
65
	private Bundle tf1;
66
	private Bundle tf2;
67
68
	public static Test suite() {
69
		return new TestSuite(BasicTest.class);
70
	}
71
72
	public BasicTest(String name) {
73
		super(name);
74
	}
75
76
	public void testIdentity() throws Exception {
77
		tb1 = installer.installBundle("resource.tb1");
78
		tb2 = installer.installBundle("resource.tb2");
79
		tb3 = installer.installBundle("resource.tb3");
80
		tb4 = installer.installBundle("resource.tb4");
81
		tf1 = installer.installBundle("resource.tf1");
82
		tf2 = installer.installBundle("resource.tf2");
83
		tb1.start();
84
		tb2.start();
85
		tb3.start();
86
		tb4.start();
87
		assertTb1();
88
		assertTb2();
89
		assertTb3();
90
		assertTb4();
91
		assertTf1();
92
		assertTf2();
93
	}
94
95
	public void testRequirementMatches() throws Exception {
96
		Bundle tb5 = installer.installBundle("resource.tb5");
97
		Resource requirer = (BundleRevision) tb5.adapt(BundleRevision.class);
98
		Capability capability1 = createCapability1();
99
		List requirements = requirer.getRequirements(capability1.getNamespace());
100
		assertRequirements(requirements, 3);
101
		Requirement requirement1 = (Requirement) requirements.get(0);
102
		// Match requirement with just a namespace (no filter, attributes, or directives).
103
		assertRequirementMatches(requirement1, capability1);
104
		Capability capability2 = createCapability2();
105
		// Different namespaces should not match.
106
		assertNotRequirementMatches(requirement1, capability2);
107
		Requirement requirement2 = (Requirement) requirements.get(1);
108
		// Make sure the expected attributes are present.
109
		assertAttribute(requirement2, "b", "a");
110
		// Match requirement with namespace and attributes. Requirement attributes have no impact on matching.
111
		assertRequirementMatches(requirement2, capability1);
112
		Requirement requirement3 = (Requirement) requirements.get(2);
113
		assertAttribute(requirement3, "b", "a");
114
		assertAttribute(requirement3, "bar", "foo");
115
		assertFilterDirective(requirement3);
116
		// Match requirement with namespace, attributes, and filter (no other directives).
117
		assertRequirementMatches(requirement3, capability1);
118
		Requirement requirement4 = (Requirement) requirements.get(3);
119
		assertAttribute(requirement4, "a", "b");
120
		assertFilterDirective(requirement4);
121
		// Filters should not match.
122
		assertNotRequirementMatches(requirement4, capability1);
123
		requirements = requirer.getRequirements(capability2.getNamespace());
124
		assertRequirements(requirements, 0);
125
		Requirement requirement5 = (Requirement) requirements.get(0);
126
		assertAttribute(requirement5, "bar", "foo");
127
		assertAttribute(requirement5, "y", "x");
128
		assertFilterDirective(requirement5);
129
		assertDirective(requirement5, "mandatory", "foo,x");
130
		// Mandatory directive should have no impact on generic capabilities or requirements.
131
		assertRequirementMatches(requirement5, capability2);
132
	}
133
134
	/*
135
	 * TB1
136
	 * Requirements:
137
	 * 		None
138
	 * Capabilities:
139
	 * 		osgi.identity;osgi.identity=resource.tb1;version=1.0.0;type=osgi.bundle
140
	 * 		osgi.wiring.host;osgi.wiring.host=resource.tb1;version=1.0.0
141
	 * Wires:
142
	 * 		osgi.identity <-> TB3
143
	 * 		osgi.wiring.host <-> TF1
144
	 * 		TB4 <-> osgi.identity (via TF1)
145
	 */
146
	private void assertTb1() {
147
		// Get the revision for TB1.
148
		BundleRevision revision = (BundleRevision) tb1.adapt(BundleRevision.class);
149
		// Make sure TB1's symbolic name and version match the manifest.
150
		String symbolicName = revision.getSymbolicName();
151
		assertSymbolicName("resource.tb1", symbolicName);
152
		Version version = revision.getVersion();
153
		assertVersion("1.0.0", version);
154
		// Make sure TB1's type is correct.
155
		String type = getType(revision);
156
		assertType(ResourceConstants.IDENTITY_TYPE_BUNDLE, type);
157
		Map arbitraryAttrs = new HashMap();
158
		arbitraryAttrs.put("attr1", "a1");
159
		arbitraryAttrs.put("attr2", "a2");
160
		Map arbitraryDirs = new HashMap();
161
		arbitraryDirs.put("dir1", "d1");
162
		arbitraryDirs.put("dir2", "d2");
163
		// Check TB1's osgi.identity capability from the revision.
164
		Capability capability = getIdentityCapability(revision);
165
		assertIdentityCapability(capability, symbolicName, version, type, arbitraryAttrs, arbitraryDirs);
166
		// Check TB1's osgi.identity capability from the resource.
167
		Resource resource = revision;
168
		capability = getIdentityCapability(resource);
169
		assertIdentityCapability(capability, symbolicName, version, type, arbitraryAttrs, arbitraryDirs);
170
		// Check TB1's osgi.identity capability from the wiring.
171
		BundleWiring wiring = (BundleWiring) tb1.adapt(BundleWiring.class);
172
		capability = getIdentityCapability(wiring);
173
		assertIdentityCapability(capability, symbolicName, version, type, arbitraryAttrs, arbitraryDirs);
174
		// There should be 1 provided osgi.identity wire (TB1 -> TB3).
175
		List wires = wiring.getProvidedWires(ResourceConstants.IDENTITY_NAMESPACE);
176
		assertWires(wires, 1);
177
		// Check the osgi.identity wire between TB1 and TB3.
178
		Wire wire = (Wire) wires.get(0);
179
		BundleRevision requirer = (BundleRevision) tb3.adapt(BundleRevision.class);
180
		Requirement requirement = getIdentityRequirement(requirer, 0);
181
		assertIdentityWire(wire, capability, revision, requirement, requirer);
182
		// There should be 1 required osgi.identity wire (TB4 -> TB1 via TF1).
183
		wires = wiring.getRequiredWires(ResourceConstants.IDENTITY_NAMESPACE);
184
		assertWires(wires, 1);
185
		// Check the osgi.identity wire between TB4 and TB1 (via TF1).
186
		wire = (Wire) wires.get(0);
187
		BundleRevision provider = (BundleRevision) tb4.adapt(BundleRevision.class);
188
		capability = getIdentityCapability(provider);
189
		requirement = getIdentityRequirement((BundleRevision) tf1.adapt(BundleRevision.class), 0);
190
		assertIdentityWire(wire, capability, provider, requirement, revision);
191
	}
192
193
	/*
194
	 * TB2
195
	 * Requirements:
196
	 * 		None
197
	 * Capabilities:
198
	 * 		None
199
	 * Wires:
200
	 * 		None
201
	 */
202
	private void assertTb2() {
203
		final BundleRevision revision = (BundleRevision) tb2.adapt(BundleRevision.class);
204
		assertNotIdentityCapability(new CapabilityProvider() {
205
			public List getCapabilities(String namespace) {
206
				return revision.getDeclaredCapabilities(namespace);
207
			}
208
		});
209
		final Resource resource = revision;
210
		assertNotIdentityCapability(new CapabilityProvider() {
211
			public List getCapabilities(String namespace) {
212
				return resource.getCapabilities(namespace);
213
			}
214
		});
215
		final BundleWiring wiring = (BundleWiring) tb2.adapt(BundleWiring.class);
216
		assertNotIdentityCapability(new CapabilityProvider() {
217
			public List getCapabilities(String namespace) {
218
				return wiring.getCapabilities(namespace);
219
			}
220
		});
221
	}
222
223
	/*
224
	 * TB3
225
	 * Requirements:
226
	 * 		osgi.identity;osgi.identity=resource.tb1;version=1.0.0;type=osgi.bundle
227
	 * 		osgi.identity;osgi.identity=resource.tf1;version=1.0.0;type=osgi.fragment
228
	 * Capabilities:
229
	 * 		osgi.identity;osgi.identity=resource.tb3;version=1.0.0;type=osgi.bundle
230
	 * 		osgi.wiring.host;osgi.wiring.host=resource.tb3;version=1.0.0
231
	 * Wires:
232
	 * 		TB1 <-> osgi.identity
233
	 * 		TF1 <-> osgi.identity
234
	 */
235
	private void assertTb3() {
236
		// Get the revision for TB3.
237
		BundleRevision revision = (BundleRevision) tb3.adapt(BundleRevision.class);
238
		// Make sure TB3's symbolic name and version match the manifest.
239
		String symbolicName = revision.getSymbolicName();
240
		assertSymbolicName("resource.tb3", symbolicName);
241
		Version version = revision.getVersion();
242
		assertVersion("1.0.0", version);
243
		// Make sure TB3's type is correct.
244
		String type = getType(revision);
245
		assertType(ResourceConstants.IDENTITY_TYPE_BUNDLE, type);
246
		// Check TB3's osgi.identity capability from the revision.
247
		Capability capability = getIdentityCapability(revision);
248
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
249
		Resource resource = revision;
250
		// Check TB3's osgi.identity capability from the resource.
251
		capability = getIdentityCapability(resource);
252
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
253
		// Check TB3's osgi.identity capability from the wiring.
254
		BundleWiring wiring = (BundleWiring) tb3.adapt(BundleWiring.class);
255
		capability = getIdentityCapability(wiring);
256
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
257
		// There should be 2 required osgi.identity wires (TB1 -> TB3 and TF1 -> TB3).
258
		List wires = wiring.getRequiredWires(ResourceConstants.IDENTITY_NAMESPACE);
259
		assertWires(wires, 2);
260
		// Check the osgi.identity wire between TB1 and TB3.
261
		Wire wire = (Wire) wires.get(0);
262
		Requirement requirement = getIdentityRequirement(revision, 0);
263
		BundleRevision provider = (BundleRevision) tb1.adapt(BundleRevision.class);
264
		capability = getIdentityCapability(provider);
265
		assertIdentityWire(wire, capability, provider, requirement, revision);
266
		// Check the osgi.identity wire between TF1 and TB3.
267
		wire = (Wire) wires.get(1);
268
		requirement = getIdentityRequirement(revision, 1);
269
		provider = (BundleRevision) tf1.adapt(BundleRevision.class);
270
		capability = getIdentityCapability(provider);
271
		assertIdentityWire(wire, capability, provider, requirement, revision);
272
	}
273
274
	/*
275
	 * TB4
276
	 * Requirements:
277
	 * 		None
278
	 * Capabilities:
279
	 * 		osgi.identity;osgi.identity=resource.tb4;version=1.0.0;type=osgi.bundle
280
	 * 		osgi.wiring.host;osgi.wiring.host=resource.tb4;version=1.0.0
281
	 * Wires:
282
	 * 		osgi.identity <-> TB1 (via TF1)
283
	 */
284
	private void assertTb4() {
285
		// Get the revision for TB4.
286
		BundleRevision revision = (BundleRevision) tb4.adapt(BundleRevision.class);
287
		// Make sure TB4's symbolic name and version match the manifest.
288
		String symbolicName = revision.getSymbolicName();
289
		assertSymbolicName("resource.tb4", symbolicName);
290
		Version version = revision.getVersion();
291
		assertVersion("1.0.0", version);
292
		// Make sure TB4's type is correct.
293
		String type = getType(revision);
294
		assertType(ResourceConstants.IDENTITY_TYPE_BUNDLE, type);
295
		// Check TB4's osgi.identity capability from the revision.
296
		Capability capability = getIdentityCapability(revision);
297
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
298
		Resource resource = revision;
299
		// Check TB4's osgi.identity capability from the resource.
300
		capability = getIdentityCapability(resource);
301
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
302
		BundleWiring wiring = (BundleWiring) tb4.adapt(BundleWiring.class);
303
		// Check TB4's osgi.identity capability from the wiring.
304
		capability = getIdentityCapability(wiring);
305
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
306
		// There should be 1 provided osgi.identity wire (TB4 -> TB1 via TF1).
307
		List wires = wiring.getProvidedWires(ResourceConstants.IDENTITY_NAMESPACE);
308
		assertWires(wires, 1);
309
		// Check the osgi.identity wire between TB4 and TB1 (via TF1).
310
		Wire wire = (Wire) wires.get(0);
311
		// The requirer will be TB1's revision since fragment requirements are merged into the host...
312
		BundleRevision requirer = (BundleRevision) tb1.adapt(BundleRevision.class);
313
		// ...but the requirement will come from the fragment.
314
		Requirement requirement = getIdentityRequirement((BundleRevision) tf1.adapt(BundleRevision.class), 0);
315
		assertIdentityWire(wire, capability, revision, requirement, requirer);
316
	}
317
318
	/*
319
	 * TF1
320
	 * Requirements:
321
	 * 		osgi.wiring.host;osgi.wiring.host=resource.tb1;version=1.0.0
322
	 * 		osgi.identity;osgi.identity=resource.tb4;version=1.0.0;type=osgi.bundle
323
	 * Capabilities:
324
	 * 		osgi.identity;osgi.identity=resource.tf1;version=1.0.0;type=osgi.fragment
325
	 * Wires:
326
	 * 		TB1 <-> osgi.wiring.host
327
	 * 		osgi.identity <-> TB3
328
	 */
329
	private void assertTf1() {
330
		// Get the revision for TF1.
331
		BundleRevision revision = (BundleRevision) tf1.adapt(BundleRevision.class);
332
		// Make sure TF1's symbolic name and version match the manifest.
333
		String symbolicName = revision.getSymbolicName();
334
		assertSymbolicName("resource.tf1", symbolicName);
335
		Version version = revision.getVersion();
336
		assertVersion("1.0.0", version);
337
		// Make sure TF1's type is correct.
338
		String type = getType(revision);
339
		assertType(ResourceConstants.IDENTITY_TYPE_FRAGMENT, type);
340
		// Check TF1's osgi.identity capability from the revision.
341
		Capability capability = getIdentityCapability(revision);
342
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
343
		// Check TF1's osgi.identity capability from the resource.
344
		Resource resource = revision;
345
		capability = getIdentityCapability(resource);
346
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
347
		// Check TF1's osgi.identity capability from the wiring.
348
		BundleWiring wiring = (BundleWiring) tf1.adapt(BundleWiring.class);
349
		capability = getIdentityCapability(wiring);
350
		assertIdentityCapability(capability, symbolicName, version, type, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
351
		// There should be 1 provided osgi.identity wire (TF1 -> TB3).
352
		List wires = wiring.getProvidedWires(ResourceConstants.IDENTITY_NAMESPACE);
353
		assertWires(wires, 1);
354
		// Check the osgi.identity wire between TF1 and TB3.
355
		Wire wire = (Wire) wires.get(0);
356
		BundleRevision requirer = (BundleRevision) tb3.adapt(BundleRevision.class);
357
		Requirement requirement = getIdentityRequirement(requirer, 1);
358
		assertIdentityWire(wire, capability, revision, requirement, requirer);
359
	}
360
361
	/*
362
	 * TF2
363
	 * Requirements:
364
	 * 		osgi.wiring.host;osgi.wiring.host=resource.tb1;version=1.0.0
365
	 * Capabilities:
366
	 * 		None
367
	 * Wires:
368
	 * 		TB1 <-> osgi.wiring.host
369
	 */
370
	private void assertTf2() {
371
		final BundleRevision revision = (BundleRevision) tf2.adapt(BundleRevision.class);
372
		assertNotIdentityCapability(new CapabilityProvider() {
373
			public List getCapabilities(String namespace) {
374
				return revision.getDeclaredCapabilities(namespace);
375
			}
376
		});
377
		final Resource resource = revision;
378
		assertNotIdentityCapability(new CapabilityProvider() {
379
			public List getCapabilities(String namespace) {
380
				return resource.getCapabilities(namespace);
381
			}
382
		});
383
		final BundleWiring wiring = (BundleWiring) tf2.adapt(BundleWiring.class);
384
		assertNotIdentityCapability(new CapabilityProvider() {
385
			public List getCapabilities(String namespace) {
386
				return wiring.getCapabilities(namespace);
387
			}
388
		});
389
	}
390
391
	private void assertAttribute(Requirement requirement, String name, Object expected) {
392
		assertEquals("Wrong attribute: " + name, expected, requirement.getAttributes().get(name));
393
	}
394
395
	private void assertCapabilities(List capabilities, int size) {
396
		assertNotNull("Null capabilities", capabilities);
397
		assertEquals("Wrong number of capabilities", size, capabilities.size());
398
	}
399
400
	private void assertDirective(Requirement requirement, String name, String expected) {
401
		assertEquals("Wrong directive", expected, requirement.getDirectives().get(name));
402
	}
403
404
	private void assertFilterDirective(Requirement requirement) {
405
		assertNotNull("Missing filter directive", requirement.getDirectives().get(ResourceConstants.REQUIREMENT_FILTER_DIRECTIVE));
406
	}
407
408
	private void assertIdentityCapability(Capability capability, String symbolicName, Version version, String type, Map arbitraryAttrs, Map arbitraryDirs) {
409
		assertEquals("Wrong namespace", ResourceConstants.IDENTITY_NAMESPACE, capability.getNamespace());
410
		assertEquals("Wrong number of attributes", 3 + arbitraryAttrs.size(), capability.getAttributes().size());
411
		// The osgi.identity attribute contains the symbolic name of the resource.
412
		assertSymbolicName(symbolicName, (String) capability.getAttributes().get(ResourceConstants.IDENTITY_NAMESPACE));
413
		// The version attribute must be of type Version.
414
		// The version attribute contains the version of the resource.
415
		assertVersion(version, (Version) capability.getAttributes().get(ResourceConstants.IDENTITY_VERSION_ATTRIBUTE));
416
		// The type attribute must be of type String.
417
		// The type attribute contains the resource type.
418
		assertType(type, (String) capability.getAttributes().get(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE));
419
		Map attributes = capability.getAttributes();
420
		for (Iterator iEntries = arbitraryAttrs.entrySet().iterator(); iEntries.hasNext();) {
421
			Map.Entry entry = (Entry) iEntries.next();
422
			assertEquals("Wrong attribute: " + entry.getKey(), entry.getValue(), attributes.get(entry.getKey()));
423
		}
424
		Map directives = capability.getDirectives();
425
		for (Iterator iEntries = arbitraryDirs.entrySet().iterator(); iEntries.hasNext();) {
426
			Map.Entry entry = (Entry) iEntries.next();
427
			assertEquals("Wrong directive: " + entry.getKey(), entry.getValue(), directives.get(entry.getKey()));
428
		}
429
	}
430
431
	private void assertIdentityWire(Wire wire, Capability capability, Resource provider, Requirement requirement, Resource requirer) {
432
		assertEquals("Wrong capability", capability, wire.getCapability());
433
		assertEquals("Wrong provider", provider, wire.getProvider());
434
		assertEquals("Wrong requirement", requirement, wire.getRequirement());
435
		assertEquals("Wrong requirer", requirer, wire.getRequirer());
436
		assertRequirementMatches(requirement, capability);
437
	}
438
439
	private void assertNotIdentityCapability(CapabilityProvider provider) {
440
		List capabilities = provider.getCapabilities(ResourceConstants.IDENTITY_NAMESPACE);
441
		// A resource with no symbolic name must not provide an identity capability.
442
		assertCapabilities(capabilities, 0);
443
	}
444
445
	private void assertNotRequirementMatches(Requirement requirement, Capability capability) {
446
		assertFalse("Requirement matches capability", requirement.matches(capability));
447
	}
448
449
	private void assertNotNull(Capability capability) {
450
		Assert.assertNotNull("Null capability", capability);
451
	}
452
453
	private void assertNotNull(Requirement requirement) {
454
		Assert.assertNotNull("Null requirement", requirement);
455
	}
456
457
	private void assertRequirementMatches(Requirement requirement, Capability capability) {
458
		assertTrue("Requirement does not match capability", requirement.matches(capability));
459
	}
460
461
	private void assertRequirements(List requirements, int index) {
462
		assertNotNull("Null requirements", requirements);
463
		assertTrue("Wrong number of requirements", requirements.size() > index);
464
	}
465
466
	private void assertSymbolicName(String expected, String actual) {
467
		assertEquals("Wrong symbolic name", expected, actual);
468
	}
469
470
	private void assertType(String expected, String actual) {
471
		assertEquals("Wrong type", expected, actual);
472
	}
473
474
	private void assertVersion(String expected, Version actual) {
475
		assertVersion(Version.parseVersion(expected), actual);
476
	}
477
478
	private void assertVersion(Version expected, Version actual) {
479
		assertEquals("Wrong version", expected, actual);
480
	}
481
482
	private void assertWires(List wires, int size) {
483
		assertNotNull("Null wires", wires);
484
		assertEquals("Wrong number of wires", size, wires.size());
485
	}
486
487
	private Capability createCapability1() {
488
		String namespace = "capability.1";
489
		Map attributes = new HashMap();
490
		attributes.put("a", "b");
491
		return new BasicCapability(namespace, attributes);
492
	}
493
494
	private Capability createCapability2() {
495
		String namespace = "capability.2";
496
		Map attributes = new HashMap();
497
		attributes.put("foo", "bar");
498
		attributes.put("x", "y");
499
		Map directives = new HashMap();
500
		directives.put(ResourceConstants.CAPABILITY_MANDATORY_DIRECTIVE, "foo,x");
501
		return new BasicCapability(namespace, attributes, directives);
502
	}
503
504
	private Capability getIdentityCapability(BundleRevision revision) {
505
		List capabilities = revision.getDeclaredCapabilities(ResourceConstants.IDENTITY_NAMESPACE);
506
		assertCapabilities(capabilities, 1);
507
		Capability capability = (Capability) capabilities.get(0);
508
		assertNotNull(capability);
509
		return capability;
510
	}
511
512
	private Capability getIdentityCapability(BundleWiring wiring) {
513
		List capabilities = wiring.getCapabilities(ResourceConstants.IDENTITY_NAMESPACE);
514
		assertCapabilities(capabilities, 1);
515
		Capability capability = (Capability) capabilities.get(0);
516
		assertNotNull(capability);
517
		return capability;
518
	}
519
520
	private Capability getIdentityCapability(Resource resource) {
521
		List capabilities = resource.getCapabilities(ResourceConstants.IDENTITY_NAMESPACE);
522
		assertCapabilities(capabilities, 1);
523
		Capability capability = (Capability) capabilities.get(0);
524
		assertNotNull(capability);
525
		return capability;
526
	}
527
528
	private Requirement getIdentityRequirement(BundleRevision revision, int index) {
529
		List requirements = revision.getDeclaredRequirements(ResourceConstants.IDENTITY_NAMESPACE);
530
		assertRequirements(requirements, index);
531
		Requirement requirement = (Requirement) requirements.get(index);
532
		assertNotNull(requirement);
533
		return requirement;
534
	}
535
536
	private String getType(BundleRevision revision) {
537
		return (revision.getTypes() & BundleRevision.TYPE_FRAGMENT) == 0 ? ResourceConstants.IDENTITY_TYPE_BUNDLE : ResourceConstants.IDENTITY_TYPE_FRAGMENT;
538
	}
539
}
(-)src/org/eclipse/osgi/tests/services/resolver/GenericCapabilityTest.java (-45 / +89 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2010 IBM Corporation and others.
2
 * Copyright (c) 2003, 2011 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 19-26 Link Here
19
import org.osgi.framework.Constants;
19
import org.osgi.framework.Constants;
20
20
21
public class GenericCapabilityTest extends AbstractStateTest {
21
public class GenericCapabilityTest extends AbstractStateTest {
22
	private static final String GENERIC_REQUIRE = "Eclipse-GenericRequire"; //$NON-NLS-1$
22
	static final String GENERIC_REQUIRE = "Eclipse-GenericRequire"; //$NON-NLS-1$
23
	private static final String GENERIC_CAPABILITY = "Eclipse-GenericCapability"; //$NON-NLS-1$
23
	static final String GENERIC_CAPABILITY = "Eclipse-GenericCapability"; //$NON-NLS-1$
24
24
25
	public static Test suite() {
25
	public static Test suite() {
26
		return new TestSuite(GenericCapabilityTest.class);
26
		return new TestSuite(GenericCapabilityTest.class);
Lines 35-41 Link Here
35
		Hashtable manifest = new Hashtable();
35
		Hashtable manifest = new Hashtable();
36
		long bundleID = 0;
36
		long bundleID = 0;
37
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
37
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
38
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapablity");
38
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
39
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
39
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
40
		StringBuffer capabililty = new StringBuffer();
40
		StringBuffer capabililty = new StringBuffer();
41
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
41
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
Lines 55-60 Link Here
55
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
55
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
56
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
56
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
57
		StringBuffer required = new StringBuffer();
57
		StringBuffer required = new StringBuffer();
58
		required.append("genericCapability:osgi.identity; selection-filter=\"(version=1.0)\",");
58
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
59
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
59
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
60
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
60
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\"");
61
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\"");
Lines 68-80 Link Here
68
		assertTrue("1.0", genCap.isResolved());
69
		assertTrue("1.0", genCap.isResolved());
69
		assertTrue("1.1", genReq.isResolved());
70
		assertTrue("1.1", genReq.isResolved());
70
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
71
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
71
		assertTrue("2.0", genSpecs.length == 3);
72
		assertTrue("2.0", genSpecs.length == 4);
72
		assertTrue("2.1", genSpecs[0].isResolved());
73
		assertTrue("2.1", genSpecs[0].isResolved());
73
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
74
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
74
		assertTrue("2.2", genSpecs[1].isResolved());
75
		assertTrue("2.2", genSpecs[1].isResolved());
75
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
76
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
76
		assertTrue("2.3", genSpecs[2].isResolved());
77
		assertTrue("2.3", genSpecs[2].isResolved());
77
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
78
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
79
		assertTrue("2.4", genSpecs[3].isResolved());
80
		assertEquals("2.4.1", genSpecs[3].getSupplier(), genCap.getGenericCapabilities()[3]);
78
	}
81
	}
79
82
80
	public void testGenericsUpdate() throws BundleException {
83
	public void testGenericsUpdate() throws BundleException {
Lines 82-88 Link Here
82
		Hashtable manifest = new Hashtable();
85
		Hashtable manifest = new Hashtable();
83
		long bundleID = 0;
86
		long bundleID = 0;
84
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
87
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
85
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapablity");
88
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
86
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
89
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
87
		StringBuffer capabililty = new StringBuffer();
90
		StringBuffer capabililty = new StringBuffer();
88
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
91
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
Lines 102-107 Link Here
102
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
105
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
103
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
106
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
104
		StringBuffer required = new StringBuffer();
107
		StringBuffer required = new StringBuffer();
108
		required.append("genericCapability:osgi.identity; selection-filter=\"(version>=1.0)\",");
105
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
109
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
106
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
110
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
107
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\"");
111
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\"");
Lines 115-131 Link Here
115
		assertTrue("1.0", genCap.isResolved());
119
		assertTrue("1.0", genCap.isResolved());
116
		assertTrue("1.1", genReq.isResolved());
120
		assertTrue("1.1", genReq.isResolved());
117
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
121
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
118
		assertTrue("2.0", genSpecs.length == 3);
122
		assertTrue("2.0", genSpecs.length == 4);
119
		assertTrue("2.1", genSpecs[0].isResolved());
123
		assertTrue("2.1", genSpecs[0].isResolved());
120
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
124
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
121
		assertTrue("2.2", genSpecs[1].isResolved());
125
		assertTrue("2.2", genSpecs[1].isResolved());
122
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
126
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
123
		assertTrue("2.3", genSpecs[2].isResolved());
127
		assertTrue("2.3", genSpecs[2].isResolved());
124
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
128
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
129
		assertTrue("2.4", genSpecs[3].isResolved());
130
		assertEquals("2.4.1", genSpecs[3].getSupplier(), genCap.getGenericCapabilities()[3]);
125
131
126
		manifest.clear();
132
		manifest.clear();
127
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
133
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
128
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapablity");
134
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
129
		manifest.put(Constants.BUNDLE_VERSION, "2.0.0");
135
		manifest.put(Constants.BUNDLE_VERSION, "2.0.0");
130
		capabililty = new StringBuffer();
136
		capabililty = new StringBuffer();
131
		capabililty.append("foo; version=\"1.3.2\"; attr1=\"value1\"; attr2=\"value2\",");
137
		capabililty.append("foo; version=\"1.3.2\"; attr1=\"value1\"; attr2=\"value2\",");
Lines 146-158 Link Here
146
		assertTrue("3.0", genCap2.isResolved());
152
		assertTrue("3.0", genCap2.isResolved());
147
		assertTrue("3.1", genReq.isResolved());
153
		assertTrue("3.1", genReq.isResolved());
148
		genSpecs = genReq.getGenericRequires();
154
		genSpecs = genReq.getGenericRequires();
149
		assertTrue("4.0", genSpecs.length == 3);
155
		assertTrue("4.0", genSpecs.length == 4);
150
		assertTrue("4.1", genSpecs[0].isResolved());
156
		assertTrue("4.1", genSpecs[0].isResolved());
151
		assertEquals("4.1.1", genSpecs[0].getSupplier(), genCap2.getGenericCapabilities()[0]);
157
		assertEquals("4.1.1", genSpecs[0].getSupplier(), genCap2.getGenericCapabilities()[0]);
152
		assertTrue("4.2", genSpecs[1].isResolved());
158
		assertTrue("4.2", genSpecs[1].isResolved());
153
		assertEquals("4.2.1", genSpecs[1].getSupplier(), genCap2.getGenericCapabilities()[1]);
159
		assertEquals("4.2.1", genSpecs[1].getSupplier(), genCap2.getGenericCapabilities()[1]);
154
		assertTrue("4.3", genSpecs[2].isResolved());
160
		assertTrue("4.3", genSpecs[2].isResolved());
155
		assertEquals("4.3.1", genSpecs[2].getSupplier(), genCap2.getGenericCapabilities()[2]);
161
		assertEquals("4.3.1", genSpecs[2].getSupplier(), genCap2.getGenericCapabilities()[2]);
162
		assertTrue("4.4", genSpecs[3].isResolved());
163
		assertEquals("4.4.1", genSpecs[3].getSupplier(), genCap2.getGenericCapabilities()[3]);
156
164
157
	}
165
	}
158
166
Lines 161-167 Link Here
161
		Hashtable manifest = new Hashtable();
169
		Hashtable manifest = new Hashtable();
162
		long bundleID = 0;
170
		long bundleID = 0;
163
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
171
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
164
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapablity");
172
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
165
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
173
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
166
		StringBuffer capabililty = new StringBuffer();
174
		StringBuffer capabililty = new StringBuffer();
167
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
175
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
Lines 181-186 Link Here
181
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
189
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
182
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
190
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
183
		StringBuffer required = new StringBuffer();
191
		StringBuffer required = new StringBuffer();
192
		required.append("genericCapability:osgi.identity; selection-filter=\"(version>=1.0)\",");
184
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
193
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
185
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
194
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
186
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\"");
195
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\"");
Lines 194-219 Link Here
194
		assertTrue("1.0", genCap.isResolved());
203
		assertTrue("1.0", genCap.isResolved());
195
		assertTrue("1.1", genReq.isResolved());
204
		assertTrue("1.1", genReq.isResolved());
196
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
205
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
197
		assertTrue("2.0", genSpecs.length == 3);
206
		assertTrue("2.0", genSpecs.length == 4);
198
		assertTrue("2.1", genSpecs[0].isResolved());
207
		assertTrue("2.1", genSpecs[0].isResolved());
199
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
208
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
200
		assertTrue("2.2", genSpecs[1].isResolved());
209
		assertTrue("2.2", genSpecs[1].isResolved());
201
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
210
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
202
		assertTrue("2.3", genSpecs[2].isResolved());
211
		assertTrue("2.3", genSpecs[2].isResolved());
203
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
212
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
213
		assertTrue("2.4", genSpecs[3].isResolved());
214
		assertEquals("2.4.1", genSpecs[3].getSupplier(), genCap.getGenericCapabilities()[3]);
204
215
205
		state.resolve(new BundleDescription[] {genCap});
216
		state.resolve(new BundleDescription[] {genCap});
206
217
207
		assertTrue("3.0", genCap.isResolved());
218
		assertTrue("3.0", genCap.isResolved());
208
		assertTrue("3.1", genReq.isResolved());
219
		assertTrue("3.1", genReq.isResolved());
209
		genSpecs = genReq.getGenericRequires();
220
		genSpecs = genReq.getGenericRequires();
210
		assertTrue("4.0", genSpecs.length == 3);
221
		assertTrue("4.0", genSpecs.length == 4);
211
		assertTrue("4.1", genSpecs[0].isResolved());
222
		assertTrue("4.1", genSpecs[0].isResolved());
212
		assertEquals("4.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
223
		assertEquals("4.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
213
		assertTrue("4.2", genSpecs[1].isResolved());
224
		assertTrue("4.2", genSpecs[1].isResolved());
214
		assertEquals("4.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
225
		assertEquals("4.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
215
		assertTrue("4.3", genSpecs[2].isResolved());
226
		assertTrue("4.3", genSpecs[2].isResolved());
216
		assertEquals("4.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
227
		assertEquals("4.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
228
		assertTrue("4.4", genSpecs[3].isResolved());
229
		assertEquals("4.4.1", genSpecs[3].getSupplier(), genCap.getGenericCapabilities()[3]);
217
230
218
	}
231
	}
219
232
Lines 223-229 Link Here
223
		long bundleID = 0;
236
		long bundleID = 0;
224
237
225
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
238
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
226
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapablity");
239
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
227
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
240
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
228
		StringBuffer capabililty = new StringBuffer();
241
		StringBuffer capabililty = new StringBuffer();
229
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
242
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
Lines 241-247 Link Here
241
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
254
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
242
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability.frag1");
255
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability.frag1");
243
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
256
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
244
		manifest.put(Constants.FRAGMENT_HOST, "genericCapablity;bundle-version=\"[1.0.0,2.0.0)\"");
257
		manifest.put(Constants.FRAGMENT_HOST, "genericCapability;bundle-version=\"[1.0.0,2.0.0)\"");
245
		capabililty = new StringBuffer();
258
		capabililty = new StringBuffer();
246
		capabililty.append("fragmentStuff");
259
		capabililty.append("fragmentStuff");
247
		manifest.put(GENERIC_CAPABILITY, capabililty.toString());
260
		manifest.put(GENERIC_CAPABILITY, capabililty.toString());
Lines 252-261 Link Here
252
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
265
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
253
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
266
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
254
		StringBuffer required = new StringBuffer();
267
		StringBuffer required = new StringBuffer();
268
		required.append("genericCapability:osgi.identity; selection-filter=\"(&(version=1.0.0)(type=osgi.bundle))\",");
255
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
269
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
256
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
270
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
257
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\",");
271
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\",");
258
		required.append("fragmentStuff");
272
		required.append("fragmentStuff,");
273
		required.append("genericCapability.frag1:osgi.identity; selection-filter=\"(&(version=1.0.0)(type=osgi.fragment))\"");
259
		manifest.put(GENERIC_REQUIRE, required.toString());
274
		manifest.put(GENERIC_REQUIRE, required.toString());
260
		BundleDescription genReq = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
275
		BundleDescription genReq = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
261
276
Lines 268-284 Link Here
268
		assertTrue("1.1", genReq.isResolved());
283
		assertTrue("1.1", genReq.isResolved());
269
		assertTrue("1.2", genCapFrag.isResolved());
284
		assertTrue("1.2", genCapFrag.isResolved());
270
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
285
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
271
		GenericDescription[] selectedCapabilities = genCap.getSelectedGenericCapabilities();
286
		GenericDescription[] selectedHostCapabilities = genCap.getSelectedGenericCapabilities();
272
		assertTrue("2.0", genSpecs.length == 4);
287
		GenericDescription[] selectedFragCapabilities = genCapFrag.getSelectedGenericCapabilities();
273
		assertEquals("Wrong number of selected capabilities", 4, selectedCapabilities.length);
288
		assertTrue("2.0", genSpecs.length == 6);
289
		assertEquals("Wrong number of selected capabilities", 5, selectedHostCapabilities.length);
290
		assertEquals("Wrong number of selected capabilities", 1, selectedFragCapabilities.length);
274
		assertTrue("2.1", genSpecs[0].isResolved());
291
		assertTrue("2.1", genSpecs[0].isResolved());
275
		assertEquals("2.1.1", genSpecs[0].getSupplier(), selectedCapabilities[0]);
292
		assertEquals("2.1.1", genSpecs[0].getSupplier(), selectedHostCapabilities[0]);
276
		assertTrue("2.2", genSpecs[1].isResolved());
293
		assertTrue("2.2", genSpecs[1].isResolved());
277
		assertEquals("2.2.1", genSpecs[1].getSupplier(), selectedCapabilities[1]);
294
		assertEquals("2.2.1", genSpecs[1].getSupplier(), selectedHostCapabilities[1]);
278
		assertTrue("2.3", genSpecs[2].isResolved());
295
		assertTrue("2.3", genSpecs[2].isResolved());
279
		assertEquals("2.3.1", genSpecs[2].getSupplier(), selectedCapabilities[2]);
296
		assertEquals("2.3.1", genSpecs[2].getSupplier(), selectedHostCapabilities[2]);
280
		assertTrue("2.4", genSpecs[3].isResolved());
297
		assertTrue("2.4", genSpecs[3].isResolved());
281
		assertEquals("2.4.1", genSpecs[3].getSupplier(), selectedCapabilities[3]);
298
		assertEquals("2.4.1", genSpecs[3].getSupplier(), selectedHostCapabilities[3]);
299
		assertTrue("2.5", genSpecs[4].isResolved());
300
		assertEquals("2.5.1", genSpecs[4].getSupplier(), selectedHostCapabilities[4]);
301
		assertTrue("2.6", genSpecs[5].isResolved());
302
		assertEquals("2.6.1", genSpecs[5].getSupplier(), selectedFragCapabilities[0]);
282
	}
303
	}
283
304
284
	public void testGenericsIntraFrags() throws BundleException {
305
	public void testGenericsIntraFrags() throws BundleException {
Lines 304-310 Link Here
304
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.equinox.generic.frag.b");
325
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.equinox.generic.frag.b");
305
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
326
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
306
		manifest.put(Constants.FRAGMENT_HOST, "org.eclipse.equinox.generic.host;bundle-version=\"1.0.0\"");
327
		manifest.put(Constants.FRAGMENT_HOST, "org.eclipse.equinox.generic.host;bundle-version=\"1.0.0\"");
307
		manifest.put("Eclipse-GenericRequire", "frag.a");
328
		StringBuffer required = new StringBuffer();
329
		required.append("org.eclipse.equinox.generic.host:osgi.identity; selection-filter=\"(&(version=1.0.0)(type=osgi.bundle))\",");
330
		required.append("frag.a,");
331
		required.append("org.eclipse.equinox.generic.frag.a:osgi.identity; selection-filter=\"(&(version=1.0.0)(type=osgi.fragment))\",");
332
		required.append("org.eclipse.equinox.generic.frag.b:osgi.identity; selection-filter=\"(&(version=1.0.0)(type=osgi.fragment))\"");
333
		manifest.put(GENERIC_REQUIRE, required.toString());
308
		BundleDescription genFragB = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
334
		BundleDescription genFragB = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
309
335
310
		state.addBundle(genHost);
336
		state.addBundle(genHost);
Lines 317-326 Link Here
317
		assertTrue("1.2", genFragB.isResolved());
343
		assertTrue("1.2", genFragB.isResolved());
318
		GenericSpecification[] genSpecs = genFragB.getGenericRequires();
344
		GenericSpecification[] genSpecs = genFragB.getGenericRequires();
319
		GenericDescription[] selected = genHost.getSelectedGenericCapabilities();
345
		GenericDescription[] selected = genHost.getSelectedGenericCapabilities();
320
		assertEquals("Wrong number of selected", 1, selected.length);
346
		assertEquals("Wrong number of selected", 1 + 1, selected.length); // + 1 for host osgi.identity cap
321
		assertTrue("2.0", genSpecs.length == 1);
347
		assertTrue("2.0", genSpecs.length == 4);
348
		GenericDescription[] selectedHostCapabilities = genHost.getSelectedGenericCapabilities();
349
		GenericDescription[] selectedFragACapabilities = genFragA.getSelectedGenericCapabilities();
350
		GenericDescription[] selectedFragBCapabilities = genFragB.getSelectedGenericCapabilities();
351
		assertEquals("Wrong number of selected capabilities", 2, selectedHostCapabilities.length);
352
		assertEquals("Wrong number of selected capabilities", 1, selectedFragACapabilities.length);
353
		assertEquals("Wrong number of selected capabilities", 1, selectedFragBCapabilities.length);
322
		assertTrue("2.1", genSpecs[0].isResolved());
354
		assertTrue("2.1", genSpecs[0].isResolved());
323
		assertEquals("2.1.1", genSpecs[0].getSupplier(), selected[0]);
355
		assertEquals("2.1.1", genSpecs[0].getSupplier(), selectedHostCapabilities[0]);
356
		assertTrue("2.2", genSpecs[1].isResolved());
357
		assertEquals("2.2.1", genSpecs[1].getSupplier(), selectedHostCapabilities[1]);
358
		assertTrue("2.3", genSpecs[2].isResolved());
359
		assertEquals("2.3.1", genSpecs[2].getSupplier(), selectedFragACapabilities[0]);
360
		assertTrue("2.4", genSpecs[3].isResolved());
361
		assertEquals("2.4.1", genSpecs[3].getSupplier(), selectedFragBCapabilities[0]);
324
	}
362
	}
325
363
326
	public void testGenericsAliases() throws BundleException {
364
	public void testGenericsAliases() throws BundleException {
Lines 333-339 Link Here
333
		Hashtable manifest = new Hashtable();
371
		Hashtable manifest = new Hashtable();
334
		long bundleID = 0;
372
		long bundleID = 0;
335
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
373
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
336
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapablity");
374
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
337
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
375
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
338
		manifest.put(Constants.EXPORT_SERVICE, "org.osgi.service.log.LogService; version=1.2");
376
		manifest.put(Constants.EXPORT_SERVICE, "org.osgi.service.log.LogService; version=1.2");
339
		manifest.put("TJW-Export", "my.great.stuff; aLong:long=5150; aDouble:double=3.14; aVersion:version=1.2.0");
377
		manifest.put("TJW-Export", "my.great.stuff; aLong:long=5150; aDouble:double=3.14; aVersion:version=1.2.0");
Lines 345-350 Link Here
345
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
383
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
346
		manifest.put(Constants.IMPORT_SERVICE, "org.osgi.service.log.LogService; selection-filter=(version>=1.0.0)");
384
		manifest.put(Constants.IMPORT_SERVICE, "org.osgi.service.log.LogService; selection-filter=(version>=1.0.0)");
347
		manifest.put("TJW-Import", "my.great.stuff; selection-filter=(&(aLong<=10000)(aLong>=5000))");
385
		manifest.put("TJW-Import", "my.great.stuff; selection-filter=(&(aLong<=10000)(aLong>=5000))");
386
		manifest.put(GENERIC_REQUIRE, "genericCapability:osgi.identity; selection-filter=\"(&(version=1.0.0)(type=osgi.bundle))\"");
348
		BundleDescription genReq = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
387
		BundleDescription genReq = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
349
388
350
		state.addBundle(genCap);
389
		state.addBundle(genCap);
Lines 354-364 Link Here
354
		assertTrue("1.0", genCap.isResolved());
393
		assertTrue("1.0", genCap.isResolved());
355
		assertTrue("1.1", genReq.isResolved());
394
		assertTrue("1.1", genReq.isResolved());
356
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
395
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
357
		assertTrue("2.0", genSpecs.length == 2);
396
		assertTrue("2.0", genSpecs.length == 3);
358
		assertTrue("2.1", genSpecs[0].isResolved());
397
		assertTrue("2.1", genSpecs[0].isResolved());
359
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
398
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[1]);
360
		assertTrue("2.2", genSpecs[1].isResolved());
399
		assertTrue("2.2", genSpecs[1].isResolved());
361
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
400
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[2]);
401
		assertTrue("2.3", genSpecs[2].isResolved());
402
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[0]);
362
	}
403
	}
363
404
364
	public void testGenericsOptionalMultiple() throws BundleException {
405
	public void testGenericsOptionalMultiple() throws BundleException {
Lines 366-372 Link Here
366
		Hashtable manifest = new Hashtable();
407
		Hashtable manifest = new Hashtable();
367
		long bundleID = 0;
408
		long bundleID = 0;
368
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
409
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
369
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapablity");
410
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
370
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
411
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
371
		StringBuffer capabililty = new StringBuffer();
412
		StringBuffer capabililty = new StringBuffer();
372
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
413
		capabililty.append("foo; version=\"1.3.1\"; attr1=\"value1\"; attr2=\"value2\",");
Lines 389-394 Link Here
389
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
430
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericRequire");
390
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
431
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
391
		StringBuffer required = new StringBuffer();
432
		StringBuffer required = new StringBuffer();
433
		required.append("genericCapability:osgi.identity; selection-filter=\"(&(version=1.0.0)(type=osgi.bundle))\",");
392
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
434
		required.append("foo; selection-filter=\"(version>=1.3.0)\",");
393
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
435
		required.append("bar:bartype; selection-filter=\"(attr1=value1)\",");
394
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\",");
436
		required.append("test.types:testtype; selection-filter=\"(&(aVersion>=2.0.0)(aLong>=5555)(aDouble>=1.00)(aUri=file:/test)(aSet=c)(aString=someString))\",");
Lines 405-425 Link Here
405
		assertTrue("1.0", genCap.isResolved());
447
		assertTrue("1.0", genCap.isResolved());
406
		assertTrue("1.1", genReq.isResolved());
448
		assertTrue("1.1", genReq.isResolved());
407
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
449
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
408
		assertTrue("2.0", genSpecs.length == 6);
450
		assertTrue("2.0", genSpecs.length == 7);
409
		assertTrue("2.1", genSpecs[0].isResolved());
451
		assertTrue("2.1", genSpecs[0].isResolved());
410
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
452
		assertEquals("2.1.1", genSpecs[0].getSupplier(), genCap.getGenericCapabilities()[0]);
411
		assertTrue("2.2", genSpecs[1].isResolved());
453
		assertTrue("2.2", genSpecs[1].isResolved());
412
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
454
		assertEquals("2.2.1", genSpecs[1].getSupplier(), genCap.getGenericCapabilities()[1]);
413
		assertTrue("2.3", genSpecs[2].isResolved());
455
		assertTrue("2.3", genSpecs[2].isResolved());
414
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
456
		assertEquals("2.3.1", genSpecs[2].getSupplier(), genCap.getGenericCapabilities()[2]);
415
		assertFalse("2.4", genSpecs[3].isResolved());
457
		assertTrue("2.3", genSpecs[3].isResolved());
416
		assertTrue("2.5", genSpecs[4].isResolved());
458
		assertEquals("2.3.1", genSpecs[3].getSupplier(), genCap.getGenericCapabilities()[3]);
417
		assertEquals("2.5.1", genSpecs[4].getSupplier(), genCap.getGenericCapabilities()[3]);
459
		assertFalse("2.4", genSpecs[4].isResolved());
418
		assertTrue("2.6", genSpecs[5].isResolved());
460
		assertTrue("2.5", genSpecs[5].isResolved());
419
		GenericDescription[] suppliers = genSpecs[5].getSuppliers();
461
		assertEquals("2.5.1", genSpecs[5].getSupplier(), genCap.getGenericCapabilities()[4]);
462
		assertTrue("2.6", genSpecs[6].isResolved());
463
		GenericDescription[] suppliers = genSpecs[6].getSuppliers();
420
		assertTrue("2.6.1", suppliers != null && suppliers.length == 2);
464
		assertTrue("2.6.1", suppliers != null && suppliers.length == 2);
421
		assertEquals("2.6.2", suppliers[0], genCap.getGenericCapabilities()[5]);
465
		assertEquals("2.6.2", suppliers[0], genCap.getGenericCapabilities()[6]);
422
		assertEquals("2.6.3", suppliers[1], genCap.getGenericCapabilities()[4]);
466
		assertEquals("2.6.3", suppliers[1], genCap.getGenericCapabilities()[5]);
423
	}
467
	}
424
468
425
	public void testGenericsCycles() throws BundleException {
469
	public void testGenericsCycles() throws BundleException {
Lines 481-498 Link Here
481
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
525
		GenericSpecification[] genSpecs = genReq.getGenericRequires();
482
		GenericDescription[] selected = genCap.getSelectedGenericCapabilities();
526
		GenericDescription[] selected = genCap.getSelectedGenericCapabilities();
483
		assertTrue("2.0", genSpecs.length == 4);
527
		assertTrue("2.0", genSpecs.length == 4);
484
		assertEquals("Wrong number of selected", 4, selected.length);
528
		assertEquals("Wrong number of selected", 4 + 1, selected.length); // + 1 for host osgi.identity caps
485
		assertTrue("2.1", genSpecs[0].isResolved());
529
		assertTrue("2.1", genSpecs[0].isResolved());
486
		assertEquals("2.1.1", genSpecs[0].getSupplier(), selected[0]);
530
		assertEquals("2.1.1", genSpecs[0].getSupplier(), selected[1]);
487
		assertTrue("2.2", genSpecs[1].isResolved());
531
		assertTrue("2.2", genSpecs[1].isResolved());
488
		assertEquals("2.2.1", genSpecs[1].getSupplier(), selected[1]);
532
		assertEquals("2.2.1", genSpecs[1].getSupplier(), selected[2]);
489
		assertTrue("2.3", genSpecs[2].isResolved());
533
		assertTrue("2.3", genSpecs[2].isResolved());
490
		assertEquals("2.3.1", genSpecs[2].getSupplier(), selected[2]);
534
		assertEquals("2.3.1", genSpecs[2].getSupplier(), selected[3]);
491
		assertTrue("2.4", genSpecs[3].isResolved());
535
		assertTrue("2.4", genSpecs[3].isResolved());
492
		assertEquals("2.4.1", genSpecs[3].getSupplier(), selected[3]);
536
		assertEquals("2.4.1", genSpecs[3].getSupplier(), selected[4]);
493
		genSpecs = genCap.getGenericRequires();
537
		genSpecs = genCap.getGenericRequires();
494
		assertTrue("3.0", genSpecs.length == 1);
538
		assertTrue("3.0", genSpecs.length == 1);
495
		assertTrue("3.1", genSpecs[0].isResolved());
539
		assertTrue("3.1", genSpecs[0].isResolved());
496
		assertEquals("3.1.1", genSpecs[0].getSupplier(), genReq.getGenericCapabilities()[0]);
540
		assertEquals("3.1.1", genSpecs[0].getSupplier(), genReq.getGenericCapabilities()[1]);
497
	}
541
	}
498
}
542
}
(-)src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java (-18 / +56 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
2
 * Copyright (c) 2010, 2011 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 13-25 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.net.URL;
15
import java.net.URL;
16
import java.util.Dictionary;
16
import java.util.*;
17
import junit.framework.Test;
17
import junit.framework.Test;
18
import junit.framework.TestSuite;
18
import junit.framework.TestSuite;
19
import org.eclipse.osgi.framework.util.Headers;
19
import org.eclipse.osgi.framework.util.Headers;
20
import org.eclipse.osgi.service.resolver.*;
20
import org.eclipse.osgi.service.resolver.*;
21
import org.osgi.framework.BundleException;
21
import org.osgi.framework.BundleException;
22
import org.osgi.framework.Constants;
22
import org.osgi.framework.Constants;
23
import org.osgi.framework.wiring.ResourceConstants;
23
24
24
public class OSGiCapabilityTest extends AbstractStateTest {
25
public class OSGiCapabilityTest extends AbstractStateTest {
25
	private static final String MANIFEST_ROOT = "test_files/genericCapability/";
26
	private static final String MANIFEST_ROOT = "test_files/genericCapability/";
Lines 105-113 Link Here
105
		assertTrue("c2", c2.isResolved());
106
		assertTrue("c2", c2.isResolved());
106
		assertTrue("c3", c3.isResolved());
107
		assertTrue("c3", c3.isResolved());
107
108
108
		checkGenericBasics(3, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
109
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
109
		checkGenericBasics(3, c2.getResolvedGenericRequires(), p2.getSelectedGenericCapabilities());
110
		checkGenericBasics(4, c2.getResolvedGenericRequires(), p2.getSelectedGenericCapabilities());
110
		checkGenericBasics(3, c3.getResolvedGenericRequires(), p3.getSelectedGenericCapabilities());
111
		checkGenericBasics(4, c3.getResolvedGenericRequires(), p3.getSelectedGenericCapabilities());
111
112
112
		File stateDir = getContext().getDataFile(getName()); //$NON-NLS-1$
113
		File stateDir = getContext().getDataFile(getName()); //$NON-NLS-1$
113
		stateDir.mkdirs();
114
		stateDir.mkdirs();
Lines 130-145 Link Here
130
		assertTrue("c2", c2.isResolved());
131
		assertTrue("c2", c2.isResolved());
131
		assertTrue("c3", c3.isResolved());
132
		assertTrue("c3", c3.isResolved());
132
133
133
		checkGenericBasics(3, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
134
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
134
		checkGenericBasics(3, c2.getResolvedGenericRequires(), p2.getSelectedGenericCapabilities());
135
		checkGenericBasics(4, c2.getResolvedGenericRequires(), p2.getSelectedGenericCapabilities());
135
		checkGenericBasics(3, c3.getResolvedGenericRequires(), p3.getSelectedGenericCapabilities());
136
		checkGenericBasics(4, c3.getResolvedGenericRequires(), p3.getSelectedGenericCapabilities());
136
	}
137
	}
137
138
138
	private void checkGenericBasics(int expectedCnt, GenericDescription[] genRequired, GenericDescription[] genProvided) {
139
	private void checkGenericBasics(int expectedCnt, GenericDescription[] genRequired, GenericDescription[] genProvided) {
140
		checkGenericBasics(expectedCnt, genRequired, genProvided, null);
141
	}
142
143
	private void checkGenericBasics(int expectedCnt, GenericDescription[] genRequired, GenericDescription[] genProvided, GenericDescription fragIdentity) {
139
		assertEquals("Expected number of capabilities do not match", expectedCnt, genRequired.length);
144
		assertEquals("Expected number of capabilities do not match", expectedCnt, genRequired.length);
140
		assertEquals("Specs do not match Descs", genRequired.length, genProvided.length);
145
		assertEquals("Specs do not match Descs", genRequired.length, genProvided.length + (fragIdentity == null ? 0 : 1));
146
		Collection providedCollection = new ArrayList(Arrays.asList(genProvided));
141
		for (int i = 0; i < genRequired.length; i++) {
147
		for (int i = 0; i < genRequired.length; i++) {
142
			assertEquals("Wrong provider for requirement.", genProvided[i], genRequired[i]);
148
			if (ResourceConstants.IDENTITY_NAMESPACE.equals(genRequired[i].getType()) && genRequired[i].getSupplier().getHost() != null)
149
				assertEquals("Wrong fragment provider: " + genRequired[i], fragIdentity, genRequired[i]);
150
			else
151
				assertTrue("Wrong provider for requirement: " + genRequired[i], providedCollection.remove(genRequired[i]));
143
		}
152
		}
144
	}
153
	}
145
154
Lines 172-178 Link Here
172
		assertTrue("c1Frag", c1Frag.isResolved());
181
		assertTrue("c1Frag", c1Frag.isResolved());
173
		assertTrue("p4", p4.isResolved());
182
		assertTrue("p4", p4.isResolved());
174
183
175
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
184
		checkGenericBasics(6, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities(), p1Frag.getSelectedGenericCapabilities()[0]);
176
185
177
		File stateDir = getContext().getDataFile(getName()); //$NON-NLS-1$
186
		File stateDir = getContext().getDataFile(getName()); //$NON-NLS-1$
178
		stateDir.mkdirs();
187
		stateDir.mkdirs();
Lines 194-200 Link Here
194
		assertTrue("c1Frag", c1Frag.isResolved());
203
		assertTrue("c1Frag", c1Frag.isResolved());
195
		assertTrue("p4", p4.isResolved());
204
		assertTrue("p4", p4.isResolved());
196
205
197
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
206
		checkGenericBasics(6, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities(), p1Frag.getSelectedGenericCapabilities()[0]);
198
207
199
		state.setResolver(platformAdmin.createResolver());
208
		state.setResolver(platformAdmin.createResolver());
200
		state.resolve(new BundleDescription[] {p1});
209
		state.resolve(new BundleDescription[] {p1});
Lines 205-211 Link Here
205
		assertTrue("c1Frag", c1Frag.isResolved());
214
		assertTrue("c1Frag", c1Frag.isResolved());
206
		assertTrue("p4", p4.isResolved());
215
		assertTrue("p4", p4.isResolved());
207
216
208
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
217
		checkGenericBasics(6, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities(), p1Frag.getSelectedGenericCapabilities()[0]);
209
	}
218
	}
210
219
211
	public void testGenericFragments02() throws BundleException {
220
	public void testGenericFragments02() throws BundleException {
Lines 233-239 Link Here
233
		assertTrue("c1", c1.isResolved());
242
		assertTrue("c1", c1.isResolved());
234
		assertFalse("c1Frag", c1Frag.isResolved());
243
		assertFalse("c1Frag", c1Frag.isResolved());
235
244
236
		checkGenericBasics(3, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
245
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
237
246
238
		File stateDir = getContext().getDataFile(getName() + 1); //$NON-NLS-1$
247
		File stateDir = getContext().getDataFile(getName() + 1); //$NON-NLS-1$
239
		stateDir.mkdirs();
248
		stateDir.mkdirs();
Lines 253-259 Link Here
253
		assertTrue("c1", c1.isResolved());
262
		assertTrue("c1", c1.isResolved());
254
		assertFalse("c1Frag", c1Frag.isResolved());
263
		assertFalse("c1Frag", c1Frag.isResolved());
255
264
256
		checkGenericBasics(3, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
265
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
257
266
258
		manifest = loadManifest("p4.osgi.MF");
267
		manifest = loadManifest("p4.osgi.MF");
259
		BundleDescription p4 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
268
		BundleDescription p4 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
Lines 267-273 Link Here
267
		assertTrue("c1Frag", c1Frag.isResolved());
276
		assertTrue("c1Frag", c1Frag.isResolved());
268
		assertTrue("p4", p4.isResolved());
277
		assertTrue("p4", p4.isResolved());
269
278
270
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
279
		checkGenericBasics(6, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities(), p1Frag.getSelectedGenericCapabilities()[0]);
271
280
272
		stateDir = getContext().getDataFile(getName() + 2); //$NON-NLS-1$
281
		stateDir = getContext().getDataFile(getName() + 2); //$NON-NLS-1$
273
		stateDir.mkdirs();
282
		stateDir.mkdirs();
Lines 288-294 Link Here
288
		assertTrue("c1Frag", c1Frag.isResolved());
297
		assertTrue("c1Frag", c1Frag.isResolved());
289
		assertTrue("p4", p4.isResolved());
298
		assertTrue("p4", p4.isResolved());
290
299
291
		checkGenericBasics(4, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities());
300
		checkGenericBasics(6, c1.getResolvedGenericRequires(), p1.getSelectedGenericCapabilities(), p1Frag.getSelectedGenericCapabilities()[0]);
292
	}
301
	}
293
302
294
	public void testGenericUses() throws BundleException {
303
	public void testGenericUses() throws BundleException {
Lines 362-367 Link Here
362
		checkUsedCapability(c4v130, p5v100Capability);
371
		checkUsedCapability(c4v130, p5v100Capability);
363
	}
372
	}
364
373
374
	public void testDeclaringIdentityCapability() {
375
		State state = buildEmptyState();
376
		Hashtable manifest = new Hashtable();
377
		long bundleID = 0;
378
		manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
379
		manifest.put(Constants.BUNDLE_SYMBOLICNAME, "genericCapability");
380
		manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
381
		StringBuffer capabililty = new StringBuffer();
382
		capabililty.append("testFailure:osgi.identity; test=failure");
383
		manifest.put(GenericCapabilityTest.GENERIC_CAPABILITY, capabililty.toString());
384
385
		try {
386
			state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
387
			fail("Expected failure to create description that specifies osgi.identity capability");
388
		} catch (BundleException e) {
389
			// expected
390
		}
391
392
		manifest.remove(GenericCapabilityTest.GENERIC_CAPABILITY);
393
		manifest.put(Constants.PROVIDE_CAPABILITY, "osgi.identity; osgi.identity=testFailure; test=failure");
394
		try {
395
			state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
396
			fail("Expected failure to create description that specifies osgi.identity capability");
397
		} catch (BundleException e) {
398
			// expected
399
		}
400
	}
401
365
	private void checkUsedImports(BundleDescription importer, ExportPackageDescription[] expectedPackages) {
402
	private void checkUsedImports(BundleDescription importer, ExportPackageDescription[] expectedPackages) {
366
		ExportPackageDescription[] imported = importer.getResolvedImports();
403
		ExportPackageDescription[] imported = importer.getResolvedImports();
367
		assertEquals("Wrong number of imports for bundle: " + importer, expectedPackages.length, imported.length);
404
		assertEquals("Wrong number of imports for bundle: " + importer, expectedPackages.length, imported.length);
Lines 381-388 Link Here
381
	private void checkUsedCapability(BundleDescription requirer, GenericDescription[] expectedCapabilities) {
418
	private void checkUsedCapability(BundleDescription requirer, GenericDescription[] expectedCapabilities) {
382
		GenericDescription[] required = requirer.getResolvedGenericRequires();
419
		GenericDescription[] required = requirer.getResolvedGenericRequires();
383
		assertEquals("Wrong number of capabilities for bundle: " + requirer, expectedCapabilities.length, required.length);
420
		assertEquals("Wrong number of capabilities for bundle: " + requirer, expectedCapabilities.length, required.length);
421
		Collection providedCollection = new ArrayList(Arrays.asList(expectedCapabilities));
384
		for (int i = 0; i < required.length; i++) {
422
		for (int i = 0; i < required.length; i++) {
385
			assertEquals("Wrong required capability from bundle: " + requirer, expectedCapabilities[i], required[i]);
423
			assertTrue("Wrong provider for requirement: " + required[i], providedCollection.remove(required[i]));
386
		}
424
		}
387
	}
425
	}
388
}
426
}
(-)test_files/genericCapability/c1.equinox.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  selection-filter="(&(rank>=100)(!(rank>=200))
17
  selection-filter="(&(rank>=100)(!(rank>=200))
18
          (percent>=0.1)(!(percent>=0.2))
18
          (percent>=0.1)(!(percent>=0.2))
19
          (test.version>=1.0)(!(test.version>=2.0))
19
          (test.version>=1.0)(!(test.version>=2.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 *:osgi.identity;
22
  selection-filter="(&(osgi.identity=p1.*)(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c1.equinox.name.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  selection-filter="(&(rank>=100)(!(rank>=200))
17
  selection-filter="(&(rank>=100)(!(rank>=200))
18
          (percent>=0.1)(!(percent>=0.2))
18
          (percent>=0.1)(!(percent>=0.2))
19
          (test.version>=1.0)(!(test.version>=2.0))
19
          (test.version>=1.0)(!(test.version>=2.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 p1.*:osgi.identity;
22
  selection-filter="(&(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c1.osgi.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  filter:="(&(rank>=100)(!(rank>=200))
17
  filter:="(&(rank>=100)(!(rank>=200))
18
          (percent>=0.1)(!(percent>=0.2))
18
          (percent>=0.1)(!(percent>=0.2))
19
          (test.version>=1.0)(!(test.version>=2.0))
19
          (test.version>=1.0)(!(test.version>=2.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 osgi.identity;
22
  filter:="(&(osgi.identity=p1.*)(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c1.osgi.frag.MF (-1 / +3 lines)
Lines 8-11 Link Here
8
  filter:="(&(rank>=100)(!(rank>=200))
8
  filter:="(&(rank>=100)(!(rank>=200))
9
          (percent>=0.1)(!(percent>=0.2))
9
          (percent>=0.1)(!(percent>=0.2))
10
          (test.version>=1.0)(!(test.version>=2.0))
10
          (test.version>=1.0)(!(test.version>=2.0))
11
          (test.string~=abc))"
11
          (test.string~=abc))",
12
 osgi.identity;
13
  filter:="(&(osgi.identity=p1.*.frag)(version=1.0)(type=osgi.fragment))"
(-)test_files/genericCapability/c2.equinox.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  selection-filter="(&(rank>=200)(!(rank>=300))
17
  selection-filter="(&(rank>=200)(!(rank>=300))
18
          (percent>=0.2)(!(percent>=0.3))
18
          (percent>=0.2)(!(percent>=0.3))
19
          (test.version>=2.0)(!(test.version>=3.0))
19
          (test.version>=2.0)(!(test.version>=3.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 *:osgi.identity;
22
  selection-filter="(&(osgi.identity=p2.*)(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c2.equinox.name.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  selection-filter="(&(rank>=200)(!(rank>=300))
17
  selection-filter="(&(rank>=200)(!(rank>=300))
18
          (percent>=0.2)(!(percent>=0.3))
18
          (percent>=0.2)(!(percent>=0.3))
19
          (test.version>=2.0)(!(test.version>=3.0))
19
          (test.version>=2.0)(!(test.version>=3.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 p2.*:osgi.identity;
22
  selection-filter="(&(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c2.osgi.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  filter:="(&(rank>=200)(!(rank>=300))
17
  filter:="(&(rank>=200)(!(rank>=300))
18
          (percent>=0.2)(!(percent>=0.3))
18
          (percent>=0.2)(!(percent>=0.3))
19
          (test.version>=2.0)(!(test.version>=3.0))
19
          (test.version>=2.0)(!(test.version>=3.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 osgi.identity;
22
  filter:="(&(osgi.identity=p2.*)(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c3.equinox.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  selection-filter="(&(rank>=300)(!(rank>=400))
17
  selection-filter="(&(rank>=300)(!(rank>=400))
18
          (percent>=0.3)(!(percent>=0.4))
18
          (percent>=0.3)(!(percent>=0.4))
19
          (test.version>=3.0)(!(test.version>=4.0))
19
          (test.version>=3.0)(!(test.version>=4.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 *:osgi.identity;
22
  selection-filter="(&(osgi.identity=p3.*)(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c3.equinox.name.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  selection-filter="(&(rank>=300)(!(rank>=400))
17
  selection-filter="(&(rank>=300)(!(rank>=400))
18
          (percent>=0.3)(!(percent>=0.4))
18
          (percent>=0.3)(!(percent>=0.4))
19
          (test.version>=3.0)(!(test.version>=4.0))
19
          (test.version>=3.0)(!(test.version>=4.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 p3.*:osgi.identity;
22
  selection-filter="(&(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c3.osgi.MF (-1 / +3 lines)
Lines 17-20 Link Here
17
  filter:="(&(rank>=300)(!(rank>=400))
17
  filter:="(&(rank>=300)(!(rank>=400))
18
          (percent>=0.3)(!(percent>=0.4))
18
          (percent>=0.3)(!(percent>=0.4))
19
          (test.version>=3.0)(!(test.version>=4.0))
19
          (test.version>=3.0)(!(test.version>=4.0))
20
          (test.string~=abc))"
20
          (test.string~=abc))",
21
 osgi.identity;
22
  filter:="(&(osgi.identity=p3.*)(version=1.0)(type=osgi.bundle))"
(-)test_files/genericCapability/c4.v100.osgi.MF (-1 / +2 lines)
Lines 3-7 Link Here
3
Bundle-SymbolicName: c4.osgi
3
Bundle-SymbolicName: c4.osgi
4
Bundle-Version: 1.0
4
Bundle-Version: 1.0
5
Require-Capability: 
5
Require-Capability: 
6
 namespace.5; filter:="(version=1.0)"
6
 namespace.5; filter:="(version=1.0)",
7
 osgi.identity; filter:="(&(osgi.identity=p5.osgi)(version=1.0)(type=osgi.bundle))"
7
Import-Package: p6, p7
8
Import-Package: p6, p7
(-)test_files/genericCapability/c4.v110.osgi.MF (-1 / +2 lines)
Lines 3-7 Link Here
3
Bundle-SymbolicName: c4.osgi
3
Bundle-SymbolicName: c4.osgi
4
Bundle-Version: 1.1
4
Bundle-Version: 1.1
5
Require-Capability: 
5
Require-Capability: 
6
 namespace.5; filter:="(namespace.5=test)"
6
 namespace.5; filter:="(namespace.5=test)",
7
 osgi.identity; filter:="(&(osgi.identity=p5.osgi)(version=1.0)(type=osgi.bundle))"
7
Import-Package: p6; p7; version="[1.0,1.1)"
8
Import-Package: p6; p7; version="[1.0,1.1)"
(-)test_files/genericCapability/c4.v120.osgi.MF (-1 / +2 lines)
Lines 3-7 Link Here
3
Bundle-SymbolicName: c4.osgi
3
Bundle-SymbolicName: c4.osgi
4
Bundle-Version: 1.2
4
Bundle-Version: 1.2
5
Require-Capability: 
5
Require-Capability: 
6
 namespace.5; filter:="(version=1.0)"
6
 namespace.5; filter:="(version=1.0)",
7
 osgi.identity; filter:="(&(osgi.identity=p5.osgi)(version=1.0)(type=osgi.bundle))"
7
DynamicImport-Package: p6, p7
8
DynamicImport-Package: p6, p7
(-)test_files/genericCapability/c4.v130.osgi.MF (-1 / +2 lines)
Lines 3-7 Link Here
3
Bundle-SymbolicName: c4.osgi
3
Bundle-SymbolicName: c4.osgi
4
Bundle-Version: 1.3
4
Bundle-Version: 1.3
5
Require-Capability: 
5
Require-Capability: 
6
 namespace.5; filter:="(version=1.0)"
6
 namespace.5; filter:="(version=1.0)",
7
 osgi.identity; filter:="(&(osgi.identity=p5.osgi)(version=1.0)(type=osgi.bundle))"
7
Require-Bundle: p6.osgi, p7.osgi
8
Require-Bundle: p6.osgi, p7.osgi

Return to bug 349618