You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "lahodaj (via GitHub)" <gi...@apache.org> on 2023/07/27 10:41:44 UTC
[GitHub] [netbeans] lahodaj opened a new pull request, #6262: Supporting source file launcher in VS Code extension
lahodaj opened a new pull request, #6262:
URL: https://github.com/apache/netbeans/pull/6262
(Single) source file launcher support has multiple problems inside VS Code - especially settings that are inside NetBeans done through file attributes are not accessible. This patch attempts to use the Run Configuration tab/settings to provide options for launching the single file. The same options are also parsed for use in the editor.
---
**^Add meaningful description above**
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
- are all your own work, and you have the right to contribute them.
- are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] arvindaprameya commented on pull request #6262: Supporting source file launcher in VS Code extension
Posted by "arvindaprameya (via GitHub)" <gi...@apache.org>.
arvindaprameya commented on PR #6262:
URL: https://github.com/apache/netbeans/pull/6262#issuecomment-1655504203
This looks good, thank you for making this change! Appoved
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj merged pull request #6262: Supporting source file launcher in VS Code extension
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj merged PR #6262:
URL: https://github.com/apache/netbeans/pull/6262
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on pull request #6262: Supporting source file launcher in VS Code extension
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6262:
URL: https://github.com/apache/netbeans/pull/6262#issuecomment-1654102026
@sdedic thanks a lot for the comments!. I've mostly (except the `-source`) reflected them under [bc9417f](https://github.com/apache/netbeans/pull/6262/commits/bc9417f46a31efa22c6827f07c71a1e5b1a8c864).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a diff in pull request #6262: Supporting source file launcher in VS Code extension
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #6262:
URL: https://github.com/apache/netbeans/pull/6262#discussion_r1276283344
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/LaunchProcess.java:
##########
@@ -105,4 +116,12 @@ private Process setupProcess(String port) throws InterruptedException {
}
return null;
}
+
+ private static List<String> readArgumentsFromAttribute(FileObject fileObject, String attributeName) {
+ Object argumentsObject = fileObject.getAttribute(attributeName);
+ if (!(argumentsObject instanceof String)) {
+ return null;
+ }
+ return Arrays.asList(((String) argumentsObject).trim().split(" ")); //NOI18N
Review Comment:
Maybe handle possible escaping (`BaseUtilities.parseParameters ?)
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/CompilerOptionsQueryImpl.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.singlesourcefile;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.stream.Collectors;
+import javax.lang.model.SourceVersion;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=CompilerOptionsQueryImplementation.class, position=99),
+ @ServiceProvider(service=ClassPathProvider.class, position=9999), //DefaultClassPathProvider has 10000
+ @ServiceProvider(service=CompilerOptionsQueryImpl.class)
+})
+public class CompilerOptionsQueryImpl implements CompilerOptionsQueryImplementation, ClassPathProvider, SourceLevelQueryImplementation2 {
+
+ private final Map<NbCodeLanguageClient, Configuration> file2Configuration = new WeakHashMap<>();
+
+ @Override
+ public CompilerOptionsQueryImplementation.Result getOptions(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).compilerOptions;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ switch (type) {
+ case ClassPath.COMPILE: case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return getConfiguration(client).compileClassPath;
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return getConfiguration(client).moduleCompileClassPath;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public SourceLevelQueryImplementation2.Result getSourceLevel(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).sourceLevelResult;
+ }
+ }
+ return null;
+ }
+
+ public boolean setConfiguration(NbCodeLanguageClient client, String vmOptions) {
+ return getConfiguration(client).setConfiguration(vmOptions);
+ }
+
+ private synchronized Configuration getConfiguration(NbCodeLanguageClient client) {
+ return file2Configuration.computeIfAbsent(client, cl -> {
+ return new Configuration();
+ });
+ }
+
+ //copied from SingleSourceFileUtil:
+ static boolean isSingleSourceFile(FileObject fObj) {
+ Project p = FileOwnerQuery.getOwner(fObj);
+ if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
+ return false;
+ }
+ return true;
+ }
+
+ private static final class OptionsResultImpl extends CompilerOptionsQueryImplementation.Result {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private List<String> args = Collections.emptyList();
+
+ public List<String> doParse(String line) {
+ return parseLine(line);
+ }
+
+ private void setArguments(List<String> newArguments) {
+ synchronized (this) {
+ args = newArguments;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public synchronized List<? extends String> getArguments() {
+ return args;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class SourceLevelResultImpl implements SourceLevelQueryImplementation2.Result {
+
+ private static final String DEFAULT_SL = String.valueOf(SourceVersion.latest().ordinal() - SourceVersion.RELEASE_0.ordinal());
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private String sourceLevel = DEFAULT_SL;
+
+ @Override
+ public synchronized String getSourceLevel() {
+ return sourceLevel;
+ }
+
+ private void setSourceLevel(String sourceLevel) {
+ synchronized (this) {
+ this.sourceLevel = sourceLevel;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class Configuration {
+ private List<String> currentOptions = Collections.emptyList();
+ public final OptionsResultImpl compilerOptions;
+ public final SourceLevelResultImpl sourceLevelResult;
+ public final ProxyClassPathImplementation compileClassPathImplementation;
+ public final ProxyClassPathImplementation compileModulePathImplementation;
+ public final ClassPath compileClassPath;
+ public final ClassPath moduleCompileClassPath;
+
+ public Configuration() {
+ compilerOptions = new OptionsResultImpl();
+ sourceLevelResult = new SourceLevelResultImpl();
+ compileClassPathImplementation = new ProxyClassPathImplementation();
+ compileModulePathImplementation = new ProxyClassPathImplementation();
+ compileClassPath = ClassPathFactory.createClassPath(compileClassPathImplementation);
+ moduleCompileClassPath = ClassPathFactory.createClassPath(compileModulePathImplementation);
+ }
+
+ private boolean setConfiguration(String vmOptions) {
+ List<String> newOptions = compilerOptions.doParse(vmOptions);
+
+ synchronized (this) {
+ if (currentOptions.equals(newOptions)) {
+ return false;
+ }
+
+ currentOptions = newOptions;
+ }
+
+ compilerOptions.setArguments(newOptions);
+
+ String classpath = "";
+ String modulepath = "";
+ String sourceLevel = SourceLevelResultImpl.DEFAULT_SL;
+
+ for (int i = 0; i < newOptions.size(); i++) {
+ if (i + 1 >= newOptions.size())
Review Comment:
Maybe limit the loop to just `newOptions.size() -1` ?
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/EnablePreviewSingleSourceFile.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.singlesourcefile;
+
+import com.google.gson.JsonPrimitive;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.lsp4j.ConfigurationItem;
+import org.eclipse.lsp4j.ConfigurationParams;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Parameters;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.java.hints.spi.preview.PreviewEnabler;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
+import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Handle error rule "compiler.err.preview.feature.disabled.plural" and provide
+ * the fix for Single Source Java File.
+ *
+ * @author Arunava Sinha
+ */
+public class EnablePreviewSingleSourceFile implements PreviewEnabler {
+
+ private static final String ENABLE_PREVIEW_FLAG = "--enable-preview"; // NOI18N
+ private static final String SOURCE_FLAG = "--source"; // NOI18N
+ private static final Pattern SOURCE_FLAG_PATTERN = Pattern.compile(SOURCE_FLAG + "[ \t]+[0-9]+");
+
+ private FileObject file;
+
+ private EnablePreviewSingleSourceFile(@NonNull FileObject file) {
+ Parameters.notNull("file", file); //NOI18N
+ this.file = file;
+ }
+
+ @Override
+ public void enablePreview(String newSourceLevel) throws Exception {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client == null) {
+ return ;
+ }
+
+ ConfigurationItem conf = new ConfigurationItem();
+ conf.setScopeUri(Utils.toUri(file));
+ conf.setSection("java+.runConfig.vmOptions"); //XXX
+ client.configuration(new ConfigurationParams(Collections.singletonList(conf))).thenApply(c -> {
+ String compilerArgs = ((JsonPrimitive) ((List<Object>) c).get(0)).getAsString();
+ if (compilerArgs == null) {
+ compilerArgs = "";
+ }
+
+ Matcher m = SOURCE_FLAG_PATTERN.matcher(compilerArgs);
+ String realNewSourceLevel = newSourceLevel;
+
+ if (realNewSourceLevel == null) {
+ realNewSourceLevel = getJdkRunVersion();
+ }
+
+ if (compilerArgs.contains(SOURCE_FLAG)) {
+ compilerArgs = m.replaceAll("--enable-preview " + SOURCE_FLAG + " " + realNewSourceLevel);
Review Comment:
Use the constant `ENABLE_PREVIEW_FLAG` ?
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/CompilerOptionsQueryImpl.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.singlesourcefile;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.stream.Collectors;
+import javax.lang.model.SourceVersion;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=CompilerOptionsQueryImplementation.class, position=99),
+ @ServiceProvider(service=ClassPathProvider.class, position=9999), //DefaultClassPathProvider has 10000
+ @ServiceProvider(service=CompilerOptionsQueryImpl.class)
+})
+public class CompilerOptionsQueryImpl implements CompilerOptionsQueryImplementation, ClassPathProvider, SourceLevelQueryImplementation2 {
+
+ private final Map<NbCodeLanguageClient, Configuration> file2Configuration = new WeakHashMap<>();
+
+ @Override
+ public CompilerOptionsQueryImplementation.Result getOptions(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).compilerOptions;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ switch (type) {
+ case ClassPath.COMPILE: case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return getConfiguration(client).compileClassPath;
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return getConfiguration(client).moduleCompileClassPath;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public SourceLevelQueryImplementation2.Result getSourceLevel(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).sourceLevelResult;
+ }
+ }
+ return null;
+ }
+
+ public boolean setConfiguration(NbCodeLanguageClient client, String vmOptions) {
+ return getConfiguration(client).setConfiguration(vmOptions);
+ }
+
+ private synchronized Configuration getConfiguration(NbCodeLanguageClient client) {
+ return file2Configuration.computeIfAbsent(client, cl -> {
+ return new Configuration();
+ });
+ }
+
+ //copied from SingleSourceFileUtil:
+ static boolean isSingleSourceFile(FileObject fObj) {
+ Project p = FileOwnerQuery.getOwner(fObj);
+ if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
+ return false;
+ }
+ return true;
+ }
+
+ private static final class OptionsResultImpl extends CompilerOptionsQueryImplementation.Result {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private List<String> args = Collections.emptyList();
+
+ public List<String> doParse(String line) {
+ return parseLine(line);
+ }
+
+ private void setArguments(List<String> newArguments) {
+ synchronized (this) {
+ args = newArguments;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public synchronized List<? extends String> getArguments() {
+ return args;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class SourceLevelResultImpl implements SourceLevelQueryImplementation2.Result {
+
+ private static final String DEFAULT_SL = String.valueOf(SourceVersion.latest().ordinal() - SourceVersion.RELEASE_0.ordinal());
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private String sourceLevel = DEFAULT_SL;
+
+ @Override
+ public synchronized String getSourceLevel() {
+ return sourceLevel;
+ }
+
+ private void setSourceLevel(String sourceLevel) {
+ synchronized (this) {
+ this.sourceLevel = sourceLevel;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class Configuration {
+ private List<String> currentOptions = Collections.emptyList();
+ public final OptionsResultImpl compilerOptions;
+ public final SourceLevelResultImpl sourceLevelResult;
+ public final ProxyClassPathImplementation compileClassPathImplementation;
+ public final ProxyClassPathImplementation compileModulePathImplementation;
+ public final ClassPath compileClassPath;
+ public final ClassPath moduleCompileClassPath;
+
+ public Configuration() {
+ compilerOptions = new OptionsResultImpl();
+ sourceLevelResult = new SourceLevelResultImpl();
+ compileClassPathImplementation = new ProxyClassPathImplementation();
+ compileModulePathImplementation = new ProxyClassPathImplementation();
+ compileClassPath = ClassPathFactory.createClassPath(compileClassPathImplementation);
+ moduleCompileClassPath = ClassPathFactory.createClassPath(compileModulePathImplementation);
+ }
+
+ private boolean setConfiguration(String vmOptions) {
+ List<String> newOptions = compilerOptions.doParse(vmOptions);
+
+ synchronized (this) {
+ if (currentOptions.equals(newOptions)) {
+ return false;
+ }
+
+ currentOptions = newOptions;
+ }
+
+ compilerOptions.setArguments(newOptions);
+
+ String classpath = "";
+ String modulepath = "";
+ String sourceLevel = SourceLevelResultImpl.DEFAULT_SL;
+
+ for (int i = 0; i < newOptions.size(); i++) {
+ if (i + 1 >= newOptions.size())
+ continue;
+ String parameter = newOptions.get(i + 1);
+ switch (newOptions.get(i)) {
+ case "-classpath": case "-cp": case "--class-path":
+ classpath = parameter;
+ break;
+ case "--module-path": case "-p":
+ modulepath = parameter;
+ break;
+ case "--source":
+ sourceLevel = parameter;
+ break;
+ }
+ }
+
+ compileClassPathImplementation.setDelegates(spec2CP(classpath));
+ compileModulePathImplementation.setDelegates(spec2CP(modulepath));
+
+ System.err.println("compileClassPath: " + compileClassPath);
Review Comment:
Debugging leftovers
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/CompilerOptionsQueryImpl.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.singlesourcefile;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.stream.Collectors;
+import javax.lang.model.SourceVersion;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=CompilerOptionsQueryImplementation.class, position=99),
+ @ServiceProvider(service=ClassPathProvider.class, position=9999), //DefaultClassPathProvider has 10000
+ @ServiceProvider(service=CompilerOptionsQueryImpl.class)
+})
+public class CompilerOptionsQueryImpl implements CompilerOptionsQueryImplementation, ClassPathProvider, SourceLevelQueryImplementation2 {
+
+ private final Map<NbCodeLanguageClient, Configuration> file2Configuration = new WeakHashMap<>();
+
+ @Override
+ public CompilerOptionsQueryImplementation.Result getOptions(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).compilerOptions;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ switch (type) {
+ case ClassPath.COMPILE: case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return getConfiguration(client).compileClassPath;
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return getConfiguration(client).moduleCompileClassPath;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public SourceLevelQueryImplementation2.Result getSourceLevel(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).sourceLevelResult;
+ }
+ }
+ return null;
+ }
+
+ public boolean setConfiguration(NbCodeLanguageClient client, String vmOptions) {
+ return getConfiguration(client).setConfiguration(vmOptions);
+ }
+
+ private synchronized Configuration getConfiguration(NbCodeLanguageClient client) {
+ return file2Configuration.computeIfAbsent(client, cl -> {
+ return new Configuration();
+ });
+ }
+
+ //copied from SingleSourceFileUtil:
+ static boolean isSingleSourceFile(FileObject fObj) {
+ Project p = FileOwnerQuery.getOwner(fObj);
+ if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
+ return false;
+ }
+ return true;
+ }
+
+ private static final class OptionsResultImpl extends CompilerOptionsQueryImplementation.Result {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private List<String> args = Collections.emptyList();
+
+ public List<String> doParse(String line) {
+ return parseLine(line);
+ }
+
+ private void setArguments(List<String> newArguments) {
+ synchronized (this) {
+ args = newArguments;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public synchronized List<? extends String> getArguments() {
+ return args;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class SourceLevelResultImpl implements SourceLevelQueryImplementation2.Result {
+
+ private static final String DEFAULT_SL = String.valueOf(SourceVersion.latest().ordinal() - SourceVersion.RELEASE_0.ordinal());
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private String sourceLevel = DEFAULT_SL;
+
+ @Override
+ public synchronized String getSourceLevel() {
+ return sourceLevel;
+ }
+
+ private void setSourceLevel(String sourceLevel) {
+ synchronized (this) {
+ this.sourceLevel = sourceLevel;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class Configuration {
+ private List<String> currentOptions = Collections.emptyList();
+ public final OptionsResultImpl compilerOptions;
+ public final SourceLevelResultImpl sourceLevelResult;
+ public final ProxyClassPathImplementation compileClassPathImplementation;
+ public final ProxyClassPathImplementation compileModulePathImplementation;
+ public final ClassPath compileClassPath;
+ public final ClassPath moduleCompileClassPath;
+
+ public Configuration() {
+ compilerOptions = new OptionsResultImpl();
+ sourceLevelResult = new SourceLevelResultImpl();
+ compileClassPathImplementation = new ProxyClassPathImplementation();
+ compileModulePathImplementation = new ProxyClassPathImplementation();
+ compileClassPath = ClassPathFactory.createClassPath(compileClassPathImplementation);
+ moduleCompileClassPath = ClassPathFactory.createClassPath(compileModulePathImplementation);
+ }
+
+ private boolean setConfiguration(String vmOptions) {
+ List<String> newOptions = compilerOptions.doParse(vmOptions);
+
+ synchronized (this) {
+ if (currentOptions.equals(newOptions)) {
+ return false;
+ }
+
+ currentOptions = newOptions;
+ }
+
+ compilerOptions.setArguments(newOptions);
+
+ String classpath = "";
+ String modulepath = "";
+ String sourceLevel = SourceLevelResultImpl.DEFAULT_SL;
+
+ for (int i = 0; i < newOptions.size(); i++) {
+ if (i + 1 >= newOptions.size())
+ continue;
+ String parameter = newOptions.get(i + 1);
+ switch (newOptions.get(i)) {
+ case "-classpath": case "-cp": case "--class-path":
+ classpath = parameter;
+ break;
+ case "--module-path": case "-p":
+ modulepath = parameter;
+ break;
+ case "--source":
Review Comment:
also `-source` with 1 dash
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6262: Supporting source file launcher in VS Code extension
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6262:
URL: https://github.com/apache/netbeans/pull/6262#discussion_r1276619099
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/CompilerOptionsQueryImpl.java:
##########
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.singlesourcefile;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.stream.Collectors;
+import javax.lang.model.SourceVersion;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=CompilerOptionsQueryImplementation.class, position=99),
+ @ServiceProvider(service=ClassPathProvider.class, position=9999), //DefaultClassPathProvider has 10000
+ @ServiceProvider(service=CompilerOptionsQueryImpl.class)
+})
+public class CompilerOptionsQueryImpl implements CompilerOptionsQueryImplementation, ClassPathProvider, SourceLevelQueryImplementation2 {
+
+ private final Map<NbCodeLanguageClient, Configuration> file2Configuration = new WeakHashMap<>();
+
+ @Override
+ public CompilerOptionsQueryImplementation.Result getOptions(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).compilerOptions;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ switch (type) {
+ case ClassPath.COMPILE: case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return getConfiguration(client).compileClassPath;
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return getConfiguration(client).moduleCompileClassPath;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public SourceLevelQueryImplementation2.Result getSourceLevel(FileObject file) {
+ if (isSingleSourceFile(file)) {
+ NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
+ if (client != null) {
+ return getConfiguration(client).sourceLevelResult;
+ }
+ }
+ return null;
+ }
+
+ public boolean setConfiguration(NbCodeLanguageClient client, String vmOptions) {
+ return getConfiguration(client).setConfiguration(vmOptions);
+ }
+
+ private synchronized Configuration getConfiguration(NbCodeLanguageClient client) {
+ return file2Configuration.computeIfAbsent(client, cl -> {
+ return new Configuration();
+ });
+ }
+
+ //copied from SingleSourceFileUtil:
+ static boolean isSingleSourceFile(FileObject fObj) {
+ Project p = FileOwnerQuery.getOwner(fObj);
+ if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
+ return false;
+ }
+ return true;
+ }
+
+ private static final class OptionsResultImpl extends CompilerOptionsQueryImplementation.Result {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private List<String> args = Collections.emptyList();
+
+ public List<String> doParse(String line) {
+ return parseLine(line);
+ }
+
+ private void setArguments(List<String> newArguments) {
+ synchronized (this) {
+ args = newArguments;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public synchronized List<? extends String> getArguments() {
+ return args;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class SourceLevelResultImpl implements SourceLevelQueryImplementation2.Result {
+
+ private static final String DEFAULT_SL = String.valueOf(SourceVersion.latest().ordinal() - SourceVersion.RELEASE_0.ordinal());
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private String sourceLevel = DEFAULT_SL;
+
+ @Override
+ public synchronized String getSourceLevel() {
+ return sourceLevel;
+ }
+
+ private void setSourceLevel(String sourceLevel) {
+ synchronized (this) {
+ this.sourceLevel = sourceLevel;
+ }
+ cs.fireChange();
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ }
+
+ private static final class Configuration {
+ private List<String> currentOptions = Collections.emptyList();
+ public final OptionsResultImpl compilerOptions;
+ public final SourceLevelResultImpl sourceLevelResult;
+ public final ProxyClassPathImplementation compileClassPathImplementation;
+ public final ProxyClassPathImplementation compileModulePathImplementation;
+ public final ClassPath compileClassPath;
+ public final ClassPath moduleCompileClassPath;
+
+ public Configuration() {
+ compilerOptions = new OptionsResultImpl();
+ sourceLevelResult = new SourceLevelResultImpl();
+ compileClassPathImplementation = new ProxyClassPathImplementation();
+ compileModulePathImplementation = new ProxyClassPathImplementation();
+ compileClassPath = ClassPathFactory.createClassPath(compileClassPathImplementation);
+ moduleCompileClassPath = ClassPathFactory.createClassPath(compileModulePathImplementation);
+ }
+
+ private boolean setConfiguration(String vmOptions) {
+ List<String> newOptions = compilerOptions.doParse(vmOptions);
+
+ synchronized (this) {
+ if (currentOptions.equals(newOptions)) {
+ return false;
+ }
+
+ currentOptions = newOptions;
+ }
+
+ compilerOptions.setArguments(newOptions);
+
+ String classpath = "";
+ String modulepath = "";
+ String sourceLevel = SourceLevelResultImpl.DEFAULT_SL;
+
+ for (int i = 0; i < newOptions.size(); i++) {
+ if (i + 1 >= newOptions.size())
+ continue;
+ String parameter = newOptions.get(i + 1);
+ switch (newOptions.get(i)) {
+ case "-classpath": case "-cp": case "--class-path":
+ classpath = parameter;
+ break;
+ case "--module-path": case "-p":
+ modulepath = parameter;
+ break;
+ case "--source":
Review Comment:
Thanks, but I don't think it should be here - these are source launcher options (as opposed to javac options), and source launcher does not support `-source`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists