Upgrade to Boot 3 for eclipse

This commit is contained in:
BoykoAlex
2022-05-11 13:47:48 -04:00
parent f009d68349
commit 873f1cb985
6 changed files with 201 additions and 4 deletions

View File

@@ -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">

View File

@@ -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;
}
}