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

Support create java function project & add java function #66

Merged
merged 5 commits into from Nov 15, 2017

Conversation

jdneo
Copy link
Member

@jdneo jdneo commented Nov 10, 2017

This PR add the following feature:

For creating java function project, we leverage maven archetype.

For adding java function, we leverage azure function maven plugin. The reason we call it in terminal is that the maven plugin does not support batch mode for this maven goal.

As to the tasks.json file for Java function, we do not use dependOn for tasks because this may cause preLaunchTask cannot be tracked error in VS Code 1.18 (see issue here).

------------- Update on Wed Nov 15 2017 09:12:33 GMT+0800 -------------
Remove the add Java function part, since the Maven plugin not support adding java function non-interactively.

@fiveisprime fiveisprime requested a review from a team November 13, 2017 15:01
Copy link
Member

@ejizba ejizba left a comment

Choose a reason for hiding this comment

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

What's the plan for create Function? If the user has to interact with the terminal, then I don't think the behavior is ship-able. We should at least display quick picks for the type of template

@@ -32,3 +35,15 @@ export function isFolderOpenInWorkspace(fsPath: string): boolean {
return false;
}
}

export function getProjectType(projectPath: string): string {
Copy link
Member

Choose a reason for hiding this comment

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

This file is for 'workspace' utilities, but this function doesn't use vscode.workspace at all. Just move it into 'createFunction' (the only place it's used)

Copy link
Member Author

@jdneo jdneo Nov 14, 2017

Choose a reason for hiding this comment

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

I think I'll use this method again for deploying Java functions. How about making a new file called 'project.ts' and move to it?

terminal.sendText(command, addNewLine);
}

export async function executeCommand(outputChannel: vscode.OutputChannel, workingDirectory: string, command: string, ...args: string[]): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

Use cpUtils.executeCommand instead

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

'-B' // in Batch Mode
);

functionAppPath = path.join(functionAppPath, artifactId);
Copy link
Member

Choose a reason for hiding this comment

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

I thought you were going to file an issue for this? It's really annoying and we need to make sure we fix it before release

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean the extra folder of artifactId?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Member

Choose a reason for hiding this comment

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

#69

break;
default:
// the maven archetype contains these files, so not check them when language is Java
const hostJsonPath: string = path.join(functionAppPath, 'host.json');
Copy link
Member

Choose a reason for hiding this comment

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

Why does the maven archetype have these files? Shouldn't it let VS Code (or the func cli) handle it? Same with the .gitignore

Copy link
Member

Choose a reason for hiding this comment

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

Do you own the maven archetype or does someone else? I thought you guys created it

const terminal: vscode.Terminal = vscode.window.createTerminal('Azure Functions');

export function runCommandInTerminal(command: string, addNewLine: boolean = true): void {
terminal.show();
Copy link
Member

Choose a reason for hiding this comment

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

We don't like using terminal because then you have no idea when the command finishes


export function getProjectType(projectPath: string): string {
let language: string = TemplateLanguage.JavaScript;
fse.readdirSync(projectPath).forEach((file: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

You should use async methods wherever possible (in this case, you would use readdir instead of readdirsync

Copy link
Member Author

Choose a reason for hiding this comment

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

Using fse.pathExists().

let language: string = TemplateLanguage.JavaScript;
fse.readdirSync(projectPath).forEach((file: string) => {
const stat: fse.Stats = fse.statSync(path.join(projectPath, file));
// Currently checking the existing pom.xml to determine whether the function project is Java language based.
Copy link
Member

Choose a reason for hiding this comment

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

Isn't pom.xml at the root of the project? Couldn't you just do fse.pathExists(path.join(projectPath, 'pom.xml'))?

If it's not always at the root, then we need to find a different way to detect Java projects - iterating through an entire folder has bad performance for the user

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it's at the root path. I like the idea of using fse.pathExists()

assert.equal(inputs.length, 0, 'Not all inputs were used.');
}

async function testInitFileExist(projectPath: string): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

nit: testProjectFilesExist

(I don't know what InitFile means)

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense.


if (template.bindingType !== 'httpTrigger') {
await localAppSettings.validateAzureWebJobsStorage();
const languageType: string = workspaceUtil.getProjectType(functionAppPath);
Copy link
Member

Choose a reason for hiding this comment

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

Why do you infer the project type? I can easily create C# and JavaScript functions in the same project from the command line today.

Shouldn't I be able to create 'Java' and 'JavaScript' functions in the same project from VS Code?

Copy link
Member Author

Choose a reason for hiding this comment

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

How about let the user choose the language he/she wants to add by showing Picks?


import * as vscode from 'vscode';

const terminal: vscode.Terminal = vscode.window.createTerminal('Azure Functions');
Copy link
Member

Choose a reason for hiding this comment

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

If the user closes/deletes the 'Azure Functions' terminal, then create new project will fail every time until they restart VS Code

'-B' // in Batch Mode
);

functionAppPath = path.join(functionAppPath, artifactId);
Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Member

@ejizba ejizba left a comment

Choose a reason for hiding this comment

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

I still think running in a terminal is a feature-blocker. Sent an email offline.

In the future, it would be better to do one PR for each feature. I'm sorry connect(); distracted us from getting this in last week, but I think the 'Create new Java Project' feature is good-to-go and it's just being blocked by issues with 'Create new Java function'

@ejizba ejizba merged commit 28b0620 into microsoft:master Nov 15, 2017
@jdneo jdneo deleted the new-pr branch February 5, 2018 09:26
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants