finished work on simple live app request mappings symbols
This commit is contained in:
@@ -48,17 +48,7 @@ public class LiveAppURLSymbolProvider {
|
||||
|
||||
for (SpringBootApp app : runningApps) {
|
||||
try {
|
||||
String mappings = app.getRequestMappings();
|
||||
JSONObject requestMappings = new JSONObject(mappings);
|
||||
Iterator<String> keys = requestMappings.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
String path = UrlUtil.extractPath(key);
|
||||
if (path != null) {
|
||||
String url = UrlUtil.createUrl(app.getHost(), app.getPort(), path);
|
||||
result.add(new SymbolInformation(url, SymbolKind.File, new Location(url, new Range(new Position(0, 0), new Position(0, 1)))));
|
||||
}
|
||||
}
|
||||
collectLiveAppSymbols(result, app);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.log(e);
|
||||
@@ -71,4 +61,21 @@ public class LiveAppURLSymbolProvider {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void collectLiveAppSymbols(List<SymbolInformation> result, SpringBootApp app) throws Exception {
|
||||
String mappings = app.getRequestMappings();
|
||||
JSONObject requestMappings = new JSONObject(mappings);
|
||||
Iterator<String> keys = requestMappings.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
String extractedPath = UrlUtil.extractPath(key);
|
||||
if (extractedPath != null) {
|
||||
String[] splitPath = UrlUtil.splitPath(extractedPath);
|
||||
for (String path : splitPath) {
|
||||
String url = UrlUtil.createUrl(app.getHost(), app.getPort(), path);
|
||||
result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.requestmapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -64,4 +67,32 @@ public class UrlUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String[] splitPath(String path) {
|
||||
if (path.contains("||")) {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
String basePath = path.substring(0, path.indexOf("||")).trim();
|
||||
result.add(basePath);
|
||||
|
||||
if (basePath.lastIndexOf('/') > 0) {
|
||||
basePath = basePath.substring(0, basePath.lastIndexOf('/'));
|
||||
}
|
||||
|
||||
String additionalPaths = path.substring(path.indexOf("||"));
|
||||
StringTokenizer tokenizer = new StringTokenizer(additionalPaths, "||");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String token = tokenizer.nextToken().trim();
|
||||
if (token.length() > 0) {
|
||||
result.add(basePath + "/" + token);
|
||||
}
|
||||
}
|
||||
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
else {
|
||||
return new String[] {path};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ public class SpringIndexer {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<? extends SymbolInformation> getAllSymbols(String query) {
|
||||
public List<SymbolInformation> getAllSymbols(String query) {
|
||||
if (initializeTask != null) {
|
||||
try {
|
||||
initializeTask.get();
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* 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:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.requestmapping.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.UrlUtil;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public class UrlUtilTest {
|
||||
|
||||
@Test
|
||||
public void testSplitPathWithoutDuplicate() {
|
||||
String path = "/superpath";
|
||||
String[] splitPath = UrlUtil.splitPath(path);
|
||||
assertEquals(1, splitPath.length);
|
||||
assertEquals("/superpath", splitPath[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitPathSimpleCaseWithEmptyOr() {
|
||||
String path = "/superpath/mypath || ";
|
||||
String[] splitPath = UrlUtil.splitPath(path);
|
||||
assertEquals(1, splitPath.length);
|
||||
assertEquals("/superpath/mypath", splitPath[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitPathSimpleCase() {
|
||||
String path = "/superpath/mypath || mypath.json";
|
||||
String[] splitPath = UrlUtil.splitPath(path);
|
||||
assertEquals(2, splitPath.length);
|
||||
assertEquals("/superpath/mypath", splitPath[0]);
|
||||
assertEquals("/superpath/mypath.json", splitPath[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitPathMultipleCases() {
|
||||
String path = "/superpath/mypath || mypath.json || somethingelse.what";
|
||||
String[] splitPath = UrlUtil.splitPath(path);
|
||||
assertEquals(3, splitPath.length);
|
||||
assertEquals("/superpath/mypath", splitPath[0]);
|
||||
assertEquals("/superpath/mypath.json", splitPath[1]);
|
||||
assertEquals("/superpath/somethingelse.what", splitPath[2]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user