Skip to content

Commit bf3e69c

Browse files
authored
Merge pull request #63 from luiseufrasio/FISH-6772-javaee8-to-jakartaee10
FISH-6772 javaee8 to jakartaee10
2 parents fa8123b + cd33842 commit bf3e69c

6 files changed

Lines changed: 257 additions & 7 deletions

File tree

.gitignore

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
**/target/
2-
**/bin/
2+
**/bin/
3+
/.metadata/.lock
4+
/.metadata/.log
5+
/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location
6+
/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version
7+
/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index
8+
/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version
9+
/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree
10+
/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
11+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs
12+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs
13+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jsch.core.prefs
14+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.j2ee.webservice.ui.prefs
15+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs
16+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs
17+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.navigator.prefs
18+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs
19+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs
20+
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.urischeme.prefs
21+
/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
22+
/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.project
23+
/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.settings/org.eclipse.core.resources.prefs
24+
/.metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache
25+
/.metadata/.plugins/org.eclipse.jdt.core/externalFilesCache
26+
/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt
27+
/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache
28+
/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat
29+
/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml
30+
/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml
31+
/.metadata/.plugins/org.eclipse.m2e.core.ui/dialog_settings.xml
32+
/.metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser
33+
/.metadata/.plugins/org.eclipse.m2e.logback/0.log
34+
/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.1.0.20221015-0744.xml
35+
/.metadata/.plugins/org.eclipse.oomph.setup/workspace.setup
36+
/.metadata/.plugins/org.eclipse.tips.ide/dialog_settings.xml
37+
/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml
38+
/.metadata/.plugins/org.eclipse.ui.intro/introstate
39+
/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml
40+
/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml
41+
/.metadata/version.ini
42+
/bundles/fish.payara.eclipse.tools.micro/.settings/org.eclipse.jdt.core.prefs
43+
/bundles/fish.payara.eclipse.tools.server/.settings/org.eclipse.jdt.core.prefs
44+
/bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/handlers/RefactorHandler.java
45+
/features/fish.payara.eclipse.tools.micro.feature/.polyglot.build.properties
46+
/features/fish.payara.eclipse.tools.server.feature/.polyglot.build.properties

bundles/fish.payara.eclipse.tools.micro/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
</attributes>
1515
</classpathentry>
1616
<classpathentry kind="output" path="target/classes"/>
17-
</classpath>
17+
</classpath>

bundles/fish.payara.eclipse.tools.server/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
</attributes>
1515
</classpathentry>
1616
<classpathentry kind="output" path="target/classes"/>
17-
</classpath>
17+
</classpath>

bundles/fish.payara.eclipse.tools.server/plugin.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ menu.openserverhome=Server Home Directory
7171
menu.opendomainhome=Domain Directory
7272
menu.payaratopmenu=Payara
7373

74+
menu.migrate=Migrate
75+
menu.convert=Convert to Jakarta EE 10
76+
7477

7578

7679

bundles/fish.payara.eclipse.tools.server/plugin.xml

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,11 @@
976976
</and>
977977
</enabledWhen>
978978
</handler>
979+
980+
<handler
981+
commandId="fish.payara.eclipse.tools.server.commands.MigrateHandler"
982+
class="fish.payara.eclipse.tools.server.handlers.MigrateHandler">
983+
</handler>
979984
</extension>
980985

