reorganize names and package locations around symbol and index caches

This commit is contained in:
Martin Lippert
2023-07-11 12:27:53 +02:00
parent 9bf67c9f4e
commit 7dfbad709f
28 changed files with 245 additions and 235 deletions

View File

@@ -15,10 +15,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
@@ -29,8 +29,8 @@ import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
@Import(AdHocPropertyHarnessTestConf.class)
public class HoverTestConf {
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {

View File

@@ -17,12 +17,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.links.JavaDocumentUriProvider;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.boot.metadata.types.TypeUtil;
import org.springframework.ide.vscode.boot.metadata.types.TypeUtilProvider;
@@ -38,8 +38,8 @@ import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
@Import(AdHocPropertyHarnessTestConf.class)
public class PropertyEditorTestConf {
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {

View File

@@ -15,11 +15,11 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.links.VSCodeSourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.java.utils.test.MockProjectObserver;
import org.springframework.ide.vscode.boot.metadata.DefaultSpringPropertyIndexProvider;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
@@ -35,8 +35,8 @@ import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
@Import(AdHocPropertyHarnessTestConf.class)
public class SourceLinksTestConf {
@Bean public SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean public IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {

View File

@@ -15,10 +15,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.DefaultSpringPropertyIndexProvider;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
@@ -30,8 +30,8 @@ import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
@Import(AdHocPropertyHarnessTestConf.class)
public class SymbolProviderTestConf {
@Bean public SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean public IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {

View File

@@ -15,12 +15,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.links.JavaDocumentUriProvider;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.java.utils.test.MockProjectObserver;
import org.springframework.ide.vscode.boot.metadata.DefaultSpringPropertyIndexProvider;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
@@ -34,8 +34,8 @@ import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
@Import(AdHocPropertyHarnessTestConf.class)
public class XmlBeansTestConf {
@Bean public SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean public IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Pivotal, Inc.
* Copyright (c) 2019, 2023 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
@@ -8,22 +8,22 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.utils.test;
package org.springframework.ide.vscode.boot.index.cache.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.Test;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheKey;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheKey;
/**
* @author Martin Lippert
*/
public class SymbolCacheKeyTest {
public class IndexCacheKeyTest {
@Test
void testCacheKey() {
SymbolCacheKey key = new SymbolCacheKey("primary", "version");
IndexCacheKey key = new IndexCacheKey("primary", "version");
assertEquals("primary", key.getPrimaryIdentifier());
assertEquals("version", key.getVersion());
@@ -32,33 +32,33 @@ public class SymbolCacheKeyTest {
@Test
void testCacheKeyParsingFromFileName() {
SymbolCacheKey key = SymbolCacheKey.parse("primary-version.json");
IndexCacheKey key = IndexCacheKey.parse("primary-version.json");
assertEquals("primary", key.getPrimaryIdentifier());
assertEquals("version", key.getVersion());
key = SymbolCacheKey.parse("primary-name-with-separator-123ABC.json");
key = IndexCacheKey.parse("primary-name-with-separator-123ABC.json");
assertEquals("primary-name-with-separator", key.getPrimaryIdentifier());
assertEquals("123ABC", key.getVersion());
}
@Test
void testCacheKeyParsingWithoutFileExtension() {
SymbolCacheKey key = SymbolCacheKey.parse("primary-version");
IndexCacheKey key = IndexCacheKey.parse("primary-version");
assertEquals("primary", key.getPrimaryIdentifier());
assertEquals("version", key.getVersion());
key = SymbolCacheKey.parse("primary-name-with-separator-123ABC");
key = IndexCacheKey.parse("primary-name-with-separator-123ABC");
assertEquals("primary-name-with-separator", key.getPrimaryIdentifier());
assertEquals("123ABC", key.getVersion());
}
@Test
void testCacheKeyEquals() {
SymbolCacheKey key1 = new SymbolCacheKey("primary", "1");
SymbolCacheKey key2 = new SymbolCacheKey("primary", "1");
IndexCacheKey key1 = new IndexCacheKey("primary", "1");
IndexCacheKey key2 = new IndexCacheKey("primary", "1");
SymbolCacheKey key3 = new SymbolCacheKey("primary", "2");
SymbolCacheKey key4 = new SymbolCacheKey("secondary", "1");
IndexCacheKey key3 = new IndexCacheKey("primary", "2");
IndexCacheKey key4 = new IndexCacheKey("secondary", "1");
assertEquals(key1, key1);
assertEquals(key2, key2);

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Pivotal, Inc.
* Copyright (c) 2019, 2023 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
@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.utils.test;
package org.springframework.ide.vscode.boot.index.cache.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -36,12 +36,12 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheKey;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheOnDisc;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
import org.springframework.ide.vscode.boot.java.requestmapping.WebfluxElementsInformation;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheKey;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheOnDisc;
import org.springframework.ide.vscode.commons.util.UriUtil;
import com.google.common.collect.ImmutableList;
@@ -49,15 +49,15 @@ import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
public class SymbolCacheOnDiscTest {
public class IndexCacheOnDiscTest {
private Path tempDir;
private SymbolCacheOnDisc cache;
private IndexCacheOnDisc cache;
@BeforeEach
public void setup() throws Exception {
tempDir = Files.createTempDirectory("cachetest");
cache = new SymbolCacheOnDisc(tempDir.toFile());
cache = new IndexCacheOnDisc(tempDir.toFile());
}
@AfterEach
@@ -67,7 +67,7 @@ public class SymbolCacheOnDiscTest {
@Test
void testEmptyCache() throws Exception {
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("something", "0"), new String[0]);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("something", "0"), new String[0]);
assertNull(result);
}
@@ -89,13 +89,13 @@ public class SymbolCacheOnDiscTest {
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol, null));
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols, ImmutableMultimap.of(
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols, ImmutableMultimap.of(
file1.toString(), "file1dep1",
file2.toString(), "file2dep1",
file2.toString(), "file2dep2"
));
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("somekey", "1"), files);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("somekey", "1"), files);
CachedSymbol[] cachedSymbols = result.getLeft();
assertNotNull(cachedSymbols);
@@ -111,8 +111,8 @@ public class SymbolCacheOnDiscTest {
assertEquals(dependencies.get(file1.toString()), ImmutableSet.of("file1dep1"));
assertEquals(dependencies.get(file2.toString()), ImmutableSet.of("file2dep1", "file2dep2"));
assertEquals(timeFile1.toMillis(), cache.getModificationTimestamp(new SymbolCacheKey("somekey", "1"), file1.toString()));
assertEquals(0, cache.getModificationTimestamp(new SymbolCacheKey("somekey", "1"), "random-non-existing-file"));
assertEquals(timeFile1.toMillis(), cache.getModificationTimestamp(new IndexCacheKey("somekey", "1"), file1.toString()));
assertEquals(0, cache.getModificationTimestamp(new IndexCacheKey("somekey", "1"), "random-non-existing-file"));
assertNull(cachedSymbols[0].getBean());
}
@@ -135,9 +135,9 @@ public class SymbolCacheOnDiscTest {
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol, null));
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols, null);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols, null);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("otherkey", "1"), files);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("otherkey", "1"), files);
assertNull(result);
}
@@ -159,14 +159,14 @@ public class SymbolCacheOnDiscTest {
EnhancedSymbolInformation enhancedSymbol = new EnhancedSymbolInformation(symbol, null);
generatedSymbols.add(new CachedSymbol("", timeFile1.toMillis(), enhancedSymbol, null));
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols, ImmutableMultimap.of(
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols, ImmutableMultimap.of(
file1.toString(), "file1dep",
file2.toString(), "file2dep"
));
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 1000));
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("somekey", "1"), files);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("somekey", "1"), files);
assertNull(result);
}
@@ -181,10 +181,10 @@ public class SymbolCacheOnDiscTest {
Files.createFile(file3);
String[] files = {file1.toString(), file2.toString()};
cache.store(new SymbolCacheKey("somekey", "1"), files, new ArrayList<>(), null);
cache.store(new IndexCacheKey("somekey", "1"), files, new ArrayList<>(), null);
String[] moreFiles = {file1.toString(), file2.toString(), file3.toString()};
assertNull(cache.retrieve(new SymbolCacheKey("somekey", "1"), moreFiles));
assertNull(cache.retrieve(new IndexCacheKey("somekey", "1"), moreFiles));
}
@Test
@@ -198,19 +198,19 @@ public class SymbolCacheOnDiscTest {
Files.createFile(file3);
String[] files = {file1.toString(), file2.toString(), file3.toString()};
cache.store(new SymbolCacheKey("somekey", "1"), files, new ArrayList<>(), null);
cache.store(new IndexCacheKey("somekey", "1"), files, new ArrayList<>(), null);
String[] fewerFiles = {file1.toString(), file2.toString()};
assertNull(cache.retrieve(new SymbolCacheKey("somekey", "1"), fewerFiles));
assertNull(cache.retrieve(new IndexCacheKey("somekey", "1"), fewerFiles));
}
@Test
void testDeleteOldCacheFileIfNewOneIsStored() throws Exception {
SymbolCacheKey key1 = new SymbolCacheKey("somekey", "1");
IndexCacheKey key1 = new IndexCacheKey("somekey", "1");
cache.store(key1, new String[0], new ArrayList<>(), null);
assertTrue(Files.exists(tempDir.resolve(Paths.get(key1.toString() + ".json"))));
SymbolCacheKey key2 = new SymbolCacheKey("somekey", "2");
IndexCacheKey key2 = new IndexCacheKey("somekey", "2");
cache.store(key2, new String[0], new ArrayList<>(), null);
assertTrue(Files.exists(tempDir.resolve(Paths.get(key2.toString() + ".json"))));
assertFalse(Files.exists(tempDir.resolve(Paths.get(key1.toString() + ".json"))));
@@ -233,9 +233,9 @@ public class SymbolCacheOnDiscTest {
generatedSymbols.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol, null));
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols, null);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols, null);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new SymbolCacheKey("somekey", "1"), files);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new IndexCacheKey("somekey", "1"), files);
assertNotNull(cachedSymbols);
assertEquals(1, cachedSymbols.length);
@@ -270,7 +270,7 @@ public class SymbolCacheOnDiscTest {
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1, null);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1, null));
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols1, null);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols1, null);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
symbol1 = new WorkspaceSymbol("symbol1", SymbolKind.Field, Either.forLeft(new Location(doc1URI, new Range(new Position(3, 10), new Position(3, 20)))));
@@ -283,13 +283,13 @@ public class SymbolCacheOnDiscTest {
generatedSymbols2.add(new CachedSymbol(doc1URI, timeFile1.toMillis() + 2000, enhancedSymbol2, null));
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
cache.update(new SymbolCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, null);
cache.update(new IndexCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, null);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new SymbolCacheKey("somekey", "1"), files);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new IndexCacheKey("somekey", "1"), files);
assertNotNull(cachedSymbols);
assertEquals(2, cachedSymbols.length);
assertEquals(timeFile1.toMillis() + 2000, cache.getModificationTimestamp(new SymbolCacheKey("somekey", "1"), file1.toString()));
assertEquals(timeFile1.toMillis() + 2000, cache.getModificationTimestamp(new IndexCacheKey("somekey", "1"), file1.toString()));
}
@Test
@@ -328,7 +328,7 @@ public class SymbolCacheOnDiscTest {
generatedSymbols.add(new CachedSymbol(doc3URI, timeFile3.toMillis(), enhancedSymbol3, null));
// store original version of the symbols to the cache
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols, null);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols, null);
// create updated and new symbols
@@ -353,10 +353,10 @@ public class SymbolCacheOnDiscTest {
long[] updatedModificationTimestamps = new long[]{timeFile1.toMillis() + 2000, timeFile2.toMillis() + 3000};
// update multiple files in the cache
cache.update(new SymbolCacheKey("somekey", "1"), updatedFiles, updatedModificationTimestamps, updatedSymbols, null);
cache.update(new IndexCacheKey("somekey", "1"), updatedFiles, updatedModificationTimestamps, updatedSymbols, null);
// double check whether all changes got stored and retrieved correctly
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new SymbolCacheKey("somekey", "1"), files);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new IndexCacheKey("somekey", "1"), files);
assertNotNull(cachedSymbols);
assertEquals(4, cachedSymbols.length);
@@ -365,9 +365,9 @@ public class SymbolCacheOnDiscTest {
assertSymbol(updatedEnhancedSymbol2, cachedSymbols);
assertSymbol(enhancedSymbol3, cachedSymbols);
assertEquals(timeFile1.toMillis() + 2000, cache.getModificationTimestamp(new SymbolCacheKey("somekey", "1"), file1.toString()));
assertEquals(timeFile2.toMillis() + 3000, cache.getModificationTimestamp(new SymbolCacheKey("somekey", "1"), file2.toString()));
assertEquals(timeFile3.toMillis(), cache.getModificationTimestamp(new SymbolCacheKey("somekey", "1"), file3.toString()));
assertEquals(timeFile1.toMillis() + 2000, cache.getModificationTimestamp(new IndexCacheKey("somekey", "1"), file1.toString()));
assertEquals(timeFile2.toMillis() + 3000, cache.getModificationTimestamp(new IndexCacheKey("somekey", "1"), file2.toString()));
assertEquals(timeFile3.toMillis(), cache.getModificationTimestamp(new IndexCacheKey("somekey", "1"), file3.toString()));
}
private void assertSymbol(EnhancedSymbolInformation enhancedSymbol, CachedSymbol[] cachedSymbols) {
@@ -395,13 +395,13 @@ public class SymbolCacheOnDiscTest {
List<CachedSymbol> generatedSymbols = ImmutableList.of();
Multimap<String, String> dependencies = ImmutableMultimap.of(file1.toString(), "dep1");
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols, dependencies);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols, dependencies);
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
Set<String> dependencies2 = ImmutableSet.of("dep1", "dep2");
cache.update(new SymbolCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols, dependencies2);
cache.update(new IndexCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols, dependencies2);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("somekey", "1"), files);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("somekey", "1"), files);
assertNotNull(result);
assertEquals(ImmutableSet.of("dep1", "dep2"), result.getRight().get(file1.toString()));
}
@@ -422,14 +422,14 @@ public class SymbolCacheOnDiscTest {
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1, null);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1, null));
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols1, null);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols1, null);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
cache.update(new SymbolCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, null);
cache.update(new IndexCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, null);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new SymbolCacheKey("somekey", "1"), files);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new IndexCacheKey("somekey", "1"), files);
assertNotNull(cachedSymbols);
assertEquals(0, cachedSymbols.length);
}
@@ -450,15 +450,15 @@ public class SymbolCacheOnDiscTest {
file1.toString(), "dep2"
);
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols1, dependencies1);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols1, dependencies1);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
assertTrue(file1.toFile().setLastModified(timeFile1.toMillis() + 2000));
Set<String> dependencies2 = ImmutableSet.of("dep2");
cache.update(new SymbolCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, dependencies2);
cache.update(new IndexCacheKey("somekey", "1"), file1.toAbsolutePath().toString(), timeFile1.toMillis() + 2000, generatedSymbols2, dependencies2);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("somekey", "1"), files);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("somekey", "1"), files);
assertNotNull(result);
assertEquals(ImmutableSet.of("dep2"), result.getRight().get(file1.toString()));
}
@@ -483,7 +483,7 @@ public class SymbolCacheOnDiscTest {
EnhancedSymbolInformation enhancedSymbol1 = new EnhancedSymbolInformation(symbol1, null);
generatedSymbols1.add(new CachedSymbol(doc1URI, timeFile1.toMillis(), enhancedSymbol1, null));
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols1, null);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols1, null);
List<CachedSymbol> generatedSymbols2 = new ArrayList<>();
WorkspaceSymbol symbol2 = new WorkspaceSymbol("symbol2", SymbolKind.Interface, Either.forLeft(new Location(doc2URI, new Range(new Position(5, 5), new Position(5, 10)))));
@@ -491,9 +491,9 @@ public class SymbolCacheOnDiscTest {
generatedSymbols2.add(new CachedSymbol(doc2URI, timeFile2.toMillis(), enhancedSymbol2, null));
cache.update(new SymbolCacheKey("somekey", "1"), file2.toString(), timeFile2.toMillis(), generatedSymbols2, null);
cache.update(new IndexCacheKey("somekey", "1"), file2.toString(), timeFile2.toMillis(), generatedSymbols2, null);
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new SymbolCacheKey("somekey", "1"), new String[]{file1.toString(), file2.toString()});
CachedSymbol[] cachedSymbols = cache.retrieveSymbols(new IndexCacheKey("somekey", "1"), new String[]{file1.toString(), file2.toString()});
assertNotNull(cachedSymbols);
assertEquals(2, cachedSymbols.length);
}
@@ -513,12 +513,12 @@ public class SymbolCacheOnDiscTest {
Multimap<String, String> dependencies1 = ImmutableMultimap.of(
file1.toString(), "dep1"
);
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols1, dependencies1);
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols1, dependencies1);
Set<String> dependencies2 = ImmutableSet.of("dep2");
cache.update(new SymbolCacheKey("somekey", "1"), file2.toString(), timeFile2.toMillis(), generatedSymbols1, dependencies2);
cache.update(new IndexCacheKey("somekey", "1"), file2.toString(), timeFile2.toMillis(), generatedSymbols1, dependencies2);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("somekey", "1"), new String[]{file1.toString(), file2.toString()});
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("somekey", "1"), new String[]{file1.toString(), file2.toString()});
assertNotNull(result);
assertEquals(ImmutableSet.of("dep2"), result.getRight().get(file2.toString()));
assertEquals(ImmutableSet.of("dep1"), result.getRight().get(file1.toString()));
@@ -526,7 +526,7 @@ public class SymbolCacheOnDiscTest {
@Test
void testProjectDeleted() throws Exception {
SymbolCacheKey key1 = new SymbolCacheKey("somekey", "1");
IndexCacheKey key1 = new IndexCacheKey("somekey", "1");
cache.store(key1, new String[0], new ArrayList<>(), null);
assertTrue(Files.exists(tempDir.resolve(Paths.get(key1.toString() + ".json"))));
@@ -564,11 +564,11 @@ public class SymbolCacheOnDiscTest {
file1.toString(), "dep1",
file2.toString(), "dep2"
);
cache.store(new SymbolCacheKey("somekey", "1"), files, generatedSymbols, dependencies);
cache.removeFile(new SymbolCacheKey("somekey", "1"), file1.toAbsolutePath().toString());
cache.store(new IndexCacheKey("somekey", "1"), files, generatedSymbols, dependencies);
cache.removeFile(new IndexCacheKey("somekey", "1"), file1.toAbsolutePath().toString());
files = new String[]{file2.toAbsolutePath().toString()};
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new SymbolCacheKey("somekey", "1"), files);
Pair<CachedSymbol[], Multimap<String, String>> result = cache.retrieve(new IndexCacheKey("somekey", "1"), files);
CachedSymbol[] cachedSymbols = result.getLeft();
assertNotNull(result);
assertEquals(1, cachedSymbols.length);

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Pivotal, Inc.
* Copyright (c) 2020, 2023 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
@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.utils.test;
package org.springframework.ide.vscode.boot.index.cache.test;
import java.io.File;
import java.io.IOException;
@@ -23,25 +23,25 @@ import java.util.TreeMap;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheKey;
import org.springframework.ide.vscode.boot.java.utils.CachedSymbol;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheKey;
import com.google.common.collect.Multimap;
/**
* @author Martin Lippert
*/
public class SymbolCacheTimestampsOnly implements SymbolCache {
public class IndexCacheTimestampsOnly implements IndexCache {
private Map<SymbolCacheKey, Map<String, Long>> timestampCache;
private Map<IndexCacheKey, Map<String, Long>> timestampCache;
public SymbolCacheTimestampsOnly() {
public IndexCacheTimestampsOnly() {
this.timestampCache = new HashMap<>();
}
@Override
public void store(SymbolCacheKey cacheKey, String[] files, List<CachedSymbol> generatedSymbols, Multimap<String,String> dependencies) {
public void store(IndexCacheKey cacheKey, String[] files, List<CachedSymbol> generatedSymbols, Multimap<String,String> dependencies) {
SortedMap<String, Long> timestampedFiles = new TreeMap<>();
timestampedFiles = Arrays.stream(files)
@@ -58,18 +58,18 @@ public class SymbolCacheTimestampsOnly implements SymbolCache {
}
@Override
public Pair<CachedSymbol[], Multimap<String, String>> retrieve(SymbolCacheKey cacheKey, String[] files) {
public Pair<CachedSymbol[], Multimap<String, String>> retrieve(IndexCacheKey cacheKey, String[] files) {
return null;
}
@Override
public void update(SymbolCacheKey cacheKey, String file, long lastModified, List<CachedSymbol> generatedSymbols, Set<String> dependencies) {
public void update(IndexCacheKey cacheKey, String file, long lastModified, List<CachedSymbol> generatedSymbols, Set<String> dependencies) {
Map<String, Long> timestampMap = timestampCache.get(cacheKey);
timestampMap.put(file, lastModified);
}
@Override
public void update(SymbolCacheKey cacheKey, String[] files, long[] lastModified, List<CachedSymbol> generatedSymbols, Multimap<String, String> dependencies) {
public void update(IndexCacheKey cacheKey, String[] files, long[] lastModified, List<CachedSymbol> generatedSymbols, Multimap<String, String> dependencies) {
Map<String, Long> timestampMap = timestampCache.get(cacheKey);
for (int i = 0; i < files.length; i++) {
@@ -78,15 +78,15 @@ public class SymbolCacheTimestampsOnly implements SymbolCache {
}
@Override
public void remove(SymbolCacheKey cacheKey) {
public void remove(IndexCacheKey cacheKey) {
}
@Override
public void removeFile(SymbolCacheKey symbolCacheKey, String file) {
public void removeFile(IndexCacheKey symbolCacheKey, String file) {
}
@Override
public long getModificationTimestamp(SymbolCacheKey cacheKey, String file) {
public long getModificationTimestamp(IndexCacheKey cacheKey, String file) {
Map<String, Long> timestampMap = timestampCache.get(cacheKey);
if (timestampMap != null) {
Long timestamp = timestampMap.get(file);

View File

@@ -8,7 +8,7 @@
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.metamodel.test;
package org.springframework.ide.vscode.boot.index.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

View File

@@ -8,7 +8,7 @@
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.metamodel.test;
package org.springframework.ide.vscode.boot.index.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -25,7 +25,7 @@ import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Test;
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheOnDisc;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheOnDisc;
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
import org.springframework.ide.vscode.commons.protocol.spring.DefaultValues;
import org.springframework.ide.vscode.commons.protocol.spring.InjectionPoint;
@@ -224,7 +224,7 @@ public class SpringMetamodelIndexTest {
Bean bean1 = new Bean("beanName1", "beanType", locationForDoc1, new InjectionPoint[] {point1, point2}, new String[] {"supertype1", "supertype2"}, emptyAnnotations);
String serialized = bean1.toString();
Gson gson = SymbolCacheOnDisc.createGson();
Gson gson = IndexCacheOnDisc.createGson();
Bean deserializedBean = gson.fromJson(serialized, Bean.class);
assertEquals("beanName1", deserializedBean.getName());
@@ -252,7 +252,7 @@ public class SpringMetamodelIndexTest {
Bean bean1 = new Bean("beanName1", "beanType", locationForDoc1, emptyInjectionPoints, emptySupertypes, emptyAnnotations);
String serialized = bean1.toString();
Gson gson = SymbolCacheOnDisc.createGson();
Gson gson = IndexCacheOnDisc.createGson();
Bean deserializedBean = gson.fromJson(serialized, Bean.class);
assertEquals("beanName1", deserializedBean.getName());

View File

@@ -8,7 +8,7 @@
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.metamodel.test;
package org.springframework.ide.vscode.boot.index.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

View File

@@ -8,7 +8,7 @@
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.metamodel.test;
package org.springframework.ide.vscode.boot.index.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

View File

@@ -32,12 +32,12 @@ import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.bootiful.AdHocPropertyHarnessTestConf;
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
@@ -73,8 +73,8 @@ public class CompilationUnitCacheTest {
@Configuration static class TestConf {
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {

View File

@@ -33,7 +33,8 @@ import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.test.IndexCacheTimestampsOnly;
import org.springframework.ide.vscode.boot.java.utils.SymbolIndexConfig;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
@@ -53,8 +54,8 @@ public class SpringIndexerMultipleFilesTest {
// in order to check the java symbol indexer feature which avoid scanning the
// same file again even if the timestamp hasn't changed
public static class TimestampingAwareCacheConfig extends SymbolProviderTestConf {
@Bean public SymbolCache symbolCache() {
return new SymbolCacheTimestampsOnly();
@Bean public IndexCache symbolCache() {
return new IndexCacheTimestampsOnly();
}
}

View File

@@ -35,11 +35,11 @@ import org.springframework.ide.vscode.boot.bootiful.AdHocPropertyHarnessTestConf
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
import org.springframework.ide.vscode.boot.editor.harness.AdHocPropertyHarness;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.java.value.ValueCompletionProcessor;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.commons.java.IJavaProject;
@@ -117,8 +117,8 @@ public class ValueCompletionTest {
);
}
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean SourceLinks sourceLinks(SimpleTextDocumentService documents, CompilationUnitCache cuCache) {

View File

@@ -40,14 +40,14 @@ import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.bootiful.AdHocPropertyHarnessTestConf;
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.index.cache.IndexCache;
import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid;
import org.springframework.ide.vscode.boot.java.handlers.BootJavaReconcileEngine;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.reconcilers.JavaReconciler;
import org.springframework.ide.vscode.boot.java.reconcilers.JdtReconciler;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
@@ -129,8 +129,8 @@ public class ValueSpelExpressionValidationTest {
);
}
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
@Bean IndexCache symbolCache() {
return new IndexCacheVoid();
}
@Bean SourceLinks sourceLinks(SimpleTextDocumentService documents, CompilationUnitCache cuCache) {