Skip to content

Commit

Permalink
Merge branch 'main' into rename-jdk-binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Achal1607 authored Jan 8, 2024
2 parents 4a876a5 + f30392b commit 2ef2354
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 33 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ jobs:
# artifact is only produced once in the matrix
base-build:
name: Base Build
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
matrix:
java: [ '17' ]
os: [ ubuntu-latest ]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:

- name: Set up JDK ${{ matrix.java }}
Expand Down Expand Up @@ -71,3 +72,9 @@ jobs:

- name: Build the Visual Studio Extension
run: ant build-vscode-ext

- name: Install virtual X server
run: sudo apt install -y xvfb

- name: Basic tests for the Visual Studio Extension
run: xvfb-run -a ant test-vscode-ext
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build/
^netbeans/
.DS_STORE
netbeans/
.DS_STORE
9 changes: 5 additions & 4 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

## Prerequisities

- JDK, version 11 or later
- JDK, version 11 or later upto JDK 20
- Ant, latest version
- Maven, latest version
- node.js, latest LTS (to build VSIX)
Expand All @@ -40,6 +40,7 @@ $ git clone https://github.com/apache/netbeans.git
$ cd netbeans/
$ git checkout f48f91e6c197d8a40bd82fc2f2d12a4e71242afe
$ cd ..
# the following target requires git executable to be on PATH:
$ ant apply-patches
$ ant build-netbeans

Expand Down Expand Up @@ -85,14 +86,14 @@ that there are VS Code integration tests - those launch VS Code with the
VS extension and check behavior of the TypeScript integration code:

```bash
java.lsp.server$ ant build-vscode-ext # first and then
java.lsp.server$ ant test-vscode-ext
$ ant build-vscode-ext # first and then
$ ant test-vscode-ext
```

In case you are behind a proxy, you may want to run the tests with

```bash
java.lsp.server$ npm_config_https_proxy=http://your.proxy.com:port ant test-vscode-ext
$ npm_config_https_proxy=http://your.proxy.com:port ant test-vscode-ext
```

when executing the tests for the first time. That shall overcome the proxy
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<!-- This file has been modified for Oracle Java Platform extension -->

