First, simple implementation of active profiles hover
This commit is contained in:
@@ -12,7 +12,6 @@ package org.springframework.ide.vscode.commons.boot.app.cli;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -30,11 +29,11 @@ import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import com.sun.tools.attach.VirtualMachineDescriptor;
|
||||
|
||||
@@ -101,16 +100,17 @@ public class SpringBootApp {
|
||||
}
|
||||
|
||||
public boolean isSpringBootApp() throws Exception {
|
||||
return (isSpringBootAppClasspath() || isSpringBootAppSysprops());
|
||||
return !containsSystemProperty("sts4.languageserver.name")
|
||||
&& (
|
||||
isSpringBootAppClasspath() ||
|
||||
isSpringBootAppSysprops()
|
||||
);
|
||||
}
|
||||
|
||||
private boolean isSpringBootAppSysprops() {
|
||||
try {
|
||||
Properties sysprops = this.vm.getSystemProperties();
|
||||
return sysprops.getProperty("sts4.languageserver.name") == null
|
||||
// Note: java.protocol.handler.pkgs may be not be in system properties, and result in NPE (at least in Mac OS)
|
||||
// To avoid NPE, just reversed the equality check
|
||||
&& "org.springframework.boot.loader".equals(sysprops.getProperty("java.protocol.handler.pkgs"));
|
||||
return "org.springframework.boot.loader".equals(sysprops.getProperty("java.protocol.handler.pkgs"));
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
@@ -373,7 +373,7 @@ public class SpringBootApp {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SpringBootApp [" +vmd.id() + ", "+vmd.displayName()+"]";
|
||||
return "Process [id=" +getProcessID() + ", name=`"+getProcessName()+"`]";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,5 +397,32 @@ public class SpringBootApp {
|
||||
System.out.println("}");
|
||||
}
|
||||
|
||||
public List<String> getActiveProfiles() {
|
||||
try {
|
||||
String _env = getEnvironment();
|
||||
if (_env != null) {
|
||||
JSONObject env = new JSONObject(_env);
|
||||
Object _profiles = env.opt("activeProfiles"); //Boot 2.0
|
||||
if (_profiles==null) {
|
||||
_profiles = env.opt("profiles"); //Boot 1.5
|
||||
}
|
||||
if (_profiles instanceof JSONArray) {
|
||||
@SuppressWarnings("unchecked")
|
||||
JSONArray profiles = (JSONArray) _profiles;
|
||||
ImmutableList.Builder<String> list = ImmutableList.builder();
|
||||
for (Object object : profiles) {
|
||||
if (object instanceof String) {
|
||||
list.add((String) object);
|
||||
}
|
||||
}
|
||||
return list.build();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.boot.app.cli;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -17,19 +18,21 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.commons.util.AsyncProcess;
|
||||
import org.springframework.ide.vscode.commons.util.ExternalCommand;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
import org.springframework.ide.vscode.commons.util.test.ACondition;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class SpringBootAppTest {
|
||||
|
||||
// private static final String appName = "actuator-client-15-test-subject"; // Boot 1.5 test app
|
||||
@@ -39,6 +42,8 @@ public class SpringBootAppTest {
|
||||
private static final Duration TIMEOUT = Duration.ofSeconds(30); // in CI build starting the app takes longer than 10s sometimes.
|
||||
//Output from CI build: Started ActuatorClientTestSubjectApplication in 22.962 seconds (JVM running for 26.028)
|
||||
|
||||
private static final List<String> TEST_PROFILES = ImmutableList.of("testing", "funny", "cameleon");
|
||||
|
||||
private static AsyncProcess testAppRunner;
|
||||
private static SpringBootApp testApp;
|
||||
|
||||
@@ -59,7 +64,8 @@ public class SpringBootAppTest {
|
||||
"java",
|
||||
"-Dserver.port=0", //let spring boot pick randomized free port
|
||||
"-jar",
|
||||
jarFile.getAbsolutePath()
|
||||
jarFile.getAbsolutePath(),
|
||||
"--spring.profiles.active="+StringUtil.collectionToCommaDelimitedString(TEST_PROFILES)
|
||||
),
|
||||
false
|
||||
);
|
||||
@@ -117,7 +123,7 @@ public class SpringBootAppTest {
|
||||
ACondition.waitFor(TIMEOUT, () -> {
|
||||
String env = testApp.getEnvironment();
|
||||
assertNonEmptyJsonObject(env);
|
||||
// System.out.println("env = "+env);
|
||||
System.out.println("env = "+new JSONObject(env).toString(3));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,6 +154,14 @@ public class SpringBootAppTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProfiles() throws Exception {
|
||||
ACondition.waitFor(TIMEOUT, () -> {
|
||||
List<String> result = testApp.getActiveProfiles();
|
||||
assertEquals(ImmutableList.copyOf(TEST_PROFILES), result);
|
||||
});
|
||||
}
|
||||
|
||||
private void assertNonEmptyJsonObject(String jsonData) {
|
||||
JSONObject parsed = new JSONObject(jsonData);
|
||||
assertFalse(parsed.keySet().isEmpty());
|
||||
|
||||
Reference in New Issue
Block a user