Skip to content

Commit

Permalink
Merge pull request #63 from luiseufrasio/FISH-6772-javaee8-to-jakarta…
Browse files Browse the repository at this point in the history
…ee10

FISH-6772 javaee8 to jakartaee10
  • Loading branch information
luiseufrasio authored Mar 29, 2023
2 parents fa8123b + cd33842 commit bf3e69c
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 7 deletions.
46 changes: 45 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
**/target/
**/bin/
**/bin/
/.metadata/.lock
/.metadata/.log
/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location
/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version
/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index
/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version
/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree
/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jsch.core.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.j2ee.webservice.ui.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.navigator.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs
/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.urischeme.prefs
/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.project
/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.settings/org.eclipse.core.resources.prefs
/.metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache
/.metadata/.plugins/org.eclipse.jdt.core/externalFilesCache
/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt
/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache
/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat
/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml
/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml
/.metadata/.plugins/org.eclipse.m2e.core.ui/dialog_settings.xml
/.metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser
/.metadata/.plugins/org.eclipse.m2e.logback/0.log
/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.1.0.20221015-0744.xml
/.metadata/.plugins/org.eclipse.oomph.setup/workspace.setup
/.metadata/.plugins/org.eclipse.tips.ide/dialog_settings.xml
/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml
/.metadata/.plugins/org.eclipse.ui.intro/introstate
/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml
/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml
/.metadata/version.ini
/bundles/fish.payara.eclipse.tools.micro/.settings/org.eclipse.jdt.core.prefs
/bundles/fish.payara.eclipse.tools.server/.settings/org.eclipse.jdt.core.prefs
/bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/handlers/RefactorHandler.java
/features/fish.payara.eclipse.tools.micro.feature/.polyglot.build.properties
/features/fish.payara.eclipse.tools.server.feature/.polyglot.build.properties
2 changes: 1 addition & 1 deletion bundles/fish.payara.eclipse.tools.micro/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
</classpath>
2 changes: 1 addition & 1 deletion bundles/fish.payara.eclipse.tools.server/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
</classpath>
3 changes: 3 additions & 0 deletions bundles/fish.payara.eclipse.tools.server/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ menu.openserverhome=Server Home Directory
menu.opendomainhome=Domain Directory
menu.payaratopmenu=Payara

menu.migrate=Migrate
menu.convert=Convert to Jakarta EE 10




50 changes: 46 additions & 4 deletions bundles/fish.payara.eclipse.tools.server/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,11 @@
</and>
</enabledWhen>
</handler>

<handler
commandId="fish.payara.eclipse.tools.server.commands.MigrateHandler"
class="fish.payara.eclipse.tools.server.handlers.MigrateHandler">
</handler>
</extension>

<!-- 3. Definitions of the menu entries putting the above defined commands in -->
Expand Down Expand Up @@ -1020,10 +1025,47 @@
</command>
</menu>
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?endof=group.build">
<menu id="fish.payara.eclipse.tools.project.actions.migrate" label="%menu.migrate">
<command commandId="fish.payara.eclipse.tools.server.commands.MigrateHandler" label="%menu.convert" style="push">
</command>
<visibleWhen>
<or>
<with variable="activeMenuSelection">
<iterate>
<adapt type="org.eclipse.core.resources.IProject"></adapt>
</iterate>
</with>
<with variable="activeMenuSelection">
<iterate>
<adapt type="org.eclipse.jdt.core.ICompilationUnit"></adapt>
</iterate>
</with>
</or>
</visibleWhen>
</menu>
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?endof=group.build">
<menu id="fish.payara.eclipse.tools.package.actions.migrate" label="%menu.migrate">
<command commandId="fish.payara.eclipse.tools.server.commands.MigrateHandler" label="%menu.convert" style="push">
</command>
<visibleWhen>
<or>
<with variable="activeMenuSelection">
<iterate>
<adapt type="org.eclipse.core.resources.IProject"></adapt>
</iterate>
</with>
<with variable="activeMenuSelection">
<iterate>
<adapt type="org.eclipse.jdt.core.ICompilationUnit"></adapt>
</iterate>
</with>
</or>
</visibleWhen>
</menu>
</menuContribution>
</extension>




