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