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 | |
5db5a3a4 AM |
15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
16 | ||
b3b03da0 | 17 | import java.util.ArrayList; |
c068a752 GB |
18 | import java.util.LinkedList; |
19 | import java.util.List; | |
c068a752 GB |
20 | |
21 | import org.eclipse.core.runtime.IConfigurationElement; | |
22 | import org.eclipse.core.runtime.Platform; | |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper; |
24 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleSource; | |
25 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisModuleHelperConfigElement; | |
c068a752 GB |
26 | |
27 | /** | |
b3b03da0 GB |
28 | * Utility class for accessing TMF analysis module extensions from the |
29 | * platform's extensions registry. | |
c068a752 GB |
30 | * |
31 | * @author Geneviève Bastien | |
32 | * @since 3.0 | |
33 | */ | |
b3b03da0 | 34 | public final class TmfAnalysisModuleSourceConfigElement implements IAnalysisModuleSource { |
c068a752 GB |
35 | |
36 | /** Extension point ID */ | |
37 | public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$ | |
38 | ||
39 | /** Extension point element 'module' */ | |
40 | public static final String MODULE_ELEM = "module"; //$NON-NLS-1$ | |
41 | ||
42 | /** Extension point element 'parameter' */ | |
43 | public static final String PARAMETER_ELEM = "parameter"; //$NON-NLS-1$ | |
44 | ||
45 | /** Extension point attribute 'ID' */ | |
46 | public static final String ID_ATTR = "id"; //$NON-NLS-1$ | |
47 | ||
48 | /** Extension point attribute 'name' */ | |
49 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$ | |
50 | ||
51 | /** Extension point attribute 'analysis_module' */ | |
52 | public static final String ANALYSIS_MODULE_ATTR = "analysis_module"; //$NON-NLS-1$ | |
53 | ||
54 | /** Extension point attribute 'automatic' */ | |
55 | public static final String AUTOMATIC_ATTR = "automatic"; //$NON-NLS-1$ | |
56 | ||
57 | /** Extension point attribute 'icon' */ | |
58 | public static final String ICON_ATTR = "icon"; //$NON-NLS-1$ | |
59 | ||
60 | /** Extension point attribute 'default_value' */ | |
61 | public static final String DEFAULT_VALUE_ATTR = "default_value"; //$NON-NLS-1$ | |
62 | ||
63 | /** Extension point element 'tracetype' */ | |
64 | public static final String TRACETYPE_ELEM = "tracetype"; //$NON-NLS-1$ | |
65 | ||
66 | /** Extension point attribute 'class' */ | |
67 | public static final String CLASS_ATTR = "class"; //$NON-NLS-1$ | |
68 | ||
69 | /** Extension point attribute 'applies' */ | |
70 | public static final String APPLIES_ATTR = "applies"; //$NON-NLS-1$ | |
71 | ||
72 | /** | |
b3b03da0 | 73 | * The mapping of available analysis ID to their corresponding helper |
c068a752 | 74 | */ |
b3b03da0 | 75 | private final List<IAnalysisModuleHelper> fAnalysisHelpers = new ArrayList<>(); |
c068a752 GB |
76 | |
77 | /** | |
78 | * Retrieves all configuration elements from the platform extension registry | |
b3b03da0 | 79 | * for the analysis module extension. |
c068a752 | 80 | * |
b3b03da0 | 81 | * @return an array of analysis module configuration elements |
c068a752 GB |
82 | */ |
83 | public static IConfigurationElement[] getTypeElements() { | |
84 | IConfigurationElement[] elements = | |
85 | Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); | |
a4524c1b | 86 | List<IConfigurationElement> typeElements = new LinkedList<>(); |
c068a752 GB |
87 | for (IConfigurationElement element : elements) { |
88 | if (element.getName().equals(MODULE_ELEM)) { | |
89 | typeElements.add(element); | |
90 | } | |
91 | } | |
5db5a3a4 | 92 | return checkNotNull(typeElements.toArray(new IConfigurationElement[typeElements.size()])); |
c068a752 GB |
93 | } |
94 | ||
c068a752 | 95 | /** |
b3b03da0 | 96 | * Constructor |
c068a752 | 97 | */ |
b3b03da0 GB |
98 | public TmfAnalysisModuleSourceConfigElement() { |
99 | populateAnalysisList(); | |
c068a752 GB |
100 | } |
101 | ||
b3b03da0 GB |
102 | @Override |
103 | public Iterable<IAnalysisModuleHelper> getAnalysisModules() { | |
104 | return fAnalysisHelpers; | |
c068a752 GB |
105 | } |
106 | ||
b3b03da0 GB |
107 | private void populateAnalysisList() { |
108 | if (fAnalysisHelpers.isEmpty()) { | |
109 | // Populate the analysis module list | |
c068a752 GB |
110 | IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); |
111 | for (IConfigurationElement ce : config) { | |
112 | String elementName = ce.getName(); | |
b3b03da0 GB |
113 | if (elementName.equals(TmfAnalysisModuleSourceConfigElement.MODULE_ELEM)) { |
114 | fAnalysisHelpers.add(new TmfAnalysisModuleHelperConfigElement(ce)); | |
c068a752 GB |
115 | } |
116 | } | |
117 | } | |
118 | } | |
119 | ||
120 | } |