Skip to content

Commit 8a03d28

Browse files
authored
Merge pull request #75 from luiseufrasio/FISH-6772-javaee8-to-jakartaee10
FISH-6772 javaee8 to jakartaee10
2 parents b8ce791 + 90ca73a commit 8a03d28

5 files changed

Lines changed: 104 additions & 89 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@
4444
/bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/handlers/RefactorHandler.java
4545
/features/fish.payara.eclipse.tools.micro.feature/.polyglot.build.properties
4646
/features/fish.payara.eclipse.tools.server.feature/.polyglot.build.properties
47+
/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.1.0.20221015-0744.xml
48+
/.metadata/
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
44
<attributes>
55
<attribute name="module" value="true"/>
66
</attributes>
77
</classpathentry>
88
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
99
<classpathentry kind="src" path="src"/>
10-
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
11-
<attributes>
12-
<attribute name="maven.pomderived" value="true"/>
13-
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
14-
</attributes>
15-
</classpathentry>
16-
<classpathentry kind="output" path="target/classes"/>
17-
</classpath>
10+
<classpathentry kind="output" path="bin"/>
11+
</classpath>
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
44
<attributes>
55
<attribute name="module" value="true"/>
66
</attributes>
77
</classpathentry>
88
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
9-
<classpathentry kind="src" path="src"/>
10-
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
11-
<attributes>
12-
<attribute name="maven.pomderived" value="true"/>
13-
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
14-
</attributes>
15-
</classpathentry>
16-
<classpathentry kind="output" path="target/classes"/>
17-
</classpath>
9+
<classpathentry kind="src" path="src/"/>
10+
<classpathentry kind="output" path="bin"/>
11+
</classpath>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ 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
74+
menu.migrate=Payara Refactor
75+
menu.convert=Transform to Jakarta EE 10
7676

7777

7878

bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/handlers/MigrateHandler.java

Lines changed: 93 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import java.io.File;
1414
import java.io.IOException;
1515
import java.io.InputStreamReader;
16-
import java.nio.file.Files;
17-
import java.nio.file.Paths;
1816
import java.util.ArrayList;
1917
import java.util.List;
2018

