Skip to content

Commit 46b180e

Browse files
committed
Add a command to build a binary of a Quarkus app
* Adds a command that generates, then executes a `tasks.json` task that builds a binary * After you have used the command once, you can build a binary either through the command or `<Ctrl>+<Shift>+B` > Quarkus: Generate a binary * The command checks to make sure GRAALVM_HOME is set before building the binary, and provides a link to the Quarkus docs if it's not set up. This PR addresses one aspect of #335 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 68dc8f8 commit 46b180e

File tree

11 files changed

+346
-52
lines changed

11 files changed

+346
-52
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The following commands are supported for both Maven and Gradle Quarkus projects:
1616
* `Quarkus: Generate a Quarkus project`: Generate a Quarkus project, based on https://code.quarkus.io/
1717
* `Quarkus: Add extensions to current project`: Add Quarkus extensions to currently opened Quarkus project
1818
* `Quarkus: Debug current Quarkus project`: Launches the Maven `quarkus:dev` plugin or the Gradle `quarkusDev` command and automatically attaches a debugger
19+
* `Quarkus: Build executable`: Launches Maven or Gradle with the correct arguments to build an executable of the application (requires GraalVM or Mandrel to be configured)
1920

2021
## Quarkus/MicroProfile `properties` Features
2122

USAGE_DATA.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ vscode-quarkus has opt-in telemetry collection, provided by [vscode-commons](htt
1515
* "Quarkus: Debug current Quarkus project"
1616
* "Quarkus: Generate a Quarkus project"
1717
* "Quarkus: Welcome"
18+
* "Quarkus: Build executable"
1819

1920
## How to opt in or out
2021

package-lock.json

Lines changed: 53 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
"command": "quarkusTools.debugQuarkusProject",
136136
"title": "Quarkus: Debug current Quarkus project"
137137
},
138+
{
139+
"command": "quarkusTools.buildBinary",
140+
"title": "Quarkus: Build executable"
141+
},
138142
{
139143
"command": "quarkusTools.welcome",
140144
"title": "Quarkus: Welcome"
@@ -272,6 +276,7 @@
272276
"@types/request-promise": "^4.1.44",
273277
"@types/semver": "^6.2.0",
274278
"@types/vscode": "^1.37.0",
279+
"@types/which": "^2.0.1",
275280
"@types/yauzl": "^2.9.1",
276281
"chai": "^4.2.0",
277282
"chai-fs": "^2.0.0",
@@ -301,6 +306,7 @@
301306
"lodash": "^4.17.21",
302307
"request": "^2.88.0",
303308
"request-promise": "^4.2.4",
309+
"which": "^2.0.2",
304310
"yauzl": "^2.10.0"
305311
}
306312
}

src/buildSupport/BuildSupport.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import * as path from 'path';
1716
import * as findUp from 'find-up';
17+
import * as path from 'path';
1818
import { Uri, WorkspaceFolder } from 'vscode';
1919
import { FsUtils } from '../utils/fsUtils';
20-
import { TaskPattern } from './TaskPattern';
2120
import { formattedPathForTerminal } from '../utils/shellUtils';
2221
import { getFilePathsFromFolder } from '../utils/workspaceUtils';
22+
import { TaskPattern } from './TaskPattern';
2323

