Commit | Line | Data |
---|---|---|
c068a752 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
c068a752 GB |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.internal.tmf.core.analysis; |
c068a752 | 14 | |
b3b03da0 | 15 | import java.util.ArrayList; |
c068a752 GB |
16 | import java.util.LinkedList; |
17 | import java.util.List; | |
c068a752 GB |
18 | |
19 | import org.eclipse.core.runtime.IConfigurationElement; | |
20 | import org.eclipse.core.runtime.Platform; | |
cebec056 | 21 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
22 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper; |
23 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleSource; | |
24 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisModuleHelperConfigElement; | |
c068a752 GB |
25 | |
26 | /** | |
b3b03da0 GB |
27 | * Utility class for accessing TMF analysis module extensions from the |
28 | * platform's extensions registry. | |
c068a752 GB |
29 | * |
30 | * @author Geneviève Bastien | |
31 | * @since 3.0 | |
32 | */ | |
b3b03da0 | 33 | public final class TmfAnalysisModuleSourceConfigElement implements IAnalysisModuleSource { |
c068a752 GB |
34 | |
35 | /** Extension point ID */ | |
36 | public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$ | |
37 | ||
38 | /** Extension point element 'module' */ | |
39 | public static final String MODULE_ELEM = "module"; //$NON-NLS-1$ | |
40 | ||
41 | /** Extension point element 'parameter' */ | |
42 | public static final String PARAMETER_ELEM = "parameter"; //$NON-NLS-1$ | |
43 | ||
44 | /** Extension point attribute 'ID' */ | |
45 | public static final String ID_ATTR = "id"; //$NON-NLS-1$ | |
46 | ||
47 | /** Extension point attribute 'name' */ | |
48 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$ | |
49 | ||
50 | /** Extension point attribute 'analysis_module' */ | |
51 | public static final String ANALYSIS_MODULE_ATTR = "analysis_module"; //$NON-NLS-1$ | |
52 | ||
53 | /** Extension point attribute 'automatic' */ | |
54 | public static final String AUTOMATIC_ATTR = "automatic"; //$NON-NLS-1$ | |
55 | ||
56 | /** Extension point attribute 'icon' */ | |
57 | public static final String ICON_ATTR = "icon"; //$NON-NLS-1$ | |
58 | ||
59 | /** Extension point attribute 'default_value' */ | |
60 | public static final String DEFAULT_VALUE_ATTR = "default_value"; //$NON-NLS-1$ | |
61 | ||
62 | /** Extension point element 'tracetype' */ | |
63 | public static final String TRACETYPE_ELEM = "tracetype"; //$NON-NLS-1$ | |
64 | ||
65 | /** Extension point attribute 'class' */ | |
66 | public static final String CLASS_ATTR = "class"; //$NON-NLS-1$ | |
67 | ||
68 | /** Extension point attribute 'applies' */ | |
69 | public static final String APPLIES_ATTR = "applies"; //$NON-NLS-1$ | |
70 | ||
71 | /** | |
b3b03da0 | 72 | * The mapping of available analysis ID to their corresponding helper |
c068a752 | 73 | */ |
b3b03da0 | 74 | private final List<IAnalysisModuleHelper> fAnalysisHelpers = new ArrayList<>(); |
c068a752 GB |
75 | |
76 | /** | |
77 | * Retrieves all configuration elements from the platform extension registry | |
b3b03da0 | 78 | * for the analysis module extension. |
c068a752 | 79 | * |
b3b03da0 | 80 | * @return an array of analysis module configuration elements |
c068a752 GB |
81 | */ |
82 | public static IConfigurationElement[] getTypeElements() { | |
83 | IConfigurationElement[] elements = | |
84 | Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); | |
a4524c1b | 85 | List<IConfigurationElement> typeElements = new LinkedList<>(); |
c068a752 GB |
86 | for (IConfigurationElement element : elements) { |
87 | if (element.getName().equals(MODULE_ELEM)) { | |
88 | typeElements.add(element); | |
89 | } | |
90 | } | |
cebec056 GB |
91 | @SuppressWarnings("null") |
92 | @NonNull IConfigurationElement[] typeElems = typeElements.toArray(new IConfigurationElement[typeElements.size()]); | |
93 | return typeElems; | |
c068a752 GB |
94 | } |
95 | ||
c068a752 | 96 | /** |
b3b03da0 | 97 | * Constructor |
c068a752 | 98 | */ |
b3b03da0 GB |
99 | public TmfAnalysisModuleSourceConfigElement() { |
100 | populateAnalysisList(); | |
c068a752 GB |
101 | } |
102 | ||
b3b03da0 GB |
103 | @Override |
104 | public Iterable<IAnalysisModuleHelper> getAnalysisModules() { | |
105 | return fAnalysisHelpers; | |
c068a752 GB |
106 | } |
107 | ||
b3b03da0 GB |
108 | private void populateAnalysisList() { |
109 | if (fAnalysisHelpers.isEmpty()) { | |
110 | // Populate the analysis module list | |
c068a752 GB |
111 | IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); |
112 | for (IConfigurationElement ce : config) { | |
113 | String elementName = ce.getName(); | |
b3b03da0 GB |
114 | if (elementName.equals(TmfAnalysisModuleSourceConfigElement.MODULE_ELEM)) { |
115 | fAnalysisHelpers.add(new TmfAnalysisModuleHelperConfigElement(ce)); | |
c068a752 GB |
116 | } |
117 | } | |
118 | } | |
119 | } | |
120 | ||
121 | } |