Some refactoring into CfJson
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfo;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
public class CfJson {
|
||||
|
||||
private Gson gson = new Gson();
|
||||
private final Logger log = LoggerFactory.getLogger(CfJson.class);
|
||||
|
||||
public CfTargetsInfo from(Settings settings) {
|
||||
try {
|
||||
JsonElement rawData = settings.getRawSettings();
|
||||
if (rawData != null) {
|
||||
return gson.fromJson(rawData, CfTargetsInfo.class);
|
||||
}
|
||||
} catch (JsonSyntaxException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CfTargetsInfo from(String rawJson) {
|
||||
return gson.fromJson(rawJson, CfTargetsInfo.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -68,6 +68,7 @@ import com.google.gson.JsonSyntaxException;
|
||||
public class ManifestYamlLanguageServer extends SimpleLanguageServer {
|
||||
|
||||
private Yaml yaml = new Yaml();
|
||||
private CfJson cfJson = new CfJson();
|
||||
private ManifestYmlSchema schema;
|
||||
private CFTargetCache cfTargetCache;
|
||||
private final CloudFoundryClientFactory cfClientFactory;
|
||||
@@ -76,7 +77,6 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
|
||||
|
||||
private final ImmutableSet<LanguageId> FALLBACK_YML_IDS = ImmutableSet.of(LanguageId.of("yml"), LanguageId.of("yaml"));
|
||||
final private ClientParamsProvider defaultClientParamsProvider;
|
||||
private Gson gson = new Gson();
|
||||
|
||||
public ManifestYamlLanguageServer() {
|
||||
this(DefaultCloudFoundryClientFactoryV2.INSTANCE, CfCliParamsProvider.getInstance());
|
||||
@@ -137,7 +137,7 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
|
||||
documents.onHover(hoverEngine);
|
||||
|
||||
workspace.onDidChangeConfiguraton(settings -> {
|
||||
CfTargetsInfo info = fromJson(CfTargetsInfo.class, settings);
|
||||
CfTargetsInfo info = cfJson.from(settings);
|
||||
if (info != null) {
|
||||
applyCfLoginParameterSettings(info);
|
||||
}
|
||||
@@ -148,17 +148,7 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
|
||||
return cfClientConfig;
|
||||
}
|
||||
|
||||
protected <T> T fromJson(Class<T> klass, Settings settings) {
|
||||
try {
|
||||
JsonElement rawData = settings.getRawSettings();
|
||||
if (rawData != null) {
|
||||
return gson.fromJson(rawData, klass);
|
||||
}
|
||||
} catch (JsonSyntaxException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void applyCfLoginParameterSettings(CfTargetsInfo info) {
|
||||
|
||||
@@ -27,14 +27,14 @@ import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTar
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfoProvder;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.DefaultCloudFoundryClientFactoryV2;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ManifestYamlActualCfClientTest {
|
||||
|
||||
private CFTargetCache cfTargetCache;
|
||||
private CfJson cfJson;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
cfJson = new CfJson();
|
||||
CfTargetsInfo info = getTargetsInfoFromEnv();
|
||||
CfTargetsInfoProvder provider = new CfTargetsInfoProvder(info);
|
||||
CfClientConfig cfClientConfig = CfClientConfig.createDefault(provider);
|
||||
@@ -56,7 +56,7 @@ public class ManifestYamlActualCfClientTest {
|
||||
+ " \"noNetworkConnection\": \"No connection to Cloud Foundry: Connect CF Target via Boot Dashboard or login via CF CLI or verify network connections\",\n"
|
||||
+ " \"noOrgSpace\": \"No org/space selected: Connect CF Target in Boot Dashboard or login via CF CLI\"\n"
|
||||
+ " }\n" + "}";
|
||||
return new Gson().fromJson(rawJson, CfTargetsInfo.class);
|
||||
return cfJson.from(rawJson);
|
||||
}
|
||||
|
||||
@Ignore @Test
|
||||
|
||||
Reference in New Issue
Block a user