diff --git a/src/debug/debug-proxy.js b/src/debug/debug-proxy.js index 7f764cf..98780c6 100644 --- a/src/debug/debug-proxy.js +++ b/src/debug/debug-proxy.js @@ -22,91 +22,195 @@ const initialProject = (session, rootPath) => { throw new Error('Cannot find com.microsoft.java.debug.plugin-*.jar'); } console.log('using', jars); - let configObj = { - "jsonrpc": "2.0", - "id": 0, - "method": "initialize", - "params": { - "processId": process.pid, - "rootPath": rootPath, - "rootUri": 'file:///' + myEncodeURI(rootPath), - "capabilities": { - "workspace": { - "didChangeConfiguration": { - "dynamicRegistration": true - }, - "didChangeWatchedFiles": { - "dynamicRegistration": true - }, - "symbol": { - "dynamicRegistration": true + let configObj; + if (rootPath.testName === "multi-root") { + configObj = { + "jsonrpc": "2.0", + "id": 0, + "method": "initialize", + "params": { + "processId": process.pid, + "rootPath": rootPath.petclinicPath, + "rootUri": 'file:///' + myEncodeURI(rootPath.petclinicPath), + "capabilities": { + "workspace": { + "didChangeConfiguration": { + "dynamicRegistration": true + }, + "didChangeWatchedFiles": { + "dynamicRegistration": true + }, + "symbol": { + "dynamicRegistration": true + }, + "executeCommand": { + "dynamicRegistration": true + } }, - "executeCommand": { - "dynamicRegistration": true + "textDocument": { + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + }, + "completion": { + "dynamicRegistration": true, + "completionItem": { + "snippetSupport": true + } + }, + "hover": { + "dynamicRegistration": true + }, + "signatureHelp": { + "dynamicRegistration": true + }, + "definition": { + "dynamicRegistration": true + }, + "references": { + "dynamicRegistration": true + }, + "documentHighlight": { + "dynamicRegistration": true + }, + "documentSymbol": { + "dynamicRegistration": true + }, + "codeAction": { + "dynamicRegistration": true + }, + "codeLens": { + "dynamicRegistration": true + }, + "formatting": { + "dynamicRegistration": true + }, + "rangeFormatting": { + "dynamicRegistration": true + }, + "onTypeFormatting": { + "dynamicRegistration": true + }, + "rename": { + "dynamicRegistration": true + }, + "documentLink": { + "dynamicRegistration": true + } } }, - "textDocument": { - "synchronization": { - "dynamicRegistration": true, - "willSave": true, - "willSaveWaitUntil": true, - "didSave": true + "initializationOptions": { + "bundles": [ + jars + ], + "workspaceFolders": [ + 'file:///' + myEncodeURI(rootPath.petclinicPath), + 'file:///' + myEncodeURI(rootPath.todoPath) + ] + }, + "trace": "off", + "workspaceFolders": [ + { + "uri": 'file:///' + myEncodeURI(rootPath.petclinicPath), + "name": "spring-petclinic" }, - "completion": { - "dynamicRegistration": true, - "completionItem": { - "snippetSupport": true + { + "uri": 'file:///' + myEncodeURI(rootPath.todoPath), + "name": "todo-app-java-on-azure" + } + ] + } + }; + } + else { + configObj = { + "jsonrpc": "2.0", + "id": 0, + "method": "initialize", + "params": { + "processId": process.pid, + "rootPath": rootPath, + "rootUri": 'file:///' + myEncodeURI(rootPath), + "capabilities": { + "workspace": { + "didChangeConfiguration": { + "dynamicRegistration": true + }, + "didChangeWatchedFiles": { + "dynamicRegistration": true + }, + "symbol": { + "dynamicRegistration": true + }, + "executeCommand": { + "dynamicRegistration": true } }, - "hover": { - "dynamicRegistration": true - }, - "signatureHelp": { - "dynamicRegistration": true - }, - "definition": { - "dynamicRegistration": true - }, - "references": { - "dynamicRegistration": true - }, - "documentHighlight": { - "dynamicRegistration": true - }, - "documentSymbol": { - "dynamicRegistration": true - }, - "codeAction": { - "dynamicRegistration": true - }, - "codeLens": { - "dynamicRegistration": true - }, - "formatting": { - "dynamicRegistration": true - }, - "rangeFormatting": { - "dynamicRegistration": true - }, - "onTypeFormatting": { - "dynamicRegistration": true - }, - "rename": { - "dynamicRegistration": true - }, - "documentLink": { - "dynamicRegistration": true + "textDocument": { + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + }, + "completion": { + "dynamicRegistration": true, + "completionItem": { + "snippetSupport": true + } + }, + "hover": { + "dynamicRegistration": true + }, + "signatureHelp": { + "dynamicRegistration": true + }, + "definition": { + "dynamicRegistration": true + }, + "references": { + "dynamicRegistration": true + }, + "documentHighlight": { + "dynamicRegistration": true + }, + "documentSymbol": { + "dynamicRegistration": true + }, + "codeAction": { + "dynamicRegistration": true + }, + "codeLens": { + "dynamicRegistration": true + }, + "formatting": { + "dynamicRegistration": true + }, + "rangeFormatting": { + "dynamicRegistration": true + }, + "onTypeFormatting": { + "dynamicRegistration": true + }, + "rename": { + "dynamicRegistration": true + }, + "documentLink": { + "dynamicRegistration": true + } } - } - }, - "initializationOptions": { - "bundles": [ - jars - ] - }, - "trace": "off" - } - }; + }, + "initializationOptions": { + "bundles": [ + jars + ] + }, + "trace": "off" + } + }; + } // console.log(JSON.stringify(configObj, null, 4)) session.send(configObj); }; @@ -131,7 +235,12 @@ export function startDebugServer(projectRoot, userSettings, config) { sock.remoteAddress + ' ' + sock.remotePort); session = null; }); - initialProject(session, projectRoot); + if (config.testName === "multi-root") { + initialProject(session, config); + } + else { + initialProject(session, projectRoot); + } session.on('ready', (data) => { console.log('ready', data); session.send({ @@ -171,7 +280,23 @@ export function startDebugServer(projectRoot, userSettings, config) { if (data.id === 'resolveMainClass') { console.log('Resolve mainClass result----> ', data.result); console.log('Resolve mainClass data id----> ', data.id); - + if (config.testName === "multi-root") { + for (let result of data.result) { + if (result.projectName === "spring-petclinic") { + Object.defineProperties(config, { + projectName: { + value: result.projectName, + writable: false + }, + mainClass: { + value: result.mainClass, + writable: false + } + }); + break; + } + } + } //resovle mainclass let resolveMainClassResult = data.result; let mainClass = new Array(); @@ -215,8 +340,8 @@ export function startDebugServer(projectRoot, userSettings, config) { session.on('jsonrpc', (data) => { if (data.id === 'resolveClasspath' && config.projectName) { - console.log('Resolve resolveClasspath result----> ', data.result); - console.log('Resolve resolveClasspath data id----> ', data.id); + //console.log('Resolve resolveClasspath result----> ', data.result); + //console.log('Resolve resolveClasspath data id----> ', data.id); resolveData.push(data.result); let resovleClasspathResult = data.result; if (!config.classPath) { diff --git a/src/debug/multiroot-test.js b/src/debug/multiroot-test.js index b7432a9..02888d1 100644 --- a/src/debug/multiroot-test.js +++ b/src/debug/multiroot-test.js @@ -2,233 +2,85 @@ import chai from 'chai' import path from 'path' import * as utils from './test-utils' chai.should(); -import { ROOT, LANGUAGE_SERVER_ROOT, LANGUAGE_SERVER_WORKSPACE } from './constants' -import { startLS, isLanguageServerStarted, killLanguageServer } from './jdt-ls-starter' +import { ROOT, LANGUAGE_SERVER_ROOT, LANGUAGE_SERVER_WORKSPACE } from './constants'; import fs from 'fs' import { assert } from 'chai' -import net, { Socket } from 'net'; -import DebugSession from './debug-session' -import mkdirp from 'mkdirp' -import glob from 'glob' import { execSync } from 'child_process' -var rimraf = require('rimraf'); -const HOST = '127.0.0.1'; -const PORT = 3333; -let server; - -describe('multi-root test', () => { +let petclinicpro; +let todopro; +describe('MultiRoot test', () => { + let config; let DATA_ROOT; - let promise2; - let another_root; - let socket; - + let debugEngine; const projectPath = path.join(ROOT, "25.multi-root"); - if (!fs.existsSync(projectPath)) { - console.log("****", "Clone project"); - let downloadCmd = `cd ${ROOT}` + '&& mkdir 25.multi-root' + '&& cd 25.multi-root' + '&& git clone https://github.com/spring-projects/spring-petclinic.git'; - let downloadCmd1 = `cd ${projectPath}` + '&& git clone https://github.com/Microsoft/todo-app-java-on-azure.git'; - execSync(downloadCmd, { stdio: [0, 1, 2] }); - if (fs.existsSync(projectPath)) { - execSync(downloadCmd1, { stdio: [0, 1, 2] }); + beforeEach(function () { + config = new MultiRoot(); + petclinicpro = path.join(config.petclinicPath, '.project'); + todopro = path.join(config.todoPath, '.project'); + if (!fs.existsSync(projectPath)) { + console.log("****", "Clone project"); + let downloadCmd = `cd ${ROOT}` + '&& mkdir 25.multi-root' + '&& cd 25.multi-root' + '&& git clone https://github.com/spring-projects/spring-petclinic.git'; + let downloadCmd1 = `cd ${projectPath}` + '&& git clone https://github.com/Microsoft/todo-app-java-on-azure.git'; + execSync(downloadCmd, { stdio: [0, 1, 2] }); + if (fs.existsSync(projectPath)) { + execSync(downloadCmd1, { stdio: [0, 1, 2] }); + } + console.log("****", "Clone finished"); } - console.log("****", "Clone finished"); + assert(!(fs.existsSync(petclinicpro) || fs.existsSync(todopro))); + this.timeout(1000 * 20); + (async () => { + debugEngine = await utils.createDebugEngine(config.petclinicPath, LANGUAGE_SERVER_ROOT, LANGUAGE_SERVER_WORKSPACE, config); + debugEngine.close(); + + })(); + + }); + it('should pass MultiRoot test.', function () { + this.timeout(1000 * 50); + (async ()=>{ + console.log("MultiRoot test started"); + })(); + console.log("MultiRoot test started"); + }); +}); + +class MultiRoot { + + get testName() { + return 'multi-root'; } - DATA_ROOT = path.join(ROOT, "25.multi-root/spring-petclinic"); - another_root = path.join(ROOT, "25.multi-root/todo-app-java-on-azure"); - let path1 = path.join(DATA_ROOT, '.project'); - let path2 = path.join(another_root, '.project'); - const myEncodeURI = (url) => { - return encodeURIComponent(url.replace(/\\/g, '/')); - }; - const initialProject = (session, rootPath, anotherPath) => { - let jars = glob.sync(path.normalize(path.join(__dirname, '../../../vscode-java-debug/server/com.microsoft.java.debug.plugin-*.jar')).replace(/\\/g, '/')); - if (jars && jars.length) { - jars = jars[0]; - } else { - throw new Error('Cannot find com.microsoft.java.debug.plugin-*.jar'); - } - console.log('using', jars); - let configObj = { - "jsonrpc": "2.0", - "id": 0, - "method": "initialize", - "params": { - "processId": process.pid, - "rootPath": rootPath, - "rootUri": 'file:///' + myEncodeURI(rootPath), - "capabilities": { - "workspace": { - "didChangeConfiguration": { - "dynamicRegistration": true - }, - "didChangeWatchedFiles": { - "dynamicRegistration": true - }, - "symbol": { - "dynamicRegistration": true - }, - "executeCommand": { - "dynamicRegistration": true - } - }, - "textDocument": { - "synchronization": { - "dynamicRegistration": true, - "willSave": true, - "willSaveWaitUntil": true, - "didSave": true - }, - "completion": { - "dynamicRegistration": true, - "completionItem": { - "snippetSupport": true - } - }, - "hover": { - "dynamicRegistration": true - }, - "signatureHelp": { - "dynamicRegistration": true - }, - "definition": { - "dynamicRegistration": true - }, - "references": { - "dynamicRegistration": true - }, - "documentHighlight": { - "dynamicRegistration": true - }, - "documentSymbol": { - "dynamicRegistration": true - }, - "codeAction": { - "dynamicRegistration": true - }, - "codeLens": { - "dynamicRegistration": true - }, - "formatting": { - "dynamicRegistration": true - }, - "rangeFormatting": { - "dynamicRegistration": true - }, - "onTypeFormatting": { - "dynamicRegistration": true - }, - "rename": { - "dynamicRegistration": true - }, - "documentLink": { - "dynamicRegistration": true - } - } - }, - "initializationOptions": { - "bundles": [ - jars - ], - "workspaceFolders": [ - 'file:///' + myEncodeURI(rootPath), - 'file:///' + myEncodeURI(anotherPath) - ] - }, - "trace": "off", - "workspaceFolders": [ - { - "uri": 'file:///' + myEncodeURI(rootPath), - "name": "spring-petclinic" - }, - { - "uri": 'file:///' + myEncodeURI(anotherPath), - "name": "todo-app-java-on-azure" - } - ] - } - }; - session.send(configObj); - }; - const initializeProject = function (rootPath, anotherPath) { - server = net.createServer(); - server.listen(PORT, HOST, () => { - console.log('Server listening on ' + - server.address().address + ':' + server.address().port); - }); + get petclinicPath() { + return path.join(ROOT, '25.multi-root/spring-petclinic'); + } - server.on('connection', (sock) => { - socket = sock; - console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort); - let session = new DebugSession(sock, sock); - let resolveData = new Array(); - sock.on('error', err => { - if (err) - console.log('-------------------', err); - }); - sock.on('close', (data) => { - console.log('CLOSED: ' + - sock.remoteAddress + ' ' + sock.remotePort); - session = null; - }); - initialProject(session, rootPath, anotherPath); - session.on('ready', (data) => { - console.log("verify target exesits"); - assert(fs.existsSync(path1) && fs.existsSync(path2)); - session.send({ - "jsonrpc": "2.0", - "id": "resolveMainClass", - "method": "workspace/executeCommand", - "params": { "command": "vscode.java.resolveMainClass", "arguments": [] } - }); - }); - session.on('jsonrpc', (data) => { - if (data.id === 'resolveMainClass') { - console.log("remianclass****", data.result); - assert(data.result.length === 2); - for (let result of data.result) { - assert(result.mainClass); - assert(result.projectName); - if (result.mainClass === "org.springframework.samples.petclinic.PetClinicApplication") { - assert(result.projectName === "spring-petclinic"); - } - if (result.mainClass === "com.microsoft.azure.sample.TodoApplication") { - assert(result.projectName === "todo-app-java-on-azure"); - } - } - console.log("Test successfully"); - socket.end(); - socket.destory(); - } - }); - }); - }; + get todoPath() { + return path.join(ROOT, '25.multi-root/todo-app-java-on-azure'); + } - beforeEach(function () { - //assert(!(fs.existsSync(path1)||fs.existsSync(path2))); - utils.timeout(1000 * 20); - initializeProject(DATA_ROOT, another_root); - }) + get sourcePath() { + return 'src/main/java'; + } - it('multi-root test', function () { - this.timeout(1000 * 50); - (async () => { - //await initializeProject(DATA_ROOT, another_root); - mkdirp.sync(LANGUAGE_SERVER_WORKSPACE); - if (isLanguageServerStarted()) { - console.log('waiting for ls down.'); - await killLanguageServer(); - await timeout(1000); + get outputPath() { + return 'target/classes'; + } + + withEngine(engine) { + utils.timeout(1000 * 50); + assert((fs.existsSync(petclinicpro) && fs.existsSync(todopro))); + assert(this.data.length === 2); + for (let result of this.data) { + if (result.mainClass === "org.springframework.samples.petclinic.PetClinicApplication") { + assert(result.projectName === "spring-petclinic"); } - try { - rimraf.sync(LANGUAGE_SERVER_WORKSPACE); - } catch (e) { - throw new Error(`Can't delete ${LANGUAGE_SERVER_WORKSPACE} folder`); + if (result.mainClass === "com.microsoft.azure.sample.TodoApplication") { + assert(result.projectName === "todo-app-java-on-azure"); } - startLS(LANGUAGE_SERVER_ROOT, LANGUAGE_SERVER_WORKSPACE); - // await utils.timeout(1000*50); - })(); + } + console.log("Test successfully"); + } +} - }) -}); diff --git a/src/debug/test-utils.js b/src/debug/test-utils.js index 37d3a75..c4fd380 100644 --- a/src/debug/test-utils.js +++ b/src/debug/test-utils.js @@ -97,9 +97,14 @@ export async function createDebugEngine(DATA_ROOT, LANGUAGE_SERVER_ROOT, LANGUAG } startLS(LANGUAGE_SERVER_ROOT, LANGUAGE_SERVER_WORKSPACE); let resolveData = await promise1; - console.log("###MainClassData-->", resolveData); + //console.log("###MainClassData-->", resolveData); + if(config.testName === "multi-root"){ + Object.defineProperty(config,'data',{ + value:resolveData[0], + writable:false + }) + } const port = parseInt(config.projectName ? resolveData[2] : resolveData[1]); - await promise1; const dc = new DebugClient('java'); await dc.start(port); @@ -116,7 +121,7 @@ export async function createDebugEngine(DATA_ROOT, LANGUAGE_SERVER_ROOT, LANGUAG "vmArgs": config.vmArgs, "encoding": config.encoding, "console": config.console, - "stopOnEntry":config.stopOnEntry, + "stopOnEntry": config.stopOnEntry, "stepFilters": config.stepFilters }); config.withEngine(engine);