Skip to content

Commit

Permalink
Support platform specific extension (redhat-developer#2183)
Browse files Browse the repository at this point in the history
* Support platform specific extension

Signed-off-by: Jinbo Wang <[email protected]>
  • Loading branch information
testforstephen authored Dec 10, 2021
1 parent 530a3f6 commit c0d043e
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 102 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ node_modules
undefined
target
dist
jre
bin/
.settings
.classpath
Expand Down
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@
"outFiles": ["${workspaceRoot}/out/**/*.js"],
"preLaunchTask": "prepareLightweightTest",
"postDebugTask": "cleanTestFolder"
},
{
"args": [
"${input:gulpTask}"
],
"name": "Launch Gulp Task",
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
}
],
"inputs": [
{
"id": "gulpTask",
"type": "promptString",
"description": "Name of the Gulp task to execute",
"default": "download_jre"
}
]
}
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ gulpfile.js
Jenkinsfile
tslint.json
webpack.config.js
.DS_Store
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ The following will be a start to finish guide to get the entire language server
```bash
$ npm install
```
5. (**\*Optional**) Build a platform specific JRE:

```bash
$ npx gulp download_jre
```
You can also use the options `--target` and `--javaVersion` to build the specified JRE version for the specified target architecture.

#

Expand Down
59 changes: 47 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ node('rhel8'){

stage "Package vscode-java"
def packageJson = readJSON file: 'package.json'
sh "vsce package -o java-${packageJson.version}-${env.BUILD_NUMBER}.vsix"
env.EXTENSION_VERSION = "${packageJson.version}"
sh "vsce package -o java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"

stage 'Test vscode-java for staging'
wrap([$class: 'Xvnc']) {
Expand All @@ -55,10 +56,28 @@ node('rhel8'){
sh "npm test --silent"
}

stage 'Upload vscode-java to staging'
def vsix = findFiles(glob: '**.vsix')
sh "rsync -Pzrlt --rsh=ssh --protocol=28 ${vsix[0].path} ${UPLOAD_LOCATION}/jdt.ls/staging"
stash name:'vsix', includes:files[0].path
stash name:'vsix', includes:vsix[0].path

// Package platform specific versions
stage "Package platform specific vscode-java"
def platforms = ["win32-x64", "linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64"]
def embeddedJRE = 17
for(platform in platforms){
sh "npx gulp download_jre --target ${platform} --javaVersion ${embeddedJRE}"
sh "vsce package --target ${platform} -o java-${platform}-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
}
stash name:'platformVsix', includes:'java-win32-*.vsix,java-linux-*.vsix,java-darwin-*.vsix'

stage 'Upload vscode-java to staging'
def artifacts = findFiles(glob: '**.vsix')
def artifactDir = "java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}"
sh "mkdir ${artifactDir}"
sh "mv *.vsix ${artifactDir}"

for(artifact in artifacts){
sh "rsync -Pzrlt --rsh=ssh --protocol=28 --relative ${artifactDir}/${artifact.path} ${UPLOAD_LOCATION}/jdt.ls/staging"
}
}

node('rhel8'){
Expand All @@ -67,24 +86,40 @@ node('rhel8'){
input message:'Approve deployment?', submitter: 'fbricon,rgrunber'
}

stage "Publish to Marketplaces"
stage "Publish to Open-vsx Marketplace"
unstash 'vsix'
def vsix = findFiles(glob: '**.vsix')
// VS Code Marketplace
withCredentials([[$class: 'StringBinding', credentialsId: 'vscode_java_marketplace', variable: 'TOKEN']]) {
sh 'vsce publish -p ${TOKEN} --packagePath' + " ${vsix[0].path}"
}

// Open-vsx Marketplace
sh "npm install -g ovsx"
withCredentials([[$class: 'StringBinding', credentialsId: 'open-vsx-access-token', variable: 'OVSX_TOKEN']]) {
sh 'ovsx publish -p ${OVSX_TOKEN}' + " ${vsix[0].path}"
}

archive includes:"**.vsix"
stage "Publish to VS Code Marketplace"
// VS Code Marketplace
withCredentials([[$class: 'StringBinding', credentialsId: 'vscode_java_marketplace', variable: 'TOKEN']]) {
// Publish a generic version
sh 'vsce publish -p ${TOKEN} --target win32-ia32 win32-arm64 linux-armhf alpine-x64 alpine-arm64'

// Publish platform specific versions
unstash 'platformVsix'
def platformVsixes = findFiles(glob: '**.vsix', excludes: vsix[0].path)
for(platformVsix in platformVsixes){
sh 'vsce publish -p ${TOKEN}' + " --packagePath ${platformVsix.path}"
}
}

stage "Publish to http://download.jboss.org/jbosstools/static/jdt.ls/stable/"
def artifacts = findFiles(glob: '**.vsix')
def artifactDir = "java-${env.EXTENSION_VERSION}"
sh "mkdir ${artifactDir}"
sh "mv *.vsix ${artifactDir}"

archive includes:"${artifactDir}/**/*.*"

// copy this stable build to Akamai-mirrored /static/ URL, so staging can be cleaned out more easily
sh "rsync -Pzrlt --rsh=ssh --protocol=28 ${vsix[0].path} ${UPLOAD_LOCATION}/static/jdt.ls/stable/"
for(artifact in artifacts){
sh "rsync -Pzrlt --rsh=ssh --protocol=28 --relative ${artifactDir}/${artifact.path} ${UPLOAD_LOCATION}/static/jdt.ls/stable/"
}
}// if publishToMarketPlace
}
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ See the [changelog](CHANGELOG.md) for the latest release. You might also find us
Setting the JDK
===============
## Java Tooling JDK
This JDK will be used to launch the Java Language Server. And by default, will also be used to compile your projects.
Now that Java extension will publish platform specific versions, it will embed a JRE for supported platforms such as `win32-x64`, `linux-x64`, `linux-arm64`, `darwin-x64`, `darwin-arm64`. The embedded JRE is used to launch the Language Server for Java. Users are only responsible for configuring [Project JDKs](#project-jdks) to compile your Java projects.

The path to the Java Development Kit can be specified by the `java.home` setting in VS Code settings (workspace/user settings). If not specified, it is searched in the following order until a JDK meets current minimum requirement.
The following part is only kept for the universal version without embedded JRE.

- the `JDK_HOME` environment variable
- the `JAVA_HOME` environment variable
- on the current system path
>The tooling JDK will be used to launch the Language Server for Java. And by default, will also be used to compile your projects.\
\
The path to the Java Development Kit can be specified by the `java.home` setting in VS Code settings (workspace/user settings). If not specified, it is searched in the following order until a JDK meets current minimum requirement.
>- the `JDK_HOME` environment variable
>- the `JAVA_HOME` environment variable
>- on the current system path
## Project JDKs
If you need to compile your projects against a different JDK version, it's recommended you configure the `java.configuration.runtimes` property in your user settings, eg:
Expand Down Expand Up @@ -107,7 +110,7 @@ Supported VS Code settings
==========================
The following settings are supported:

* `java.home` : Absolute path to JDK home folder used to launch the Java Language Server. Requires VS Code restart.
* `java.home` : **Deprecated, only used for universal version without embedded JRE.** Absolute path to JDK home folder used to launch the Java Language Server. Requires VS Code restart.
* `java.jdt.ls.vmargs` : Extra VM arguments used to launch the Java Language Server. Requires VS Code restart.
* `java.errors.incompleteClasspath.severity` : Specifies the severity of the message when the classpath is incomplete for a Java file. Supported values are `ignore`, `info`, `warning`, `error`.
* `java.trace.server` : Traces the communication between VS Code and the Java language server.
Expand Down
104 changes: 104 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,119 @@ const gulp = require('gulp');
const cp = require('child_process');
const decompress = require('gulp-decompress');
const download = require('gulp-download');
const request = require('request');
const glob = require('glob');
const fse = require('fs-extra');
const path = require('path');
const url = require("url");
const argv = require('minimist')(process.argv.slice(2));
const server_dir = '../eclipse.jdt.ls';
const originalTestFolder = path.join(__dirname, 'test', 'resources', 'projects', 'maven', 'salut');
const tempTestFolder = path.join(__dirname, 'test-temp');
const testSettings = path.join(tempTestFolder, '.vscode', 'settings.json');
//...

gulp.task('clean_jre', function(done) {
if (fse.existsSync('./jre')) {
fse.removeSync('./jre');
}

done();
});

// Pls update the latest JRE if a new JDK is announced.
const LATEST_JRE = 17;

/**
* Usage:
* npx gulp download_jre // Download the latest JRE for the platform of the current running machine.
* npx gulp download_jre --target darwin-x64 --javaVersion 17 // Download the specified JRE for the specified platform.
*
* Supported platforms:
* win32-x64,
* linux-x64,
* linux-arm64,
* darwin-x64,
* darwin-arm64
*/
gulp.task('download_jre', async function(done) {
if (fse.existsSync('./jre')) {
fse.removeSync('./jre');
}

const platformMapping = {
"linux-arm64": "linux-aarch64",
"linux-x64": "linux-x86_64",
"darwin-arm64": "macosx-aarch64",
"darwin-x64": "macosx-x86_64",
"win32-x64": "win32-x86_64"
}

const targetPlatform = argv.target || process.platform + "-" + process.arch;
if (targetPlatform && Object.keys(platformMapping).includes(targetPlatform)) {
const javaVersion = (!argv.javaVersion || argv.javaVersion === "latest") ? LATEST_JRE : argv.javaVersion;
console.log("Downloading justj JRE " + javaVersion + " for the platform " + targetPlatform) + "...";

const manifestUrl = `https://download.eclipse.org/justj/jres/${javaVersion}/downloads/latest/justj.manifest`;
// Download justj.manifest file
const manifest = await new Promise(function(resolve, reject) {
request.get(manifestUrl, function(err, response, body) {
if(err || response.statusCode >= 400) {
reject(err || `${response.statusCode} returned from ${manifestUrl}`);
} else {
resolve(String(body));
}
});
});

if (!manifest) {
done(new Error(`Failed to download justj.manifest, please check if the link ${manifestUrl} is valid.`))
return;
}

/**
* Here are the contents for a sample justj.manifest file:
* ../20211012_0921/org.eclipse.justj.openjdk.hotspot.jre.full.stripped-17-linux-aarch64.tar.gz
* ../20211012_0921/org.eclipse.justj.openjdk.hotspot.jre.full.stripped-17-linux-x86_64.tar.gz
* ../20211012_0921/org.eclipse.justj.openjdk.hotspot.jre.full.stripped-17-macosx-aarch64.tar.gz
* ../20211012_0921/org.eclipse.justj.openjdk.hotspot.jre.full.stripped-17-macosx-x86_64.tar.gz
* ../20211012_0921/org.eclipse.justj.openjdk.hotspot.jre.full.stripped-17-win32-x86_64.tar.gz
*/
const javaPlatform = platformMapping[targetPlatform];
const list = manifest.split(/\r?\n/);
const jreIdentifier = list.find((value) => {
return value.indexOf("org.eclipse.justj.openjdk.hotspot.jre.full.stripped") >= 0 && value.indexOf(javaPlatform) >= 0;
});

if (!jreIdentifier) {
done(new Error(`justj doesn't support the jre ${javaVersion} for the platform ${javaPlatform} (${targetPlatform}), please refer to the link ${manifestUrl} for the supported platforms.`));
return;
}

const jreDownloadUrl = `https://download.eclipse.org/justj/jres/${javaVersion}/downloads/latest/${jreIdentifier}`;
const parsedDownloadUrl = url.parse(jreDownloadUrl);
const jreFileName = path.basename(parsedDownloadUrl.pathname)
.replace(/[\.7z|\.bz2|\.gz|\.rar|\.tar|\.zip|\.xz]*$/, "");
const idx = jreFileName.indexOf('-');
const jreVersionLabel = idx >= 0 ? jreFileName.substring(idx + 1) : jreFileName;
// Download justj JRE.
await new Promise(function(resolve, reject) {
download(jreDownloadUrl)
.on('error', reject)
.pipe(decompress({strip: 0}))
.pipe(gulp.dest('./jre/' + jreVersionLabel))
.on('end', resolve);
});
} else {
console.log("[Error] download_jre failed, please specify a valid target platform via --target argument. Here are the supported platform list:");
for (const platform of Object.keys(platformMapping)) {
console.log(platform);
}
}

done();
});

gulp.task('download_server', function(done) {
fse.removeSync('./server');
download("http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz")
Expand Down
Loading

0 comments on commit c0d043e

Please sign in to comment.