981986
<!-- 3. Definitions of the menu entries putting the above defined commands in -->
@@ -1020,10 +1025,47 @@
10201025
</command>
10211026
</menu>
10221027
</menuContribution>
1028+
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?endof=group.build">
1029+
<menu id="fish.payara.eclipse.tools.project.actions.migrate" label="%menu.migrate">
1030+
<command commandId="fish.payara.eclipse.tools.server.commands.MigrateHandler" label="%menu.convert" style="push">
1031+
</command>
1032+
<visibleWhen>
1033+
<or>
1034+
<with variable="activeMenuSelection">
1035+
<iterate>
1036+
<adapt type="org.eclipse.core.resources.IProject"></adapt>
1037+
</iterate>
1038+
</with>
1039+
<with variable="activeMenuSelection">
1040+
<iterate>
1041+
<adapt type="org.eclipse.jdt.core.ICompilationUnit"></adapt>
1042+
</iterate>
1043+
</with>
1044+
</or>
1045+
</visibleWhen>
1046+
</menu>
1047+
</menuContribution>
1048+
<menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?endof=group.build">
1049+
<menu id="fish.payara.eclipse.tools.package.actions.migrate" label="%menu.migrate">
1050+
<command commandId="fish.payara.eclipse.tools.server.commands.MigrateHandler" label="%menu.convert" style="push">
1051+
</command>
1052+
<visibleWhen>
1053+
<or>
1054+
<with variable="activeMenuSelection">
1055+
<iterate>
1056+
<adapt type="org.eclipse.core.resources.IProject"></adapt>
1057+
</iterate>
1058+
</with>
1059+
<with variable="activeMenuSelection">
1060+
<iterate>
1061+
<adapt type="org.eclipse.jdt.core.ICompilationUnit"></adapt>
1062+
</iterate>
1063+
</with>
1064+
</or>
1065+
</visibleWhen>
1066+
</menu>
1067+
</menuContribution>
10231068
</extension>
1024-
1025-
1026-
10271069

