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 8 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
57 changes: 55 additions & 2 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

import * as fs from "fs";
import * as Path from "path";
import * as vscode from "vscode";
import axios from "axios";
import { LibertyProject } from "./libertyProject";
import * as starterProject from "./starterProject";
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 +146,58 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi
}
}

/**
* Downloads a starter project from https://start.openliberty.io/
* @param state see {@link starterProject.State}
* @param libProject see {@link LibertyProject}
*/
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}`;
var targetDir = `${state.dir}/${state.a}`;
const targetUri = vscode.Uri.file(targetDir);

/**
* Decides what window to use when opening the project
*/
async function toBeHereOrNotToBeHere() {
var newWin = false;
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0].uri.fsPath != targetDir) {
await vscode.window.showInformationMessage("Where would you like to open the project?", "Current Window", "New Window")
.then(selection => {
if (selection != "Current Window") { newWin = true; }
});
}
vscode.commands.executeCommand(`vscode.openFolder`, targetUri, newWin);
}

/**
* gets zip -> unzips zip -> removes zip
*/
(async function(): Promise<void> {
let downloadLocation = `${targetDir}.zip`;
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: targetDir }));
fs.unlink(downloadLocation, async (err) => { toBeHereOrNotToBeHere() })
})
});
}())

/**
* TODO: Convert to async/await
* Waits 3 seconds and refreshes the file explorer.
*/
await new Promise((resolve) => {
setTimeout(() => { resolve(true); }, 3000);
}).then(function() {vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer");});
}

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