Upgrade to Boot 3 for eclipse
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
class="org.springframework.ide.eclipse.boot.core.BootPropertyTester"
|
||||
id="org.springsource.ide.eclipse.boot.BootPropertyTester"
|
||||
namespace="org.springsource.ide.eclipse.boot"
|
||||
properties="isBootProject,isBootResource,hasBootDevTools"
|
||||
properties="isBootProject,isBootResource,hasBootDevTools,isBoot2Project,isBoot2Resource"
|
||||
type="org.eclipse.core.resources.IResource">
|
||||
<!-- type="java.lang.Object" -->
|
||||
</propertyTester>
|
||||
@@ -19,7 +19,7 @@
|
||||
class="org.springframework.ide.eclipse.boot.core.BootJavaElementPropertyTester"
|
||||
id="org.springframework.ide.eclipse.boot.core.BootJavaElementPropertyTester"
|
||||
namespace="org.springsource.ide.eclipse.boot.javaelement"
|
||||
properties="isInBootProject,isInBootProjectWithDevTools"
|
||||
properties="isInBootProject,isInBootProjectWithDevTools,isInBoot2Project"
|
||||
type="org.eclipse.jdt.core.IJavaElement">
|
||||
<!-- type="java.lang.Object" -->
|
||||
</propertyTester>
|
||||
|
||||
@@ -31,6 +31,19 @@ public class BootJavaElementPropertyTester extends PropertyTester {
|
||||
if (je instanceof IJavaElement && "isInBootProjectWithDevTools".equals(property)) {
|
||||
return hasBootDevTools((IJavaElement) je);
|
||||
}
|
||||
if (je instanceof IJavaElement && "isInBoot2Project".equals(property)) {
|
||||
return isInBoot2Project((IJavaElement) je);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isInBoot2Project(IJavaElement je) {
|
||||
if (je!=null) {
|
||||
IJavaProject jp = je.getJavaProject();
|
||||
if (jp!=null) {
|
||||
return BootPropertyTester.isBoot2Project(jp.getProject());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,12 @@ public class BootPropertyTester extends PropertyTester {
|
||||
if (rsrc instanceof IResource && "hasBootDevTools".equals(property)) {
|
||||
return hasBootDevTools(((IResource) rsrc).getProject());
|
||||
}
|
||||
if (rsrc instanceof IProject && "isBoot2Project".equals(property)) {
|
||||
return expectedValue.equals(isBoot2Project((IProject)rsrc));
|
||||
}
|
||||
if (rsrc instanceof IResource && "isBoot2Resource".equals(property)) {
|
||||
return expectedValue.equals(isBoot2Resource((IResource) rsrc));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -128,6 +134,30 @@ public class BootPropertyTester extends PropertyTester {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isBoot2Project(IProject project) {
|
||||
if (project==null || ! project.isAccessible()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (project.hasNature(JavaCore.NATURE_ID)) {
|
||||
if (!isExcludedProject(project)) {
|
||||
IJavaProject jp = JavaCore.create(project);
|
||||
IClasspathEntry[] classpath = jp.getResolvedClasspath(true);
|
||||
//Look for a 'spring-boot' jar or project entry
|
||||
|
||||
for (IClasspathEntry e : classpath) {
|
||||
if ((isBootJar(e) || isBootProject(e)) && isVersion(e, "2.")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CorePlugin.log(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasBootDevTools(IProject project) {
|
||||
try {
|
||||
ISpringBootProject bootProject = SpringBootCore.getDefault().project(project);
|
||||
@@ -231,6 +261,14 @@ public class BootPropertyTester extends PropertyTester {
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object isBoot2Resource(IResource rsrc) {
|
||||
if (rsrc==null || ! rsrc.isAccessible()) {
|
||||
return false;
|
||||
}
|
||||
boolean result = isBoot2Project(rsrc.getProject());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isBootProject(IClasspathEntry e) {
|
||||
if (e.getEntryKind()==IClasspathEntry.CPE_PROJECT) {
|
||||
IPath path = e.getPath();
|
||||
@@ -240,6 +278,16 @@ public class BootPropertyTester extends PropertyTester {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isVersion(IClasspathEntry e, String v) {
|
||||
if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
|
||||
IPath path = e.getPath();
|
||||
String name = path.lastSegment();
|
||||
String version = getVersionFromJarName(name);
|
||||
return version.startsWith(v);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isBootJar(IClasspathEntry e) {
|
||||
if (e.getEntryKind()==IClasspathEntry.CPE_LIBRARY) {
|
||||
IPath path = e.getPath();
|
||||
|
||||
@@ -173,6 +173,10 @@
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="org.springframework.tooling.boot.ls.commands.UpgradeToBoot3Handler"
|
||||
commandId="org.springframework.tooling.boot.ls.UpgradeToBoot3">
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
@@ -187,6 +191,12 @@
|
||||
categoryId="org.springframework.ide.eclipse.commands"
|
||||
name="Toggle Comment">
|
||||
</command>
|
||||
<command
|
||||
categoryId="org.springframework.ide.eclipse.commands"
|
||||
description="Upgrade Spring Boot 2.x prohect to Spring Boot 3.x"
|
||||
id="org.springframework.tooling.boot.ls.UpgradeToBoot3"
|
||||
name="Upgrade to Boot 3">
|
||||
</command>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
@@ -355,6 +365,70 @@
|
||||
class="org.springframework.tooling.boot.ls.prefs.RemoteAppsFromPrefsDataContributor">
|
||||
</injection>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
allPopups="false"
|
||||
locationURI="popup:org.springframework.ide.eclipse.ui.tools?after=boot">
|
||||
<command
|
||||
commandId="org.springframework.tooling.boot.ls.UpgradeToBoot3"
|
||||
id="org.springframework.tooling.boot.ls.UpgradeToBoot3"
|
||||
label="Upgrade to Boot 3"
|
||||
style="push">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<and>
|
||||
<count
|
||||
value="1">
|
||||
</count>
|
||||
<iterate>
|
||||
<or>
|
||||
<adapt
|
||||
type="org.eclipse.core.resources.IResource">
|
||||
<and>
|
||||
<test
|
||||
forcePluginActivation="true"
|
||||
property="org.springsource.ide.eclipse.boot.isBoot2Resource">
|
||||
</test>
|
||||
<or>
|
||||
<test
|
||||
property="org.eclipse.core.resources.name"
|
||||
value="pom.xml">
|
||||
</test>
|
||||
<adapt
|
||||
type="org.eclipse.core.resources.IProject">
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.m2e.core.maven2Nature">
|
||||
</test>
|
||||
</adapt>
|
||||
</or>
|
||||
</and>
|
||||
</adapt>
|
||||
<and>
|
||||
<instanceof
|
||||
value="org.eclipse.jdt.core.IJavaProject">
|
||||
</instanceof>
|
||||
<test
|
||||
property="org.springsource.ide.eclipse.commons.java.projectNature"
|
||||
value="org.eclipse.m2e.core.maven2Nature">
|
||||
</test>
|
||||
<test
|
||||
forcePluginActivation="true"
|
||||
property="org.springsource.ide.eclipse.boot.javaelement.isInBoot2Project">
|
||||
</test>
|
||||
</and>
|
||||
</or>
|
||||
</iterate>
|
||||
<systemTest
|
||||
property="sts.rewrite.recipes"
|
||||
value="true">
|
||||
</systemTest>
|
||||
</and>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
<!--
|
||||
<extension
|
||||
point="org.eclipse.wildwebdeveloper.xml.lemminxExtension">
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 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 java.util.concurrent.CompletableFuture;
|
||||
|
||||
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.jdt.annotation.NonNull;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor;
|
||||
import org.eclipse.lsp4j.ExecuteCommandParams;
|
||||
import org.eclipse.lsp4j.services.LanguageServer;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.springsource.ide.eclipse.commons.livexp.util.Log;
|
||||
|
||||
public class UpgradeToBoot3Handler extends AbstractHandler {
|
||||
|
||||
private static final String UPGRADE_TO_BOOT_3_COMMAND_ID = "sts/rewrite/recipe/org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0";
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
|
||||
IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
|
||||
Object o = selection.getFirstElement();
|
||||
if (o instanceof IResource) {
|
||||
IProject project = ((IResource) o).getProject();
|
||||
if (project != null) {
|
||||
List<@NonNull LanguageServer> usedLanguageServers = LanguageServiceAccessor.getActiveLanguageServers(serverCapabilities -> true);
|
||||
|
||||
if (!usedLanguageServers.isEmpty()) {
|
||||
ExecuteCommandParams commandParams = new ExecuteCommandParams();
|
||||
commandParams.setCommand(UPGRADE_TO_BOOT_3_COMMAND_ID);
|
||||
commandParams.setArguments(List.of(project.getLocationURI().toString()));
|
||||
|
||||
try {
|
||||
CompletableFuture.allOf(usedLanguageServers.stream().map(ls ->
|
||||
ls.getWorkspaceService().executeCommand(commandParams)).toArray(CompletableFuture[]::new));
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class BasicJandexIndex {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BasicJandexIndex.class);
|
||||
|
||||
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
|
||||
private static final String USER_HOME = "user.home";
|
||||
|
||||
@FunctionalInterface
|
||||
public static interface IndexFileFinder {
|
||||
@@ -53,7 +53,7 @@ public class BasicJandexIndex {
|
||||
}
|
||||
|
||||
public static File getIndexFolder() {
|
||||
File folder = new File(System.getProperty(JAVA_IO_TMPDIR), "jandex");
|
||||
File folder = new File(System.getProperty(USER_HOME), ".sts-jandex");
|
||||
if (!folder.isDirectory()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user