PT #168807109: Switch XML scanning to specific folders rather than globs
This commit is contained in:
@@ -228,7 +228,7 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
|
||||
liveInformation.put("automatic-tracking", liveInformationAutomaticTracking);
|
||||
|
||||
supportXML.put("on", preferenceStore.getBoolean(Constants.PREF_SUPPORT_SPRING_XML_CONFIGS));
|
||||
supportXML.put("scan-folders-globs", preferenceStore.getString(Constants.PREF_XML_CONFIGS_SCAN_FOLDERS));
|
||||
supportXML.put("scan-folders", preferenceStore.getString(Constants.PREF_XML_CONFIGS_SCAN_FOLDERS));
|
||||
supportXML.put("hyperlinks", preferenceStore.getString(Constants.PREF_XML_CONFIGS_HYPERLINKS));
|
||||
supportXML.put("content-assist", preferenceStore.getString(Constants.PREF_XML_CONFIGS_CONTENT_ASSIST));
|
||||
bootChangeDetection.put("on", preferenceStore.getBoolean(Constants.PREF_CHANGE_DETECTION));
|
||||
|
||||
@@ -32,7 +32,7 @@ public class PrefsInitializer extends AbstractPreferenceInitializer {
|
||||
preferenceStore.setDefault(Constants.PREF_SUPPORT_SPRING_XML_CONFIGS, false);
|
||||
preferenceStore.setDefault(Constants.PREF_XML_CONFIGS_HYPERLINKS, true);
|
||||
preferenceStore.setDefault(Constants.PREF_XML_CONFIGS_CONTENT_ASSIST, true);
|
||||
preferenceStore.setDefault(Constants.PREF_XML_CONFIGS_SCAN_FOLDERS, "**/src/main/**");
|
||||
preferenceStore.setDefault(Constants.PREF_XML_CONFIGS_SCAN_FOLDERS, "src/main");
|
||||
preferenceStore.setDefault(Constants.PREF_CHANGE_DETECTION, false);
|
||||
preferenceStore.setDefault(Constants.PREF_SCAN_JAVA_TEST_SOURCES, false);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ public class SpringBootLanguageServer extends STS4LanguageServerProcessStreamCon
|
||||
private List<String> getJVMArgs() {
|
||||
List<String> args = new ArrayList<>();
|
||||
|
||||
// args.add("-Xdebug");
|
||||
// args.add("-Xrunjdwp:server=y,transport=dt_socket,address=1044,suspend=n");
|
||||
args.add("-Dlsp.completions.indentation.enable=true");
|
||||
args.add("-Xmx1024m");
|
||||
args.add("-XX:TieredStopAtLevel=1");
|
||||
|
||||
@@ -10,13 +10,11 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.app;
|
||||
|
||||
import java.nio.file.FileSystems;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.ListenerList;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
@@ -32,8 +30,6 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class BootJavaConfig implements InitializingBean {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BootJavaConfig.class);
|
||||
|
||||
public static final boolean LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED_DEFAULT = true;
|
||||
public static final int LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY_DEFAULT = 5000;
|
||||
|
||||
@@ -69,19 +65,30 @@ public class BootJavaConfig implements InitializingBean {
|
||||
}
|
||||
|
||||
public String[] xmlBeansFoldersToScan() {
|
||||
String folders = settings.getString("boot-java", "support-spring-xml-config", "scan-folders-globs");
|
||||
String[] patterns = folders == null ? new String[0] : folders.split("\\s*,\\s*");
|
||||
// Validate patterns
|
||||
List<String> validatedPatterns = new ArrayList<>(patterns.length);
|
||||
for (String pattern : patterns) {
|
||||
try {
|
||||
FileSystems.getDefault().getPathMatcher("glob:" + pattern);
|
||||
validatedPatterns.add(pattern);
|
||||
} catch (Throwable t) {
|
||||
log.error("Failed to parse glob pattern: '{}'", pattern);
|
||||
String foldersStr = settings.getString("boot-java", "support-spring-xml-config", "scan-folders");
|
||||
if (foldersStr != null) {
|
||||
foldersStr = foldersStr.trim();
|
||||
}
|
||||
String[] folders = foldersStr == null || foldersStr.isEmpty()? new String[0] : foldersStr.split("\\s*,\\s*");
|
||||
List<String> cleanedFolders = new ArrayList<>(folders.length);
|
||||
for (String folder : folders) {
|
||||
int startIndex = 0;
|
||||
int endIndex = folder.length();
|
||||
if (folder.startsWith(File.separator)) {
|
||||
startIndex += File.separator.length();
|
||||
}
|
||||
if (folder.endsWith(File.separator)) {
|
||||
endIndex -= File.separator.length();
|
||||
}
|
||||
if (startIndex > 0 || endIndex < folder.length()) {
|
||||
if (startIndex < endIndex) {
|
||||
cleanedFolders.add(folder.substring(startIndex, endIndex));
|
||||
}
|
||||
} else {
|
||||
cleanedFolders.add(folder);
|
||||
}
|
||||
}
|
||||
return validatedPatterns.toArray(new String[validatedPatterns.size()]);
|
||||
return cleanedFolders.toArray(new String[cleanedFolders.size()]);
|
||||
}
|
||||
|
||||
public boolean isChangeDetectionEnabled() {
|
||||
|
||||
@@ -179,7 +179,7 @@ public class SpringSymbolIndex implements InitializingBean {
|
||||
server.getAsync().execute(() ->
|
||||
configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(config.isSpringXMLSupportEnabled())
|
||||
.xmlScanFoldersGlobs(config.xmlBeansFoldersToScan())
|
||||
.xmlScanFolders(config.xmlBeansFoldersToScan())
|
||||
.scanTestJavaSources(config.isScanJavaTestSourcesEnabled())
|
||||
.build()
|
||||
)
|
||||
@@ -207,38 +207,53 @@ public class SpringSymbolIndex implements InitializingBean {
|
||||
synchronized (this) {
|
||||
if (config.isScanXml() && !(Arrays.asList(this.indexers).contains(springIndexerXML))) {
|
||||
this.indexers = new SpringIndexer[] { springIndexerJava, springIndexerXML };
|
||||
springIndexerXML.setScanFolderGlobs(config.getXmlScanFoldersGlobs());
|
||||
List<String> globPattern = Arrays.asList(springIndexerXML.getFileWatchPatterns());
|
||||
watchXMLDeleteRegistration = getWorkspaceService().getFileObserver().onFileDeleted(globPattern,
|
||||
(file) -> {
|
||||
deleteDocument(new TextDocumentIdentifier(file).getUri());
|
||||
});
|
||||
watchXMLCreatedRegistration = getWorkspaceService().getFileObserver().onFileCreated(globPattern,
|
||||
(file) -> {
|
||||
createDocument(new TextDocumentIdentifier(file).getUri());
|
||||
});
|
||||
watchXMLChangedRegistration = getWorkspaceService().getFileObserver().onFileChanged(globPattern,
|
||||
(file) -> {
|
||||
updateDocument(new TextDocumentIdentifier(file).getUri(), null, "xml changed");
|
||||
});
|
||||
springIndexerXML.updateScanFolders(config.getXmlScanFolders());
|
||||
addXmlFileListeners(Arrays.asList(springIndexerXML.getFileWatchPatterns()));
|
||||
} else if (!config.isScanXml() && Arrays.asList(this.indexers).contains(springIndexerXML)) {
|
||||
this.indexers = new SpringIndexer[] { springIndexerJava };
|
||||
springIndexerXML.setScanFolderGlobs(new String[0]);
|
||||
|
||||
getWorkspaceService().getFileObserver().unsubscribe(watchXMLChangedRegistration);
|
||||
getWorkspaceService().getFileObserver().unsubscribe(watchXMLCreatedRegistration);
|
||||
getWorkspaceService().getFileObserver().unsubscribe(watchXMLDeleteRegistration);
|
||||
|
||||
watchXMLChangedRegistration = null;
|
||||
watchXMLCreatedRegistration = null;
|
||||
watchXMLDeleteRegistration = null;
|
||||
springIndexerXML.updateScanFolders(new String[0]);
|
||||
removeXmlFileListeners();
|
||||
} else if (config.isScanXml()) {
|
||||
springIndexerXML.setScanFolderGlobs(config.getXmlScanFoldersGlobs());
|
||||
if (springIndexerXML.updateScanFolders(config.getXmlScanFolders())) {
|
||||
// should remove the old listeners before adding the new ones
|
||||
addXmlFileListeners(Arrays.asList(springIndexerXML.getFileWatchPatterns()));
|
||||
}
|
||||
}
|
||||
springIndexerJava.setScanTestJavaSources(config.isScanTestJavaSources());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addXmlFileListeners(List<String> globPattern) {
|
||||
removeXmlFileListeners();
|
||||
watchXMLDeleteRegistration = getWorkspaceService().getFileObserver().onFileDeleted(globPattern,
|
||||
(file) -> {
|
||||
deleteDocument(new TextDocumentIdentifier(file).getUri());
|
||||
});
|
||||
watchXMLCreatedRegistration = getWorkspaceService().getFileObserver().onFileCreated(globPattern,
|
||||
(file) -> {
|
||||
createDocument(new TextDocumentIdentifier(file).getUri());
|
||||
});
|
||||
watchXMLChangedRegistration = getWorkspaceService().getFileObserver().onFileChanged(globPattern,
|
||||
(file) -> {
|
||||
updateDocument(new TextDocumentIdentifier(file).getUri(), null, "xml changed");
|
||||
});
|
||||
}
|
||||
|
||||
private void removeXmlFileListeners() {
|
||||
if (watchXMLChangedRegistration != null) {
|
||||
getWorkspaceService().getFileObserver().unsubscribe(watchXMLChangedRegistration);
|
||||
watchXMLChangedRegistration = null;
|
||||
}
|
||||
if (watchXMLCreatedRegistration != null) {
|
||||
getWorkspaceService().getFileObserver().unsubscribe(watchXMLCreatedRegistration);
|
||||
watchXMLCreatedRegistration = null;
|
||||
}
|
||||
if (watchXMLDeleteRegistration != null) {
|
||||
getWorkspaceService().getFileObserver().unsubscribe(watchXMLDeleteRegistration);
|
||||
watchXMLDeleteRegistration = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
try {
|
||||
synchronized(this) {
|
||||
|
||||
@@ -13,14 +13,9 @@ package org.springframework.ide.vscode.boot.java.utils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -44,7 +39,6 @@ import org.springframework.ide.vscode.commons.util.UriUtil;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -58,7 +52,7 @@ public class SpringIndexerXML implements SpringIndexer {
|
||||
private final SymbolCache cache;
|
||||
private final JavaProjectFinder projectFinder;
|
||||
|
||||
private String[] scanFolderGlobs = new String[0];
|
||||
private String[] scanFolders = new String[0];
|
||||
|
||||
public SpringIndexerXML(SymbolHandler handler, Map<String, SpringIndexerXMLNamespaceHandler> namespaceHandler,
|
||||
SymbolCache cache, JavaProjectFinder projectFinder) {
|
||||
@@ -68,25 +62,32 @@ public class SpringIndexerXML implements SpringIndexer {
|
||||
this.projectFinder = projectFinder;
|
||||
}
|
||||
|
||||
public void setScanFolderGlobs(String[] scanFolderGlobs) {
|
||||
if (!Arrays.equals(this.scanFolderGlobs, scanFolderGlobs)) {
|
||||
public boolean updateScanFolders(String[] scanFoldes) {
|
||||
if (!Arrays.equals(this.scanFolders, scanFoldes)) {
|
||||
clearIndex();
|
||||
this.scanFolderGlobs = scanFolderGlobs;
|
||||
this.scanFolders = scanFoldes;
|
||||
populateIndex();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getFileWatchPatterns() {
|
||||
String[] patterns = new String[scanFolderGlobs.length];
|
||||
for (int i = 0; i < scanFolderGlobs.length; i++) {
|
||||
String[] patterns = new String[scanFolders.length * 2];
|
||||
for (int i = 0; i < scanFolders.length; i+=2) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(scanFolderGlobs[i]);
|
||||
if (scanFolderGlobs[i].charAt(scanFolderGlobs[i].length() - 1) != '/') {
|
||||
sb.append('/');
|
||||
}
|
||||
sb.append("*.xml");
|
||||
patterns[i] = sb.toString();
|
||||
sb.append("**/");
|
||||
sb.append(scanFolders[i]);
|
||||
sb.append('/');
|
||||
StringBuilder pattern1 = new StringBuilder(sb);
|
||||
pattern1.append("*.xml");
|
||||
patterns[i] = pattern1.toString();
|
||||
|
||||
StringBuilder pattern2 = new StringBuilder(sb);
|
||||
pattern2.append("**/");
|
||||
pattern2.append("*.xml");
|
||||
patterns[i + 1] = pattern2.toString();
|
||||
}
|
||||
return patterns;
|
||||
}
|
||||
@@ -217,61 +218,25 @@ public class SpringIndexerXML implements SpringIndexer {
|
||||
|
||||
private String[] getFiles(IJavaProject project) throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
String[] globs = scanFolderGlobs;
|
||||
if (globs.length == 0) {
|
||||
return new String[0];
|
||||
}
|
||||
List<PathMatcher> matchers = new ArrayList<>(globs.length);
|
||||
for (String glob : globs) {
|
||||
matchers.add(FileSystems.getDefault().getPathMatcher("glob:" + glob));
|
||||
}
|
||||
Path projectPath = Paths.get(project.getLocationUri());
|
||||
String[] xmlFiles = Arrays.stream(scanFolders)
|
||||
.map(folder -> projectPath.resolve(folder))
|
||||
.filter(Files::isDirectory)
|
||||
.flatMap(folder -> {
|
||||
try {
|
||||
return Files.walk(folder);
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
return Stream.empty();
|
||||
}
|
||||
})
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(file -> file.getFileName().toString().endsWith(".xml"))
|
||||
.map(file -> file.toString())
|
||||
.toArray(String[]::new);
|
||||
|
||||
List<Path> outputFolders = IClasspathUtil.getOutputFolders(project.getClasspath()).map(f -> Paths.get(f.toURI())).collect(Collectors.toList());
|
||||
ImmutableList.Builder<String> builder = ImmutableList.builder();
|
||||
Files.walkFileTree(Paths.get(project.getLocationUri()), new FileVisitor<Path>() {
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
if (dir.getFileName().toString().startsWith(".")) {
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
if (outputFolders.contains(dir)) {
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
String fileName = file.getFileName().toString();
|
||||
if (fileName.endsWith(".xml")) {
|
||||
Path parent = file.getParent();
|
||||
if (parent != null) {
|
||||
for (PathMatcher matcher : matchers) {
|
||||
if (matcher.matches(parent)) {
|
||||
builder.add(file.toString());
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
||||
ImmutableList<String> list = builder.build();
|
||||
log.info("Found {} XML files to scan in {}ms", list.size(), System.currentTimeMillis() - start);
|
||||
return list.toArray(new String[list.size()]);
|
||||
log.info("Found {} XML files to scan in {}ms", xmlFiles.length, System.currentTimeMillis() - start);
|
||||
return xmlFiles;
|
||||
}
|
||||
|
||||
private SymbolCacheKey getCacheKey(IJavaProject project) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface SymbolIndexConfig {
|
||||
|
||||
private boolean scanTestJavaSources = false;
|
||||
|
||||
private String[] xmlScanFoldersGlobs = new String[0];
|
||||
private String[] xmlScanFolders = new String[0];
|
||||
|
||||
private Builder() {
|
||||
|
||||
@@ -34,8 +34,8 @@ public interface SymbolIndexConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder xmlScanFoldersGlobs(String[] xmlScanFoldersGlobs) {
|
||||
this.xmlScanFoldersGlobs = xmlScanFoldersGlobs;
|
||||
public Builder xmlScanFolders(String[] xmlScanFolders) {
|
||||
this.xmlScanFolders = xmlScanFolders;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ public interface SymbolIndexConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getXmlScanFoldersGlobs() {
|
||||
return xmlScanFoldersGlobs;
|
||||
public String[] getXmlScanFolders() {
|
||||
return xmlScanFolders;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -65,7 +65,7 @@ public interface SymbolIndexConfig {
|
||||
|
||||
boolean isScanTestJavaSources();
|
||||
|
||||
String[] getXmlScanFoldersGlobs();
|
||||
String[] getXmlScanFolders();
|
||||
|
||||
static Builder builder() {
|
||||
return new Builder();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class SpringIndexerXMLProjectTest {
|
||||
harness.intialize(null);
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(true)
|
||||
.xmlScanFoldersGlobs(new String[] { "**/src/main/**", "**/config" })
|
||||
.xmlScanFolders(new String[] { "src/main", "config" })
|
||||
.build());
|
||||
|
||||
project = projects.mavenProject("test-annotation-indexing-xml-project");
|
||||
@@ -129,31 +129,52 @@ public class SpringIndexerXMLProjectTest {
|
||||
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(true)
|
||||
.xmlScanFoldersGlobs(new String[] { "**/src/main/**" })
|
||||
.xmlScanFolders(new String[] { "src/main" })
|
||||
.build());
|
||||
allSymbols = indexer.getAllSymbols("");
|
||||
assertEquals(1, allSymbols.size());
|
||||
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(true)
|
||||
.xmlScanFoldersGlobs(new String[] { "**/config", "**/src/main/**" })
|
||||
.xmlScanFolders(new String[] { "config", "src/main" })
|
||||
.build());
|
||||
allSymbols = indexer.getAllSymbols("");
|
||||
assertEquals(5, allSymbols.size());
|
||||
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(true)
|
||||
.xmlScanFoldersGlobs(new String[] { "**/config" })
|
||||
.xmlScanFolders(new String[] { "config" })
|
||||
.build());
|
||||
allSymbols = indexer.getAllSymbols("");
|
||||
assertEquals(4, allSymbols.size());
|
||||
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(false)
|
||||
.xmlScanFoldersGlobs(new String[] { "**/config", "**/src/main/**" })
|
||||
.xmlScanFolders(new String[] { "config", "src/main" })
|
||||
.build());
|
||||
allSymbols = indexer.getAllSymbols("");
|
||||
assertEquals(0, allSymbols.size());
|
||||
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(true)
|
||||
.xmlScanFolders(new String[] { "config", "src/main" })
|
||||
.build());
|
||||
allSymbols = indexer.getAllSymbols("");
|
||||
assertEquals(5, allSymbols.size());
|
||||
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(true)
|
||||
.xmlScanFolders(new String[0])
|
||||
.build());
|
||||
allSymbols = indexer.getAllSymbols("");
|
||||
assertEquals(0, allSymbols.size());
|
||||
|
||||
indexer.configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(true)
|
||||
.xmlScanFolders(new String[0])
|
||||
.build());
|
||||
allSymbols = indexer.getAllSymbols(" ");
|
||||
assertEquals(0, allSymbols.size());
|
||||
}
|
||||
|
||||
private boolean containsSymbol(List<? extends SymbolInformation> symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public class XmlBeansHyperlinkTest {
|
||||
Map<String, Object> supportXML = new HashMap<>();
|
||||
supportXML.put("on", true);
|
||||
supportXML.put("hyperlinks", true);
|
||||
supportXML.put("scan-folders-globs", "**/src/main/**");
|
||||
supportXML.put("scan-folders", "/src/main/");
|
||||
Map<String, Object> bootJavaObj = new HashMap<>();
|
||||
bootJavaObj.put("support-spring-xml-config", supportXML);
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
@@ -156,12 +156,78 @@ public class XmlBeansHyperlinkTest {
|
||||
editor.assertLinkTargets("simpleObj", Collections.singleton(expectedLocation));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanRefNoHyperlink_FolderNotScanned() throws Exception {
|
||||
Map<String, Object> supportXML = new HashMap<>();
|
||||
supportXML.put("on", true);
|
||||
supportXML.put("hyperlinks", true);
|
||||
supportXML.put("scan-folders", " ");
|
||||
Map<String, Object> bootJavaObj = new HashMap<>();
|
||||
bootJavaObj.put("support-spring-xml-config", supportXML);
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
settings.put("boot-java", bootJavaObj);
|
||||
|
||||
harness.getServer().getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(new Gson().toJsonTree(settings)));
|
||||
|
||||
Path xmlFilePath = Paths.get(project.getLocationUri()).resolve("beans.xml");
|
||||
Editor editor = harness.newEditor(LanguageId.XML,
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<beans xmlns=\"http://www.springframework.org/schema/beans\"\n" +
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||
"xsi:schemaLocation=\"http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd\">\n" +
|
||||
|
||||
"<bean id=\"someBean\" class=\"u.t.r.TestBean\"\n" +
|
||||
"<property name=\"simple\" ref=\"simpleObj\"></property>\n" +
|
||||
"</bean>\n" +
|
||||
"</beans>\n",
|
||||
UriUtil.toUri(xmlFilePath.toFile()).toString()
|
||||
);
|
||||
Path rootContextFilePath = Paths.get(project.getLocationUri()).resolve("src/main/webapp/WEB-INF/spring/root-context.xml");
|
||||
Location expectedLocation = new Location();
|
||||
expectedLocation.setUri(UriUtil.toUri(rootContextFilePath.toFile()).toString());
|
||||
expectedLocation.setRange(new Range(new Position(6,7), new Position(6, 21)));
|
||||
editor.assertNoLinkTargets("simpleObj");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanRefHyperlink_SpecifyScanFolderDifferently() throws Exception {
|
||||
Map<String, Object> supportXML = new HashMap<>();
|
||||
supportXML.put("on", true);
|
||||
supportXML.put("hyperlinks", true);
|
||||
supportXML.put("scan-folders", " src/main/ ");
|
||||
Map<String, Object> bootJavaObj = new HashMap<>();
|
||||
bootJavaObj.put("support-spring-xml-config", supportXML);
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
settings.put("boot-java", bootJavaObj);
|
||||
|
||||
harness.getServer().getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(new Gson().toJsonTree(settings)));
|
||||
|
||||
Path xmlFilePath = Paths.get(project.getLocationUri()).resolve("beans.xml");
|
||||
Editor editor = harness.newEditor(LanguageId.XML,
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<beans xmlns=\"http://www.springframework.org/schema/beans\"\n" +
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||
"xsi:schemaLocation=\"http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd\">\n" +
|
||||
|
||||
"<bean id=\"someBean\" class=\"u.t.r.TestBean\"\n" +
|
||||
"<property name=\"simple\" ref=\"simpleObj\"></property>\n" +
|
||||
"</bean>\n" +
|
||||
"</beans>\n",
|
||||
UriUtil.toUri(xmlFilePath.toFile()).toString()
|
||||
);
|
||||
Path rootContextFilePath = Paths.get(project.getLocationUri()).resolve("src/main/webapp/WEB-INF/spring/root-context.xml");
|
||||
Location expectedLocation = new Location();
|
||||
expectedLocation.setUri(UriUtil.toUri(rootContextFilePath.toFile()).toString());
|
||||
expectedLocation.setRange(new Range(new Position(6,7), new Position(6, 21)));
|
||||
editor.assertLinkTargets("simpleObj", Collections.singleton(expectedLocation));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoHyperlinkWhenXmlSupportOff() throws Exception {
|
||||
Map<String, Object> supportXML = new HashMap<>();
|
||||
supportXML.put("on", false);
|
||||
supportXML.put("hyperlinks", true);
|
||||
supportXML.put("scan-folders-globs", "**/src/main/**");
|
||||
supportXML.put("scan-folders", "src/main");
|
||||
Map<String, Object> bootJavaObj = new HashMap<>();
|
||||
bootJavaObj.put("support-spring-xml-config", supportXML);
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
@@ -188,7 +254,7 @@ public class XmlBeansHyperlinkTest {
|
||||
Map<String, Object> supportXML = new HashMap<>();
|
||||
supportXML.put("on", true);
|
||||
supportXML.put("hyperlinks", false);
|
||||
supportXML.put("scan-folders-globs", "**/src/main/**");
|
||||
supportXML.put("scan-folders", "src/main");
|
||||
Map<String, Object> bootJavaObj = new HashMap<>();
|
||||
bootJavaObj.put("support-spring-xml-config", supportXML);
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.project.harness;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<packaging>war</packaging>
|
||||
<version>1.0.0-BUILD-SNAPSHOT</version>
|
||||
<properties>
|
||||
<java-version>1.7</java-version>
|
||||
<java-version>1.8</java-version>
|
||||
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
|
||||
<org.aspectj-version>1.6.10</org.aspectj-version>
|
||||
<org.slf4j-version>1.6.6</org.slf4j-version>
|
||||
@@ -136,10 +136,10 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<compilerArgument>-Xlint:all</compilerArgument>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
|
||||
@@ -46,10 +46,10 @@ export const BootConfigSchema: PreferenceSchema = {
|
||||
description: 'Enable/Disable Content Assist in Spring XML Config file editor',
|
||||
default: true
|
||||
},
|
||||
'boot-java.support-spring-xml-config.scan-folders-globs': {
|
||||
'boot-java.support-spring-xml-config.scan-folders': {
|
||||
type: 'string',
|
||||
description: 'Scan Spring XML in folders',
|
||||
default: '**/src/main/**'
|
||||
default: 'src/main'
|
||||
},
|
||||
'boot-java.change-detection.on': {
|
||||
type: 'boolean',
|
||||
@@ -80,7 +80,7 @@ export interface BootConfiguration {
|
||||
'boot-java.support-spring-xml-config.on': boolean;
|
||||
'boot-java.support-spring-xml-config.hyperlinks': boolean;
|
||||
'boot-java.support-spring-xml-config.content-assist': boolean;
|
||||
'boot-java.support-spring-xml-config.scan-folders-globs': string;
|
||||
'boot-java.support-spring-xml-config.scan-folders': string;
|
||||
'boot-java.change-detection.on': boolean;
|
||||
'boot-java.highlight-codelens.on': boolean;
|
||||
'spring-boot.ls.javahome': string;
|
||||
|
||||
@@ -99,9 +99,9 @@
|
||||
"description": "Enable/Disable Content Assist in Spring XML Config file editor",
|
||||
"default": true
|
||||
},
|
||||
"boot-java.support-spring-xml-config.scan-folders-globs": {
|
||||
"boot-java.support-spring-xml-config.scan-folders": {
|
||||
"type": "string",
|
||||
"default": "**/src/main/**",
|
||||
"default": "src/main",
|
||||
"description": "Scan Spring XML in folders"
|
||||
},
|
||||
"boot-java.highlight-codelens.on": {
|
||||
|
||||
Reference in New Issue
Block a user