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

Open liberty starter #112

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"activationEvents": [
"workspaceContains:**/pom.xml",
"workspaceContains:**/build.gradle",
"onCommand:liberty.starterProject",
"onCommand:liberty.dev.start",
"onCommand:liberty.dev.stop",
"onCommand:liberty.dev.custom",
Expand All @@ -55,6 +56,11 @@
]
},
"commands": [
{
"command": "liberty.starterProject",
"category": "Open Liberty",
"title": "Open Liberty Starter Project"
},
{
"command": "liberty.explorer.refresh",
"title": "%contributes.commands.liberty.explorer.refresh%",
Expand Down Expand Up @@ -114,7 +120,7 @@
{
"command": "liberty.dev.start",
"when": "viewItem == libertyMavenProject || viewItem == libertyGradleProject || viewItem == libertyMavenProjectContainer || viewItem == libertyGradleProjectContainer",
"group": "libertyCore@1"
"group": "libertyCore@2"
},
{
"command": "liberty.dev.stop",
Expand Down Expand Up @@ -214,7 +220,7 @@
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^7.0.2",
"@types/node": "^13.13.36",
"@types/node": "^13.13.52",
"@types/vscode": "^1.36.0",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
Expand All @@ -228,11 +234,16 @@
"webpack-cli": "^4.6.0"
},
"dependencies": {
"@microsoft/vscode-file-downloader-api": "^1.0.1",
"@types/fs-extra": "^8.1.0",
"@types/xml2js": "^0.4.5",
"axios": "^0.27.2",
"fs-extra": "^9.0.0",
"gradle-to-js": "^2.0.0",
"semver": "^7.3.2",
"unzip-stream": "^0.3.1",
"update": "^0.7.4",
"vsce": "^2.9.2",
"xml2js": "^0.4.23"
}
}
9 changes: 9 additions & 0 deletions src/definitions/starterOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import axios from "axios";

export async function getProjectOptions(): Promise<any> {
const response = await axios({
method: "get",
url: 'https://start.openliberty.io/api/start/info',
})
return response.data;
}
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import * as devCommands from "./liberty/devCommands";
import { starterProject } from './liberty/starterProject';

import { LibertyProject, ProjectProvider } from "./liberty/libertyProject";

Expand All @@ -20,6 +21,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
context.subscriptions.push(
vscode.commands.registerCommand("extension.open.project", (pomPath) => devCommands.openProject(pomPath)),
);
context.subscriptions.push(
vscode.commands.registerCommand('liberty.starterProject', () => starterProject(context))
);

context.subscriptions.push(
vscode.commands.registerCommand("liberty.dev.start", (libProject?: LibertyProject) => devCommands.startDevMode(libProject)),
);
Expand Down
38 changes: 36 additions & 2 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import * as fs from "fs";
import * as Path from "path";
import * as vscode from "vscode";
import axios from "axios";
import { LibertyProject } from "./libertyProject";
import { getReport } from "../util/helperUtil";
import { LIBERTY_MAVEN_PROJECT, LIBERTY_GRADLE_PROJECT, LIBERTY_MAVEN_PROJECT_CONTAINER, LIBERTY_GRADLE_PROJECT_CONTAINER } from "../definitions/constants";
import { getGradleTestReport } from "../util/gradleUtil";
import { pathExists } from "fs-extra";

export const terminals: { [libProjectId: number]: LibertyProject } = {};
let _customParameters = "";

Expand Down Expand Up @@ -145,6 +145,40 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi
}
}

export async function buildStarterProject( state?: any, libProject?: LibertyProject | undefined): Promise<void> {
var apiURL = `https://start.openliberty.io/api/start?a=${state.a}&b=${state.b}&e=${state.e}&g=${state.g}&j=${state.j}&m=${state.m}`;
const downloadStarterProject = async function(downloadLocation: string): Promise<void> {
axios({
method: "get",
url: apiURL,
responseType: "stream"
}).then( function (response){
response.data.pipe(fs.createWriteStream(downloadLocation))
.on("close", () => {
var unzip = require("unzip-stream");
fs.createReadStream(downloadLocation).pipe(unzip.Extract({ path: `${state.dir}/${state.a}`}));
fs.unlink(downloadLocation, async (err) => {
const folderUri = vscode.Uri.file(state.dir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to open the parent folder of the newly generated project rather than the newly generated project. For example, if I generate into my downloads, my entire downloads folder is opened in VS Code rather than just the app-name project I generated

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fb3698a. Not sure if it is the flow we are looking for. I also used a timeout to refresh the file explore. I'll go back and use async/await, when I have more time.

if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0].uri.fsPath != state.dir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea here that if the workspace is empty we automatically add the newly generated project to the current workspace?

Copy link
Author

@Jonathan-Maciel Jonathan-Maciel Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if it's empty or the target dir is the same as the currrent, then we don't ask to open in a new window.

await vscode.window.showInformationMessage("Where would you like to open the project?", "Current Window", "New Window")
.then(selection => {
if (selection == "Current Window") {
vscode.commands.executeCommand(`vscode.openFolder`, folderUri);
} else {
vscode.commands.executeCommand(`vscode.openFolder`, folderUri, true);
}
});
} else {
vscode.commands.executeCommand(`vscode.openFolder`, folderUri);
}
})
})
});
}
let zipPath = `${state.dir}/${state.a}.zip`;
downloadStarterProject(zipPath);
}

// run tests on dev mode
export async function runTests(libProject?: LibertyProject | undefined): Promise<void> {
if (libProject !== undefined) {
Expand Down
Loading