</stateChange>
</eventHandler>
</stateProvider>
+
+ <timeGraphView id="test.builtin.sp.output">
+ <head>
+ <analysis id="test.builtin.sp" />
+ <label value="Test output of XML builtin module" />
+ </head>
+ <entry path="cpu">
+ <display type="self" />
+ </entry>
+ </timeGraphView>
</tmfxml>
\ No newline at end of file
org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui",
org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui",
org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui",
- org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui,
- org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests",
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;
+ x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,
+ org.eclipse.tracecompass.tmf.analysis.xml.ui,
+ org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests,
+ org.eclipse.tracecompass.tmf.analysis.xml.ui.tests",
org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.ui,org.eclipse.tracecompass.tmf.analysis.xml.core.tests",
org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests",
org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui"
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.net.URL;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.TmfAnalysisModuleHelperXml.XmlAnalysisModuleType;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleSource;
import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
-import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
*/
public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
- /** Extension point ID */
- private static final String TMF_XML_BUILTIN_ID = "org.eclipse.linuxtools.tmf.analysis.xml.core.files"; //$NON-NLS-1$
- private static final String XML_FILE_ELEMENT = "xmlfile"; //$NON-NLS-1$
-
- private static final String XML_FILE_ATTRIB = "file"; //$NON-NLS-1$
/*
* Legacy (Linux Tools) XML directory.
}
private static void populateBuiltinModules() {
- /* Get the XML files advertised through the extension point */
- IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_XML_BUILTIN_ID);
- for (IConfigurationElement element : elements) {
- if (element.getName().equals(XML_FILE_ELEMENT)) {
- final String filename = element.getAttribute(XML_FILE_ATTRIB);
- final String name = element.getContributor().getName();
- // Run this in a safe runner in case there is an exception
- // (IOException, FileNotFoundException, NPE, etc).
- // This makes sure other extensions are not prevented from
- // working if one is faulty.
- SafeRunner.run(new ISafeRunnable() {
-
- @Override
- public void run() throws IOException {
- if (name != null) {
- Bundle bundle = Platform.getBundle(name);
- if (bundle != null) {
- URL xmlUrl = bundle.getResource(filename);
- if (xmlUrl == null) {
- throw new FileNotFoundException(filename);
- }
- URL locatedURL = FileLocator.toFileURL(xmlUrl);
- processFile(new File(locatedURL.getFile()));
- }
- }
- }
-
- @Override
- public void handleException(Throwable exception) {
- // Handled sufficiently in SafeRunner
- }
- });
- }
+ Map<String, IPath> files = XmlUtils.listBuiltinFiles();
+ for (IPath xmlPath : files.values()) {
+ processFile(xmlPath.toFile());
}
}
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/** Name of the XSD schema file */
private static final String XSD = "xmlDefinition.xsd"; //$NON-NLS-1$
+ /** Extension point ID and attributes */
+ private static final String TMF_XML_BUILTIN_ID = "org.eclipse.linuxtools.tmf.analysis.xml.core.files"; //$NON-NLS-1$
+ private static final String XML_FILE_ELEMENT = "xmlfile"; //$NON-NLS-1$
+ private static final String XML_FILE_ATTRIB = "file"; //$NON-NLS-1$
+
/**
* Extension for XML files
- * @since 2.0
*/
public static final String XML_EXTENSION = "xml"; //$NON-NLS-1$
* the key is the file name.
*
* @return A map with all the XML analysis files
- * @since 2.0
*/
public static synchronized @NonNull Map<String, File> listFiles() {
IPath pathToFiles = XmlUtils.getXmlFilesPath();
return Collections.unmodifiableMap(fileMap);
}
+ /**
+ * List all files advertised through the builtin extension point. It returns a map where the key is the file name.
+ *
+ * @return A map with all the XMl analysis builtin files
+ */
+ public static synchronized @NonNull Map<String, IPath> listBuiltinFiles() {
+ /* Get the XML files advertised through the extension point */
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_XML_BUILTIN_ID);
+ Map<String, IPath> map = new HashMap<>();
+ for (IConfigurationElement element : elements) {
+ if (element.getName().equals(XML_FILE_ELEMENT)) {
+ final String filename = element.getAttribute(XML_FILE_ATTRIB);
+ final String name = element.getContributor().getName();
+ // Run this in a safe runner in case there is an exception
+ // (IOException, FileNotFoundException, NPE, etc).
+ // This makes sure other extensions are not prevented from
+ // working if one is faulty.
+ SafeRunner.run(new ISafeRunnable() {
+
+ @Override
+ public void run() throws IOException {
+ if (name != null) {
+ Bundle bundle = Platform.getBundle(name);
+ if (bundle != null) {
+ URL xmlUrl = bundle.getResource(filename);
+ if (xmlUrl == null) {
+ throw new FileNotFoundException(filename);
+ }
+ URL locatedURL = FileLocator.toFileURL(xmlUrl);
+ map.put(filename, new Path(locatedURL.getPath()));
+ }
+ }
+ }
+
+ @Override
+ public void handleException(Throwable exception) {
+ // Handled sufficiently in SafeRunner
+ }
+ });
+ }
+ }
+ return map;
+ }
+
/**
* Delete an XML analysis file
*
* @param name
* The XML file to delete
- * @since 2.0
*/
public static void deleteFile(String name) {
Map<String, File> files = listFiles();
* @param to
* The full path of the file to write to
* @return Whether the file was successfully exported
- * @since 2.0
*/
public static IStatus exportXmlFile(String from, String to) {
* @param fileName
* The file name
* @return The list of IDs
- * @since 2.0
*/
public static List<String> getAnalysisIdsFromFile(String fileName) {
List<String> ids = new ArrayList<>();
* If any parse errors occur.
* @throws IOException
* If any IO errors occur.
- * @since 2.0
*/
public static Document getDocumentFromFile(File file) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
org.eclipse.tracecompass.tmf.analysis.xml.core,
org.eclipse.tracecompass.tmf.analysis.xml.ui,
org.eclipse.tracecompass.tmf.ui,
- org.eclipse.tracecompass.tmf.analysis.xml.core.tests
+ org.eclipse.tracecompass.tmf.analysis.xml.core.tests,
+ org.eclipse.tracecompass.tmf.core.tests
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: com.google.common.collect;version="15.0.0",
--- /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.analysis.xml.ui.tests.module;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub;
+import org.junit.Test;
+
+/**
+ * Test that XML-defined outputs are added to the analysis modules they are for
+ *
+ * @author Geneviève Bastien
+ */
+public class XmlAnalysisOutputSourceTest {
+
+ private static final String BUILTIN_MODULE = "test.builtin.sp";
+ private static final String BUILTIN_OUTPUT= "Test output of XML builtin module";
+
+ /**
+ * Test the
+ * {@link TmfXmlAnalysisOutputSource#moduleCreated(IAnalysisModule)} method
+ */
+ @Test
+ public void testBuiltinOutput() {
+
+ TmfTrace trace = new TmfXmlTraceStub();
+ try {
+ trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null));
+
+ IAnalysisModule module = trace.getAnalysisModule(BUILTIN_MODULE);
+ assertNotNull(module);
+
+ Iterator<IAnalysisOutput> iterator = module.getOutputs().iterator();
+ assertTrue(iterator.hasNext());
+ IAnalysisOutput output = iterator.next();
+ assertEquals(BUILTIN_OUTPUT, output.getName());
+
+ } finally {
+ trace.dispose();
+ }
+
+ }
+
+}
\ No newline at end of file
org.eclipse.core.filesystem
Export-Package: org.eclipse.tracecompass.internal.tmf.analysis.xml.ui;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.ui.tests",
org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.handler;x-internal:=true,
- org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module;x-internal:=true,
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.ui.tests",
org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views;x-internal:=true,
org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests",
org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph;x-internal:=true,
import java.io.File;
import java.io.IOException;
import java.util.List;
-import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
import javax.xml.parsers.ParserConfigurationException;
@Override
public void moduleCreated(IAnalysisModule module) {
- Map<String, File> files = XmlUtils.listFiles();
- for (File xmlFile : files.values()) {
+ // Get all the XML files, builtin and not builtin
+ Set<File> files = XmlUtils.listBuiltinFiles().values().stream()
+ .map(p -> p.toFile())
+ .collect(Collectors.toSet());
+ XmlUtils.listFiles().values().stream()
+ .forEach(f -> files.add(f));
+
+ for (File xmlFile : files) {
if (!XmlUtils.xmlValidate(xmlFile).isOK()) {
continue;
}