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 exporting jar with custom task #350

Merged
merged 19 commits into from
Nov 13, 2020
Merged

Support exporting jar with custom task #350

merged 19 commits into from
Nov 13, 2020

Conversation

CsCherrYY
Copy link
Contributor

@CsCherrYY CsCherrYY commented Oct 15, 2020

This PR enables the Java Project Manager to support exporting jar with custom task. In this PR, you can change the value of the fields to customize what to export. The available template of tasks can be found at Terminal->Configure Tasks.... Here is an example of tasks.json including an export jar task:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "java",
			"label": "java: exportjar:demo",
			"mainClass": "demo.App",
			"targetPath": "${workspaceFolder}/${workspaceFolderBasename}.jar",
			"elements": [
				"${compileOutput}",
				"${testCompileOutput}",
				"${dependencies}",
				"${testDependencies}",
				"!${compileOutput}/demo/innerPkg",
				"C:/work/demo/test.iml"
			],
			"problemMatcher": []
		}
	]
}

The following attributes are mandatory for every task configuration:

  • type - the type of export jar task, should always be java.
  • label - the name of export jar task. When you are going to run a task from Terminal->Run Task..., the labels of all available tasks will appear in the list.

Here are some optional attributes available to all launch configurations:

  • mainClass - the mainClass in MANIFEST.MF. If this attribute is not specified, the wizard to select the mainClass will appear during the export process.
  • targetPath - the target path of jar. VS Code variables is available in this attribute. If this attribute is not specified, the export process will apply the setting java.project.exportJar.targetPath.
  • elements - The array of elements to export. If this attribute is not specified, the wizard to select the elements will appear during the export process. This attribute is using glob patterns so you can also use ! to specify which not to include. Both absolute path and relative path to the project folder are supported here.

These reserved words are available in the elements:

  • ${compileOutput} - the folders containing output class files in the runtime scope.
  • ${testCompileOutput} - the folders containing output class files in the test scope.
  • ${dependencies} - the artifact dependencies in the runtime scope.
  • ${testDependencies} - the artifact dependencies in the test scope.
    Note: The reserved words can be used to stand for a specific project. For example, if your workspace includes more than one workspace folder, one of them is demo. The ${compileOutput} will stand for the folders containing output class files in the runtime scope of all the workspace folders while the ${compileOutput:demo} stands for those of folder demo only.

You can run the custom task by clicking Terminal->Run Task and select the java type. Then the wizard will show all the available export jar tasks.

@CsCherrYY CsCherrYY requested a review from jdneo October 15, 2020 09:09
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/PathTrie.ts Outdated Show resolved Hide resolved
src/exportJarSteps/GenerateJarExecutor.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/GenerateJarExecutor.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
@CsCherrYY CsCherrYY requested a review from jdneo October 22, 2020 08:55
@CsCherrYY CsCherrYY linked an issue Oct 22, 2020 that may be closed by this pull request
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
package.nls.json Outdated Show resolved Hide resolved
package.nls.json Outdated Show resolved Hide resolved
package.nls.json Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/views/nodeCache/Trie.ts Outdated Show resolved Hide resolved
src/exportJarSteps/GenerateJarExecutor.ts Outdated Show resolved Hide resolved
package.nls.json Outdated Show resolved Hide resolved
src/views/nodeCache/Trie.ts Outdated Show resolved Hide resolved
@CsCherrYY CsCherrYY requested a review from jdneo October 29, 2020 01:55
package.nls.zh.json Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/utility.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
@CsCherrYY CsCherrYY requested a review from jdneo November 2, 2020 06:55
package.json Outdated Show resolved Hide resolved
package.nls.json Outdated Show resolved Hide resolved
package.nls.zh.json Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/GenerateJarExecutor.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
@jdneo jdneo added this to the 0.15.0 milestone Nov 3, 2020
@jdneo jdneo added the enhancement New feature or request label Nov 3, 2020
@jdneo
Copy link
Member

jdneo commented Nov 3, 2020

"label": "java: exportjar:demo-noMain" // The label of this task to show in the wizard from Terminal->Run Task...

Do we have this field?

@CsCherrYY
Copy link
Contributor Author

"label": "java: exportjar:demo-noMain" // The label of this task to show in the wizard from Terminal->Run Task...

Do we have this field?

It's a VS Code built-in field. Its value is in this format: task.type: task.name

