id="org.eclipse.linuxtools.tmf.core.tests.analysis.testParamProvider">
</analysisId>
</parameterProvider>
+ <listener
+ class="org.eclipse.tracecompass.tmf.tests.stubs.analysis.NewModuleListenerStub">
+ </listener>
</extension>
<extension
point="org.eclipse.linuxtools.tmf.core.tracetype">
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.tests.analysis;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
+import org.eclipse.tracecompass.tmf.tests.stubs.analysis.NewModuleListenerStub;
+import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis;
+import org.junit.Test;
+
+/**
+ * Test the analysis listener extension point
+ *
+ * @author Geneviève Bastien
+ */
+public class AnalysisListenerTest {
+
+ private static final @NonNull String MODULE_GENERIC_ID = "test.id";
+ private static final @NonNull String MODULE_GENERIC_NAME = "Test analysis";
+
+ /**
+ * Test if the listener was created by using a manually created module
+ */
+ @Test
+ public void testNewModuleListener() {
+ TestAnalysis module = new TestAnalysis();
+
+ module.setName(MODULE_GENERIC_NAME);
+ module.setId(MODULE_GENERIC_ID);
+
+ int countBefore = NewModuleListenerStub.getModuleCount();
+ TmfAnalysisManager.analysisModuleCreated(module);
+ /*
+ * The listener should have run on this module and the count increment
+ * by 1
+ */
+ assertEquals(countBefore + 1, NewModuleListenerStub.getModuleCount());
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.tests.stubs.analysis;
+
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.analysis.ITmfNewAnalysisModuleListener;
+
+/**
+ * A test listener for newly created modules
+ *
+ * @author Geneviève Bastien
+ */
+public class NewModuleListenerStub implements ITmfNewAnalysisModuleListener {
+
+ private static int fNewModuleCount = 0;
+
+ @Override
+ public void moduleCreated(IAnalysisModule module) {
+ fNewModuleCount++;
+ }
+
+ /**
+ * Get the count of newly created modules
+ *
+ * @return the number of modules that were created
+ */
+ public static int getModuleCount() {
+ return fNewModuleCount;
+ }
+
+}
<element ref="source"/>
<element ref="output"/>
<element ref="parameterProvider"/>
+ <element ref="listener"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<attribute name="applies_experiment" type="boolean">
<annotation>
<documentation>
- If true, indicate that an instance of this analysis will also be added to an experiment containing one or more trace(s) it applies to. In this case, the analysis will be run on the full experiment and the result is more than just the aggregation of each trace's analysis (default false).
+ If true, indicate that an instance of this analysis will also be added to an experiment containing one or more trace(s) it applies to. In this case, the analysis will be run on the full experiment and the result is more than just the aggregation of each trace's analysis (default false).
</documentation>
</annotation>
</attribute>
</complexType>
</element>
+ <element name="listener">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ Specify a class that will listen to new modules created. This listener will listen to the creation of any module.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.tracecompass.tmf.core.analysis.ITmfNewAnalysisModuleListener"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appinfo>
<meta.section type="since"/>
}
/**
- * Return the analysis module sources advertised in the extension
- * point, in iterable format.
+ * Return the analysis module sources advertised in the extension point, in
+ * iterable format.
*
* @return List of {@link IAnalysisModuleSource}
*/
}
return sources;
}
+
}
*/
public static final String MODULE_CLASS_ELEM = "analysisModuleClass"; //$NON-NLS-1$
+ /** Extension point element 'listener' */
+ private static final String LISTENER_ELEM = "listener"; //$NON-NLS-1$
+
private TmfAnalysisModuleOutputs() {
}
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID);
for (IConfigurationElement ce : config) {
String elementName = ce.getName();
+ ITmfNewAnalysisModuleListener listener = null;
if (elementName.equals(OUTPUT_ELEM)) {
- try {
- IAnalysisOutput output = (IAnalysisOutput) ce.createExecutableExtension(CLASS_ATTR);
- if (output == null) {
- Activator.logWarning("An output could not be created"); //$NON-NLS-1$
- continue;
- }
- ITmfNewAnalysisModuleListener listener = null;
- for (IConfigurationElement childCe : ce.getChildren()) {
- if (childCe.getName().equals(ANALYSIS_ID_ELEM)) {
- listener = new TmfNewAnalysisOutputListener(output, childCe.getAttribute(ID_ATTR), null);
- } else if (childCe.getName().equals(MODULE_CLASS_ELEM)) {
- listener = new TmfNewAnalysisOutputListener(output, null, childCe.createExecutableExtension(CLASS_ATTR).getClass().asSubclass(IAnalysisModule.class));
- }
- }
- if (listener != null) {
- newModuleListeners.add(listener);
- }
- } catch (InvalidRegistryObjectException | CoreException e) {
- Activator.logError("Error creating module output listener", e); //$NON-NLS-1$
- }
+ listener = getListenerFromOutputElement(ce);
+ } else if (elementName.equals(LISTENER_ELEM)) {
+ listener = getListenerFromListenerElement(ce);
+ }
+ if (listener != null) {
+ newModuleListeners.add(listener);
}
}
return newModuleListeners;
}
+
+ private static ITmfNewAnalysisModuleListener getListenerFromOutputElement(IConfigurationElement ce) {
+ ITmfNewAnalysisModuleListener listener = null;
+ try {
+ IAnalysisOutput output = (IAnalysisOutput) ce.createExecutableExtension(CLASS_ATTR);
+ if (output == null) {
+ Activator.logWarning("An output could not be created"); //$NON-NLS-1$
+ return listener;
+ }
+ for (IConfigurationElement childCe : ce.getChildren()) {
+ if (childCe.getName().equals(ANALYSIS_ID_ELEM)) {
+ listener = new TmfNewAnalysisOutputListener(output, childCe.getAttribute(ID_ATTR), null);
+ } else if (childCe.getName().equals(MODULE_CLASS_ELEM)) {
+ listener = new TmfNewAnalysisOutputListener(output, null, childCe.createExecutableExtension(CLASS_ATTR).getClass().asSubclass(IAnalysisModule.class));
+ }
+ }
+ } catch (InvalidRegistryObjectException | CoreException e) {
+ Activator.logError("Error creating module output listener", e); //$NON-NLS-1$
+ }
+ return listener;
+ }
+
+ private static ITmfNewAnalysisModuleListener getListenerFromListenerElement(IConfigurationElement ce) {
+ ITmfNewAnalysisModuleListener listener = null;
+ try {
+ listener = (ITmfNewAnalysisModuleListener) ce.createExecutableExtension(CLASS_ATTR);
+ } catch (CoreException e) {
+ Activator.logError("Error creating new module listener", e); //$NON-NLS-1$
+ }
+ return listener;
+ }
+
}