# Oracle Java Platform Extension for Visual Studio Code
[![Visual Studio Marketplace](https://img.shields.io/visual-studio-marketplace/v/Oracle.oracle-java?style=for-the-badge&label=VS%20Marketplace&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=Oracle.oracle-java)
[![Installs](https://img.shields.io/visual-studio-marketplace/i/Oracle.oracle-java?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=Oracle.oracle-java)
[![Build Status](https://img.shields.io/github/actions/workflow/status/oracle/javavscode/main.yml?branch=main&style=for-the-badge&logo=github)](https://github.com/oracle/javavscode/actions?query=workflow:Java%20Platform%20Support%20for%20Visual%20Studio%20Code)
[![License](https://img.shields.io/github/license/oracle/javavscode?style=for-the-badge&logo=apache)](https://github.com/oracle/javavscode/blob/main/LICENSE.txt)

The Oracle Java Platform extension brings full featured Java development (edit-compile-debug & test cycle) for Maven and Gradle projects to VS Code, and is available on the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=Oracle.oracle-java).

Expand Down Expand Up @@ -121,6 +125,13 @@ Move members refactoring provides dedicated form as well.
* Inline redundant variable
* Constructor and method argument refactoring

## Formatter Preferences
Easily update default formatter preferences by adjusting a simple configuration option to tailor settings according to specific needs.

Go to VSCode `View | Command Palette | Preferences:Open User Settings | Extensions | Java` and set `Jdk › Format: Settings Path:` option to the formatter preferences file.

Please refer to [Java formatting preferences](https://github.com/oracle/javavscode/wiki/Java-formatting-preferences) wiki for more info.

## Organize Imports
Out of the box support for organizing imports in Java sources is available. It removes unused imports, groups imports by packages and updates your imports whenever a file is saved. In addition to the defaults, there is a rich set of configuration options.

Expand Down
52 changes: 39 additions & 13 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<property name="nbplatform.default.harness.dir" location="${nbplatform.default.netbeans.dest.dir}/harness" />
<property name="nbantext.jar" location="netbeans/nbbuild/build/nbantext.jar" />
<property name="nb_all" location="netbeans" />
<property name="patches" value="patches/6218.diff patches/6330.diff patches/6478-6480.diff patches/6481.diff patches/6771.diff patches/mvn-sh.diff patches/rename-debugger.diff" />
<condition property="cmd.suffix" value=".cmd" else="">
<os family="windows"/>
</condition>
Expand Down Expand Up @@ -141,7 +142,11 @@
<delete file="${basedir}/vscode/THIRD_PARTY_LICENSES.txt"/>
</target>
<target name="test-lsp-server" description="Tests the LSP server behavior">
<ant dir="nbcode" target="test" inheritall="false" inheritrefs="false" />
<ant dir="nbcode" target="test" inheritall="false" inheritrefs="false">
<property name="nbplatform.default.netbeans.dest.dir" location="${nbplatform.default.netbeans.dest.dir}" />
<property name="nbplatform.default.harness.dir" location="${nbplatform.default.harness.dir}" />
<property name="nbantext.jar" location="${nbantext.jar}" />
</ant>
</target>

<target name="test-vscode-ext" depends="test-lsp-server" description="Tests the Visual Studio Code extension built by 'build-vscode-ext' target.">
Expand All @@ -168,21 +173,42 @@
</target>

<target name="apply-patches">
<patch patchfile="patches/6218.diff" strip="1" dir="netbeans" failonerror="true"/>
<patch patchfile="patches/6330.diff" strip="1" dir="netbeans" failonerror="true"/>
<patch patchfile="patches/6478-6480.diff" strip="1" dir="netbeans" failonerror="true"/>
<patch patchfile="patches/6481.diff" strip="1" dir="netbeans" failonerror="true"/>
<patch patchfile="patches/mvn-sh.diff" strip="1" dir="netbeans" failonerror="true"/>
<patch patchfile="patches/rename-debugger.diff" strip="1" dir="netbeans" failonerror="true"/>
<exec executable="git">
<arg value="apply"/>
<arg value="--directory=netbeans"/>
<arg value="--whitespace=nowarn"/>
<arg line="${patches}"/>
</exec>
</target>

<target name="unapply-patches">
<patch patchfile="patches/rename-debugger.diff" strip="1" dir="netbeans" failonerror="true" reverse="true"/>
<patch patchfile="patches/mvn-sh.diff" strip="1" dir="netbeans" failonerror="true" reverse="true"/>
<patch patchfile="patches/6218.diff" strip="1" dir="netbeans" failonerror="true" reverse="true"/>
<patch patchfile="patches/6330.diff" strip="1" dir="netbeans" failonerror="true" reverse="true"/>
<patch patchfile="patches/6478-6480.diff" strip="1" dir="netbeans" failonerror="true" reverse="true"/>
<patch patchfile="patches/6481.diff" strip="1" dir="netbeans" failonerror="true" reverse="true"/>
<!--in the reverse order:-->
<echo file="${build.dir}/Reverse.java">
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class Reverse {
public static void main(String[] args) {
List&lt;String> patches = Arrays.asList(args[0].split(" "));
Collections.reverse(patches);
System.out.print(patches.stream().collect(Collectors.joining(" ")));
}
}
</echo>
<java sourcefile="${build.dir}/Reverse.java"
outputproperty="reverse.patches"
fork="true">
<arg value="${patches}" />
</java>
<echo>${reverse.patches}</echo>
<exec executable="git">
<arg value="apply"/>
<arg value="--directory=netbeans"/>
<arg value="--whitespace=nowarn"/>
<arg value="--reverse"/>
<arg line="${reverse.patches}"/>
</exec>
</target>

<target name="build-netbeans">
Expand Down
13 changes: 13 additions & 0 deletions patches/6771.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java
index d893783f6995..3f90097b6053 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java
@@ -80,7 +80,7 @@
public final class SurroundWithHint extends CodeActionsProvider {

private static final String COMMAND_INSERT_SNIPPET = "editor.action.insertSnippet";
- private static final String COMMAND_SURROUND_WITH = "surround.with";
+ private static final String COMMAND_SURROUND_WITH = "nbls.surround.with";
private static final String DOTS = "...";
private static final String SNIPPET = "snippet";
private static final String SELECTION_VAR = "${selection}";
7 changes: 7 additions & 0 deletions vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ Move members refactoring provides dedicated form as well.
* Inline redundant variable
* Constructor and method argument refactoring

## Formatter Preferences
Easily update default formatter preferences by adjusting a simple configuration option to tailor settings according to specific needs.

Go to VSCode `View | Command Palette | Preferences:Open User Settings | Extensions | Java` and set `Jdk › Format: Settings Path:` option to the formatter preferences file.

Please refer to [Java formatting preferences](https://github.com/oracle/javavscode/wiki/Java-formatting-preferences) wiki for more info.

## Organize Imports
Out of the box support for organizing imports in Java sources is available. It removes unused imports, groups imports by packages and updates your imports whenever a file is saved. In addition to the defaults, there is a rich set of configuration options.

Expand Down
14 changes: 7 additions & 7 deletions vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,33 @@
"command": "jdk.java.goto.super.implementation",
"when": "nbJdkReady && editorLangId == java && editorTextFocus",
"group": "navigation@100"
},
{
"command": "jdk.project.run",
"when": "nbJdkReady && editorLangId == java && resourceExtname == .java",
"group": "javadebug@1"
},
{
"command": "jdk.project.debug",
"when": "nbJdkReady && editorLangId == java && resourceExtname == .java",
"group": "javadebug@2"
}
],
"explorer/context": [
{
"command": "jdk.workspace.new",
"when": "nbJdkReady && explorerResourceIsFolder",
"group": "navigation@3"
},
{
"command": "jdk.project.run",
"when": "nbJdkReady && resourceExtname == .java",
"group": "javadebug@1"
},
{
"command": "jdk.project.debug",
"when": "nbJdkReady && resourceExtname == .java",
"group": "javadebug@2"
}
],
"commandPalette": [
Expand All @@ -483,6 +503,9 @@
{
"command": "jdk.workspace.newproject"
},
{
"command": "jdk.download.jdk"
},
{
"command": "jdk.workspace.compile",
"when": "nbJdkReady"
Expand Down Expand Up @@ -696,8 +719,8 @@
"dependencies": {
"@vscode/debugadapter": "1.55.1",
"@vscode/webview-ui-toolkit": "^1.2.2",
"axios": "^1.5.0",
"axios": "^1.6.0",
"jsonc-parser": "3.2.0",
"vscode-languageclient": "^8.1.0"
}
}
}
2 changes: 1 addition & 1 deletion vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
throw `Client ${c} doesn't support new project`;
}
}));
context.subscriptions.push(vscode.commands.registerCommand(COMMAND_PREFIX + ".download.jdk", async () => { openJDKSelectionView(log); }));
context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.workspace.compile', () =>
wrapCommandWithProgress(COMMAND_PREFIX + '.build.workspace', 'Compiling workspace...', log, true)
));
Expand Down Expand Up @@ -1109,7 +1110,6 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
}
}));
ctx.subscriptions.push(vscode.commands.registerCommand(COMMAND_PREFIX + ".select.editor.projects", () => revealActiveEditor()));
ctx.subscriptions.push(vscode.commands.registerCommand(COMMAND_PREFIX + ".download.jdk", () => openJDKSelectionView(log)));

