November 30, 2017
++ The Eclipse Foundation makes available all content in this plug-in + ("Content"). Unless otherwise indicated below, the Content + is provided to you under the terms and conditions of the Eclipse + Public License Version 2.0 ("EPL"). A copy of the EPL is + available at http://www.eclipse.org/legal/epl-2.0. + For purposes of the EPL, "Program" will mean the Content. +
+ ++ If you did not receive this Content directly from the Eclipse + Foundation, the Content is being redistributed by another party + ("Redistributor") and different terms and conditions may + apply to your use of any object code in the Content. Check the + Redistributor's license that was provided with the Content. If no such + license exists, contact the Redistributor. Unless otherwise indicated + below, the terms and conditions of the EPL still apply to any source + code in the Content and such source code may be obtained at http://www.eclipse.org. +
+ + + \ No newline at end of file diff --git a/debug/org.eclipse.unittest.ui.ota4j/build.properties b/debug/org.eclipse.unittest.ui.ota4j/build.properties new file mode 100644 index 00000000000..e56e3db94ec --- /dev/null +++ b/debug/org.eclipse.unittest.ui.ota4j/build.properties @@ -0,0 +1,24 @@ +############################################################################### +# Copyright (c) 2025 Eclipse contributors and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Eclipse contributors - initial API and implementation +############################################################################### +bin.includes = plugin.xml,\ + about.html,\ + plugin.properties,\ + .,\ + META-INF/,\ + schema/ + +source.. = src/ +output.. = bin/ +src.includes = about.html,\ + schema/ diff --git a/debug/org.eclipse.unittest.ui.ota4j/examples/sample-test-events.xml b/debug/org.eclipse.unittest.ui.ota4j/examples/sample-test-events.xml new file mode 100644 index 00000000000..bdbb315674c --- /dev/null +++ b/debug/org.eclipse.unittest.ui.ota4j/examples/sample-test-events.xml @@ -0,0 +1,97 @@ + + ++ * This client can be used to integrate test frameworks that output OTA4J format + * with the Eclipse Unit Test view. + *
+ * + * @since 1.0 + */ +public class OpenTestReportingClient implements ITestRunnerClient { + + private final ITestRunSession fSession; + private final Reader fEventReader; + private Thread fReaderThread; + private volatile boolean fStopped; + + /** + * Creates a new Open Test Reporting client. + * + * @param session the test run session to update + * @param eventReader the reader providing the OTA4J event stream + */ + public OpenTestReportingClient(ITestRunSession session, Reader eventReader) { + fSession = session; + fEventReader = eventReader; + fStopped = false; + } + + @Override + public void startMonitoring() { + fReaderThread = new Thread("OTA4J Event Reader") { //$NON-NLS-1$ + @Override + public void run() { + try { + OpenTestReportingReader reader = new OpenTestReportingReader(fSession); + reader.readEvents(fEventReader); + + if (!fStopped) { + fSession.notifyTestSessionCompleted(null); + } + } catch (IOException | XMLStreamException e) { + if (!fStopped) { + fSession.notifyTestSessionAborted(null, new Exception("Failed to read OTA4J events", e)); //$NON-NLS-1$ + } + } finally { + try { + fEventReader.close(); + } catch (IOException e) { + // Ignore close errors + } + } + } + }; + fReaderThread.start(); + } + + @Override + public void stopTest() { + fStopped = true; + stopMonitoring(); + } + + @Override + public void stopMonitoring() { + if (fReaderThread != null && fReaderThread.isAlive()) { + try { + fEventReader.close(); + } catch (IOException e) { + // Ignore close errors + } + fReaderThread.interrupt(); + try { + fReaderThread.join(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } +} diff --git a/debug/org.eclipse.unittest.ui.ota4j/src/org/eclipse/unittest/ui/ota4j/OpenTestReportingReader.java b/debug/org.eclipse.unittest.ui.ota4j/src/org/eclipse/unittest/ui/ota4j/OpenTestReportingReader.java new file mode 100644 index 00000000000..1ff6c7cb3e5 --- /dev/null +++ b/debug/org.eclipse.unittest.ui.ota4j/src/org/eclipse/unittest/ui/ota4j/OpenTestReportingReader.java @@ -0,0 +1,315 @@ +/******************************************************************************* + * Copyright (c) 2025 Eclipse contributors and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eclipse contributors - initial API and implementation + *******************************************************************************/ +package org.eclipse.unittest.ui.ota4j; + +import java.io.IOException; +import java.io.Reader; +import java.time.Duration; +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.eclipse.unittest.model.ITestElement; +import org.eclipse.unittest.model.ITestElement.FailureTrace; +import org.eclipse.unittest.model.ITestElement.Result; +import org.eclipse.unittest.model.ITestRunSession; +import org.eclipse.unittest.model.ITestSuiteElement; + +/** + * Reads Open Test Reporting events from an XML stream and translates them into + * calls to the Unit Test API. + *+ * This class uses StAX (Streaming API for XML) to process events efficiently + * with a low memory footprint, suitable for streaming test results. + *
+ * + * @since 1.0 + */ +public class OpenTestReportingReader { + + private static final String EVENTS_NS = "https://schemas.opentest4j.org/reporting/events/0.2.0"; + private static final String CORE_NS = "https://schemas.opentest4j.org/reporting/core/0.2.0"; + + private final ITestRunSession fSession; + private final Map+ * This is a convenience method that creates a {@link OpenTestReportingReader} + * and processes the events from the specified file. + *
+ * + * @param session the test run session to update + * @param file the file containing OTA4J events + * @throws IOException if an I/O error occurs while reading the file + * @throws XMLStreamException if an error occurs while parsing the XML + */ + public static void readEventsFromFile(ITestRunSession session, File file) + throws IOException, XMLStreamException { + try (Reader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) { + OpenTestReportingReader ota4jReader = new OpenTestReportingReader(session); + ota4jReader.readEvents(reader); + } + } + + /** + * Reads Open Test Reporting events from a file path and updates the test + * session. + *+ * This is a convenience method that creates a {@link OpenTestReportingReader} + * and processes the events from the specified file path. + *
+ * + * @param session the test run session to update + * @param filePath the path to the file containing OTA4J events + * @throws IOException if an I/O error occurs while reading the file + * @throws XMLStreamException if an error occurs while parsing the XML + */ + public static void readEventsFromFile(ITestRunSession session, String filePath) + throws IOException, XMLStreamException { + readEventsFromFile(session, new File(filePath)); + } +} diff --git a/debug/org.eclipse.unittest.ui.ota4j/src/org/eclipse/unittest/ui/ota4j/package-info.java b/debug/org.eclipse.unittest.ui.ota4j/src/org/eclipse/unittest/ui/ota4j/package-info.java new file mode 100644 index 00000000000..6d13626b724 --- /dev/null +++ b/debug/org.eclipse.unittest.ui.ota4j/src/org/eclipse/unittest/ui/ota4j/package-info.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2025 Eclipse contributors and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eclipse contributors - initial API and implementation + *******************************************************************************/ + +/** + * Provides support for integrating Open Test Reporting (OTA4J) format with the + * Eclipse Unit Test view. + *+ * This package contains classes that read OTA4J XML event streams and translate + * them into calls to the {@link org.eclipse.unittest.model.ITestRunSession} + * API. The main entry points are: + *
+ *+ * The Open Test Reporting format is a vendor-neutral format for test execution + * results, defined by the + * OTA4J project. This integration allows test frameworks that output OTA4J + * format to display their results in the Eclipse Unit Test view without requiring + * framework-specific adapters. + *
+ *
+ * // Create a test run session
+ * ITestRunSession session = ...;
+ *
+ * // Create a reader for the OTA4J event stream
+ * Reader eventReader = new FileReader("test-results.xml");
+ * OpenTestReportingClient client = new OpenTestReportingClient(session, eventReader);
+ *
+ * // Start monitoring the event stream
+ * client.startMonitoring();
+ *
+ *
+ * @since 1.0
+ */
+package org.eclipse.unittest.ui.ota4j;
diff --git a/debug/pom.xml b/debug/pom.xml
index 90bfce4a80c..63417dd906f 100644
--- a/debug/pom.xml
+++ b/debug/pom.xml
@@ -36,6 +36,7 @@