-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from luiseufrasio/FISH-6772-javaee8-to-jakarta…
…ee10 FISH-6772 javaee8 to jakartaee10
- Loading branch information
Showing
6 changed files
with
257 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
...ra.eclipse.tools.server/src/fish/payara/eclipse/tools/server/handlers/MigrateHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
|
||
} |