diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java index 91816db719b2..2da6702dc7c4 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java @@ -114,7 +114,7 @@ public abstract class NbLaunchDelegate { public abstract void preLaunch(Map launchArguments, DebugAdapterContext context); public abstract void postLaunch(Map launchArguments, DebugAdapterContext context); - + protected void notifyFinished(DebugAdapterContext ctx, boolean success) { // Remove a possibly staled debugger listener DebuggerManagerListener listener = debuggerListeners.remove(ctx); @@ -167,7 +167,7 @@ public void write(String str) throws IOException { @Override public void flush() throws IOException { - // nop + // nop } @Override @@ -199,10 +199,10 @@ public void progressHandleCreated(ProgressOperationEvent e) { testProgressHandler != null ? Lookups.fixed(contextObject, ioContext, progress, testProgressHandler) : Lookups.fixed(contextObject, ioContext, progress), Lookup.getDefault() ); - + ProjectConfiguration selectConfiguration = null; ProjectConfigurationProvider pcp = null; - + Object o = launchArguments.get("launchConfiguration"); if (o instanceof String) { if (prj != null) { @@ -218,23 +218,22 @@ public void progressHandleCreated(ProgressOperationEvent e) { runContext.add(params); runContext.add(ioContext); runContext.add(progress); - - Lookup lookup; - if (singleMethod != null) { - runContext.add(singleMethod); - } + if (selectConfiguration != null) { runContext.add(selectConfiguration); } - - lookup = Lookups.fixed(runContext.toArray(new Object[0])); + + Lookup lookup = new ProxyLookup( + createTargetLookup(prj, singleMethod, toRun), + Lookups.fixed(runContext.toArray(new Object[runContext.size()])) + ); // the execution Lookup is fully populated now. If the Project supports Configurations, - // check if the action is actually enabled in the prescribed configuration. If it is not, + // check if the action is actually enabled in the prescribed configuration. If it is not, if (pcp != null) { final ActionProvider ap = providerAndCommand.first(); final String cmd = providerAndCommand.second(); if (!ap.isActionEnabled(cmd, lookup)) { - + // attempt to locate a different configuration that enables the action: ProjectConfiguration supportive = null; int confIndex = runContext.indexOf(selectConfiguration); @@ -255,10 +254,10 @@ public void progressHandleCreated(ProgressOperationEvent e) { String msg; String recommended = defConfig ? Bundle.ERR_LaunchDefaultConfiguration(): Bundle.ERR_LaunchSupportiveConfigName(supportive.getDisplayName()); if (debug) { - msg = supportive == null ? + msg = supportive == null ? Bundle.ERR_UnsupportedLaunchDebug() : Bundle.ERR_UnsupportedLaunchDebugConfig(selectConfiguration.getDisplayName(), recommended); } else { - msg = supportive == null ? + msg = supportive == null ? Bundle.ERR_UnsupportedLaunch() : Bundle.ERR_UnsupportedLaunchConfig(selectConfiguration.getDisplayName(), recommended); } LanguageClient client = context.getLspSession().getLookup().lookup(LanguageClient.class); @@ -487,7 +486,7 @@ private static List argsToStringList(Object o) { throw new IllegalArgumentException("Expected String or String list"); } } - + private static CompletableFuture> findTargetWithPossibleRebuild(Project proj, boolean preferProjActions, FileObject toRun, SingleMethod singleMethod, boolean debug, boolean testRun, NbProcessConsole ioContext) throws IllegalArgumentException { Pair providerAndCommand = findTarget(proj, preferProjActions, toRun, singleMethod, debug, testRun); if (providerAndCommand != null) { @@ -550,7 +549,7 @@ public void finished(boolean success) { ActionProvider provider = null; String command = null; Collection actionProviders = findActionProviders(prj); - Lookup testLookup = preferProjActions && prj != null ? Lookups.singleton(prj) : (singleMethod != null) ? Lookups.fixed(toRun, singleMethod) : Lookups.singleton(toRun); + Lookup testLookup = createTargetLookup(preferProjActions ? prj : null, singleMethod, toRun); String[] actions; if (!mainSource && singleMethod != null) { actions = debug ? new String[] {SingleMethod.COMMAND_DEBUG_SINGLE_METHOD} @@ -564,7 +563,7 @@ public void finished(boolean success) { if (debug && !mainSource) { // We are calling COMMAND_DEBUG_TEST_SINGLE instead of a missing COMMAND_DEBUG_TEST // This is why we need to add the file to the lookup - testLookup = (singleMethod != null) ? Lookups.fixed(toRun, singleMethod) : Lookups.singleton(toRun); + testLookup = createTargetLookup(null, singleMethod, toRun); } } else { actions = debug ? mainSource ? new String[] {ActionProvider.COMMAND_DEBUG_SINGLE} @@ -625,11 +624,26 @@ public void invokeAction(String command, Lookup context) throws IllegalArgumentE return Pair.of(provider, command); } - private static Collection findActionProviders(Project prj) { + static Lookup createTargetLookup(Project prj, SingleMethod singleMethod, FileObject toRun) { + List arr = new ArrayList<>(); + if (prj != null) { + arr.add(Lookups.singleton(prj)); + } + if (singleMethod != null) { + Lookup methodLookup = Lookups.singleton(singleMethod); + arr.add(methodLookup); + } + if (toRun != null) { + arr.add(toRun.getLookup()); + } + return new ProxyLookup(arr.toArray(new Lookup[0])); + } + + static Collection findActionProviders(Project prj) { Collection actionProviders = new ArrayList<>(); if (prj != null) { - ActionProvider ap = prj.getLookup().lookup(ActionProvider.class); - actionProviders.add(ap); + Collection ap = prj.getLookup().lookupAll(ActionProvider.class); + actionProviders.addAll(ap); } actionProviders.addAll(Lookup.getDefault().lookupAll(ActionProvider.class)); return actionProviders; diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java index ba5588804f4b..489670f57254 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java @@ -138,7 +138,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams params) { - throw new UnsupportedOperationException(); + return CompletableFuture.completedFuture(new MessageActionItem(params.getActions().get(0).getTitle())); } @Override diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegateTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegateTest.java new file mode 100644 index 000000000000..2035554950f8 --- /dev/null +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegateTest.java @@ -0,0 +1,167 @@ +/* + * 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.debugging.launch; + +import java.io.IOException; +import java.util.Collection; +import org.junit.Test; +import static org.junit.Assert.*; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.project.ActionProvider; +import org.netbeans.spi.project.ProjectFactory; +import org.netbeans.spi.project.ProjectState; +import org.netbeans.spi.project.SingleMethod; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ServiceProvider; + +public class NbLaunchDelegateTest { + + public NbLaunchDelegateTest() { + } + + @Test + public void testFileObjectsLookup() throws Exception { + FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createData("test.txt"); + Lookup lkp = NbLaunchDelegate.createTargetLookup(null, null, fo); + assertEquals(fo, lkp.lookup(FileObject.class)); + + DataObject obj = lkp.lookup(DataObject.class); + assertNotNull("DataObject also found", obj); + + assertEquals("It's FileObject's data object", obj, DataObject.find(fo)); + assertNull("No single method", lkp.lookup(SingleMethod.class)); + } + + @Test + public void testFileObjectsLookupWithSingleMethod() throws Exception { + FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createData("test-with-method.txt"); + SingleMethod m = new SingleMethod(fo, "main"); + Lookup lkp = NbLaunchDelegate.createTargetLookup(null, m, fo); + assertEquals(fo, lkp.lookup(FileObject.class)); + + DataObject obj = lkp.lookup(DataObject.class); + assertNotNull("DataObject also found", obj); + + assertEquals("It's FileObject's data object", obj, DataObject.find(fo)); + + assertEquals("Found single method", m, lkp.lookup(SingleMethod.class)); + } + + @Test + public void testFindsMavenProject() throws Exception { + FileObject dir = FileUtil.createMemoryFileSystem().getRoot().createFolder("testprj"); + FileObject xml = dir.createData("build.xml"); + Project prj = ProjectManager.getDefault().findProject(dir); + assertNotNull("Project dir recognized", prj); + + SingleMethod m = new SingleMethod(xml, "main"); + Lookup lkp = NbLaunchDelegate.createTargetLookup(prj, null, null); + assertNull("No file object", lkp.lookup(FileObject.class)); + DataObject obj = lkp.lookup(DataObject.class); + assertNull("No DataObject ", obj); + assertNull("No single method", lkp.lookup(SingleMethod.class)); + assertEquals(prj, lkp.lookup(Project.class)); + } + + @Test + public void testFindsWithFileObjectAndDataObject() throws Exception { + FileObject dir = FileUtil.createMemoryFileSystem().getRoot().createFolder("testprj"); + FileObject xml = dir.createData("build.xml"); + Project prj = ProjectManager.getDefault().findProject(dir); + assertNotNull("Project dir recognized", prj); + + SingleMethod m = new SingleMethod(xml, "main"); + Lookup lkp = NbLaunchDelegate.createTargetLookup(prj, m, xml); + assertEquals("File object is available", xml, lkp.lookup(FileObject.class)); + DataObject obj = lkp.lookup(DataObject.class); + assertNotNull("DataObject is available", obj); + assertEquals("DataObject's FileObject is correct", xml, obj.getPrimaryFile()); + assertEquals("Single method is also present", m, lkp.lookup(SingleMethod.class)); + assertEquals(prj, lkp.lookup(Project.class)); + } + + @Test + public void testFindsWithFileObjectAndDataObjectNoMethod() throws Exception { + FileObject dir = FileUtil.createMemoryFileSystem().getRoot().createFolder("testprj"); + FileObject xml = dir.createData("build.xml"); + Project prj = ProjectManager.getDefault().findProject(dir); + assertNotNull("Project dir recognized", prj); + + Lookup lkp = NbLaunchDelegate.createTargetLookup(prj, null, xml); + assertEquals("File object is available", xml, lkp.lookup(FileObject.class)); + DataObject obj = lkp.lookup(DataObject.class); + assertNotNull("DataObject is available", obj); + assertEquals("DataObject's FileObject is correct", xml, obj.getPrimaryFile()); + assertNull("No Single method is present", lkp.lookup(SingleMethod.class)); + assertEquals(prj, lkp.lookup(Project.class)); + } + + @Test + public void testAvoidNPEWithoutActionsProviderInLookup() throws Exception { + MockProjectFactory.MockProject prj = new MockProjectFactory.MockProject(FileUtil.getConfigRoot()); + Collection all = NbLaunchDelegate.findActionProviders(prj); + assertFalse("There shall be no null in " + all, all.contains(null)); + } + + @ServiceProvider(service = ProjectFactory.class) + public static final class MockProjectFactory implements ProjectFactory { + + @Override + public boolean isProject(FileObject projectDirectory) { + return projectDirectory.getNameExt().equals("testprj"); + } + + @Override + public Project loadProject(FileObject projectDirectory, ProjectState state) throws IOException { + if (isProject(projectDirectory)) { + return new MockProject(projectDirectory); + } else { + return null; + } + } + + @Override + public void saveProject(Project project) throws IOException, ClassCastException { + } + + private static final class MockProject implements Project { + private final FileObject dir; + + MockProject(FileObject dir) { + this.dir = dir; + } + + @Override + public FileObject getProjectDirectory() { + return dir; + } + + @Override + public Lookup getLookup() { + return Lookups.fixed(this); + } + + } + } +} diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java index 5447ba3045c5..1b8d71ec96fb 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java @@ -318,7 +318,10 @@ protected void setUp() throws Exception { protected void tearDown() throws Exception { super.tearDown(); TextDocumentServiceImpl.HOOK_NOTIFICATION = null; - serverThread.stop(); + try { + serverThread.stop(); + } catch (UnsupportedOperationException ex) { + } OpenProjects.getDefault().close(OpenProjects.getDefault().getOpenProjects()); } @@ -371,7 +374,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -711,7 +714,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -816,7 +819,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -963,7 +966,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1046,7 +1049,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1110,7 +1113,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams params) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(params.getActions().get(0).getTitle())); } @Override @@ -1168,7 +1171,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams params) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(params.getActions().get(0).getTitle())); } @Override @@ -1281,7 +1284,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1336,7 +1339,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1385,7 +1388,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1443,7 +1446,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1511,7 +1514,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1649,7 +1652,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1806,7 +1809,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1911,7 +1914,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -1981,7 +1984,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2120,7 +2123,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2209,7 +2212,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2299,7 +2302,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2392,7 +2395,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2482,7 +2485,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2573,7 +2576,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2681,7 +2684,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2784,7 +2787,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2887,7 +2890,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -2989,7 +2992,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -3134,7 +3137,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -3701,7 +3704,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -3843,7 +3846,7 @@ public void showMessage(MessageParams params) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -4726,7 +4729,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -4805,7 +4808,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -4888,7 +4891,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -4967,7 +4970,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -5030,7 +5033,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -5164,7 +5167,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override @@ -5226,7 +5229,7 @@ public void showMessage(MessageParams arg0) { @Override public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { - throw new UnsupportedOperationException("Not supported yet."); + return CompletableFuture.completedFuture(new MessageActionItem(arg0.getActions().get(0).getTitle())); } @Override diff --git a/java/java.mx.project/test/unit/src/org/netbeans/modules/java/mx/project/ParseSuitesTest.java b/java/java.mx.project/test/unit/src/org/netbeans/modules/java/mx/project/ParseSuitesTest.java index 9c53905162e7..36ebed73e704 100644 --- a/java/java.mx.project/test/unit/src/org/netbeans/modules/java/mx/project/ParseSuitesTest.java +++ b/java/java.mx.project/test/unit/src/org/netbeans/modules/java/mx/project/ParseSuitesTest.java @@ -20,14 +20,17 @@ import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; +import java.net.URL; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.java.mx.project.suitepy.MxDistribution; import org.netbeans.modules.java.mx.project.suitepy.MxSuite; public final class ParseSuitesTest extends NbTestCase { @@ -40,6 +43,15 @@ public void testParseThemAll() throws IOException { assertSuitePys(getDataDir(), 15); } + public void testParseMultiLineSuite() throws IOException { + URL url = getClass().getResource("multilinetexts.py"); + MxSuite suite = MxSuite.parse(url); + assertNotNull("suite parsed", suite); + MxDistribution tool = suite.distributions().get("TOOLCHAIN"); + assertNotNull("toolchain found", tool); + assertEquals("No deps", 0, tool.dependencies().size()); + } + public static void main(String... args) throws IOException { if (args.length == 0) { throw new IOException("Specify parameter to directory with suite.py files you want to verify!"); diff --git a/java/java.mx.project/test/unit/src/org/netbeans/modules/java/mx/project/multilinetexts.py b/java/java.mx.project/test/unit/src/org/netbeans/modules/java/mx/project/multilinetexts.py new file mode 100644 index 000000000000..b6f8f120764f --- /dev/null +++ b/java/java.mx.project/test/unit/src/org/netbeans/modules/java/mx/project/multilinetexts.py @@ -0,0 +1,53 @@ +# 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. + + +suite = { + "mxversion": "7.5.0", + "name" : "multilinetexts", + "version" : "1.0.0", + "repositories" : { + }, + "libraries" : { + }, + "licenses" : { +}, + "distributions" : { + "TOOLCHAIN": { + "native": True, + "platformDependent": True, + "os": { + "linux": { + "layout": { + "toolchain.multi": { + "source_type": "string", + "value": ''' +line1 +line2 +line3 +line5 +''' + }, + }, + "dependencies": [ + ], + }, + }, + "maven" : False, + }, + }, +}