Skip to content

Commit

Permalink
Merge pull request #26 from bia-technologies/feature/25
Browse files Browse the repository at this point in the history
Фикс ошибки - не обновляется отчет после перезапуска
  • Loading branch information
alkoleft authored May 4, 2023
2 parents 8689412 + 7bbdd96 commit 5383cf6
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 331 deletions.
4 changes: 2 additions & 2 deletions viewer/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
org.apache.commons.lang3,
com._1c.g5.v8.dt.bsl.core;bundle-version="6.0.300",
org.eclipse.handly;bundle-version="1.5.0",
com._1c.g5.v8.dt.lcore;bundle-version="3.1.900"
com._1c.g5.v8.dt.lcore;bundle-version="3.1.900",
com.google.gson
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: com._1c.g5.v8.dt.bm.index.emf,
com._1c.g5.v8.dt.bsl.model,
com._1c.g5.v8.dt.stacktraces.model,
com._1c.g5.wiring,
com.google.common.base,
com.google.gson;version="2.8.2",
javax.xml.parsers,
lombok;resolution:=optional,
lombok.experimental;resolution:=optional,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2023 BIA-Technologies Limited Liability Company.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

package ru.biatech.edt.junit.launcher.lifecycle;

import lombok.Getter;
import lombok.Setter;
import org.eclipse.debug.core.ILaunch;

import java.time.Instant;

