fix(maven): refresh stale SNAPSHOT sources on dependency reload (#5490)

After a SNAPSHOT dependency was republished and the project reloaded, navigating into it still showed the old sources: SNAPSHOT file names never change, the cached sources jar was reused as long as it existed, and open library editors kept their text. A sources jar older than its binary jar is now stale and replaced atomically; Maven reload waits for jdtls to finish importing, refreshes stale cached SNAPSHOT sources before reattaching archives, and refreshes open library editors. First-time source downloads still follow the Maven setting.
This commit is contained in:
l0ng-ai
2026-11-24 01:09:14 +08:00
committed by GitHub
parent 9d94b00911
commit abab90ca60
12 changed files with 508 additions and 105 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OpenIDEA Java usages
Bundle-SymbolicName: ai.openidea.usages;singleton:=true
Bundle-Version: 1.17.0
Bundle-Version: 1.18.0
Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.jdt.ls.core,org.eclipse.jdt.core,
org.eclipse.jdt.core.manipulation,org.eclipse.core.runtime,
+1 -1
View File
@@ -88,7 +88,7 @@ is not a claim of full IntelliJ feature parity.
## Rebuild and delivery
The checked-in jar is embedded by ide-sdk `include_bytes!`, installed as
`java-usages-1.17.0.jar`, and added alongside existing initialization bundles.
`java-usages-1.18.0.jar`, and added alongside existing initialization bundles.
Users need no compiler, Maven or Python. Manifest/install version must change
when replacing the bundle because OSGi caches bundles.
Binary file not shown.
+1
View File
@@ -19,6 +19,7 @@
</delegateCommandHandler>
<delegateCommandHandler class="ai.openidea.archives.RefreshArchivesCommand">
<command id="openidea.java.refreshArchives"/>
<command id="openidea.java.updateProjectConfigurations"/>
</delegateCommandHandler>
<delegateCommandHandler class="ai.openidea.sources.GeneratedSourcesCommand">
<command id="openidea.java.generatedSources"/>
@@ -1,10 +1,12 @@
package ai.openidea.archives;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -16,6 +18,8 @@ import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.lsp4j.TextDocumentIdentifier;
/**
* Re-reads library archives replaced in place (a SNAPSHOT installed again keeps its path). The
@@ -26,6 +30,17 @@ import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
public final class RefreshArchivesCommand implements IDelegateCommandHandler {
@Override
public Object executeCommand(String command, List<Object> arguments, IProgressMonitor monitor) throws Exception {
if ("openidea.java.updateProjectConfigurations".equals(command)) {
List<TextDocumentIdentifier> files = arguments.stream()
.filter(String.class::isInstance)
.map(uri -> new TextDocumentIdentifier((String) uri))
.toList();
Collection<IProject> projects = ProjectUtils.getProjectsFromDocumentIdentifiers(files);
if (!projects.isEmpty()) {
JavaLanguageServerPlugin.getProjectsManager().updateProjects(projects, true).join(0, monitor);
}
return null;
}
IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
model.refreshExternalArchives(null, monitor);
Set<IPath> archives = new HashSet<>();