10281070
<!--
10291071
Properties that are being shown for the Payara / GlassFish server when e.g. the server is right clicked
@@ -1226,5 +1268,5 @@
12261268
provider="fish.payara.eclipse.tools.server.jaxrsLibraryproviderID">
12271269
</panel>
12281270
</extension>
1229-
1271+
12301272
</plugin>
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/******************************************************************************
2+
* Copyright (c) 2023 Payara Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v20.html
7+
* SPDX-License-Identifier: EPL-2.0
8+
******************************************************************************/
9+
10+
package fish.payara.eclipse.tools.server.handlers;
11+
12+
import java.io.BufferedReader;
13+
import java.io.File;
14+
import java.io.IOException;
15+
import java.io.InputStreamReader;
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
19+
import org.eclipse.core.commands.AbstractHandler;
20+
import org.eclipse.core.commands.ExecutionEvent;
21+
import org.eclipse.core.commands.ExecutionException;
22+
import org.eclipse.core.resources.IProject;
23+
import org.eclipse.core.resources.IResource;
24+
import org.eclipse.core.runtime.IPath;
25+
import org.eclipse.jdt.core.ICompilationUnit;
26+
import org.eclipse.jdt.core.IJavaProject;
27+
import org.eclipse.jface.dialogs.MessageDialog;
28+
import org.eclipse.jface.viewers.ISelection;
29+
import org.eclipse.jface.viewers.IStructuredSelection;
30+
import org.eclipse.swt.widgets.DirectoryDialog;
31+
import org.eclipse.swt.widgets.Shell;
32+
import org.eclipse.ui.PlatformUI;
33+
import org.eclipse.ui.console.ConsolePlugin;
34+
import org.eclipse.ui.console.IConsole;
35+
import org.eclipse.ui.console.MessageConsole;
36+
import org.eclipse.ui.console.MessageConsoleStream;
37+
import org.eclipse.ui.handlers.HandlerUtil;
38+
39+
public class MigrateHandler extends AbstractHandler {
40+
41+
public static final String PAYARA_TRANSFORMER = "fish.payara.transformer";
42+
public static final String PAYARA_TRANSFORMER_MAVEN = "fish.payara.transformer.maven";
43+
public static final String PAYARA_TRANSFORMER_VERSION = "0.2.10";
44+
45+
@Override
46+
public Object execute(ExecutionEvent event) throws ExecutionException {
47+
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
48+
IStructuredSelection selection = getSelection(event);
49+
if (selection != null && !selection.isEmpty()) {
50+
Object firstElement = selection.getFirstElement();
51+
IPath resourcePath = null;
52+
IPath projectPath = null;
53+
String name = "";
54+
boolean isFile = false;
55+
if (firstElement instanceof IResource) {
56+
IResource resource = (IResource) firstElement;
57+
resourcePath = resource.getLocation();
58+
projectPath = resourcePath;
59+
name = resource.getName();
60+
} else if (firstElement instanceof IJavaProject) {
61+
IJavaProject javaProject = (IJavaProject) firstElement;
62+
IProject project = javaProject.getProject();
63+
resourcePath = project.getLocation();
64+
projectPath = resourcePath;
65+
name = project.getName();
66+
} else if (firstElement instanceof ICompilationUnit) {
67+
ICompilationUnit file = (ICompilationUnit) firstElement;
68+
resourcePath = file.getResource().getLocation();
69+
projectPath = file.getJavaProject().getProject().getLocation();
70+
name = file.getElementName();
71+
isFile = true;
72+
}
73+
if (resourcePath != null && projectPath != null && !"".equals(name)) {
74+
String srcPath = resourcePath.toOSString();
75+
String srcProjectPath = projectPath.toOSString();
76+
String destinationPath = chooseDestinationPath(srcProjectPath, name, isFile);
77+
if ("".equals(destinationPath)) return null;
78+
int exitCode = runMvnCommand(srcProjectPath, srcPath, destinationPath);
79+
if (exitCode == 0) {
80+
MessageDialog.openInformation(shell, "Success", "Project " + destinationPath + " created successfully.");
81+
} else {
82+
MessageDialog.openError(shell, "Error", "Maven command failed with exit code " + exitCode + ".");
83+
}
84+
}
85+
}
86+
return null;
87+
}
88+
89+
private String chooseDestinationPath(String srcPath, String name, boolean isFile) {
90+
Shell shell = new Shell();
91+
DirectoryDialog dialog = new DirectoryDialog(shell);
92+
dialog.setText("Choose a destination Folder");
93+
dialog.setMessage("Please select a Directory:");
94+
dialog.setFilterPath(srcPath);
95+
String selectedDirectory = dialog.open();
96+
if (selectedDirectory != null) {
97+
if (isFile) {
98+
return selectedDirectory + "/" + name;
99+
}
100+
return selectedDirectory + "/" + name + "-JakartaEE10";
101+
}
102+
return "";
103+
}
104+
105+
private IStructuredSelection getSelection(ExecutionEvent event) {
106+
ISelection selection = HandlerUtil.getCurrentSelection(event);
107+
if (selection instanceof IStructuredSelection) {
108+
return (IStructuredSelection) selection;
109+
}
110+
return null;
111+
}
112+
113+
private int runMvnCommand(String srcProjectPath, String srcPath, String targetPath) {
114+
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
115+
116+
MessageConsole console = new MessageConsole("Maven Command Console", null);
117+
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console});
118+
119+
MessageConsoleStream consoleStream = console.newMessageStream();
120+
121+
try {
122+
List<String> command = new ArrayList<>();
123+
command.add(getMvnCommand());
124+
command.add("package");
125+
command.add(getTransformCommand());
126+
command.add("-DselectedSource=" + srcPath);
127+
command.add("-DselectedTarget=" + targetPath);
128+
ProcessBuilder builder = new ProcessBuilder(command);
129+
builder.environment().put("PATH", System.getenv("PATH"));
130+
builder.directory(new File(srcProjectPath));
131+
builder.redirectErrorStream(true);
132+
Process process = builder.start();
133+
134+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
135+
String line = null;
136+
while ((line = reader.readLine()) != null) {
137+
consoleStream.println(line);
138+
}
139+
140+
return process.waitFor();
141+
} catch (IOException | InterruptedException e) {
142+
MessageDialog.openError(shell, "Error", "An error occurred while running the Maven command: " + e.getMessage());
143+
return -1;
144+
}
145+
}
146+
147+
private String getTransformCommand() {
148+
return String.format("%s:%s:%s:run",
149+
PAYARA_TRANSFORMER, PAYARA_TRANSFORMER_MAVEN, PAYARA_TRANSFORMER_VERSION);
150+
}
151+
152+
private String getMvnCommand() {
153+
String osName = System.getProperty("os.name");
154+
if (osName.contains("Windows")) {
155+
return "mvn.cmd";
156+
} else {
157+
return "mvn";
158+
}
159+
}
160+
161+
}

0 commit comments

Comments
 (0)