@Getter
public class LifecycleItem {
private final ILaunch testLaunch;
@Setter
private ILaunch mainLaunch;
private final String name;
private boolean active = true;
private Instant start;
private Instant end;

public LifecycleItem(ILaunch testLaunch, String name) {
this.testLaunch = testLaunch;
this.name = name;
}

public void onStop() {
active = true;
end = Instant.now();
}

public void onStart() {
active = true;
start = Instant.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
import org.eclipse.debug.core.ILaunch;

public interface LifecycleListener {
void handle(int eventType, ILaunch launch);
void handle(int eventType, LifecycleItem item);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package ru.biatech.edt.junit.launcher.lifecycle;

import com.google.common.base.Strings;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import org.eclipse.debug.core.DebugEvent;
Expand All @@ -32,7 +31,6 @@
import ru.biatech.edt.junit.launcher.v8.LaunchHelper;
import ru.biatech.edt.junit.ui.JUnitMessages;

import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -76,8 +74,8 @@ public void removeTerminated() {

for (var item : monitor.monitoringItems.values()) {
if (!item.isActive()) {
removed.add(item.mainLaunch);
removed.add(item.testLaunch);
removed.add(item.getMainLaunch());
removed.add(item.getTestLaunch());
}
}

Expand All @@ -93,34 +91,32 @@ private void debug(String message) {
TestViewerPlugin.log().debug(message);
}

private void riseEvent(int eventType, MonitoringItem item) {
TestViewerPlugin.log().debug("Launch event: {0} for {1}", LifecycleEvent.getPresent(eventType), item.name);
private void riseEvent(int eventType, LifecycleItem item) {
TestViewerPlugin.log().debug("Launch event: {0} for {1}", LifecycleEvent.getPresent(eventType), item.getName());
if (LifecycleEvent.isStop(eventType)) {
try {
item.testLaunch.terminate();
item.getTestLaunch().terminate();
} catch (DebugException e) {
TestViewerPlugin.log().logError("Terminate test launch", e);
}
}
listeners.forEach(l -> l.handle(eventType, item.mainLaunch));
listeners.forEach(l -> l.handle(eventType, item));
}

private void onItemStart(MonitoringItem item) {
item.active = true;
item.start = Instant.now();
private void onItemStart(LifecycleItem item) {
item.onStart();
riseEvent(LifecycleEvent.START, item);
removeTerminated();
}

private void onItemStop(MonitoringItem item, int eventType) {
item.active = false;
item.end = Instant.now();
private void onItemStop(LifecycleItem item, int eventType) {
item.onStop();
riseEvent(eventType, item);
}

private static class LaunchMonitor implements ILaunchListener, IDebugEventSetListener {
ReentrantLock lock = new ReentrantLock();
Map<ILaunch, MonitoringItem> monitoringItems = new HashMap<>();
Map<ILaunch, LifecycleItem> monitoringItems = new HashMap<>();

@Override
public void handleDebugEvents(DebugEvent[] events) {
Expand All @@ -136,9 +132,8 @@ public void handleDebugEvents(DebugEvent[] events) {
if (monitoringItems.containsKey(launch)) {
var item = monitoringItems.get(launch);
handleProcesses(item);
if (item.active) {
debug("Finish " + item.name);
item.active = false;
if (item.isActive()) {
debug("Finish " + item.getName());
onTerminate(item, process);
}
}
Expand All @@ -156,8 +151,8 @@ public void launchRemoved(ILaunch launch) {
if (monitoringItems.containsKey(launch)) {
var item = monitoringItems.get(launch);
handleProcesses(item);
if (item.active) {
debug("canceled " + item.name);
if (item.isActive()) {
debug("canceled " + item.getName());
onItemStop(item, LifecycleEvent.CANCELED);
}
}
Expand All @@ -172,16 +167,14 @@ public void launchAdded(ILaunch launch) {
var configuration = launch.getLaunchConfiguration();

if (LaunchHelper.isRunTestConfiguration(configuration)) {
var item = new MonitoringItem();
item.testLaunch = launch;
item.name = configuration.getName();
var item = new LifecycleItem(launch, configuration.getName());
monitoringItems.put(launch, item);
onItemStart(item);
} else if (LaunchHelper.isOnecConfiguration(configuration) && !Strings.isNullOrEmpty(LaunchConfigurationAttributes.getTestKind(configuration))) {
var name = configuration.getName();
for (var item : monitoringItems.values()) {
if (name.contains(item.name)) {
item.mainLaunch = launch;
if (name.contains(item.getName())) {
item.setMainLaunch(launch);
handleProcesses(item);
monitoringItems.put(launch, item);
break;
Expand All @@ -199,12 +192,15 @@ public void launchChanged(ILaunch launch) {
}
}

private void handleProcesses(MonitoringItem item) {
if (item.testLaunch.getProcesses().length < item.mainLaunch.getProcesses().length) {
var processes = new HashSet<>(List.of(item.testLaunch.getProcesses()));
for (var process : item.mainLaunch.getProcesses()) {
private void handleProcesses(LifecycleItem item) {
if (item.getMainLaunch() == null) {
return;
}
if (item.getTestLaunch().getProcesses().length < item.getMainLaunch().getProcesses().length) {
var processes = new HashSet<>(List.of(item.getTestLaunch().getProcesses()));
for (var process : item.getMainLaunch().getProcesses()) {
if (!processes.contains(process)) {
item.testLaunch.addProcess(process);
item.getTestLaunch().addProcess(process);
}
}
}
Expand All @@ -218,27 +214,18 @@ private void onLaunchEvent(String eventName, ILaunch launch) {
debug(message);
}

private void onTerminate(MonitoringItem item, IProcess process) {
private void onTerminate(LifecycleItem item, IProcess process) {
int exitCode = 0;
try {
exitCode = process.getExitValue();
} catch (DebugException e) { /* do nothing*/ }
if (exitCode != 0) {
TestViewerPlugin.log().warning(JUnitMessages.JUnitLaunchListener_ProcessError, item.name, process.getLabel(), exitCode);
TestViewerPlugin.log().warning(JUnitMessages.JUnitLaunchListener_ProcessError, item.getName(), process.getLabel(), exitCode);
onItemStop(item, LifecycleEvent.FINISHED_WITH_ERROR);
} else {
onItemStop(item, LifecycleEvent.FINISHED);
}
}
}

@Getter
private static class MonitoringItem {
private ILaunch testLaunch;
private ILaunch mainLaunch;
private String name;
private boolean active = true;
private Instant start;
private Instant end;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public static void setTestMethods(ILaunchConfigurationWorkingCopy configuration,
configuration.setAttribute(TEST_FULL_NAME, value);
}

public static void clearFilter(ILaunchConfigurationWorkingCopy configuration) {
configuration.removeAttribute(TEST_FULL_NAME);
configuration.removeAttribute(TEST_MODULE);
configuration.removeAttribute(TEST_EXTENSION);
}

public static List<String> getTestMethods(ILaunchConfiguration configuration) {
try {
return configuration.getAttribute(TEST_FULL_NAME, (List<String>) null);
Expand All @@ -91,7 +97,7 @@ public static String getTestModuleName(ILaunchConfiguration configuration) {
return getAttribute(configuration, TEST_MODULE);
}

public static String getTestKind(ILaunchConfiguration configuration){
public static String getTestKind(ILaunchConfiguration configuration) {
return getAttribute(configuration, ATTR_TEST_RUNNER_KIND);
}

Expand All @@ -102,4 +108,12 @@ public static String getAttribute(ILaunchConfiguration configuration, String att
throw new RuntimeException(e);
}
}

public static String getWorkPath(ILaunchConfiguration configuration) {
return getAttribute(configuration, WORK_PATH);
}

public static String getProject(ILaunchConfiguration configuration) {
return getAttribute(configuration, PROJECT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public List<String> getTestModules(IExtensionProject extensionProject) {
.collect(Collectors.toList());
}

public Path getWorkPath(ILaunchConfiguration configuration) {
var reportLocation = Platform.getStateLocation(TestViewerPlugin.getBundleContext().getBundle()).append(configuration.getName());
public Path getWorkPath(String name) {
var reportLocation = Platform.getStateLocation(TestViewerPlugin.getBundleContext().getBundle()).append(name);
var path = reportLocation.toFile().toPath();
try {
Files.createDirectories(path);
Expand All @@ -165,7 +165,7 @@ public void runTestMethod(String moduleName, String methodName, String launchMod
TestViewerPlugin.log().logError(e);
return;
}

LaunchConfigurationAttributes.clearFilter(copy);
LaunchConfigurationAttributes.setTestMethods(copy, List.of(methodFullName));
DebugUITools.launch(copy, launchMode);
}
Expand All @@ -181,6 +181,11 @@ public ITestKind getTestRunnerKind(ILaunchConfiguration launchConfiguration) {
return ITestKind.NULL;
}

public Path getReportPath(ILaunchConfiguration configuration) {
var workPath = LaunchConfigurationAttributes.getWorkPath(configuration);
return Path.of(workPath, REPORT_FILE_NAME);
}

public IV8Project getProject(ILaunchConfiguration configuration) {
// TODO
// try {
Expand Down
Loading

0 comments on commit 5383cf6

Please sign in to comment.