integrated xml beans scanner into spring index

This commit is contained in:
Martin Lippert
2024-12-19 12:07:25 +01:00
parent 6decc62c98
commit 9bffd04ebe
3 changed files with 54 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Pivotal, Inc.
* Copyright (c) 2019, 2024 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
@@ -26,6 +26,7 @@ import org.springframework.ide.vscode.boot.java.beans.CachedBean;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
import org.springframework.lang.NonNull;
@@ -101,6 +102,7 @@ public class SpringIndexerXMLNamespaceHandlerBeans implements SpringIndexerXMLNa
generatedSymbols.add(cachedSymbol);
// TODO: bean index
generatedBeans.add(new CachedBean(docURI, new Bean(beanID, fqBeanClass, location, null, null, null)));
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Pivotal, Inc.
* Copyright (c) 2019, 2024 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
@@ -29,10 +29,12 @@ import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.BootLanguageServerBootApp;
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.bootiful.XmlBeansTestConf;
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
import org.springframework.ide.vscode.boot.java.beans.BeansSymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.utils.SymbolIndexConfig;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.languageserver.starter.LanguageServerAutoConf;
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
@@ -51,7 +53,8 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode;
public class SpringIndexerXMLProjectTest {
@Autowired private BootLanguageServerHarness harness;
@Autowired private SpringSymbolIndex indexer;
@Autowired private SpringSymbolIndex symbolIndex;
@Autowired private SpringMetamodelIndex springIndex;
@Autowired private MockProjectObserver projectObserver;
private ProjectsHarness projects = ProjectsHarness.INSTANCE;
@@ -61,7 +64,7 @@ public class SpringIndexerXMLProjectTest {
@BeforeEach
public void setup() throws Exception {
harness.intialize(null);
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.xmlScanFolders(new String[] { "src/main", "config" })
.build());
@@ -73,13 +76,13 @@ public class SpringIndexerXMLProjectTest {
// trigger project creation
projectObserver.doWithListeners(l -> l.created(project));
CompletableFuture<Void> initProject = indexer.waitOperation();
CompletableFuture<Void> initProject = symbolIndex.waitOperation();
initProject.get(5, TimeUnit.SECONDS);
}
@Test
void testScanningSimpleSpringXMLConfig() throws Exception {
List<? extends WorkspaceSymbol> allSymbols = indexer.getAllSymbols("");
List<? extends WorkspaceSymbol> allSymbols = symbolIndex.getAllSymbols("");
assertEquals(5, allSymbols.size());
@@ -89,7 +92,7 @@ public class SpringIndexerXMLProjectTest {
assertTrue(SpringIndexerTest.containsSymbol(allSymbols, "@+ 'namedParameterJdbcTemplate' NamedParameterJdbcTemplate", docUri, 12, 14, 12, 45));
assertTrue(SpringIndexerTest.containsSymbol(allSymbols, "@+ 'persistenceExceptionTranslationPostProcessor' PersistenceExceptionTranslationPostProcessor", docUri, 18, 10, 18, 97));
List<? extends SymbolAddOnInformation> addon = indexer.getAdditonalInformation(docUri);
List<? extends SymbolAddOnInformation> addon = symbolIndex.getAdditonalInformation(docUri);
assertEquals(4, addon.size());
assertEquals(1, addon.stream()
@@ -116,69 +119,90 @@ public class SpringIndexerXMLProjectTest {
String beansOnClasspathDocUri = directory.toPath().resolve("src/main/resources/beans.xml").toUri().toString();
assertTrue(SpringIndexerTest.containsSymbol(allSymbols, "@+ 'sb' SimpleBean", beansOnClasspathDocUri, 6, 14, 6, 21));
addon = indexer.getAdditonalInformation(beansOnClasspathDocUri);
addon = symbolIndex.getAdditonalInformation(beansOnClasspathDocUri);
assertEquals(1, addon.size());
assertEquals("sb", ((BeansSymbolAddOnInformation) addon.get(0)).getBeanID());
Bean[] beans = springIndex.getBeansOfProject("test-annotation-indexing-xml-project");
assertEquals(5, beans.length);
assertTrue(containsBean("sb", "org.test.SimpleBean", beansOnClasspathDocUri, beans));
assertTrue(containsBean("transactionManager", "org.springframework.jdbc.datasource.DataSourceTransactionManager", docUri, beans));
assertTrue(containsBean("jdbcTemplate", "org.springframework.jdbc.core.JdbcTemplate", docUri, beans));
assertTrue(containsBean("namedParameterJdbcTemplate", "org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate", docUri, beans));
assertTrue(containsBean("persistenceExceptionTranslationPostProcessor", "org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor", docUri, beans));
}
@Test
private boolean containsBean(String beanName, String beanType, String docURI, Bean[] beans) {
for (Bean bean : beans) {
if (bean.getName().equals(beanName)
&& bean.getType().equals(beanType)
&& bean.getLocation().getUri().equals(docURI)) {
return true;
}
}
return false;
}
@Test
void testReindexXMLConfig() throws Exception {
List<? extends WorkspaceSymbol> allSymbols = indexer.getAllSymbols("");
List<? extends WorkspaceSymbol> allSymbols = symbolIndex.getAllSymbols("");
assertEquals(5, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.build());
allSymbols = indexer.getAllSymbols("");
allSymbols = symbolIndex.getAllSymbols("");
assertEquals(0, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.xmlScanFolders(new String[]{ "src/main"})
.build());
allSymbols = indexer.getAllSymbols("");
allSymbols = symbolIndex.getAllSymbols("");
assertEquals(1, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.xmlScanFolders(new String[]{"config", "src/main"})
.build());
allSymbols = indexer.getAllSymbols("");
allSymbols = symbolIndex.getAllSymbols("");
assertEquals(5, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.xmlScanFolders(new String[]{"config"})
.build());
allSymbols = indexer.getAllSymbols("");
allSymbols = symbolIndex.getAllSymbols("");
assertEquals(4, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(false)
.xmlScanFolders(new String[]{"config", "src/main"})
.build());
allSymbols = indexer.getAllSymbols("");
allSymbols = symbolIndex.getAllSymbols("");
assertEquals(0, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.xmlScanFolders(new String[]{"config", "src/main"})
.build());
allSymbols = indexer.getAllSymbols("");
allSymbols = symbolIndex.getAllSymbols("");
assertEquals(5, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.xmlScanFolders(new String[0])
.build());
allSymbols = indexer.getAllSymbols("");
allSymbols = symbolIndex.getAllSymbols("");
assertEquals(0, allSymbols.size());
indexer.configureIndexer(SymbolIndexConfig.builder()
symbolIndex.configureIndexer(SymbolIndexConfig.builder()
.scanXml(true)
.xmlScanFolders(new String[0])
.build());
allSymbols = indexer.getAllSymbols(" ");
allSymbols = symbolIndex.getAllSymbols(" ");
assertEquals(0, allSymbols.size());
}

View File

@@ -4,12 +4,12 @@
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>test-annotation-indexing-non-boot-project</artifactId>
<artifactId>test-annotation-indexing-xml-project</artifactId>
<groupId>test-projects</groupId>
<version>5.1.3</version>
<packaging>jar</packaging>
<name>test-annotation-indexing-non-boot-project</name>
<name>test-annotation-indexing-xml-project</name>
<description>Test projects for regular non-boot spring project - annotation indexing</description>
<properties>