diff --git a/vscode-extensions/commons/commons-cf/pom.xml b/vscode-extensions/commons/commons-cf/pom.xml index 677e43a09..a80147c9d 100644 --- a/vscode-extensions/commons/commons-cf/pom.xml +++ b/vscode-extensions/commons/commons-cf/pom.xml @@ -11,13 +11,6 @@ 0.0.1-SNAPSHOT ../pom.xml - - - 2.1.0.RELEASE - 3.0.4.RELEASE - 0.6.0.RELEASE - - @@ -28,22 +21,22 @@ org.cloudfoundry cloudfoundry-client-reactor - ${cloudfoundry.client.version} + ${cloudfoundry-client-version} org.cloudfoundry cloudfoundry-operations - ${cloudfoundry.client.version} + ${cloudfoundry-client-version} io.projectreactor reactor-core - ${client.reactor.version} + ${reactor-version} io.projectreactor.ipc reactor-netty - ${reactor.netty} + ${reactor-netty} \ No newline at end of file diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/target/CFClientParams.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/target/CFClientParams.java index aaeb639bd..479f7b65b 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/target/CFClientParams.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/target/CFClientParams.java @@ -148,4 +148,12 @@ public class CFClientParams { return true; } + @Override + public String toString() { + return "CFClientParams [apiUrl=" + apiUrl + ", username=" + username + ", credentials=" + credentials + + ", skipSslValidation=" + skipSslValidation + ", orgName=" + orgName + ", spaceName=" + spaceName + + "]"; + } + + } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CloudFoundryClientFactory.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CloudFoundryClientFactory.java new file mode 100644 index 000000000..f54a993ae --- /dev/null +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CloudFoundryClientFactory.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; + +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientParams; + +public interface CloudFoundryClientFactory { + + ClientRequests getClient(CFClientParams params) throws Exception; + +} \ No newline at end of file diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultCloudFoundryClientFactoryV2.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultCloudFoundryClientFactoryV2.java index 06db48663..312f69f0a 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultCloudFoundryClientFactoryV2.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultCloudFoundryClientFactoryV2.java @@ -12,9 +12,9 @@ package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientParams; -public class DefaultCloudFoundryClientFactoryV2 { +public class DefaultCloudFoundryClientFactoryV2 implements CloudFoundryClientFactory { - public static final DefaultCloudFoundryClientFactoryV2 INSTANCE = new DefaultCloudFoundryClientFactoryV2(); + public static final CloudFoundryClientFactory INSTANCE = new DefaultCloudFoundryClientFactoryV2(); /** * Use 'INSTANCE' constant instead. This class is a singleton. @@ -23,7 +23,11 @@ public class DefaultCloudFoundryClientFactoryV2 { private CloudFoundryClientCache cache = new CloudFoundryClientCache(); - public ClientRequests getClient(CFClientParams params) { + /* (non-Javadoc) + * @see org.springframework.ide.vscode.commons.cloudfoundry.client.v2.CloudFoundryClientFactory#getClient(org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientParams) + */ + @Override + public ClientRequests getClient(CFClientParams params) throws Exception { return new DefaultClientRequestsV2(cache, params); } } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/ReactorUtils.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/ReactorUtils.java index 53037c797..aaec46eca 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/ReactorUtils.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/ReactorUtils.java @@ -38,11 +38,12 @@ public class ReactorUtils { private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(45); // reflects default timeout of Mono.block in reactor 2.x. public static boolean DUMP_STACK_ON_TIMEOUT = false; - /** - * Convert a {@link CancelationToken} into a Mono that raises - * an {@link OperationCanceledException} when the token is canceled. - */ - public static Mono toMono(CancelationToken cancelToken) { + // TODO: uncommented when cancellation is handled in vscode +// /** +// * Convert a {@link CancelationToken} into a Mono that raises +// * an {@link OperationCanceledException} when the token is canceled. +// */ +// public static Mono toMono(CancelationToken cancelToken) { // return Mono.delay(Duration.ofSeconds(1)) // .then((ping) -> // cancelToken.isCanceled() @@ -50,9 +51,7 @@ public class ReactorUtils { // : Mono.empty() // ) // .repeatWhenEmpty((x) -> x); - - return Mono.empty(); - } +// } /** * Similar to Mono.get but logs a more traceable version of the exception to Eclipse's error @@ -79,9 +78,12 @@ public class ReactorUtils { */ public static T get(Duration timeout, CancelationToken cancelationToken, Mono mono) throws Exception { try { - return Mono.first(mono, - toMono(cancelationToken)) - .otherwise(errorFilter(cancelationToken)) + return mono + // TODO: uncomment when cancellation properly supported in vscode +// Mono +// .first(mono, +// toMono(cancelationToken)) +// .otherwise(errorFilter(cancelationToken)) .block(timeout); } catch (Exception e) { dumpStacks(); diff --git a/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java b/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java index d6351d66f..7e2982a7d 100644 --- a/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java +++ b/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java @@ -10,33 +10,32 @@ *******************************************************************************/ package org.springframework.ide.vscode.commons.cloudfoundry.client; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; import org.junit.Ignore; import org.junit.Test; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack; -import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientParams; import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientParamsFactory; -import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.ClientRequests; +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientTarget; +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientTargets; +import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.CloudFoundryClientFactory; import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.DefaultCloudFoundryClientFactoryV2; public class CFClientTest { - @Ignore @Test public void testGetBuildpacksFromCliParams() throws Exception { - CFClientParams params = CFClientParamsFactory.INSTANCE.getParams().get(0); - assertNotNull(params); + + @Ignore @Test public void testGetBuildpacksFromCliParamsTarget() throws Exception { - ClientRequests requests = DefaultCloudFoundryClientFactoryV2.INSTANCE.getClient(params); + CFClientParamsFactory paramsFactory = CFClientParamsFactory.INSTANCE; + CloudFoundryClientFactory clientFactory = DefaultCloudFoundryClientFactoryV2.INSTANCE; - assertNotNull(requests); + CFClientTargets targets = new CFClientTargets(paramsFactory, clientFactory); + CFClientTarget target = targets.getTargets().get(0); - List buildPacks = requests.getBuildpacks(); + List buildPacks = target.getBuildpacks(); assertTrue(!buildPacks.isEmpty()); - } } diff --git a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java index 79cce2554..0221ba872 100644 --- a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java +++ b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java @@ -238,6 +238,22 @@ public class Editor { assertEquals(expect.toString(), actual.toString()); } + public void assertContainsCompletions(String... expectTextAfter) throws Exception { + StringBuilder actual = new StringBuilder(); + + for (CompletionItem completion : getCompletions()) { + Editor editor = this.clone(); + editor.apply(completion); + actual.append(editor.getText()); + actual.append("\n-------------------\n"); + } + String actualText = actual.toString(); + + for (String after : expectTextAfter) { + assertContains(after, actualText); + } + } + public void apply(CompletionItem completion) throws Exception { TextEdit edit = completion.getTextEdit(); String docText = document.getText(); diff --git a/vscode-extensions/commons/pom.xml b/vscode-extensions/commons/pom.xml index d0aa2f5b4..78b1128a2 100644 --- a/vscode-extensions/commons/pom.xml +++ b/vscode-extensions/commons/pom.xml @@ -62,7 +62,10 @@ 2.5.0 2.10 0.1.0-SNAPSHOT - 3.0.2.RELEASE + + 3.0.4.RELEASE + 0.6.0.RELEASE + 2.1.0.RELEASE diff --git a/vscode-extensions/vscode-manifest-yaml/pom.xml b/vscode-extensions/vscode-manifest-yaml/pom.xml index 741d863fc..46b14d30c 100644 --- a/vscode-extensions/vscode-manifest-yaml/pom.xml +++ b/vscode-extensions/vscode-manifest-yaml/pom.xml @@ -42,6 +42,12 @@ commons-yaml ${project.version} + + + org.springframework.ide.vscode + commons-cf + ${project.version} + org.springframework.ide.vscode diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFBuildpacksProvider.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFBuildpacksProvider.java new file mode 100644 index 000000000..21ebd3e3c --- /dev/null +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFBuildpacksProvider.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.manifest.yaml; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.inject.Provider; + +import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack; +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientTarget; +import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint; +import org.springframework.ide.vscode.commons.yaml.schema.YValueHint; + +public class ManifestYamlCFBuildpacksProvider implements Provider> { + + private final List targets; + private static final Logger logger = Logger.getLogger(ManifestYamlCFBuildpacksProvider.class.getName()); + + + public ManifestYamlCFBuildpacksProvider(List targets) { + this.targets = targets; + } + + + @Override + public Collection get() { + List hints = new ArrayList<>(); + + if (targets != null) { + for (CFClientTarget cfClientTarget : targets) { + + List buildpacks; + try { + buildpacks = cfClientTarget.getBuildpacks(); + if (buildpacks != null) { + for (CFBuildpack buildpack : buildpacks) { + String name = buildpack.getName(); + String label = getBuildpackLabel(cfClientTarget, buildpack); + YValueHint hint = new BasicYValueHint(name, label); + if (!hints.contains(hint)) { + hints.add(hint); + } + } + } + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + } + return hints; + } + + protected String getBuildpackLabel(CFClientTarget target, CFBuildpack buildpack) { + return buildpack.getName() + " (" + target.getName() + ")"; + } + +} diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFServicesProvider.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFServicesProvider.java new file mode 100644 index 000000000..b80b1377b --- /dev/null +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFServicesProvider.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.manifest.yaml; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.inject.Provider; + +import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance; +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientTarget; +import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint; +import org.springframework.ide.vscode.commons.yaml.schema.YValueHint; + +public class ManifestYamlCFServicesProvider implements Provider> { + + private final List targets; + + private static final Logger logger = Logger.getLogger(ManifestYamlCFServicesProvider.class.getName()); + + public ManifestYamlCFServicesProvider(List targets) { + this.targets = targets; + } + + @Override + public Collection get() { + List hints = new ArrayList<>(); + + if (targets != null) { + for (CFClientTarget cfClientTarget : targets) { + + try { + List services = cfClientTarget.getClientRequests().getServices(); + if (services != null) { + for (CFServiceInstance service : services) { + String name = service.getName(); + String label = getServiceLabel(cfClientTarget, service); + YValueHint hint = new BasicYValueHint(name, label); + if (!hints.contains(hint)) { + hints.add(hint); + } + } + } + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + } + return hints; + } + + private String getServiceLabel(CFClientTarget cfClientTarget, CFServiceInstance service) { + return service.getName() + " - " + service.getPlan() + " (" + cfClientTarget.getParams().getOrgName() + " - " + + cfClientTarget.getParams().getSpaceName() + ")"; + } +} diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java index 6e2ac5259..c52d606cc 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java @@ -1,12 +1,20 @@ package org.springframework.ide.vscode.manifest.yaml; import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.inject.Provider; import org.eclipse.lsp4j.CompletionOptions; import org.eclipse.lsp4j.ServerCapabilities; import org.eclipse.lsp4j.TextDocumentSyncKind; +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientParamsFactory; +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientTarget; +import org.springframework.ide.vscode.commons.cloudfoundry.client.target.CFClientTargets; +import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.CloudFoundryClientFactory; +import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.DefaultCloudFoundryClientFactoryV2; import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngine; import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngineAdapter; import org.springframework.ide.vscode.commons.languageserver.hover.HoverInfoProvider; @@ -32,16 +40,25 @@ import com.google.common.collect.ImmutableList; public class ManifestYamlLanguageServer extends SimpleLanguageServer { - private static final Provider> NO_BUILDPACKS = () -> ImmutableList.of(); + private static final Provider> NO_PROVIDER = () -> ImmutableList.of(); + private static Logger logger = Logger.getLogger(ManifestYamlLanguageServer.class.getName()); private Yaml yaml = new Yaml(); - private YamlSchema schema = new ManifestYmlSchema(NO_BUILDPACKS); + private YamlSchema schema; + private CFClientTargets cfClientTargets; public ManifestYamlLanguageServer() { SimpleTextDocumentService documents = getTextDocumentService(); YamlASTProvider parser = new YamlParser(yaml); + + CFClientTargets cfTargets = getCFTargets(); + + Provider> buildPacksProvider = getBuildpacksProvider(cfTargets); + Provider> servicesProvider = getServicesProvider(cfTargets); + + schema = new ManifestYmlSchema(buildPacksProvider, servicesProvider); YamlStructureProvider structureProvider = YamlStructureProvider.DEFAULT; YamlAssistContextProvider contextProvider = new SchemaBasedYamlAssistContextProvider(schema); @@ -72,7 +89,48 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer { documents.onCompletionResolve(completionEngine::resolveCompletion); documents.onHover(hoverEngine ::getHover); } + + private CFClientTargets getCFTargets() { + if (cfClientTargets == null) { + CFClientParamsFactory paramsFactory = CFClientParamsFactory.INSTANCE; + CloudFoundryClientFactory clientFactory = DefaultCloudFoundryClientFactoryV2.INSTANCE; + cfClientTargets = new CFClientTargets(paramsFactory, clientFactory); + } + return cfClientTargets; + } + private Provider> getBuildpacksProvider(CFClientTargets targets) { + + try { + if (targets != null) { + List cfTargets = targets.getTargets(); + if (cfTargets != null && !cfTargets.isEmpty()) {; + return new ManifestYamlCFBuildpacksProvider(cfTargets); + } + } + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + + return NO_PROVIDER; + } + + private Provider> getServicesProvider(CFClientTargets targets) { + + try { + if (targets != null) { + List cfTargets = targets.getTargets(); + if (cfTargets != null && !cfTargets.isEmpty()) { + return new ManifestYamlCFServicesProvider(cfTargets); + } + } + + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + + return null; + } @Override protected ServerCapabilities getServerCapabilities() { diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java index 8840d1873..778500476 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java @@ -19,6 +19,7 @@ import org.springframework.ide.vscode.commons.util.Renderable; import org.springframework.ide.vscode.commons.util.Renderables; import org.springframework.ide.vscode.commons.yaml.schema.YType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory; +import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YTypedPropertyImpl; @@ -41,7 +42,7 @@ public class ManifestYmlSchema implements YamlSchema { "name", "host", "hosts" ); - public ManifestYmlSchema(Provider> buildpackProvider) { + public ManifestYmlSchema(Provider> buildpackProvider, Provider> servicesProvider) { this.buildpackProvider = buildpackProvider; YTypeFactory f = new YTypeFactory(); TYPE_UTIL = f.TYPE_UTIL; @@ -51,15 +52,20 @@ public class ManifestYmlSchema implements YamlSchema { YBeanType application = f.ybean("Application"); YAtomicType t_path = f.yatomic("Path"); - - YAtomicType t_buildpack = f.yatomic("Buildpack"); + YAtomicType t_buildpack = f.yatomic("Buildpack"); t_buildpack.addHintProvider(this.buildpackProvider); + + YType t_service_string = f.yatomic("String"); + if (servicesProvider != null && t_service_string instanceof AbstractType) { + ((AbstractType)t_service_string).addHintProvider(servicesProvider); + } + YType t_services = f.yseq(t_service_string); YAtomicType t_boolean = f.yenum("boolean", "true", "false"); YType t_string = f.yatomic("String"); YType t_strings = f.yseq(t_string); - + YAtomicType t_memory = f.yatomic("Memory"); t_memory.addHints("256M", "512M", "1024M"); t_memory.parseWith(ManifestYmlValueParsers.MEMORY); @@ -94,7 +100,7 @@ public class ManifestYmlSchema implements YamlSchema { f.yprop("no-route", t_boolean), f.yprop("path", t_path), f.yprop("random-route", t_boolean), - f.yprop("services", t_strings), + f.yprop("services", t_services), f.yprop("stack", t_string), f.yprop("timeout", t_pos_integer), f.yprop("health-check-type", t_health_check_type) diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFTest.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFTest.java new file mode 100644 index 000000000..59e374587 --- /dev/null +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.manifest.yaml; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.ide.vscode.languageserver.testharness.Editor; +import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness; + +public class ManifestYamlEditorCFTest { + LanguageServerHarness harness; + + @Before + public void setup() throws Exception { + harness = new LanguageServerHarness(ManifestYamlLanguageServer::new); + harness.intialize(null); + } + + /* + * Optional test that is here only to be run in certain conditions. Tests if + * buildpack completion values are actually fetched from PWS if the test env + * also has a CLI that is alread connected to PWS. Enable only if underlying + * conditions for CF connection from vscode are present. For example, CLI is + * installed. + */ + @Ignore + @Test + public void optionalDynamicBuildpacksPWSUsingCliParams() throws Exception { + // No special test harness setup to use CLI. It is a "default" CF client params + // provider in the CF vscode framework. + // Just have to make sure the test env has a CLI that is connected to + // PWS + assertContainsCompletions("buildpack: <*>", "buildpack: java_buildpack<*>"); + } + + @Ignore + @Test + public void optionalDynamicServicesPWSUsingCliParams() throws Exception { + // No special test harness setup to use CLI. It is a "default" CF client params + // provider in the CF vscode framework. + // Just have to make sure the test env has a CLI that is connected to + // PWS + assertContainsCompletions( "services:\n"+ + " - <*>", "sql"); + } + + ////////////////////////////////////////////////////////////////////////////// + + private void assertContainsCompletions(String textBefore, String... textAfter) throws Exception { + Editor editor = harness.newEditor(textBefore); + editor.assertContainsCompletions(textAfter); + } + +} diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java index 02a5f4727..2c01cfa78 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java @@ -82,7 +82,7 @@ public class ManifestYmlSchemaTest { "timeout" }; - ManifestYmlSchema schema = new ManifestYmlSchema(null); + ManifestYmlSchema schema = new ManifestYmlSchema(null, null); @Test public void toplevelProperties() throws Exception {