JavaDebugger server side tests (#3705)

6.19.x
Anatoliy Bazko 2017-01-13 13:31:06 +02:00 committed by GitHub
parent d7faa2e67b
commit e3d59cd8f7
13 changed files with 597 additions and 82 deletions

View File

@ -26,10 +26,6 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-elemental</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
@ -44,15 +40,11 @@
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project</artifactId>
<artifactId>che-core-api-debug-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
<artifactId>che-core-api-model</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
@ -66,10 +58,6 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-app</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-ui</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-debugger-ide</artifactId>
@ -78,6 +66,10 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-java-ext-lang-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-java-ext-lang-shared</artifactId>
</dependency>
<dependency>
<groupId>org.vectomatic</groupId>
<artifactId>lib-gwt-svg</artifactId>
@ -97,30 +89,23 @@
<artifactId>gwtmockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.gwt-test-utils</groupId>
<artifactId>gwt-test-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockitong</groupId>
<artifactId>mockitong</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/java</testSourceDirectory>
<outputDirectory>target/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
@ -129,24 +114,7 @@
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>analyze</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>

View File

@ -16,13 +16,13 @@ import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.DebugConfiguration;
import org.eclipse.che.ide.api.debug.DebugConfigurationPage;
import org.eclipse.che.ide.api.machine.DevMachine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import static java.lang.Boolean.TRUE;
import static org.mockito.Matchers.eq;
@ -32,7 +32,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** @author Artem Zatsarynnyi */
@RunWith(MockitoJUnitRunner.class)
@Listeners(MockitoTestNGListener.class)
public class JavaDebugConfigurationPagePresenterTest {
private static final String HOST = "localhost";
@ -51,7 +51,7 @@ public class JavaDebugConfigurationPagePresenterTest {
@InjectMocks
private JavaDebugConfigurationPagePresenter pagePresenter;
@Before
@BeforeMethod
public void setUp() {
when(configuration.getHost()).thenReturn(HOST);
when(configuration.getPort()).thenReturn(PORT);

View File

@ -10,22 +10,21 @@
*******************************************************************************/
package org.eclipse.che.plugin.jdb.ide.configuration;
import com.google.gwtmockito.GwtMockitoTestRunner;
import org.eclipse.che.ide.api.debug.DebugConfiguration;
import org.eclipse.che.ide.api.debug.DebugConfigurationPage;
import org.eclipse.che.ide.api.icon.IconRegistry;
import org.eclipse.che.plugin.jdb.ide.JavaDebuggerResources;
import org.eclipse.che.plugin.jdb.ide.debug.JavaDebugger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import static org.junit.Assert.assertEquals;
import static org.testng.Assert.assertEquals;
/** @author Artem Zatsarynnyi */
@RunWith(GwtMockitoTestRunner.class)
@Listeners(MockitoTestNGListener.class)
public class JavaDebugConfigurationTypeTest {
@Mock

View File

@ -22,9 +22,16 @@
<packaging>jar</packaging>
<name>Che Plugin :: Java :: Java Debugger Server</name>
<properties>
<docker.showLogs>true</docker.showLogs>
<findbugs.excludeFilterFile>${project.build.testSourceDirectory}/../resources/findbugs-exclude.xml</findbugs.excludeFilterFile>
<java.image.name>java-8-jdk:debugger</java.image.name>
<run.cmd>java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -Xmx128m com.HelloWorld</run.cmd>
</properties>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
@ -45,6 +52,10 @@
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-debug</artifactId>
@ -79,6 +90,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>org.eclipse.core.resources</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>org.eclipse.jdt.ui</artifactId>
@ -99,7 +114,22 @@
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-test</artifactId>
<artifactId>che-core-api-model</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace-shared</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-java-ext-lang-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@ -136,6 +166,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.mycila</groupId>
@ -145,9 +180,100 @@
<exclude>**/*.tokens</exclude>
<exclude>**/*.g</exclude>
<exclude>**/*.txt</exclude>
<exclude>**/*.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<debug.port>${debug.port}</debug.port>
</systemPropertyVariables>
<includes>
<include>**/JavaDebuggerTest.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<executions>
<execution>
<id>build</id>
<phase>process-test-resources</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<images>
<image>
<alias>java</alias>
<name>${java.image.name}</name>
<build>
<from>java:8-jdk</from>
<assembly>
<descriptor>${project.build.testOutputDirectory}/docker-assembly.xml</descriptor>
</assembly>
<workdir>maven</workdir>
</build>
<run>
<ports>
<port>debug.port:8001</port>
</ports>
<wait>
<log>Listening for transport dt_socket at address: 8001</log>
<time>20000</time>
</wait>
<restartPolicy>
<name>always</name>
</restartPolicy>
<cmd>
<shell>${run.cmd}</shell>
</cmd>
</run>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -20,7 +20,7 @@ import java.util.Comparator;
*
* @author andrew00x
*/
final class BreakPointComparator implements Comparator<Breakpoint> {
public final class BreakPointComparator implements Comparator<Breakpoint> {
@Override
public int compare(Breakpoint o1, Breakpoint o2) {
String className1 = o1.getLocation().getTarget();

View File

@ -47,8 +47,10 @@ import org.eclipse.che.api.debug.shared.model.action.StartAction;
import org.eclipse.che.api.debug.shared.model.action.StepIntoAction;
import org.eclipse.che.api.debug.shared.model.action.StepOutAction;
import org.eclipse.che.api.debug.shared.model.action.StepOverAction;
import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl;
import org.eclipse.che.api.debug.shared.model.impl.DebuggerInfoImpl;
import org.eclipse.che.api.debug.shared.model.impl.FieldImpl;
import org.eclipse.che.api.debug.shared.model.impl.LocationImpl;
import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl;
import org.eclipse.che.api.debug.shared.model.impl.VariableImpl;
import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl;
@ -203,7 +205,6 @@ public class JavaDebugger implements EventsHandler, Debugger {
@Override
public void disconnect() throws DebuggerException {
resume(newDto(ResumeActionDto.class));
vm.dispose();
LOG.debug("Close connection to {}:{}", host, port);
}
@ -259,7 +260,12 @@ public class JavaDebugger implements EventsHandler, Debugger {
throw new DebuggerException(e.getMessage(), e);
}
debuggerCallback.onEvent(new BreakpointActivatedEventImpl(breakpoint));
debuggerCallback.onEvent(
new BreakpointActivatedEventImpl(
new BreakpointImpl(breakpoint.getLocation(),
true,
breakpoint.getCondition())));
LOG.debug("Add breakpoint: {}", location);
}
@ -290,7 +296,7 @@ public class JavaDebugger implements EventsHandler, Debugger {
classPrepareRequests.put(className, request);
}
LOG.debug("Deferred breakpoint: {}", breakpoint.getLocation());
LOG.debug("Deferred breakpoint: {}", breakpoint.getLocation().toString());
}
@Override
@ -342,13 +348,15 @@ public class JavaDebugger implements EventsHandler, Debugger {
@Override
public void resume(ResumeAction action) throws DebuggerException {
lock.lock();
try {
invalidateCurrentThread();
vm.resume();
LOG.debug("Resume VM");
} catch (VMCannotBeModifiedException e) {
throw new DebuggerException(e.getMessage(), e);
} finally {
resetCurrentThread();
lock.unlock();
}
}
@ -386,7 +394,7 @@ public class JavaDebugger implements EventsHandler, Debugger {
.withVariablePath(
newDto(VariablePathDto.class)
.withPath(singletonList(var.getName()))
)
)
.withPrimitive(var.isPrimitive()));
}
return dump;
@ -569,7 +577,13 @@ public class JavaDebugger implements EventsHandler, Debugger {
if (hitBreakpoint) {
com.sun.jdi.Location jdiLocation = event.location();
Location location = debuggerUtil.getLocation(jdiLocation);
Location location;
try {
location = debuggerUtil.getLocation(jdiLocation);
} catch (DebuggerException e) {
location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber());
}
debuggerCallback.onEvent(new SuspendEventImpl(location));
}
@ -666,12 +680,12 @@ public class JavaDebugger implements EventsHandler, Debugger {
try {
return parser.evaluate(new Evaluator(vm, getCurrentThread()));
} catch (ExpressionException e) {
throw new DebuggerException(e.getMessage());
throw new DebuggerException(e.getMessage(), e);
} finally {
final long endTime = System.currentTimeMillis();
LOG.debug("==>> Evaluate time: {} ms", (endTime - startTime));
// Evaluation of expression may update state of frame.
resetCurrentFrame();
invalidateCurrentFrame();
}
}
@ -699,13 +713,13 @@ public class JavaDebugger implements EventsHandler, Debugger {
thread = t;
}
private void resetCurrentFrame() {
private void invalidateCurrentFrame() {
stackFrame = null;
}
private void resetCurrentThread() {
this.stackFrame = null;
private void invalidateCurrentThread() {
this.thread = null;
invalidateCurrentFrame();
}
private EventRequestManager getEventManager() throws DebuggerException {

View File

@ -10,16 +10,14 @@
*******************************************************************************/
package org.eclipse.che.plugin.jdb.server.utils;
import javax.validation.constraints.NotNull;
import org.eclipse.che.api.debug.shared.model.Location;
import org.eclipse.che.api.debug.shared.model.impl.LocationImpl;
import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
@ -37,6 +35,7 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IRegion;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
@ -126,7 +125,6 @@ public class JavaDebuggerUtils {
List<IType> result = new ArrayList<>();
SearchEngine searchEngine = new SearchEngine();
searchEngine.searchAllTypeNames(packages,
names,
scope,

View File

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@ -0,0 +1,352 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* 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
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.jdb.server;
import com.google.common.collect.ImmutableMap;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.model.project.ProjectConfig;
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.debug.shared.model.Breakpoint;
import org.eclipse.che.api.debug.shared.model.DebuggerInfo;
import org.eclipse.che.api.debug.shared.model.Location;
import org.eclipse.che.api.debug.shared.model.StackFrameDump;
import org.eclipse.che.api.debug.shared.model.Variable;
import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent;
import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent;
import org.eclipse.che.api.debug.shared.model.event.DisconnectEvent;
import org.eclipse.che.api.debug.shared.model.event.SuspendEvent;
import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl;
import org.eclipse.che.api.debug.shared.model.impl.LocationImpl;
import org.eclipse.che.api.debug.shared.model.impl.VariableImpl;
import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl;
import org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl;
import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl;
import org.eclipse.che.api.debug.shared.model.impl.action.StepIntoActionImpl;
import org.eclipse.che.api.debug.shared.model.impl.action.StepOutActionImpl;
import org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl;
import org.eclipse.che.api.debugger.server.Debugger;
import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;
import org.eclipse.che.api.project.server.ProjectManager;
import org.eclipse.che.api.project.server.ProjectRegistry;
import org.eclipse.che.api.project.server.WorkspaceProjectsSyncer;
import org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry;
import org.eclipse.che.api.project.server.importer.ProjectImporterRegistry;
import org.eclipse.che.api.project.server.type.ProjectTypeRegistry;
import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher;
import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler;
import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider;
import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider;
import org.eclipse.che.api.vfs.watcher.FileWatcherManager;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
import org.eclipse.che.plugin.java.server.projecttype.JavaProjectType;
import org.eclipse.che.plugin.java.server.projecttype.JavaValueProviderFactory;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
import java.nio.file.PathMatcher;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.stream.Collectors;
import static java.util.Collections.singletonList;
import static org.mockito.Mockito.mock;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
/**
* @author Anatolii Bazko
*/
public class JavaDebuggerTest {
private Debugger debugger;
private BlockingQueue<DebuggerEvent> events;
@Test(priority = 1)
public void testGetInfo() throws Exception {
DebuggerInfo info = debugger.getInfo();
assertEquals(info.getHost(), "localhost");
assertEquals(info.getPort(), Integer.parseInt(System.getProperty("debug.port")));
assertNotNull(info.getName());
assertNotNull(info.getVersion());
}
@Test(priority = 2)
public void testStartDebugger() throws Exception {
BreakpointImpl breakpoint = new BreakpointImpl(new LocationImpl("com.HelloWorld", 17), false, null);
debugger.start(new StartActionImpl(singletonList(breakpoint)));
DebuggerEvent debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof BreakpointActivatedEvent);
debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof SuspendEvent);
Location location = ((SuspendEvent)debuggerEvent).getLocation();
assertEquals(location.getLineNumber(), 17);
assertEquals(location.getTarget(), "com.HelloWorld");
}
@Test(priority = 3)
public void testAddBreakpoint() throws Exception {
int breakpointsCount = debugger.getAllBreakpoints().size();
debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 18), false, null));
DebuggerEvent debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof BreakpointActivatedEvent);
Breakpoint breakpoint = ((BreakpointActivatedEvent)debuggerEvent).getBreakpoint();
assertEquals(breakpoint.getLocation().getLineNumber(), 18);
assertEquals(breakpoint.getLocation().getTarget(), "com.HelloWorld");
assertTrue(breakpoint.isEnabled());
assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount + 1);
}
@Test(priority = 5, expectedExceptions = DebuggerException.class)
public void testAddBreakpointToUnExistedLocation() throws Exception {
debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 1), false, null));
}
@Test(priority = 6)
public void testRemoveBreakpoint() throws Exception {
debugger.deleteBreakpoint(new LocationImpl("com.HelloWorld", 17));
assertEquals(debugger.getAllBreakpoints().size(), 1);
}
@Test(priority = 7)
public void testRemoveUnExistedBreakpoint() throws Exception {
int breakpointsCount = debugger.getAllBreakpoints().size();
debugger.deleteBreakpoint(new LocationImpl("com.HelloWorld", 2));
assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount);
}
@Test(priority = 8)
public void testGetAllBreakpoints() throws Exception {
assertFalse(debugger.getAllBreakpoints().isEmpty());
debugger.deleteAllBreakpoints();
assertTrue(debugger.getAllBreakpoints().isEmpty());
debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 18), false, null));
DebuggerEvent debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof BreakpointActivatedEvent);
assertEquals(debugger.getAllBreakpoints().size(), 1);
Breakpoint breakpoint = debugger.getAllBreakpoints().get(0);
assertEquals(breakpoint.getLocation().getLineNumber(), 18);
assertEquals(breakpoint.getLocation().getTarget(), "com.HelloWorld");
assertTrue(breakpoint.isEnabled());
}
@Test(priority = 9)
public void testSteps() throws Exception {
debugger.deleteAllBreakpoints();
debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 20), false, null));
assertTrue(events.take() instanceof BreakpointActivatedEvent);
debugger.resume(new ResumeActionImpl());
DebuggerEvent debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof SuspendEvent);
Location location = ((SuspendEvent)debuggerEvent).getLocation();
assertEquals(location.getTarget(), "com.HelloWorld");
assertEquals(location.getLineNumber(), 20);
assertEquals(location.getExternalResourceId(), -1);
assertEquals(location.getResourceProjectPath(), "/test");
assertEquals(location.getResourcePath(), "/test/src/com/HelloWorld.java");
debugger.stepInto(new StepIntoActionImpl());
debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof SuspendEvent);
location = ((SuspendEvent)debuggerEvent).getLocation();
assertEquals(location.getTarget(), "com.HelloWorld");
assertEquals(location.getLineNumber(), 28);
debugger.stepOut(new StepOutActionImpl());
debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof SuspendEvent);
location = ((SuspendEvent)debuggerEvent).getLocation();
assertEquals(location.getTarget(), "com.HelloWorld");
assertEquals(location.getLineNumber(), 20);
debugger.stepOver(new StepOverActionImpl());
debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof SuspendEvent);
location = ((SuspendEvent)debuggerEvent).getLocation();
assertEquals(location.getTarget(), "com.HelloWorld");
assertEquals(location.getLineNumber(), 21);
debugger.stepOver(new StepOverActionImpl());
debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof SuspendEvent);
location = ((SuspendEvent)debuggerEvent).getLocation();
assertEquals(location.getTarget(), "com.HelloWorld");
assertEquals(location.getLineNumber(), 23);
debugger.stepOver(new StepOverActionImpl());
debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof SuspendEvent);
location = ((SuspendEvent)debuggerEvent).getLocation();
assertEquals(location.getTarget(), "com.HelloWorld");
assertEquals(location.getLineNumber(), 24);
}
@Test(priority = 10)
public void testEvaluateExpression() throws Exception {
assertEquals(debugger.evaluate("2+2"), "4");
assertEquals(debugger.evaluate("\"hello\""), "\"hello\"");
assertEquals(debugger.evaluate("test"), "\"hello\"");
}
@Test(priority = 11)
public void testSetAndGetValue() throws Exception {
assertEquals(debugger.getValue(new VariablePathImpl("test")).getValue(), "\"hello\"");
assertEquals(debugger.getValue(new VariablePathImpl("msg")).getValue(), "\"Hello, debugger!\"");
debugger.setValue(new VariableImpl("\"new hello\"", (new VariablePathImpl("test"))));
assertEquals(debugger.getValue(new VariablePathImpl("test")).getValue(), "\"new hello\"");
StackFrameDump stackFrameDump = debugger.dumpStackFrame();
Set<String> vars = stackFrameDump.getVariables().stream().map(Variable::getName).collect(Collectors.toSet());
assertTrue(vars.contains("args"));
assertTrue(vars.contains("msg"));
assertTrue(vars.contains("test"));
}
@Test(priority = 12)
public void testDisconnect() throws Exception {
debugger.disconnect();
DebuggerEvent debuggerEvent = events.take();
assertTrue(debuggerEvent instanceof DisconnectEvent);
}
@BeforeClass
protected void initProjectApi() throws Exception {
TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder(new ArrayList<>());
File root = new File("target/test-classes/workspace");
assertTrue(root.exists());
File indexDir = new File("target/fs_index");
assertTrue(indexDir.mkdirs());
Set<PathMatcher> filters = new HashSet<>();
filters.add(path -> true);
FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
EventService eventService = new EventService();
LocalVirtualFileSystemProvider vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory()));
ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
ProjectRegistry projectRegistry = new ProjectRegistry(workspaceHolder,
vfsProvider,
projectTypeRegistry,
projectHandlerRegistry,
eventService);
projectRegistry.initProjects();
ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
ProjectManager projectManager = new ProjectManager(vfsProvider,
eventService,
projectTypeRegistry,
projectRegistry,
projectHandlerRegistry,
importerRegistry,
fileWatcherNotificationHandler,
fileTreeWatcher,
workspaceHolder,
mock(FileWatcherManager.class));
ResourcesPlugin resourcesPlugin =
new ResourcesPlugin("target/index",
root.getAbsolutePath(),
() -> projectRegistry,
() -> projectManager);
resourcesPlugin.start();
JavaPlugin javaPlugin = new JavaPlugin(root.getAbsolutePath() + "/.settings", resourcesPlugin, projectRegistry);
javaPlugin.start();
projectRegistry.setProjectType("test", "java", false);
JavaModelManager.getDeltaState().initializeRoots(true);
events = new ArrayBlockingQueue<>(10);
Map<String, String> connectionProperties = ImmutableMap.of("host", "localhost",
"port", System.getProperty("debug.port"));
JavaDebuggerFactory factory = new JavaDebuggerFactory();
debugger = factory.create(connectionProperties, events::add);
}
private static class TestWorkspaceHolder extends WorkspaceProjectsSyncer {
private List<ProjectConfigDto> projects;
TestWorkspaceHolder() {
this.projects = new ArrayList<>();
}
TestWorkspaceHolder(List<ProjectConfigDto> projects) {
this.projects = projects;
}
@Override
public List<? extends ProjectConfig> getProjects() {
return projects;
}
@Override
public String getWorkspaceId() {
return "id";
}
@Override
protected void addProject(ProjectConfig project) throws ServerException {}
@Override
protected void updateProject(ProjectConfig project) throws ServerException {}
@Override
protected void removeProject(ProjectConfig project) throws ServerException {}
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2017 Codenvy, S.A.
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
Contributors:
Codenvy, S.A. - initial API and implementation
-->
<assembly>
<files>
<file>
<source>${project.build.testOutputDirectory}/workspace/test/out/com/HelloWorld.class</source>
<outputDirectory>./com</outputDirectory>
</file>
</files>
</assembly>

View File

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* 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
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package com;
public class HelloWorld {
public static void main(String[] args) {
String test = "hello";
System.out.println(test);
String msg = say("world");
System.out.println(msg);
msg = say("debugger");
System.out.println(msg);
}
private static String say(String message) {
return "Hello, " + message + "!";
}
}

View File

@ -103,4 +103,16 @@ public class LocationImpl implements Location {
result = 31 * result + Objects.hashCode(resourceProjectPath);
return result;
}
@Override
public String toString() {
return "LocationImpl{" +
"target='" + target + '\'' +
", lineNumber=" + lineNumber +
", resourcePath='" + resourcePath + '\'' +
", externalResource=" + externalResource +
", externalResourceId=" + externalResourceId +
", resourceProjectPath='" + resourceProjectPath + '\'' +
'}';
}
}

View File

@ -270,7 +270,6 @@
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.15.16</version>
<executions>
<execution>
<id>start</id>