Modulith integration improved with manual refresh
This commit is contained in:
@@ -256,6 +256,10 @@
|
||||
class="org.springframework.tooling.boot.ls.commands.RewriteRefactoringsHandler$UpgradeBootVersion"
|
||||
commandId="org.springframework.tooling.boot.ls.rewrite.boot-upgrade">
|
||||
</handler>
|
||||
<handler
|
||||
class="org.springframework.tooling.boot.ls.commands.RefreshModulithMetadata"
|
||||
commandId="org.springframework.tooling.boot.ls.modulith.metadata.refresh">
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
@@ -282,6 +286,11 @@
|
||||
id="org.springframework.tooling.boot.ls.rewrite.boot-upgrade"
|
||||
name="Upgrade Spring Boot Version...">
|
||||
</command>
|
||||
<command
|
||||
description="Refresh project's Modulith metadata and re-validate the project"
|
||||
id="org.springframework.tooling.boot.ls.modulith.metadata.refresh"
|
||||
name="Refresh Modulith Metadata">
|
||||
</command>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
@@ -644,6 +653,80 @@
|
||||
name="org.springframework.tooling.boot.ls.rewrite"
|
||||
visible="true">
|
||||
</separator>
|
||||
<command
|
||||
commandId="org.springframework.tooling.boot.ls.modulith.metadata.refresh"
|
||||
id="org.springframework.tooling.boot.ls.modulith.metadata.refresh"
|
||||
label="Refresh Modulith Metadata"
|
||||
style="push">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<and>
|
||||
<count
|
||||
value="1">
|
||||
</count>
|
||||
<iterate>
|
||||
<or>
|
||||
<adapt
|
||||
type="org.eclipse.core.resources.IFile">
|
||||
<and>
|
||||
<test
|
||||
args="spring-modulith-core"
|
||||
forcePluginActivation="true"
|
||||
property="org.springframework.tooling.boot.isProjectWithDependencyResource">
|
||||
</test>
|
||||
<or>
|
||||
<and>
|
||||
<test
|
||||
property="org.eclipse.core.resources.path"
|
||||
value="/*/pom.xml">
|
||||
</test>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.m2e.core.maven2Nature">
|
||||
</test>
|
||||
</and>
|
||||
<and>
|
||||
<test
|
||||
property="org.eclipse.core.resources.path"
|
||||
value="/*/build.gradle">
|
||||
</test>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.buildship.core.gradleprojectnature">
|
||||
</test>
|
||||
</and>
|
||||
</or>
|
||||
</and>
|
||||
</adapt>
|
||||
<adapt
|
||||
type="org.eclipse.core.resources.IProject">
|
||||
<and>
|
||||
<test
|
||||
args="spring-modulith-core"
|
||||
forcePluginActivation="true"
|
||||
property="org.springframework.tooling.boot.isProjectWithDependencyResource">
|
||||
</test>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.jdt.core.javanature">
|
||||
</test>
|
||||
<or>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.m2e.core.maven2Nature">
|
||||
</test>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.buildship.core.gradleprojectnature">
|
||||
</test>
|
||||
</or>
|
||||
</and>
|
||||
</adapt>
|
||||
</or>
|
||||
</iterate>
|
||||
</and>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
<extension
|
||||
@@ -659,7 +742,7 @@
|
||||
class="org.springframework.tooling.boot.ls.BootProjectTester"
|
||||
id="org.springframework.tooling.boot"
|
||||
namespace="org.springframework.tooling.boot"
|
||||
properties="isBootResource"
|
||||
properties="isBootResource,isProjectWithDependencyResource"
|
||||
type="java.lang.Object">
|
||||
</propertyTester>
|
||||
</extension>
|
||||
|
||||
@@ -39,7 +39,23 @@ public class BootProjectTester extends PropertyTester {
|
||||
if (project != null) {
|
||||
IJavaProject jp = JavaCore.create(project);
|
||||
if (jp != null) {
|
||||
return isBootProject(project);
|
||||
return isProjectWithDependency(jp, "spring-boot");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("isProjectWithDependencyResource".equals(property)) {
|
||||
IResource resource = null;
|
||||
if (receiver instanceof IAdaptable) {
|
||||
resource = ((IAdaptable) receiver).getAdapter(IResource.class);
|
||||
} else if (receiver instanceof IDocument) {
|
||||
resource = LSPEclipseUtils.getFile((IDocument) receiver);
|
||||
}
|
||||
if (resource != null) {
|
||||
IProject project = resource.getProject();
|
||||
if (project != null) {
|
||||
IJavaProject jp = JavaCore.create(project);
|
||||
if (jp != null) {
|
||||
return isProjectWithDependency(jp, (String) args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,42 +63,38 @@ public class BootProjectTester extends PropertyTester {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBootProject(IProject project) {
|
||||
if (project==null || ! project.isAccessible()) {
|
||||
private static boolean isProjectWithDependency(IJavaProject jp, String dep) {
|
||||
if (jp == null || ! jp.getProject().isAccessible()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (project.hasNature(JavaCore.NATURE_ID)) {
|
||||
IJavaProject jp = JavaCore.create(project);
|
||||
IClasspathEntry[] classpath = jp.getResolvedClasspath(true);
|
||||
//Look for a 'spring-boot' jar or project entry
|
||||
IClasspathEntry[] classpath = jp.getResolvedClasspath(true);
|
||||
|
||||
for (IClasspathEntry e : classpath) {
|
||||
if (isBootJar(e) || isBootProject(e)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (IClasspathEntry e : classpath) {
|
||||
if (isDependencyJar(dep, e) || isDependencyProject(dep, e)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CorePlugin.log(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBootJar(IClasspathEntry e) {
|
||||
|
||||
private static boolean isDependencyJar(String dep, IClasspathEntry e) {
|
||||
if (e.getEntryKind()==IClasspathEntry.CPE_LIBRARY) {
|
||||
IPath path = e.getPath();
|
||||
String name = path.lastSegment();
|
||||
return name.endsWith(".jar") && name.startsWith("spring-boot");
|
||||
return name.endsWith(".jar") && name.startsWith(dep);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBootProject(IClasspathEntry e) {
|
||||
private static boolean isDependencyProject(String dep, IClasspathEntry e) {
|
||||
if (e.getEntryKind()==IClasspathEntry.CPE_PROJECT) {
|
||||
IPath path = e.getPath();
|
||||
String name = path.lastSegment();
|
||||
return name.startsWith("spring-boot");
|
||||
return name.startsWith(dep);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2023 VMware, 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
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.boot.ls.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.lsp4e.LanguageServers;
|
||||
import org.eclipse.lsp4e.LanguageServersRegistry;
|
||||
import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition;
|
||||
import org.eclipse.lsp4j.ExecuteCommandParams;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.springframework.tooling.boot.ls.BootLanguageServerPlugin;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class RefreshModulithMetadata extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
|
||||
Object o = selection.getFirstElement();
|
||||
IProject project = null;
|
||||
if (o instanceof IResource) {
|
||||
project = ((IResource) o).getProject();
|
||||
} else if (o instanceof IProject) {
|
||||
project = (IProject) o;
|
||||
} else if (o instanceof IAdaptable) {
|
||||
project = ((IAdaptable) o).getAdapter(IProject.class);
|
||||
}
|
||||
if (project != null) {
|
||||
LanguageServerDefinition def = LanguageServersRegistry.getInstance().getDefinition(BootLanguageServerPlugin.BOOT_LS_DEFINITION_ID);
|
||||
Assert.isLegal(def != null, "No definition found for Boot Language Server");
|
||||
|
||||
final String uri = project.getLocationURI().toASCIIString();
|
||||
ExecuteCommandParams commandParams = new ExecuteCommandParams();
|
||||
commandParams.setCommand("sts/modulith/metadata/refresh");
|
||||
commandParams.setArguments(List.of(uri));
|
||||
|
||||
LanguageServers.forProject(project).withPreferredServer(def).computeFirst(ls -> ls.getWorkspaceService().executeCommand(commandParams));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user