2424
interface BuildSupportData {
2525
buildFile: string;
2626
defaultExecutable: string;
2727
quarkusDev: string;
28+
quarkusBinary: string;
2829
wrapper: string;
2930
wrapperWindows: string;
3031
taskBeginsPattern: string;
@@ -56,6 +57,7 @@ export interface TerminalCommandOptions {
5657
}
5758

5859
export abstract class BuildSupport {
60+
5961
buildSupportData: BuildSupportData;
6062

6163
constructor(buildSupportData: BuildSupportData) {
@@ -77,6 +79,13 @@ export abstract class BuildSupport {
7779
*/
7880
public abstract getQuarkusDevCommand(folderPath: string, options?: TerminalCommandOptions): Promise<TerminalCommand>;
7981

82+
/**
83+
* Returns a command that builds the Quarkus application into a binary
84+
* @param folderPath
85+
* @param options
86+
*/
87+
public abstract getQuarkusBinaryCommand(folderPath: string, options?: TerminalCommandOptions): Promise<TerminalCommand>;
88+
8089
/**
8190
* Returns an appropriate build tool command depending on `options` and `buildFilePath`
8291
*
@@ -183,9 +192,18 @@ export abstract class BuildSupport {
183192
return this.buildSupportData.quarkusDev;
184193
}
185194

195+
public getQuarkusBinary(): string {
196+
return this.buildSupportData.quarkusBinary;
197+
}
198+
186199
public getQuarkusDevTaskName(workspaceFolder: WorkspaceFolder, projectFolder: string): string {
187200
const relativePath: string = path.relative(workspaceFolder.uri.fsPath, projectFolder);
188-
return this.buildSupportData.quarkusDev + (relativePath.length > 0 ? ` (${relativePath})` : '');
201+
return this.buildSupportData.quarkusDev + (relativePath.length > 0 ? ` (${relativePath})` : '');
202+
}
203+
204+
public getQuarkusBinaryTaskName(workspaceFolder: WorkspaceFolder, projectFolder: string): string {
205+
const relativePath: string = path.relative(workspaceFolder.uri.fsPath, projectFolder);
206+
return this.buildSupportData.quarkusBinary + (relativePath.length > 0 ? ` (${relativePath})` : '');
189207
}
190208

191209
public getDefaultExecutable(): string {

src/buildSupport/GradleBuildSupport.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class GradleBuildSupport extends BuildSupport {
2323
buildFile: 'build.gradle',
2424
defaultExecutable: 'gradle',
2525
quarkusDev: 'quarkusDev',
26+
quarkusBinary: 'buildNative',
2627
wrapper: 'gradlew',
2728
wrapperWindows: 'gradlew.bat',
2829
taskBeginsPattern: '^.*Starting a Gradle Daemon*',
@@ -49,4 +50,11 @@ export class GradleBuildSupport extends BuildSupport {
4950
const gradle: string = await this.getCommand(folderPath, options.buildFilePath, { windows: options.windows });
5051
return { command: [gradle, quarkusDev].join(' ') };
5152
}
53+
54+
public async getQuarkusBinaryCommand(folderPath: string, options?: TerminalCommandOptions): Promise<TerminalCommand> {
55+
const quarkusBinary: string = `${this.getQuarkusBinary()} --console=plain`;
56+
const gradle: string = await this.getCommand(folderPath, options.buildFilePath, { windows: options.windows });
57+
return { command: [gradle, quarkusBinary].join(' ') };
58+
}
59+
5260
}

src/buildSupport/MavenBuildSupport.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import { formattedPathForTerminal } from '../utils/shellUtils';
1717
import { BuildSupport, TerminalCommand, TerminalCommandOptions } from "./BuildSupport";
1818

1919
export class MavenBuildSupport extends BuildSupport {
20+
2021
constructor() {
2122
super({
2223
buildFile: 'pom.xml',
2324
defaultExecutable: 'mvn',
2425
quarkusDev: 'quarkus:dev',
26+
quarkusBinary: 'package -Pnative',
2527
wrapper: 'mvnw',
2628
wrapperWindows: 'mvnw.cmd',
2729
taskBeginsPattern: '^.*Scanning for projects...*',
@@ -46,7 +48,12 @@ export class MavenBuildSupport extends BuildSupport {
4648
const pomPath: string = options.buildFilePath ? `-f ${await formattedPathForTerminal(options.buildFilePath)}` : '';
4749
const mvn: string = await this.getCommand(folderPath, options && options.buildFilePath, { windows: options && options.windows });
4850
return { command: [mvn, this.getQuarkusDev(), pomPath].join(' ') };
51+
}
4952

53+
public async getQuarkusBinaryCommand(folderPath: string, options?: TerminalCommandOptions): Promise<TerminalCommand> {
54+
const pomPath: string = options.buildFilePath ? `-f ${await formattedPathForTerminal(options.buildFilePath)}` : '';
55+
const mvn: string = await this.getCommand(folderPath, options && options.buildFilePath, { windows: options && options.windows });
56+
return { command: [mvn, this.getQuarkusBinary(), pomPath].join(' ') };
5057
}
5158

5259
}

src/commands/registerCommands.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { requestStandardMode } from "../utils/requestStandardMode";
55
import { sendCommandFailedTelemetry, sendCommandSucceededTelemetry } from "../utils/telemetryUtils";
66
import { WelcomeWebview } from "../webviews/WelcomeWebview";
77
import { addExtensionsWizard } from "../wizards/addExtensions/addExtensionsWizard";
8+
import { buildBinary } from "../wizards/binary/buildBinary";
89
import { startDebugging } from "../wizards/debugging/startDebugging";
910
import { generateProjectWizard } from "../wizards/generateProject/generationWizard";
1011
import { deployToOpenShift } from "../wizards/deployToOpenShift/deployToOpenShift";
@@ -43,6 +44,12 @@ export function registerVSCodeCommands(context: ExtensionContext): void {
4344
* Command for deploying current Quarkus project to OpenShift with OpenShift Connector
4445
*/
4546
registerCommandWithTelemetry(context, VSCodeCommands.DEPLOY_TO_OPENSHIFT, withStandardMode(deployToOpenShift, "Deploying to OpenShift"));
47+
48+
/**
49+
* Command for building a binary
50+
*/
51+
registerCommandWithTelemetry(context, VSCodeCommands.BUILD_BINARY, withStandardMode(buildBinary, "Building a binary"));
52+
4653
}
4754

4855
/**

src/definitions/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export namespace VSCodeCommands {
1919
export const CREATE_PROJECT = 'quarkusTools.createProject';
2020
export const ADD_EXTENSIONS = 'quarkusTools.addExtension';
2121
export const DEBUG_QUARKUS_PROJECT = 'quarkusTools.debugQuarkusProject';
22+
export const BUILD_BINARY = 'quarkusTools.buildBinary';
2223
export const QUARKUS_WELCOME = 'quarkusTools.welcome';
2324
export const DEPLOY_TO_OPENSHIFT = 'quarkusTools.deployToOpenShift';
2425
}

0 commit comments

Comments
 (0)