<!--
Properties that are being shown for the Payara / GlassFish server when e.g. the server is right clicked
Expand Down Expand Up @@ -1226,5 +1268,5 @@
provider="fish.payara.eclipse.tools.server.jaxrsLibraryproviderID">
</panel>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/******************************************************************************
* Copyright (c) 2023 Payara Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/

package fish.payara.eclipse.tools.server.handlers;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
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.IPath;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.ui.handlers.HandlerUtil;

public class MigrateHandler extends AbstractHandler {

public static final String PAYARA_TRANSFORMER = "fish.payara.transformer";
public static final String PAYARA_TRANSFORMER_MAVEN = "fish.payara.transformer.maven";
public static final String PAYARA_TRANSFORMER_VERSION = "0.2.10";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
IStructuredSelection selection = getSelection(event);
if (selection != null && !selection.isEmpty()) {
Object firstElement = selection.getFirstElement();
IPath resourcePath = null;
IPath projectPath = null;
String name = "";
boolean isFile = false;
if (firstElement instanceof IResource) {
IResource resource = (IResource) firstElement;
resourcePath = resource.getLocation();
projectPath = resourcePath;
name = resource.getName();
} else if (firstElement instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) firstElement;
IProject project = javaProject.getProject();
resourcePath = project.getLocation();
projectPath = resourcePath;
name = project.getName();
} else if (firstElement instanceof ICompilationUnit) {
ICompilationUnit file = (ICompilationUnit) firstElement;
resourcePath = file.getResource().getLocation();
projectPath = file.getJavaProject().getProject().getLocation();
name = file.getElementName();
isFile = true;
}
if (resourcePath != null && projectPath != null && !"".equals(name)) {
String srcPath = resourcePath.toOSString();
String srcProjectPath = projectPath.toOSString();
String destinationPath = chooseDestinationPath(srcProjectPath, name, isFile);
if ("".equals(destinationPath)) return null;
int exitCode = runMvnCommand(srcProjectPath, srcPath, destinationPath);
if (exitCode == 0) {
MessageDialog.openInformation(shell, "Success", "Project " + destinationPath + " created successfully.");
} else {
MessageDialog.openError(shell, "Error", "Maven command failed with exit code " + exitCode + ".");
}
}
}
return null;
}

private String chooseDestinationPath(String srcPath, String name, boolean isFile) {
Shell shell = new Shell();
DirectoryDialog dialog = new DirectoryDialog(shell);
dialog.setText("Choose a destination Folder");
dialog.setMessage("Please select a Directory:");
dialog.setFilterPath(srcPath);
String selectedDirectory = dialog.open();
if (selectedDirectory != null) {
if (isFile) {
return selectedDirectory + "/" + name;
}
return selectedDirectory + "/" + name + "-JakartaEE10";
}
return "";
}

private IStructuredSelection getSelection(ExecutionEvent event) {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
return (IStructuredSelection) selection;
}
return null;
}

private int runMvnCommand(String srcProjectPath, String srcPath, String targetPath) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

MessageConsole console = new MessageConsole("Maven Command Console", null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console});

MessageConsoleStream consoleStream = console.newMessageStream();

try {
List<String> command = new ArrayList<>();
command.add(getMvnCommand());
command.add("package");
command.add(getTransformCommand());
command.add("-DselectedSource=" + srcPath);
command.add("-DselectedTarget=" + targetPath);
ProcessBuilder builder = new ProcessBuilder(command);
builder.environment().put("PATH", System.getenv("PATH"));
builder.directory(new File(srcProjectPath));
builder.redirectErrorStream(true);
Process process = builder.start();

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
consoleStream.println(line);
}

return process.waitFor();
} catch (IOException | InterruptedException e) {
MessageDialog.openError(shell, "Error", "An error occurred while running the Maven command: " + e.getMessage());
return -1;
}
}

private String getTransformCommand() {
return String.format("%s:%s:%s:run",
PAYARA_TRANSFORMER, PAYARA_TRANSFORMER_MAVEN, PAYARA_TRANSFORMER_VERSION);
}

private String getMvnCommand() {
String osName = System.getProperty("os.name");
if (osName.contains("Windows")) {
return "mvn.cmd";
} else {
return "mvn";
}
}

}

0 comments on commit bf3e69c

Please sign in to comment.