// attempt to reveal NOW:
if (netbeansConfig.get("revealActiveInProjects")) {
Expand Down
31 changes: 28 additions & 3 deletions vscode/src/jdkDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,29 @@ import axios from 'axios';
import * as https from 'https';
import * as child_process from 'child_process';
import * as vscode from 'vscode';
import * as crypto from 'crypto';
import { JDK_RELEASES_TRACK_URL, OPEN_JDK_VERSION_DOWNLOAD_LINKS, ORACLE_JDK_BASE_DOWNLOAD_URL, ORACLE_JDK_VERSION_FALLBACK_DOWNLOAD_VERSIONS } from './constants';
import { handleLog } from './extension';
import { promisify } from 'util';

let customView: vscode.WebviewPanel;
let logger: vscode.OutputChannel;

export const calculateChecksum = async (filePath: string): Promise<string> => {
const ALGORITHM = 'sha256';
const hash = crypto.createHash(ALGORITHM);
const pipeline = promisify(require('stream').pipeline);
const readStream = fs.createReadStream(filePath);

await pipeline(
readStream,
hash
);

const checksum = hash.digest('hex');
return checksum;
}

export const fetchDropdownOptions = async () => {

// Detect OS of the machine
Expand Down Expand Up @@ -172,9 +190,16 @@ export function JDKDownloader(JDKType: string, osType: string, osArchitecture: s
response.pipe(writeStream);

writeStream.on('finish', async () => {
vscode.window.showInformationMessage(`${JDKType} ${JDKVersion} for ${osType} download completed!`);

await extractJDK(path.join(targetDirectory, fileName), installationPath, JDKVersion, osType, JDKType);
const checkSumObtained = await calculateChecksum(filePath);
const checkSumExpected = (await axios.get(`${downloadUrl}.sha256`)).data;
if (checkSumExpected === checkSumObtained) {
vscode.window.showInformationMessage(`${JDKType} ${JDKVersion} for ${osType} download completed!`);
await extractJDK(filePath, installationPath, JDKVersion, osType, JDKType);
}
else {
handleLog(logger, `Checksums don't match! \n Expected: ${checkSumExpected} \n Obtained: ${checkSumObtained}`);
vscode.window.showErrorMessage(`"${JDKType} ${JDKVersion} for ${osType} download failed, wrong checksum."`);
}
});

writeStream.on('error', error => {
Expand Down
5 changes: 5 additions & 0 deletions vscode/src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ suite('Extension Test Suite', function () {
if (refactorActions && refactorActions.length > 0) {
for await (const action of refactorActions) {
if (action.command && action.command.arguments) {
if (action.command.command === myExtension.COMMAND_PREFIX + ".surround.with") {
//this action has a popup where the user needs to
//select a template that should be used for the surround:
continue;
}
await commands.executeCommand(action.command.command, ...action.command.arguments);
await commands.executeCommand('undo');
}
Expand Down

0 comments on commit 2ef2354

Please sign in to comment.