diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java index aa6aece9d..6f6917d3b 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java @@ -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)); diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java index ca8706717..88db25744 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java @@ -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); } diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java index 4656b3064..31fc73b6b 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java @@ -41,6 +41,8 @@ public class SpringBootLanguageServer extends STS4LanguageServerProcessStreamCon private List getJVMArgs() { List 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"); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java index 43dfa389d..2806eae4f 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java @@ -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 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 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() { diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/SpringSymbolIndex.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/SpringSymbolIndex.java index 43a69bb93..6d11b00b7 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/SpringSymbolIndex.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/SpringSymbolIndex.java @@ -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 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 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) { diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerXML.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerXML.java index 9ced6cbad..ffc9082fa 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerXML.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerXML.java @@ -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 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 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 outputFolders = IClasspathUtil.getOutputFolders(project.getClasspath()).map(f -> Paths.get(f.toURI())).collect(Collectors.toList()); - ImmutableList.Builder builder = ImmutableList.builder(); - Files.walkFileTree(Paths.get(project.getLocationUri()), new FileVisitor() { - - @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 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) { diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SymbolIndexConfig.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SymbolIndexConfig.java index e66dc254d..6402a3ebb 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SymbolIndexConfig.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SymbolIndexConfig.java @@ -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(); diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/SpringIndexerXMLProjectTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/SpringIndexerXMLProjectTest.java index c7f4f247d..69e20fe07 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/SpringIndexerXMLProjectTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/SpringIndexerXMLProjectTest.java @@ -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 symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) { diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/XmlBeansHyperlinkTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/XmlBeansHyperlinkTest.java index e58e789d7..cfabc5130 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/XmlBeansHyperlinkTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/XmlBeansHyperlinkTest.java @@ -64,7 +64,7 @@ public class XmlBeansHyperlinkTest { Map 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 bootJavaObj = new HashMap<>(); bootJavaObj.put("support-spring-xml-config", supportXML); Map settings = new HashMap<>(); @@ -156,12 +156,78 @@ public class XmlBeansHyperlinkTest { editor.assertLinkTargets("simpleObj", Collections.singleton(expectedLocation)); } + @Test + public void testBeanRefNoHyperlink_FolderNotScanned() throws Exception { + Map supportXML = new HashMap<>(); + supportXML.put("on", true); + supportXML.put("hyperlinks", true); + supportXML.put("scan-folders", " "); + Map bootJavaObj = new HashMap<>(); + bootJavaObj.put("support-spring-xml-config", supportXML); + Map 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, + "\n" + + "\n" + + + "\n" + + "\n" + + "\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 supportXML = new HashMap<>(); + supportXML.put("on", true); + supportXML.put("hyperlinks", true); + supportXML.put("scan-folders", " src/main/ "); + Map bootJavaObj = new HashMap<>(); + bootJavaObj.put("support-spring-xml-config", supportXML); + Map 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, + "\n" + + "\n" + + + "\n" + + "\n" + + "\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 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 bootJavaObj = new HashMap<>(); bootJavaObj.put("support-spring-xml-config", supportXML); Map settings = new HashMap<>(); @@ -188,7 +254,7 @@ public class XmlBeansHyperlinkTest { Map 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 bootJavaObj = new HashMap<>(); bootJavaObj.put("support-spring-xml-config", supportXML); Map settings = new HashMap<>(); diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/project/harness/ProjectsHarness.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/project/harness/ProjectsHarness.java index e9a476175..43712362f 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/project/harness/ProjectsHarness.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/project/harness/ProjectsHarness.java @@ -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; diff --git a/headless-services/spring-boot-language-server/src/test/resources/test-projects/test-xml-hyperlinks/pom.xml b/headless-services/spring-boot-language-server/src/test/resources/test-projects/test-xml-hyperlinks/pom.xml index f7e29f8a5..604b8f9cb 100644 --- a/headless-services/spring-boot-language-server/src/test/resources/test-projects/test-xml-hyperlinks/pom.xml +++ b/headless-services/spring-boot-language-server/src/test/resources/test-projects/test-xml-hyperlinks/pom.xml @@ -8,7 +8,7 @@ war 1.0.0-BUILD-SNAPSHOT - 1.7 + 1.8 3.1.1.RELEASE 1.6.10 1.6.6 @@ -136,10 +136,10 @@ org.apache.maven.plugins maven-compiler-plugin - 2.5.1 + 3.8.0 - 1.6 - 1.6 + 1.8 + 1.8 -Xlint:all true true diff --git a/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts b/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts index 724c27b79..b53cb2c0a 100644 --- a/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts +++ b/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts @@ -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; diff --git a/vscode-extensions/vscode-spring-boot/package.json b/vscode-extensions/vscode-spring-boot/package.json index e60b5e9ba..def45edd6 100644 --- a/vscode-extensions/vscode-spring-boot/package.json +++ b/vscode-extensions/vscode-spring-boot/package.json @@ -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": {