1 /*******************************************************************************
2  * Copyright (c) 2007, 2018 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.pde.api.tools.internal.provisional;
15 
16 /**
17  * Class containing constants and utility methods for @since values.
18  *
19  * This covers the corresponding profiles:
20  * <ul>
21  * <li>CDC-1.0_Foundation-1.0</li>
22  * <li>CDC-1.1_Foundation-1.1</li>
23  * <li>J2SE-1.2</li>
24  * <li>J2SE-1.3</li>
25  * <li>J2SE-1.4</li>
26  * <li>J2SE-1.5</li>
27  * <li>JavaSE-1.6</li>
28  * <li>JavaSE-1.7</li>
29  * <li>JavaSE-1.8</li>
30  * <li>JavaSE-9</li>
31  * <li>JRE-1.1</li>
32  * <li>OSGi_Minimum-1.0</li>
33  * <li>OSGi_Minimum-1.1</li>
34  * <li>OSGi_Minimum-1.2</li>
35  * </ul>
36  *
37  * @since 1.0.0
38  */
39 public final class ProfileModifiers {
40 
41 	public static final int NO_PROFILE_VALUE = 0;
42 
43 	public static final String CDC_1_0_FOUNDATION_1_0_NAME = "CDC-1.0/Foundation-1.0"; //$NON-NLS-1$
44 	public static final String CDC_1_1_FOUNDATION_1_1_NAME = "CDC-1.1/Foundation-1.1"; //$NON-NLS-1$
45 	public static final String J2SE_1_2_NAME = "J2SE-1.2"; //$NON-NLS-1$
46 	public static final String J2SE_1_3_NAME = "J2SE-1.3"; //$NON-NLS-1$
47 	public static final String J2SE_1_4_NAME = "J2SE-1.4"; //$NON-NLS-1$
48 	public static final String J2SE_1_5_NAME = "J2SE-1.5"; //$NON-NLS-1$
49 	public static final String JAVASE_1_6_NAME = "JavaSE-1.6"; //$NON-NLS-1$
50 	public static final String JAVASE_1_7_NAME = "JavaSE-1.7"; //$NON-NLS-1$
51 	public static final String JAVASE_1_8_NAME = "JavaSE-1.8"; //$NON-NLS-1$
52 	public static final String JAVASE_9_NAME = "JavaSE-9"; //$NON-NLS-1$
53 	public static final String JRE_1_1_NAME = "JRE-1.1"; //$NON-NLS-1$
54 	public static final String OSGI_MINIMUM_1_0_NAME = "OSGi/Minimum-1.0"; //$NON-NLS-1$
55 	public static final String OSGI_MINIMUM_1_1_NAME = "OSGi/Minimum-1.1"; //$NON-NLS-1$
56 	public static final String OSGI_MINIMUM_1_2_NAME = "OSGi/Minimum-1.2"; //$NON-NLS-1$
57 
58 	/**
59 	 * Constant indicating the corresponding element has been defined in the
60 	 * CDC-1.0_Foundation-1.0 profile
61 	 */
62 	public static final int CDC_1_0_FOUNDATION_1_0 = 0x0001;
63 
64 	/**
65 	 * Constant indicating the corresponding element has been defined in the
66 	 * CDC-1.1_Foundation-1.1 profile
67 	 */
68 	public static final int CDC_1_1_FOUNDATION_1_1 = 0x0002;
69 
70 	/**
71 	 * Constant indicating the corresponding element has been defined in the
72 	 * JRE-1.1 profile
73 	 */
74 	public static final int JRE_1_1 = 0x0004;
75 
76 	/**
77 	 * Constant indicating the corresponding element has been defined in the
78 	 * J2SE-1.2 profile
79 	 */
80 	public static final int J2SE_1_2 = 0x0008;
81 
82 	/**
83 	 * Constant indicating the corresponding element has been defined in the
84 	 * J2SE-1.3 profile
85 	 */
86 	public static final int J2SE_1_3 = 0x0010;
87 
88 	/**
89 	 * Constant indicating the corresponding element has been defined in the
90 	 * J2SE-1.4 profile
91 	 */
92 	public static final int J2SE_1_4 = 0x0020;
93 
94 	/**
95 	 * Constant indicating the corresponding element has been defined in the
96 	 * J2SE-1.5 profile
97 	 */
98 	public static final int J2SE_1_5 = 0x0040;
99 
100 	/**
101 	 * Constant indicating the corresponding element has been defined in the
102 	 * JavaSE-1.6 profile
103 	 */
104 	public static final int JAVASE_1_6 = 0x0080;
105 
106 	/**
107 	 * Constant indicating the corresponding element has been defined in the
108 	 * JavaSE-1.7 profile
109 	 */
110 	public static final int JAVASE_1_7 = 0x0100;
111 
112 	/**
113 	 * Constant indicating the corresponding element has been defined in the
114 	 * JavaSE-1.8 profile
115 	 */
116 	public static final int JAVASE_1_8 = 0x1000;
117 	/**
118 	 * Constant indicating the corresponding element has been defined in the
119 	 * JavaSE-9 profile
120 	 */
121 	public static final int JAVASE_9 = 0x10000;
122 	/**
123 	 * /** Constant indicating the corresponding element has been defined in the
124 	 * OSGi_Minimum-1.0 profile
125 	 */
126 	public static final int OSGI_MINIMUM_1_0 = 0x0200;
127 
128 	/**
129 	 * Constant indicating the corresponding element has been defined in the
130 	 * OSGi_Minimum-1.1 profile
131 	 */
132 	public static final int OSGI_MINIMUM_1_1 = 0x0400;
133 
134 	/**
135 	 * Constant indicating the corresponding element has been defined in the
136 	 * OSGi_Minimum-1.2 profile
137 	 */
138 	public static final int OSGI_MINIMUM_1_2 = 0x0800;
139 
140 	/**
141 	 * Constant indicating all the OSGi profiles are defined
142 	 */
143 	public static final int OSGI_MINIMUM_MASK = OSGI_MINIMUM_1_0 | OSGI_MINIMUM_1_1 | OSGI_MINIMUM_1_2;
144 
145 	/**
146 	 * Constant indicating all the CDC/Foundation profiles are defined
147 	 */
148 	public static final int CDC_FOUNDATION_MAX = 0x0003;
149 
150 	/**
151 	 * Constant indicating all the jres profiles are defined
152 	 */
153 	public static final int JRES_MAX = JRE_1_1 | J2SE_1_2 | J2SE_1_3 | J2SE_1_4 | J2SE_1_5 | JAVASE_1_6 | JAVASE_1_7 | JAVASE_1_8 | JAVASE_9;
154 
155 	/**
156 	 * Constructor no instantiating
157 	 */
ProfileModifiers()158 	private ProfileModifiers() {
159 	}
160 
161 	/**
162 	 * Returns if the CDC_1_0_FOUNDATION_1_0 modifier has been set in the given
163 	 * modifiers.
164 	 *
165 	 * @param modifiers the given modifiers
166 	 * @return true if the CDC_1_0_FOUNDATION_1_0 modifier has been set in the
167 	 *         specified modifiers, false otherwise
168 	 */
isCDC_1_0_FOUNDATION_1_0(int modifiers)169 	public static boolean isCDC_1_0_FOUNDATION_1_0(int modifiers) {
170 		return (modifiers & CDC_1_0_FOUNDATION_1_0) > 0;
171 	}
172 
173 	/**
174 	 * Returns if the CDC_1_1_FOUNDATION_1_1 modifier has been set in the given
175 	 * modifiers.
176 	 *
177 	 * @param modifiers the given modifiers
178 	 * @return true if the CDC_1_1_FOUNDATION_1_1 modifier has been set in the
179 	 *         specified modifiers, false otherwise
180 	 */
isCDC_1_1_FOUNDATION_1_1(int modifiers)181 	public static boolean isCDC_1_1_FOUNDATION_1_1(int modifiers) {
182 		return (modifiers & CDC_1_1_FOUNDATION_1_1) > 0;
183 	}
184 
185 	/**
186 	 * Returns if the J2SE_1_2 modifier has been set in the given modifiers.
187 	 *
188 	 * @param modifiers the given modifiers
189 	 * @return true if the J2SE_1_2 modifier has been set in the specified
190 	 *         modifiers, false otherwise
191 	 */
isJ2SE_1_2(int modifiers)192 	public static boolean isJ2SE_1_2(int modifiers) {
193 		return (modifiers & J2SE_1_2) > 0;
194 	}
195 
196 	/**
197 	 * Returns if the J2SE_1_3 modifier has been set in the given modifiers.
198 	 *
199 	 * @param modifiers the given modifiers
200 	 * @return true if the J2SE_1_3 modifier has been set in the specified
201 	 *         modifiers, false otherwise
202 	 */
isJ2SE_1_3(int modifiers)203 	public static boolean isJ2SE_1_3(int modifiers) {
204 		return (modifiers & J2SE_1_3) > 0;
205 	}
206 
207 	/**
208 	 * Returns if the J2SE_1_4 modifier has been set in the given modifiers.
209 	 *
210 	 * @param modifiers the given modifiers
211 	 * @return true if the J2SE_1_4 modifier has been set in the specified
212 	 *         modifiers, false otherwise
213 	 */
isJ2SE_1_4(int modifiers)214 	public static boolean isJ2SE_1_4(int modifiers) {
215 		return (modifiers & J2SE_1_4) > 0;
216 	}
217 
218 	/**
219 	 * Returns if the J2SE_1_5 modifier has been set in the given modifiers.
220 	 *
221 	 * @param modifiers the given modifiers
222 	 * @return true if the J2SE_1_5 modifier has been set in the specified
223 	 *         modifiers, false otherwise
224 	 */
isJ2SE_1_5(int modifiers)225 	public static boolean isJ2SE_1_5(int modifiers) {
226 		return (modifiers & J2SE_1_5) > 0;
227 	}
228 
229 	/**
230 	 * Returns if the JAVASE_1_6 modifier has been set in the given modifiers.
231 	 *
232 	 * @param modifiers the given modifiers
233 	 * @return true if the JAVASE_1_6 modifier has been set in the specified
234 	 *         modifiers, false otherwise
235 	 */
isJAVASE_1_6(int modifiers)236 	public static boolean isJAVASE_1_6(int modifiers) {
237 		return (modifiers & JAVASE_1_6) > 0;
238 	}
239 
240 	/**
241 	 * Returns if the JAVASE_1_7 modifier has been set in the given modifiers.
242 	 *
243 	 * @param modifiers the given modifiers
244 	 * @return true if the JAVASE_1_7 modifier has been set in the specified
245 	 *         modifiers, false otherwise
246 	 */
isJAVASE_1_7(int modifiers)247 	public static boolean isJAVASE_1_7(int modifiers) {
248 		return (modifiers & JAVASE_1_7) > 0;
249 	}
250 
251 	/**
252 	 * Returns if the JAVASE_1_8 modifier has been set in the given modifiers.
253 	 *
254 	 * @param modifiers the given modifiers
255 	 * @return true if the JAVASE_1_8 modifier has been set in the specified
256 	 *         modifiers, false otherwise
257 	 */
isJAVASE_1_8(int modifiers)258 	public static boolean isJAVASE_1_8(int modifiers) {
259 		return (modifiers & JAVASE_1_8) > 0;
260 	}
261 
262 	/**
263 	 * Returns if the JAVASE_9 modifier has been set in the given modifiers.
264 	 *
265 	 * @param modifiers the given modifiers
266 	 * @return true if the JAVASE_9 modifier has been set in the specified
267 	 *         modifiers, false otherwise
268 	 */
isJAVASE_9(int modifiers)269 	public static boolean isJAVASE_9(int modifiers) {
270 		return (modifiers & JAVASE_9) > 0;
271 	}
272 
273 	/**
274 	 * Returns if the JRE_1_1 modifier has been set in the given modifiers.
275 	 *
276 	 * @param modifiers the given modifiers
277 	 * @return true if the JRE_1_1 modifier has been set in the specified
278 	 *         modifiers, false otherwise
279 	 */
isJRE_1_1(int modifiers)280 	public static boolean isJRE_1_1(int modifiers) {
281 		return (modifiers & JRE_1_1) > 0;
282 	}
283 
284 	/**
285 	 * Returns if the OSGI_MINIMUM_1_0 modifier has been set in the given
286 	 * modifiers.
287 	 *
288 	 * @param modifiers the given modifiers
289 	 * @return true if the OSGI_MINIMUM_1_0 modifier has been set in the
290 	 *         specified modifiers, false otherwise
291 	 */
isOSGI_MINIMUM_1_0(int modifiers)292 	public static boolean isOSGI_MINIMUM_1_0(int modifiers) {
293 		return (modifiers & OSGI_MINIMUM_1_0) > 0;
294 	}
295 
296 	/**
297 	 * Returns if the OSGI_MINIMUM_1_1 modifier has been set in the given
298 	 * modifiers.
299 	 *
300 	 * @param modifiers the given modifiers
301 	 * @return true if the OSGI_MINIMUM_1_1 modifier has been set in the
302 	 *         specified modifiers, false otherwise
303 	 */
isOSGI_MINIMUM_1_1(int modifiers)304 	public static boolean isOSGI_MINIMUM_1_1(int modifiers) {
305 		return (modifiers & OSGI_MINIMUM_1_1) > 0;
306 	}
307 
308 	/**
309 	 * Returns if the OSGI_MINIMUM_1_2 modifier has been set in the given
310 	 * modifiers.
311 	 *
312 	 * @param modifiers the given modifiers
313 	 * @return true if the OSGI_MINIMUM_1_2 modifier has been set in the
314 	 *         specified modifiers, false otherwise
315 	 */
isOSGI_MINIMUM_1_2(int modifiers)316 	public static boolean isOSGI_MINIMUM_1_2(int modifiers) {
317 		return (modifiers & OSGI_MINIMUM_1_2) > 0;
318 	}
319 
getValue(String profileName)320 	public static int getValue(String profileName) {
321 		if (profileName == null) {
322 			return NO_PROFILE_VALUE;
323 		}
324 		if (CDC_1_0_FOUNDATION_1_0_NAME.equals(profileName)) {
325 			return CDC_1_0_FOUNDATION_1_0;
326 		}
327 		if (CDC_1_1_FOUNDATION_1_1_NAME.equals(profileName)) {
328 			return CDC_1_1_FOUNDATION_1_1;
329 		}
330 		if (J2SE_1_2_NAME.equals(profileName)) {
331 			return J2SE_1_2;
332 		}
333 		if (J2SE_1_3_NAME.equals(profileName)) {
334 			return J2SE_1_3;
335 		}
336 		if (J2SE_1_4_NAME.equals(profileName)) {
337 			return J2SE_1_4;
338 		}
339 		if (J2SE_1_5_NAME.equals(profileName)) {
340 			return J2SE_1_5;
341 		}
342 		if (JAVASE_1_6_NAME.equals(profileName)) {
343 			return JAVASE_1_6;
344 		}
345 		if (JAVASE_1_7_NAME.equals(profileName)) {
346 			return JAVASE_1_7;
347 		}
348 		if (JAVASE_1_8_NAME.equals(profileName)) {
349 			return JAVASE_1_8;
350 		}
351 		if (JAVASE_9_NAME.equals(profileName)) {
352 			return JAVASE_9;
353 		}
354 		if (JRE_1_1_NAME.equals(profileName)) {
355 			return JRE_1_1;
356 		}
357 		if (OSGI_MINIMUM_1_0_NAME.equals(profileName)) {
358 			return OSGI_MINIMUM_1_0;
359 		}
360 		if (OSGI_MINIMUM_1_1_NAME.equals(profileName)) {
361 			return OSGI_MINIMUM_1_1;
362 		}
363 		if (OSGI_MINIMUM_1_2_NAME.equals(profileName)) {
364 			return OSGI_MINIMUM_1_2;
365 		}
366 		return NO_PROFILE_VALUE;
367 	}
368 
getName(int profile)369 	public static String getName(int profile) {
370 		switch (profile) {
371 			case CDC_1_0_FOUNDATION_1_0:
372 				return CDC_1_0_FOUNDATION_1_0_NAME;
373 			case CDC_1_1_FOUNDATION_1_1:
374 				return CDC_1_1_FOUNDATION_1_1_NAME;
375 			case J2SE_1_2:
376 				return J2SE_1_2_NAME;
377 			case J2SE_1_3:
378 				return J2SE_1_3_NAME;
379 			case J2SE_1_4:
380 				return J2SE_1_4_NAME;
381 			case J2SE_1_5:
382 				return J2SE_1_5_NAME;
383 			case JAVASE_1_6:
384 				return JAVASE_1_6_NAME;
385 			case JAVASE_1_7:
386 				return JAVASE_1_7_NAME;
387 			case JAVASE_1_8:
388 				return JAVASE_1_8_NAME;
389 			case JAVASE_9:
390 				return JAVASE_9_NAME;
391 			case JRE_1_1:
392 				return JRE_1_1_NAME;
393 			case OSGI_MINIMUM_1_0:
394 				return OSGI_MINIMUM_1_0_NAME;
395 			case OSGI_MINIMUM_1_1:
396 				return OSGI_MINIMUM_1_1_NAME;
397 			case OSGI_MINIMUM_1_2:
398 				return OSGI_MINIMUM_1_2_NAME;
399 			default:
400 				return null;
401 		}
402 	}
403 
isJRE(int value)404 	public static boolean isJRE(int value) {
405 		return (value & JRES_MAX) != 0;
406 	}
407 
isJRE(String name)408 	public static boolean isJRE(String name) {
409 		int value = getValue(name);
410 		return isJRE(value);
411 	}
412 
isOSGi(String name)413 	public static boolean isOSGi(String name) {
414 		int value = getValue(name);
415 		return isOSGi(value);
416 	}
417 
isOSGi(int value)418 	public static boolean isOSGi(int value) {
419 		return (value & OSGI_MINIMUM_MASK) != 0;
420 	}
421 
isCDC_Foundation(String name)422 	public static boolean isCDC_Foundation(String name) {
423 		int value = getValue(name);
424 		return isCDC_Foundation(value);
425 	}
426 
isCDC_Foundation(int value)427 	public static boolean isCDC_Foundation(int value) {
428 		return (value & CDC_FOUNDATION_MAX) != 0;
429 	}
430 
getAllIds()431 	public static int[] getAllIds() {
432 		return new int[] {
433 				CDC_1_0_FOUNDATION_1_0, CDC_1_1_FOUNDATION_1_1, JRE_1_1,
434 				J2SE_1_2, J2SE_1_3, J2SE_1_4, J2SE_1_5, JAVASE_1_6, JAVASE_1_7,
435 				JAVASE_1_8, JAVASE_9,OSGI_MINIMUM_1_0, OSGI_MINIMUM_1_1,
436 				OSGI_MINIMUM_1_2, };
437 	}
438 }