Fix regression causing bogus warnings when there are no cf targets

This commit is contained in:
Kris De Volder
2017-06-29 17:08:59 -07:00
parent e8425e6026
commit 55960a8c1e
6 changed files with 39 additions and 30 deletions

View File

@@ -30,9 +30,12 @@ public class ManifestYamlCFBuildpacksProvider extends AbstractCFHintsProvider {
@Override
public Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {
if (targets==null || targets.isEmpty()) {
//no targets... means we don't know anything. Indicate this by returning null...
// this "don't know" value will suppress bogus warnings in the reconciler.
return null;
}
List<YValueHint> hints = new ArrayList<>();
for (CFTarget cfTarget : targets) {
List<CFBuildpack> buildpacks = cfTarget.getBuildpacks();
@@ -51,12 +54,7 @@ public class ManifestYamlCFBuildpacksProvider extends AbstractCFHintsProvider {
}
}
}
// Contract for the reconciler: return null if values cannot be
// resolved. Otherwise
// return non-empty list of buildpacks. For CF targets, a non-empty list
// of buildpacks is
// typically expected.
return !hints.isEmpty() ? hints : null;
return hints;
}
protected String getBuildpackLabel(CFTarget target, CFBuildpack buildpack) {

View File

@@ -29,9 +29,12 @@ public class ManifestYamlCFDomainsProvider extends AbstractCFHintsProvider {
@Override
public Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {
if (targets==null || targets.isEmpty()) {
//no targets... means we don't know anything. Indicate this by returning null...
// this "don't know" value will suppress bogus warnings in the reconciler.
return null;
}
List<YValueHint> hints = new ArrayList<>();
for (CFTarget cfTarget : targets) {
List<CFDomain> domains = cfTarget.getDomains();
@@ -48,10 +51,7 @@ public class ManifestYamlCFDomainsProvider extends AbstractCFHintsProvider {
}
}
}
// Contract for the reconciler: return null if values cannot be
// resolved. Otherwise
// return non-empty list
return !hints.isEmpty() ? hints : null;
return hints;
}
protected String getLabel(CFTarget target, CFDomain domain) {

View File

@@ -30,14 +30,12 @@ public class ManifestYamlCFServicesProvider extends AbstractCFHintsProvider {
@Override
public Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {
// NOTE: empty list of services is a VALID result. A CF target may have
// no service instances
// created, so if empty list is returned from the client, then RETURN empty list. don't
// return null
// for empty services cases
if (targets==null || targets.isEmpty()) {
//no targets... means we don't know anything. Indicate this by returning null...
// this "don't know" value will suppress bogus warnings in the reconciler.
return null;
}
List<YValueHint> hints = new ArrayList<>();
for (CFTarget cfTarget : targets) {
List<CFServiceInstance> services = cfTarget.getServices();
Renderable targetLabel = Renderables.text(cfTarget.getLabel());
@@ -54,7 +52,6 @@ public class ManifestYamlCFServicesProvider extends AbstractCFHintsProvider {
}
}
}
return hints;
}

View File

@@ -33,7 +33,6 @@ import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcil
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService;
import org.springframework.ide.vscode.commons.languageserver.util.TextDocumentContentChange;
import org.springframework.ide.vscode.commons.util.text.LanguageId;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
import org.springframework.ide.vscode.commons.yaml.ast.YamlASTProvider;

View File

@@ -35,13 +35,12 @@ public class ManifestYamlStacksProvider extends AbstractCFHintsProvider {
@Override
protected Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {
// NOTE: empty list of services is a VALID result. A CF target may have
// no service instances
// created, so if empty list is returned from the client, then RETURN empty list. don't
// return null
// for empty services cases
if (targets==null || targets.isEmpty()) {
//no targets... means we don't know anything. Indicate this by returning null...
// this "don't know" value will suppress bogus warnings in the reconciler.
return null;
}
List<YValueHint> hints = new ArrayList<>();
for (CFTarget cfTarget : targets) {
List<CFStack> stacks = cfTarget.getStacks();
Renderable targetLabel = Renderables.text(cfTarget.getLabel());
@@ -57,7 +56,6 @@ public class ManifestYamlStacksProvider extends AbstractCFHintsProvider {
}
}
}
return hints;
}

View File

@@ -24,6 +24,7 @@ import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack;
@@ -997,6 +998,22 @@ public class ManifestYamlEditorTest {
);
}
@Test public void noReconcileErrorsWhenNoTargets() throws Exception {
cloudfoundry.reset();
when(cloudfoundry.defaultParamsProvider.getParams()).thenReturn(ImmutableList.of());
Editor editor = harness.newEditor(
"applications:\n" +
"- name: foo\n" +
" buildpack: bad-buildpack\n" +
" stack: blah\n" +
" domain: something-domain.com\n" +
" services:\n" +
" - bad-service\n" +
" bogus: bad" //a token error to make sure reconciler is actually running!
);
editor.assertProblems("bogus|Unknown property");
}
@Test
public void noReconcileErrorsWhenCFFactoryThrows() throws Exception {
reset(cloudfoundry.factory);