Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3fdf5b971d7389be3d052c67b59778df563c0063 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*******************************************************************************
 * Copyright (c) 2011, 2017 Sonatype, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Sonatype, Inc. - initial implementation and ideas
 ******************************************************************************/
package org.eclipse.equinox.p2.tests;

import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class IULoader {

	private static Annotation[] annos;

	public static void loadIUs(Object o) {
		Class<? extends Object> classWithIUs = o.getClass();
		annos = classWithIUs.getAnnotations();
		for (int i = 0; i < annos.length; i++) {
			System.out.println(annos[i]);
		}

		Field[] fields = classWithIUs.getFields();
		for (int i = 0; i < fields.length; i++) {
			Annotation[] a = fields[i].getAnnotations();
			for (int j = 0; j < a.length; j++) {
				if (a[j] instanceof IUDescription) {
					IUDescription ml = (IUDescription) a[j]; // here it is !!!
					ReducedCUDFParser parser = new ReducedCUDFParser();
					try (InputStream is = new ByteArrayInputStream(ml.content().getBytes())) {
						parser.parse(is, false, null);
						fields[i].set(o, parser.getIU());
					} catch (IllegalArgumentException e) {
						throw new RuntimeException(e);
					} catch (IllegalAccessException e) {
						throw new RuntimeException(e);
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
			}
		}
	}
}

Back to the top