@CsCherrYY CsCherrYY requested a review from jdneo November 3, 2020 08:44
Copy link
Member

@jdneo jdneo left a comment

Choose a reason for hiding this comment

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

very close, just a few more comments

package.nls.json Outdated
"configuration.java.project.exportJar.targetPath": "The default output path of export jar",
"taskDefinitions.java.project.exportJar.elements": "The content list of export jar.",
"taskDefinitions.java.project.exportJar.mainMethod": "The main method in the manifest of exported jar.",
"taskDefinitions.java.project.exportJar.targetPath": "The output path of the exported jar. This will override configuration.java.project.exportJar.targetPath."
Copy link
Member

Choose a reason for hiding this comment

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

I think we can use markdown description here and link to configuration.java.project.exportJar.targetPath. Similar as:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that VS Code does not support markdown description in the taskDefinitions currently. So I couldn't find a way to link to the settings in the tasks.json file.

src/exportJarSteps/ExportJarTaskProvider.ts Show resolved Hide resolved
src/exportJarSteps/ExportJarTaskProvider.ts Outdated Show resolved Hide resolved
@jdneo
Copy link
Member

jdneo commented Nov 4, 2020

Some more feedbacks:
image

  1. Can we remove problemMatcher when generating the task?
  2. Default mainMethod should be filled if there is only one main entry
  3. CompileOutput -> compileOutput and same to other reserved words

@CsCherrYY
Copy link
Contributor Author

Some more feedbacks:
image

  1. Can we remove problemMatcher when generating the task?
  2. Default mainMethod should be filled if there is only one main entry
  3. CompileOutput -> compileOutput and same to other reserved words

Thanks a lot! Will apply them.

@CsCherrYY
Copy link
Contributor Author

Some more feedbacks:
image

  1. Can we remove problemMatcher when generating the task?
  2. Default mainMethod should be filled if there is only one main entry
  3. CompileOutput -> compileOutput and same to other reserved words

It seems that problemMatcher cannot be removed programmly. The default echo task comes from literal template. Other tasks generated will include a problemMatcher property, whether it is undefined or used.

@jdneo
Copy link
Member

jdneo commented Nov 6, 2020

@CsCherrYY Please resolve the conflict

package.json Outdated
{
"type": "java",
"properties": {
"elements": {
Copy link
Contributor

Choose a reason for hiding this comment

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

A reference about how to support intellisense for constant literals when configuring elements.

https://github.com/microsoft/vscode-java-debug/blob/master/package.json#L346-L373

constant

Copy link
Member

Choose a reason for hiding this comment

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

@testforstephen beautiful!

1. Rearranged the order of the task properties
2. Rename: mainMethod -> mainClass in many places to avoid any misunderstanding, including renaming ResolveMainClassExecutor to ResolveMainMethodExecutor
3.  Support intellisense in tasks.json
4. Fix a bug on invisible project
package.nls.json Outdated
"taskDefinitions.java.project.exportJar.elements": "The content list of the exported jar.",
"taskDefinitions.java.project.exportJar.mainClass": "The main class in the manifest of the exported jar.",
"taskDefinitions.java.project.exportJar.targetPath": "The output path of the exported jar. This will override configuration.java.project.exportJar.targetPath.",
"taskDefinitions.java.project.exportJar.compileOutput": "All of the output folders in the runtime scope.",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jdneo What do you think of the wording here, including output folders and dependencies ? Are them the proper ones? Or could you please give some suggestions?

CsCherrYY and others added 4 commits November 9, 2020 20:09
Signed-off-by: Shi Chen <chenshi@microsoft.com>
1. Rename "runtimeDependencies" to "dependencies".
2. Rename "Runtime" to "runtime" and "Test" to "test" in the export jar wizard.
3. When configure default task, only "compileOutput" and "dependencies" are provided by default.
4. Add a new try-catch in jdtls.ext so that some  exceptions such as duplicate files during export can be collected and the export process will not abort by them.
Copy link
Member

@jdneo jdneo left a comment

Choose a reason for hiding this comment

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

Thanks @CsCherrYY

@jdneo jdneo merged commit a1d66be into master Nov 13, 2020
@jdneo jdneo deleted the CustomTask branch November 13, 2020 07:17
@CsCherrYY CsCherrYY changed the title Support custom task to export jar Support exporting jar with custom task Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some exporting jar suggestions
3 participants