Unverified Commit 321d779a authored by Neil C Smith's avatar Neil C Smith Committed by GitHub
Browse files

Merge pull request #3483 from apache/delivery

Sync delivery to release130 for 13-rc2
parents d77f0692 c9af6eaf
......@@ -32,6 +32,7 @@
/nbbuild/user.build.properties
/nbbuild/gitinfo.properties
/nbbuild/netbeansrelease.properties
/nbbuild/netbeansrelease.json
/nbi/engine/native/*/*/dist/
/nb-javac/
/java.source.nbjavac/test/test-nb-javac/nbproject/private/
......
......@@ -38,13 +38,12 @@ Apache NetBeans is an open source development environment, tooling platform, and
* Git
* Ant 1.9.9 or above
* JDK 8 or 11 (to build NetBeans)
* JDK 9 or above (to run NetBeans)
* JDK 11 (to build NetBeans)
* JDK 11 or above (to run NetBeans)
* MinGW (optional), to build Windows Launchers
#### Notes:
* NetBeans also runs with JDK 8, although then it will not include tools for the JDK 9 Shell.
* NetBeans license violation checks are managed via the [rat-exclusions.txt](https://github.com/apache/netbeans/blob/master/nbbuild/rat-exclusions.txt) file.
* Set JAVA_HOME and ANT_HOME appropriately or leave them undefined.
......
......@@ -22,6 +22,3 @@ project.xpath.pom.xml=//bootclasspath[contains(text(),'jfxrt')],//executable[con
extra.modules=org\\.netbeans\\.libs\\.javafx\\.(linux|win|macosx)
extra.modules.recommended.max.jdk=11
extra.modules.1=org.netbeans.modules.nbjavac.*
extra.modules.1.recommended.min.jdk=9
......@@ -549,7 +549,8 @@ public class ActionProviderImpl implements ActionProvider {
acts.add(act);
}
}
acts.add(createCustomGradleAction(project, LBL_Custom_run_tasks(), new CustomActionMapping("name"), lookup, true));
acts.add(createCustomGradleAction(project, LBL_Custom_run_tasks(),
new CustomActionMapping(ActionMapping.CUSTOM_PREFIX), lookup, true));
SwingUtilities.invokeLater(() -> {
boolean selected = menu.isSelected();
menu.remove(loading);
......
......@@ -71,7 +71,7 @@ public abstract class AbstractProjectLoader {
public ReloadContext(NbGradleProjectImpl project, NbGradleProject.Quality aim, GradleCommandLine cmd, String description) {
this.project = project;
this.previous = project.isGradleProjectLoaded() ? project.getGradleProject() : FallbackProjectLoader.createFallbackProject(project.getGradleFiles());
this.previous = project.isGradleProjectLoaded() ? project.projectWithQuality(null, FALLBACK, false, false) : FallbackProjectLoader.createFallbackProject(project.getGradleFiles());
this.aim = aim;
this.cmd = cmd;
this.description = description;
......
......@@ -50,6 +50,8 @@ import static org.netbeans.modules.gradle.spi.newproject.Bundle.*;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.gradle.GradleProjectLoader;
......@@ -65,6 +67,8 @@ import org.openide.util.NbBundle;
* @author Laszlo Kishalmi
*/
public final class TemplateOperation implements Runnable {
private static final Logger LOG = Logger.getLogger(TemplateOperation.class.getName());
public interface ProjectConfigurator {
void configure(Project project);
}
......@@ -108,6 +112,7 @@ public final class TemplateOperation implements Runnable {
if (handle != null) {
handle.progress(step.getMessage(), work++);
}
LOG.log(Level.FINE, "Executing Gradle Project Template Operation {0}", step);
Set<FileObject> filesToOpen = step.execute();
if (filesToOpen != null) {
importantFiles.addAll(filesToOpen);
......@@ -260,8 +265,7 @@ public final class TemplateOperation implements Runnable {
public Set<FileObject> execute() {
GradleConnector gconn = GradleConnector.newConnector();
target.mkdirs();
ProjectConnection pconn = gconn.forProjectDirectory(target).connect();
try {
try (ProjectConnection pconn = gconn.forProjectDirectory(target).connect()) {
List<String> args = new ArrayList<>();
args.add("init");
// gradle init --type java-application --test-framework junit-jupiter --dsl groovy --package com.example --project-name example
......@@ -293,8 +297,6 @@ public final class TemplateOperation implements Runnable {
} catch (GradleConnectionException | IllegalStateException ex) {
// Well for some reason we were not able to load Gradle.
// Ignoring that for now
} finally {
pconn.close();
}
return Collections.singleton(FileUtil.toFileObject(target));
}
......@@ -320,7 +322,14 @@ public final class TemplateOperation implements Runnable {
steps.add(new PreloadProject(projectDir));
}
private static class CreateDirStep implements OperationStep {
private static abstract class BaseOperationStep implements OperationStep {
@Override
public final String toString() {
return "Step: " + getMessage();
}
}
private static final class CreateDirStep extends BaseOperationStep {
final String message;
final File dir;
......@@ -344,9 +353,10 @@ public final class TemplateOperation implements Runnable {
}
return null;
}
}
private static class ConfigureProjectStep implements OperationStep {
private static final class ConfigureProjectStep extends BaseOperationStep {
final File dir;
final ProjectConfigurator configurator;
......@@ -367,9 +377,10 @@ public final class TemplateOperation implements Runnable {
try {
FileObject projectDir = FileUtil.toFileObject(dir);
Project project = ProjectManager.getDefault().findProject(projectDir);
ProjectTrust.getDefault().trustProject(project);
NbGradleProjectImpl impl = project != null ? project.getLookup().lookup(NbGradleProjectImpl.class): null;
if (impl != null) {
impl.fireProjectReload(true);
impl.projectWithQuality(null, Quality.FULL, false, false);
configurator.configure(project);
}
......@@ -380,7 +391,7 @@ public final class TemplateOperation implements Runnable {
}
}
private static class PreloadProject implements OperationStep {
private static final class PreloadProject extends BaseOperationStep {
final File dir;
......@@ -410,7 +421,7 @@ public final class TemplateOperation implements Runnable {
}
project = ProjectManager.getDefault().findProject(projectDir);
if (project != null) {
//Let's trust the generate project
//Let's trust the generated project
ProjectTrust.getDefault().trustProject(project);
NbGradleProjectImpl nbProject = project.getLookup().lookup(NbGradleProjectImpl.class);
if (nbProject != null) {
......@@ -430,7 +441,7 @@ public final class TemplateOperation implements Runnable {
}
private static class InitGradleWrapper implements OperationStep {
private static final class InitGradleWrapper extends BaseOperationStep {
final File projectDir;
......@@ -447,21 +458,18 @@ public final class TemplateOperation implements Runnable {
@Override
public Set<FileObject> execute() {
GradleConnector gconn = GradleConnector.newConnector();
ProjectConnection pconn = gconn.forProjectDirectory(projectDir).connect();
try {
try (ProjectConnection pconn = gconn.forProjectDirectory(projectDir).connect()) {
pconn.newBuild().withArguments("--offline").forTasks("wrapper").run(); //NOI18N
} catch (GradleConnectionException | IllegalStateException ex) {
// Well for some reason we were not able to load Gradle.
// Ignoring that for now
} finally {
pconn.close();
}
return null;
}
}
private static class CopyFromFileTemplate implements OperationStep {
private static final class CopyFromFileTemplate extends BaseOperationStep {
final File target;
final Map<String, ? extends Object> tokens;
final boolean important;
......@@ -524,7 +532,7 @@ public final class TemplateOperation implements Runnable {
}
private static class CopyFromTemplate implements OperationStep {
private static final class CopyFromTemplate extends BaseOperationStep {
final File target;
final Map<String, ? extends Object> tokens;
final boolean important;
......
......@@ -37,6 +37,7 @@ import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
......@@ -56,6 +57,8 @@ import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.ResourceOperationKind;
import org.eclipse.lsp4j.SemanticTokens;
import org.eclipse.lsp4j.SemanticTokensCapabilities;
import org.eclipse.lsp4j.SemanticTokensClientCapabilitiesRequests;
import org.eclipse.lsp4j.SemanticTokensLegend;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.SymbolCapabilities;
......@@ -367,6 +370,7 @@ public class LSPBindings {
dsc.setHierarchicalDocumentSymbolSupport(true);
dsc.setSymbolKind(new SymbolKindCapabilities(Arrays.asList(SymbolKind.values())));
tdcc.setDocumentSymbol(dsc);
tdcc.setSemanticTokens(new SemanticTokensCapabilities(new SemanticTokensClientCapabilitiesRequests(true), KNOWN_TOKEN_TYPES, KNOWN_TOKEN_MODIFIERS, Arrays.asList()));
WorkspaceClientCapabilities wcc = new WorkspaceClientCapabilities();
wcc.setWorkspaceEdit(new WorkspaceEditCapabilities());
wcc.getWorkspaceEdit().setDocumentChanges(true);
......@@ -387,6 +391,15 @@ public class LSPBindings {
}
}
}
private static final List<String> KNOWN_TOKEN_TYPES = Collections.unmodifiableList(Arrays.asList(
"namespace", "package", "function", "method", "macro", "parameter",
"variable", "struct", "enum", "class", "typeAlias", "typeParameter",
"field", "enumMember", "keyword"
));
private static final List<String> KNOWN_TOKEN_MODIFIERS = Collections.unmodifiableList(Arrays.asList(
"static", "definition", "declaration"
));
public static synchronized Set<LSPBindings> getAllBindings() {
Set<LSPBindings> allBindings = Collections.newSetFromMap(new IdentityHashMap<>());
......
......@@ -42,6 +42,7 @@ import org.eclipse.lsp4j.CompletionList;
import org.eclipse.lsp4j.CompletionOptions;
import org.eclipse.lsp4j.CompletionParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.InsertReplaceEdit;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.ParameterInformation;
import org.eclipse.lsp4j.ServerCapabilities;
......@@ -189,13 +190,14 @@ public class CompletionProviderImpl implements CompletionProvider {
commit("");
}
private void commit(String appendText) {
if (i.getTextEdit().isRight()) {
Either<TextEdit, InsertReplaceEdit> edit = i.getTextEdit();
if (edit != null && edit.isRight()) {
//TODO: the NetBeans client does not current support InsertReplaceEdits, should not happen
Completion.get().hideDocumentation();
Completion.get().hideCompletion();
return ;
}
TextEdit te = i.getTextEdit().getLeft();
TextEdit te = edit != null ? edit.getLeft() : null;
NbDocument.runAtomic((StyledDocument) doc, () -> {
try {
int endPos;
......
......@@ -18,12 +18,12 @@
*/
package org.netbeans.modules.lsp.client.bindings;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import javax.swing.text.AttributeSet;
import javax.swing.text.Document;
......@@ -32,11 +32,9 @@ import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.SemanticTokens;
import org.eclipse.lsp4j.SemanticTokensLegend;
import org.eclipse.lsp4j.SemanticTokensParams;
import org.eclipse.lsp4j.SemanticTokensWithRegistrationOptions;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.generator.JsonRpcData;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.api.editor.mimelookup.MimePath;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.api.editor.settings.AttributesUtilities;
import org.netbeans.api.editor.settings.FontColorSettings;
......@@ -65,6 +63,10 @@ public class SemanticHighlight implements BackgroundTask {
@Override
public void run(LSPBindings bindings, FileObject file) {
try {
SemanticTokensWithRegistrationOptions options = bindings.getInitResult().getCapabilities().getSemanticTokensProvider();
if (options == null) {
return ;
}
OffsetsBag target = new OffsetsBag(doc);
SemanticTokensParams params = new SemanticTokensParams(new TextDocumentIdentifier(Utils.toURI(file)));
SemanticTokens tokens = bindings.getTextDocumentService().semanticTokensFull(params).get();
......@@ -130,7 +132,7 @@ public class SemanticHighlight implements BackgroundTask {
AttributeSet statik = isStatic ? fcs.getTokenFontColors("mod-static") : null;
if (colors != null && statik != null) {
return AttributesUtilities.createComposite(colors, statik);
return AttributesUtilities.createComposite(adjustAttributes(colors), adjustAttributes(statik));
} else if (colors != null) {
return colors;
} else if (statik != null) {
......@@ -153,6 +155,22 @@ public class SemanticHighlight implements BackgroundTask {
return bag;
}
private static AttributeSet adjustAttributes(AttributeSet as) {
Collection<Object> attrs = new LinkedList<Object>();
for (Enumeration<?> e = as.getAttributeNames(); e.hasMoreElements(); ) {
Object key = e.nextElement();
Object value = as.getAttribute(key);
if (value != Boolean.FALSE) {
attrs.add(key);
attrs.add(value);
}
}
return AttributesUtilities.createImmutable(attrs.toArray());
}
@MimeRegistration(mimeType="", service=HighlightsLayerFactory.class)
public static final class HighlightsLayerFactoryImpl implements HighlightsLayerFactory {
......@@ -164,44 +182,5 @@ public class SemanticHighlight implements BackgroundTask {
}
}
// @JsonRpcData
// public static class SemanticTokensParams {
//
// private TextDocumentIdentifier textDocument;
//
// public SemanticTokensParams() {
// }
//
// public SemanticTokensParams(TextDocumentIdentifier textDocument) {
// this.textDocument = textDocument;
// }
//
// public TextDocumentIdentifier getTextDocument() {
// return textDocument;
// }
//
// public void setTextDocument(TextDocumentIdentifier textDocument) {
// this.textDocument = textDocument;
// }
//
// }
//
// @JsonRpcData
// public static class SemanticTokens {
// private List<Number> data;
//
// public List<Number> getData() {
// return data;
// }
//
// public void setData(List<Number> data) {
// this.data = data;
// }
//
// }
// public interface SemanticService {
// @JsonRequest("textDocument/semanticTokens/full")
// public CompletableFuture<SemanticTokens> semanticTokensFull(SemanticTokensParams params);
// }
}
......@@ -67,6 +67,7 @@
<fontcolor name="mod-typeParameter" default="identifier"/>
<fontcolor name="mod-field" default="field"/>
<fontcolor name="mod-enumMember" default="field"/>
<fontcolor name="mod-keyword" default="keyword"/>
<fontcolor name="mod-namespace-declaration" default="identifier"/>
<fontcolor name="mod-package-declaration" default="identifier"/>
......@@ -82,6 +83,7 @@
<fontcolor name="mod-typeParameter-declaration" default="identifier"/>
<fontcolor name="mod-field-declaration" default="field"/>
<fontcolor name="mod-enumMember-declaration" default="field"/>
<fontcolor name="mod-keyword-declaration" default="keyword"/>
<fontcolor name="mod-static" >
<font style="italic" />
......
......@@ -281,6 +281,7 @@ public class OrganizeImports {
break;
case ANNOTATION_TYPE:
case CLASS:
case RECORD:
case ENUM:
case INTERFACE:
Element glob = global(element, starImports);
......
......@@ -68,12 +68,14 @@ public class Utils {
case ENUM:
return SymbolKind.Enum;
case CLASS:
case RECORD:
return SymbolKind.Class;
case ANNOTATION_TYPE:
return SymbolKind.Interface;
case INTERFACE:
return SymbolKind.Interface;
case ENUM_CONSTANT:
case RECORD_COMPONENT:
return SymbolKind.EnumMember;
case FIELD:
return SymbolKind.Field; //TODO: constant
......@@ -110,6 +112,7 @@ public class Utils {
case INTERFACE:
case ENUM:
case ANNOTATION_TYPE:
case RECORD:
TypeElement te = (TypeElement) e;
StringBuilder sb = new StringBuilder();
sb.append(fqn ? te.getQualifiedName() : te.getSimpleName());
......@@ -140,6 +143,7 @@ public class Utils {
return sb.toString();
case FIELD:
case ENUM_CONSTANT:
case RECORD_COMPONENT:
return e.getSimpleName().toString();
case CONSTRUCTOR:
case METHOD:
......
......@@ -1947,8 +1947,8 @@ public class TextDocumentServiceImpl implements TextDocumentService, LanguageCli
static BiConsumer<String, Object> HOOK_NOTIFICATION = null;
private static final Map<ColoringAttributes, List<String>> COLORING_TO_TOKEN_TYPE_CANDIDATES = new HashMap<ColoringAttributes, List<String>>() {{
put(ColoringAttributes.FIELD, Arrays.asList("member"));
put(ColoringAttributes.RECORD_COMPONENT, Arrays.asList("member"));
put(ColoringAttributes.FIELD, Arrays.asList("field", "member"));
put(ColoringAttributes.RECORD_COMPONENT, Arrays.asList("field", "member"));
put(ColoringAttributes.LOCAL_VARIABLE, Arrays.asList("variable"));
put(ColoringAttributes.PARAMETER, Arrays.asList("parameter"));
put(ColoringAttributes.METHOD, Arrays.asList("method", "function"));
......@@ -1959,6 +1959,7 @@ public class TextDocumentServiceImpl implements TextDocumentService, LanguageCli
put(ColoringAttributes.ANNOTATION_TYPE, Arrays.asList("interface"));
put(ColoringAttributes.ENUM, Arrays.asList("enum"));
put(ColoringAttributes.TYPE_PARAMETER_DECLARATION, Arrays.asList("typeParameter"));
put(ColoringAttributes.KEYWORD, Arrays.asList("keyword"));
}};
private static final Map<ColoringAttributes, List<String>> COLORING_TO_TOKEN_MODIFIERS_CANDIDATES = new HashMap<ColoringAttributes, List<String>>() {{
......@@ -2011,7 +2012,7 @@ public class TextDocumentServiceImpl implements TextDocumentService, LanguageCli
modifiers |= mod;
}
}
if (tokenType.isPresent()) {
if (tokenType.isPresent() && tokenType.get() >= 0) {
result.add(line - lastLine);
result.add((int) (currentOffset - currentLineStart - column));
result.add(e.getKey().length());
......
......@@ -159,11 +159,13 @@ import org.netbeans.modules.java.lsp.server.refactoring.ChangeMethodParameterUI;
import org.netbeans.modules.java.lsp.server.refactoring.ParameterUI;
import org.netbeans.modules.java.lsp.server.ui.MockHtmlViewer;
import org.netbeans.modules.java.source.BootClassPathUtil;
import org.netbeans.modules.java.source.parsing.JavacParser;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.parsing.impl.indexing.implspi.CacheFolderProvider;
import org.netbeans.spi.java.classpath.ClassPathProvider;
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
import org.netbeans.spi.java.queries.AnnotationProcessingQueryImplementation;
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
import org.netbeans.spi.lsp.ErrorProvider;
import org.netbeans.spi.project.ProjectFactory;
import org.netbeans.spi.project.ProjectState;
......@@ -710,10 +712,12 @@ public class ServerTest extends NbTestCase {
" public void innerMethod() {\n" +
" }\n" +
" }\n" +
" record R(int i) {}\n" +
"}\n";
try (Writer w = new FileWriter(src)) {
w.write(code);
}
file2SourceLevel.put(FileUtil.toFileObject(src.getParentFile()), "17");
FileUtil.refreshFor(getWorkDir());
Launcher<LanguageServer> serverLauncher = LSPLauncher.createClientLauncher(new LspClient() {
@Override
......@@ -758,7 +762,7 @@ public class ServerTest extends NbTestCase {
" character = 0\n" +
" ]\n" +
" end = Position [\n" +
" line = 8\n" +
" line = 9\n" +
" character = 1\n" +
" ]\n" +
"]:(Class:Inner:Range [\n" +
......@@ -779,6 +783,24 @@ public class ServerTest extends NbTestCase {
" line = 6\n" +
" character = 9\n" +
" ]\n" +
"]:()), Class:R:Range [\n" +
" start = Position [\n" +
" line = 8\n" +
" character = 4\n" +
" ]\n" +
" end = Position [\n" +
" line = 8\n" +
" character = 22\n" +
" ]\n" +
"]:(Field:i:Range [\n" +
" start = Position [\n" +
" line = 8\n" +
" character = 13\n" +
" ]\n" +
" end = Position [\n" +
" line = 8\n" +
" character = 18\n" +
" ]\n" +
"]:()), Field:field:Range [\n" +
" start = Position [\n" +
" line = 1\n" +
......@@ -4713,6 +4735,66 @@ public class ServerTest extends NbTestCase {
"3:20-26:method:[]");
}
public void testSemanticHighlighting2() throws Exception {
File src = new File(getWorkDir(), "Test.java");
src.getParentFile().mkdirs();
String code = "public class Test {\n" +
" private static final int C = 0;\n" +
" public int method(int p) {\n" +
" int l = p + method(0);\n" +
" }\n" +
"}\n";
try (Writer w = new FileWriter(src)) {
w.write(code);
}
FileUtil.refreshFor(getWorkDir());
Launcher<LanguageServer> serverLauncher = LSPLauncher.createClientLauncher(new LanguageClient() {
@Override
public void telemetryEvent(Object arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void publishDiagnostics(PublishDiagnosticsParams params) {
}
@Override
public void showMessage(MessageParams arg0) {
}
@Override
public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void logMessage(MessageParams arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
}, client.getInputStream(), client.getOutputStream());
serverLauncher.startListening();
LanguageServer server = serverLauncher.getRemoteProxy();
ClientCapabilities clientCaps = new ClientCapabilities();
TextDocumentClientCapabilities textCaps = new TextDocumentClientCapabilities();
clientCaps.setTextDocument(textCaps);
SemanticTokensCapabilities sematicTokensCapabilities = new SemanticTokensCapabilities(true);
sematicTokensCapabilities.setTokenTypes(Arrays.asList("field", "method", "function", "class", "interface", "enum", "typeParameter"));
sematicTokensCapabilities.setTokenModifiers(Arrays.asList("declaration", "static"));
textCaps.setSemanticTokens(sematicTokensCapabilities);