@@ -24,16 +22,26 @@
2422
import org.eclipse.core.resources.IProject;
2523
import org.eclipse.core.resources.IResource;
2624
import org.eclipse.core.runtime.IPath;
25+
import org.eclipse.core.runtime.IProgressMonitor;
26+
import org.eclipse.core.runtime.IStatus;
27+
import org.eclipse.core.runtime.Status;
28+
import org.eclipse.core.runtime.jobs.Job;
2729
import org.eclipse.jdt.core.ICompilationUnit;
2830
import org.eclipse.jdt.core.IJavaProject;
2931
import org.eclipse.jface.dialogs.MessageDialog;
3032
import org.eclipse.jface.viewers.ISelection;
3133
import org.eclipse.jface.viewers.IStructuredSelection;
3234
import org.eclipse.swt.widgets.DirectoryDialog;
35+
import org.eclipse.swt.widgets.Display;
3336
import org.eclipse.swt.widgets.Shell;
37+
import org.eclipse.ui.IWorkbenchPage;
38+
import org.eclipse.ui.IWorkbenchWindow;
39+
import org.eclipse.ui.PartInitException;
3440
import org.eclipse.ui.PlatformUI;
3541
import org.eclipse.ui.console.ConsolePlugin;
3642
import org.eclipse.ui.console.IConsole;
43+
import org.eclipse.ui.console.IConsoleConstants;
44+
import org.eclipse.ui.console.IConsoleView;
3745
import org.eclipse.ui.console.MessageConsole;
3846
import org.eclipse.ui.console.MessageConsoleStream;
3947
import org.eclipse.ui.handlers.HandlerUtil;
@@ -42,74 +50,96 @@ public class MigrateHandler extends AbstractHandler {
4250

4351
public static final String PAYARA_TRANSFORMER = "fish.payara.transformer";
4452
public static final String PAYARA_TRANSFORMER_MAVEN = "fish.payara.transformer.maven";
45-
public static final String PAYARA_TRANSFORMER_VERSION = "0.2.10";
53+
public static final String PAYARA_TRANSFORMER_VERSION = "0.2.14";
54+
55+
private IPath resourcePath = null;
56+
private IPath projectPath = null;
57+
private String name = "";
4658

4759
@Override
4860
public Object execute(ExecutionEvent event) throws ExecutionException {
49-
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
61+
IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
62+
Shell shell = activeWorkbenchWindow.getShell();
5063
IStructuredSelection selection = getSelection(event);
5164
if (selection != null && !selection.isEmpty()) {
5265
Object firstElement = selection.getFirstElement();
53-
IPath resourcePath = null;
54-
IPath projectPath = null;
55-
String name = "";
56-
boolean isFile = false;
57-
if (firstElement instanceof IResource) {
58-
IResource resource = (IResource) firstElement;
59-
resourcePath = resource.getLocation();
60-
projectPath = resourcePath;
61-
name = resource.getName();
62-
} else if (firstElement instanceof IJavaProject) {
63-
IJavaProject javaProject = (IJavaProject) firstElement;
64-
IProject project = javaProject.getProject();
65-
resourcePath = project.getLocation();
66-
projectPath = resourcePath;
67-
name = project.getName();
68-
} else if (firstElement instanceof ICompilationUnit) {
69-
ICompilationUnit file = (ICompilationUnit) firstElement;
70-
resourcePath = file.getResource().getLocation();
71-
projectPath = file.getJavaProject().getProject().getLocation();
72-
name = file.getElementName();
73-
isFile = true;
74-
}
66+
67+
final boolean isFile = checkIfFile(firstElement);
7568
if (resourcePath != null && projectPath != null && !"".equals(name)) {
7669
String srcPath = resourcePath.toOSString();
7770
String srcProjectPath = projectPath.toOSString();
7871
String destinationPath = chooseDestinationPath(srcProjectPath, name, isFile);
7972
if ("".equals(destinationPath)) return null;
80-
int exitCode = runMvnCommand(srcProjectPath, srcPath, destinationPath);
81-
if (exitCode == 0) {
82-
MessageDialog.openInformation(shell, "Success", "Project " + destinationPath + " created successfully.");
83-
} else {
84-
MessageDialog.openError(shell, "Error", "Maven command failed with exit code " + exitCode + ".");
85-
}
73+
74+
Job job = new Job("Running Maven Command") {
75+
@Override
76+
protected IStatus run(IProgressMonitor monitor) {
77+
Display.getDefault().asyncExec(() -> {
78+
try {
79+
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
80+
IConsoleView consoleView = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
81+
MessageConsole console = new MessageConsole("Maven Command Console", null);
82+
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
83+
consoleView.display(console);
84+
85+
int exitCode = runMvnCommand(console, page, srcProjectPath, srcPath, destinationPath, shell);
86+
if (exitCode == 0) {
87+
Display.getDefault().asyncExec(() -> {
88+
MessageDialog.openInformation(shell, "Success", (isFile ? "File " : "Project ") + destinationPath + " created successfully.");
89+
});
90+
} else {
91+
Display.getDefault().asyncExec(() -> {
92+
MessageDialog.openError(shell, "Error", "Maven command failed with exit code " + exitCode + ".");
93+
});
94+
}
95+
} catch (PartInitException e) {
96+
e.printStackTrace();
97+
}
98+
});
99+
return Status.OK_STATUS;
100+
}
101+
};
102+
job.schedule();
86103
}
87104
}
88105
return null;
89106
}
90107

91-
private String chooseDestinationPath(String srcPath, String name, boolean isFile) {
108+
private boolean checkIfFile(Object firstElement) {
109+
if (firstElement instanceof IResource) {
110+
IResource resource = (IResource) firstElement;
111+
resourcePath = resource.getLocation();
112+
projectPath = resourcePath;
113+
name = resource.getName();
114+
} else if (firstElement instanceof IJavaProject) {
115+
IJavaProject javaProject = (IJavaProject) firstElement;
116+
IProject project = javaProject.getProject();
117+
resourcePath = project.getLocation();
118+
projectPath = resourcePath;
119+
name = project.getName();
120+
} else if (firstElement instanceof ICompilationUnit) {
121+
ICompilationUnit file = (ICompilationUnit) firstElement;
122+
resourcePath = file.getResource().getLocation();
123+
projectPath = file.getJavaProject().getProject().getLocation();
124+
name = file.getElementName();
125+
return true;
126+
}
127+
return false;
128+
}
129+
130+
private String chooseDestinationPath(String srcPath, String name, boolean isFile) {
92131
Shell shell = new Shell();
93132
DirectoryDialog dialog = new DirectoryDialog(shell);
94133
dialog.setText("Choose a " + (isFile ? "New File" : "") + " destination Folder");
95134
dialog.setMessage("Please select a Directory:");
96135
dialog.setFilterPath(srcPath);
97136
String selectedDirectory = dialog.open();
98137
if (selectedDirectory != null) {
99-
if (isFile) {
100-
String targetDir = selectedDirectory + "/jakartaee10/";
101-
try {
102-
Files.createDirectories(Paths.get(targetDir));
103-
return targetDir + name;
104-
} catch (IOException e) {
105-
throw new RuntimeException(e);
106-
}
107-
}
108-
return selectedDirectory + "/" + name + "-JakartaEE10";
138+
return selectedDirectory + "/" + name;
109139
}
110140
return "";
111141
}
112-
142+
113143
private IStructuredSelection getSelection(ExecutionEvent event) {
114144
ISelection selection = HandlerUtil.getCurrentSelection(event);
115145
if (selection instanceof IStructuredSelection) {
@@ -118,36 +148,31 @@ private IStructuredSelection getSelection(ExecutionEvent event) {
118148
return null;
119149
}
120150

121-
private int runMvnCommand(String srcProjectPath, String srcPath, String targetPath) {
122-
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
123-
124-
MessageConsole console = new MessageConsole("Maven Command Console", null);
125-
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console});
126-
127-
MessageConsoleStream consoleStream = console.newMessageStream();
128-
151+
private int runMvnCommand(MessageConsole console, IWorkbenchPage page, String srcProjectPath, String srcPath, String targetPath, Shell shell) {
129152
try {
130-
List<String> command = new ArrayList<>();
131-
command.add(getMvnCommand());
132-
command.add("package");
133-
command.add(getTransformCommand());
134-
command.add("-DselectedSource=" + srcPath);
135-
command.add("-DselectedTarget=" + targetPath);
136-
ProcessBuilder builder = new ProcessBuilder(command);
137-
builder.environment().put("PATH", System.getenv("PATH"));
138-
builder.directory(new File(srcProjectPath));
139-
builder.redirectErrorStream(true);
140-
Process process = builder.start();
141-
142-
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
143-
String line = null;
153+
MessageConsoleStream consoleStream = console.newMessageStream();
154+
155+
List<String> command = new ArrayList<>();
156+
command.add(getMvnCommand());
157+
command.add(getTransformCommand());
158+
command.add("-DselectedSource=" + srcPath);
159+
command.add("-DselectedTarget=" + targetPath);
160+
ProcessBuilder builder = new ProcessBuilder(command);
161+
builder.environment().put("PATH", System.getenv("PATH"));
162+
builder.directory(new File(srcProjectPath));
163+
builder.redirectErrorStream(true);
164+
Process process = builder.start();
165+
166+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
167+
String line = null;
144168
while ((line = reader.readLine()) != null) {
145169
consoleStream.println(line);
146170
}
147-
171+
148172
return process.waitFor();
149173
} catch (IOException | InterruptedException e) {
150-
MessageDialog.openError(shell, "Error", "An error occurred while running the Maven command: " + e.getMessage());
174+
MessageDialog.openError(shell, "Error",
175+
"An error occurred while running the Maven command: " + e.getMessage());
151176
return -1;
152177
}
153178
}

0 commit comments

Comments
 (0)