Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-6474: adding support to migrate to jakarta 10 #164

23 changes: 22 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"onCommand:payara.server.config.open",
"onCommand:payara.server.app.deploy",
"onCommand:payara.server.app.debug",
"onCommand:payara.server.app.migrate",
"onCommand:payara.micro.create.project",
"onCommand:payara.micro.refresh",
"onCommand:payara.micro.refresh.all",
Expand Down Expand Up @@ -212,6 +213,11 @@
"dark": "resources/theme/dark/endpoint.svg"
}
},
{
"command": "payara.server.app.migrate",
"title" : "Migrate to Jakarta EE 10",
"category": "Payara"
},
{
"command": "payara.micro.create.project",
"title": "Generate a Payara Micro project",
Expand Down Expand Up @@ -431,6 +437,10 @@
"command": "payara.server.app.rest.endpoint",
"when": "never"
},
{
"command": "payara.server.app.migrate",
"when": "never"
},
{
"command": "payara.micro.start",
"when": "never"
Expand Down Expand Up @@ -470,6 +480,11 @@
"command": "payara.server.app.debug",
"when": "explorerResourceIsFolder == true || resourceLangId == java || resourceFilename == pom.xml || resourceFilename == build.gradle || resourceExtname == .war || resourceExtname == .jar",
"group": "run@1"
},
{
"command": "payara.server.app.migrate",
"when": "explorerResourceIsFolder == true || resourceExtname == .properties || resourceExtname == .mf || resourceExtname == .tag || resourceLangId == tld || resourceExtname == .jsp || resourceLangId == xml || resourceLangId == java || resourceExtname == .war || resourceExtname == .jar || resourceExtname == .ear || resourceExtname == .rar",
"group": "run@2"
}
],
"view/item/context": [
Expand Down Expand Up @@ -652,6 +667,11 @@
"command": "payara.server.app.debug",
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+maven|gradle\\b)(?=.*?\\b\\+uri\\b)/",
"group": "java-project@1"
},
{
"command": "payara.server.app.migrate",
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+maven|gradle\\b)(?=.*?\\b\\+uri\\b)/",
"group": "java-project@1"
}
]
}
Expand Down Expand Up @@ -693,6 +713,7 @@
"os": "^0.1.1",
"tslint": "^6.1.0",
"typescript": "^4.0.3",
"vscode-test": "^1.2.2"
"vscode-test": "^1.2.2",
"vscode-uri": "3.0.6"
}
}
6 changes: 6 additions & 0 deletions src/main/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
restEndpoint => payaraServerInstanceController.openRestEndpoint(restEndpoint)
)
);
context.subscriptions.push(
vscode.commands.registerCommand(
'payara.server.app.migrate',
uri => payaraServerInstanceController.migrateToJakarta10(uri)
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
Expand Down
24 changes: 24 additions & 0 deletions src/main/fish/payara/project/Maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { PayaraMicroProject } from '../micro/PayaraMicroProject';
import { MicroPluginReader } from './MicroPluginReader';
import { MavenPomReader } from './MavenPomReader';
import { PayaraMicroMavenPlugin } from '../micro/PayaraMicroMavenPlugin';
import { PayaraServerTransformPlugin } from '../server/PayaraServerTransformPlugin';
import { ProjectOutputWindowProvider } from './ProjectOutputWindowProvider';
import { MavenMicroPluginReader } from './MavenMicroPluginReader';
import { BuildReader } from './BuildReader';
Expand Down Expand Up @@ -393,6 +394,20 @@ export class Maven implements Build {
return this.fireCommand(commands, () => { }, onExit, onError);
}

public migrateToJakarta10(
onExit: (code: number) => any,
onError: (err: Error) => any, source: String, target: String
): ChildProcess | undefined {
let taskManager: TaskManager = new TaskManager();
let taskDefinition = taskManager.getPayaraConfig(this.workspaceFolder, this.getTranformExecutionConfig());
let commands = taskDefinition.command.split(/\s+/);
if(source && target) {
commands.push('-DselectedSource='+source);
commands.push('-DselectedTarget='+target);
}
return this.fireCommand(commands, () => { }, onExit, onError);
}

private getDefaultServerBuildConfig(remote: boolean): TaskDefinition {
return {
label: "payara-server-build",
Expand Down Expand Up @@ -448,5 +463,14 @@ export class Maven implements Build {
};
}

private getTranformExecutionConfig(): TaskDefinition {
return {
label: "payara-tranform",
type: "shell",
command: `mvn package ${PayaraServerTransformPlugin.GROUP_ID}:${PayaraServerTransformPlugin.ARTIFACT_ID}:${PayaraServerTransformPlugin.VERSION}:${PayaraServerTransformPlugin.RUN_GOAL}`,
group: "build"
};
}


}
157 changes: 156 additions & 1 deletion src/main/fish/payara/server/PayaraServerInstanceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { FileResult } from 'tmp';
import { URL } from 'url';
import * as isPort from 'validator/lib/isPort';
import * as vscode from 'vscode';
import { OpenDialogOptions, OutputChannel, QuickPickItem, Uri, DebugConfiguration } from 'vscode';
import * as vscodeUri from 'vscode-uri';
import { OpenDialogOptions, MessageOptions, OutputChannel, QuickPickItem, MessageItem, Uri, DebugConfiguration, WorkspaceFolder} from 'vscode';
import { ApplicationInstance } from '../project/ApplicationInstance';
import { DeploymentSupport } from '../project/DeploymentSupport';
import * as ui from "../../../UI";
Expand All @@ -46,6 +47,8 @@ import { RestEndpoint } from '../project/RestEndpoint';
import { PayaraInstanceController } from '../common/PayaraInstanceController';
import { PayaraRemoteServerInstance } from './PayaraRemoteServerInstance';
import { PayaraLocalServerInstance } from './PayaraLocalServerInstance';
import { PayaraServerTransformPlugin } from '../server/PayaraServerTransformPlugin';
import { Maven } from '../project/Maven';

export class PayaraServerInstanceController extends PayaraInstanceController {

Expand Down Expand Up @@ -863,6 +866,158 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
this.instanceProvider.updateServerConfig();
}

public async migrateToJakarta10(uri: string) {
console.log("selected resource:" + vscodeUri.URI.parse(uri).fsPath);

//verify if the source is a directory
if(uri && fs.existsSync(vscodeUri.URI.parse(uri).fsPath) && fs.lstatSync(vscodeUri.URI.parse(uri).fsPath).isDirectory()) {
//request to select the folder
let directorySelected = await vscode.window.showOpenDialog({
canSelectFolders: true,
canSelectFiles: false,
canSelectMany: false,
openLabel: 'Select folder',
title: 'Selecting folder to migrate file or files'
});

let selectedCancelorNo = false;

console.log('Folder selected'+ directorySelected);
//if no selection showing message informing that it is needed to select a valid folder
if (!directorySelected || directorySelected.length < 1) {
let options: vscode.MessageOptions = {
modal: true,
detail: 'Please add a valid folder to make the migration to Jakarta 10'
};
vscode.window.showWarningMessage("Missed folder", options, ...["Ok"]).then((item)=>{
console.log(item);
});
return;
}

//if it is the same folder show dialog for override selection
if(directorySelected && directorySelected[0].fsPath == vscodeUri.URI.parse(uri.toString()).fsPath) {
let options: vscode.MessageOptions = {
modal: true
};

await vscode.window.showWarningMessage("Do you want to override folder?", options, ...["No", "Yes"]).then((item)=>{
console.log(item);
if(item.toString() != 'Yes') {
selectedCancelorNo = true;
}
});
}

//if selection was cancel or no just return
if(directorySelected && directorySelected[0].fsPath == vscodeUri.URI.parse(uri.toString()).fsPath && selectedCancelorNo) {
return;
}

//processing the options selected for the transform process
let source = vscodeUri.URI.parse(uri).fsPath;
let workspaceFolder: vscode.WorkspaceFolder = {
uri: (vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined),
name: "name",
index: 0
};
let mvn = new Maven(null, workspaceFolder);

mvn.migrateToJakarta10( async (code: number) => {
console.log("Code:"+code);
if(code > 0) {
vscode.window.showErrorMessage('Error ocurred during execution please check output');
}
},
async (error: { message: any; }) => {
console.log("error");
vscode.window.showErrorMessage(error.message+':'+' please check output');
}, source, directorySelected[0].fsPath);

//showing dialog with message regarding to make manual changes for the pom configuration files
let options: vscode.MessageOptions = {
modal: true,
detail: 'After migrating application you should need to apply pom configuration files by hand. The suggested dependencies for Jakarta 10 are: \n'
+ PayaraServerTransformPlugin.JAKARTA_10_DEPENDENCY_EE_API + ' \n or \n'+PayaraServerTransformPlugin.JAKARTA_10_DEPENDENCY_WEB_API
};

vscode.window.showWarningMessage("Information", options, ...["Ok"]).then((item)=>{
console.log(item);
});

} else if (uri && fs.existsSync(vscodeUri.URI.parse(uri).fsPath) && fs.lstatSync(vscodeUri.URI.parse(uri).fsPath).isFile()) {
//request to select the folder
let directorySelected = await vscode.window.showOpenDialog({
canSelectFolders: true,
canSelectFiles: false,
canSelectMany: false,
openLabel: 'Select folder',
title: 'Selecting folder to migrate file'
});

let selectedCancelorNo = false;

console.log('Folder selected:'+ directorySelected);

//if no selection showing message informing that it is needed to select a valid folder
if (!directorySelected || directorySelected.length < 1) {
let options: vscode.MessageOptions = {
modal: true,
detail: 'Please add a valid folder to make the migration to Jakarta 10'
};
vscode.window.showWarningMessage("Missed folder", options, ...["Ok"]).then((item)=>{
console.log(item);
});
}

//if it is the same file on the same folder show dialog for override selection
if(directorySelected && directorySelected[0].fsPath == vscodeUri.URI.parse(path.parse(uri.toString()).dir).fsPath) {
let options: vscode.MessageOptions = {
modal: true
};

await vscode.window.showWarningMessage("Do you want to override file?", options, ...["No", "Yes"]).then((item)=>{
console.log(item);
if(item.toString() != 'Yes') {
selectedCancelorNo = true;
}
});
}

//if selection was cancel or no just return
if(directorySelected && directorySelected[0].fsPath == vscodeUri.URI.parse(path.parse(uri.toString()).dir).fsPath && selectedCancelorNo) {
return;
}

//processing the options selected for the transform process
let source = vscodeUri.URI.parse(uri).fsPath;
let workspaceFolder: vscode.WorkspaceFolder = {
uri: (vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined),
name: "name",
index: 0
};

let finalNameFile = "";
finalNameFile = path.join(directorySelected[0].fsPath, path.parse(vscodeUri.URI.parse(uri).fsPath).base);

let mvn = new Maven(null, workspaceFolder);
let result = await mvn.migrateToJakarta10( async (code: number) => {
console.log("Code:"+code);
if(code > 0) {
vscode.window.showErrorMessage('Error ocurred during execution please check output');
}
},
async (error: { message: any; }) => {
console.log("error");
vscode.window.showErrorMessage(error.message+':'+' please check output');
}, source, finalNameFile);
console.log(result);

} else {
vscode.window.showErrorMessage('Please select a file or folder');
}
}

}

interface State {
Expand Down
43 changes: 43 additions & 0 deletions src/main/fish/payara/server/PayaraServerTransformPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

/*
* Copyright (c) 2022 Payara Foundation and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

export namespace PayaraServerTransformPlugin {

export const ARTIFACT_ID = 'fish.payara.transformer.maven';
export const GROUP_ID = 'fish.payara.transformer';
export const VERSION = '0.2.11';
export const RUN_GOAL = 'run';
export const JAKARTA_10_DEPENDENCY_EE_API = ` \
\n <dependency> \
\n \t \t <groupId>jakarta.platform</groupId> \
\n \t \t <artifactId>jakarta.jakartaee-api</artifactId> \
\n \t \t <version>10.0.0</version> \
\n \t \t <scope>provided</scope> \
\n</dependency> \
\n `;
export const JAKARTA_10_DEPENDENCY_WEB_API = ` \
\n <dependency> \
\n \t \t <groupId>jakarta.platform</groupId> \
\n \t \t <artifactId>jakarta.jakartaee-web-api</artifactId> \
\n \t \t <version>10.0.0</version> \
\n \t \t <scope>provided</scope> \
\n </dependency> \
`;

}
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
],
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
"strict": true,
"strictNullChecks": false /* disable strict mode for null checks*/
/* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
Expand Down