1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org.eclipse.tracecompass.internal.tmf.core.analysis;
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17 import java.util.ArrayList;
18 import java.util.LinkedList;
19 import java.util.List;
21 import org.eclipse.core.runtime.IConfigurationElement;
22 import org.eclipse.core.runtime.Platform;
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;
28 * Utility class for accessing TMF analysis module extensions from the
29 * platform's extensions registry.
31 * @author Geneviève Bastien
33 public final class TmfAnalysisModuleSourceConfigElement implements IAnalysisModuleSource {
35 /** Extension point ID */
36 public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$
38 /** Extension point element 'module' */
39 public static final String MODULE_ELEM = "module"; //$NON-NLS-1$
41 /** Extension point element 'parameter' */
42 public static final String PARAMETER_ELEM = "parameter"; //$NON-NLS-1$
44 /** Extension point attribute 'ID' */
45 public static final String ID_ATTR = "id"; //$NON-NLS-1$
47 /** Extension point attribute 'name' */
48 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
50 /** Extension point attribute 'analysis_module' */
51 public static final String ANALYSIS_MODULE_ATTR = "analysis_module"; //$NON-NLS-1$
53 /** Extension point attribute 'automatic' */
54 public static final String AUTOMATIC_ATTR = "automatic"; //$NON-NLS-1$
56 /** Extension point attribute 'applies_experiment' */
57 public static final String APPLIES_EXP_ATTR = "applies_experiment"; //$NON-NLS-1$
59 /** Extension point attribute 'icon' */
60 public static final String ICON_ATTR = "icon"; //$NON-NLS-1$
62 /** Extension point attribute 'default_value' */
63 public static final String DEFAULT_VALUE_ATTR = "default_value"; //$NON-NLS-1$
65 /** Extension point element 'tracetype' */
66 public static final String TRACETYPE_ELEM = "tracetype"; //$NON-NLS-1$
68 /** Extension point attribute 'class' */
69 public static final String CLASS_ATTR = "class"; //$NON-NLS-1$
71 /** Extension point attribute 'applies' */
72 public static final String APPLIES_ATTR = "applies"; //$NON-NLS-1$
75 * The mapping of available analysis ID to their corresponding helper
77 private final List<IAnalysisModuleHelper> fAnalysisHelpers = new ArrayList<>();
80 * Retrieves all configuration elements from the platform extension registry
81 * for the analysis module extension.
83 * @return an array of analysis module configuration elements
85 public static IConfigurationElement[] getTypeElements() {
86 IConfigurationElement[] elements =
87 Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID);
88 List<IConfigurationElement> typeElements = new LinkedList<>();
89 for (IConfigurationElement element : elements) {
90 if (element.getName().equals(MODULE_ELEM)) {
91 typeElements.add(element);
94 return checkNotNull(typeElements.toArray(new IConfigurationElement[typeElements.size()]));
100 public TmfAnalysisModuleSourceConfigElement() {
101 populateAnalysisList();
105 public Iterable<IAnalysisModuleHelper> getAnalysisModules() {
106 return fAnalysisHelpers;
109 private void populateAnalysisList() {
110 if (fAnalysisHelpers.isEmpty()) {
111 // Populate the analysis module list
112 IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID);
113 for (IConfigurationElement ce : config) {
114 String elementName = ce.getName();
115 if (elementName.equals(TmfAnalysisModuleSourceConfigElement.MODULE_ELEM)) {
116 fAnalysisHelpers.add(new TmfAnalysisModuleHelperConfigElement(ce));