Detect boot app processes launched from fatjar / thinjar boot launcher

This commit is contained in:
Kris De Volder
2017-10-20 15:40:01 -07:00
parent a328dfb378
commit 9d83e25d90
5 changed files with 110 additions and 29 deletions

View File

@@ -1,3 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@@ -0,0 +1,59 @@
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=false
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=false
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_type_arguments=false
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_lambda=true
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true

View File

@@ -32,6 +32,7 @@ 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.sun.tools.attach.VirtualMachine;
@@ -100,13 +101,33 @@ public class SpringBootApp {
}
public boolean isSpringBootApp() throws Exception {
Properties props = this.vm.getSystemProperties();
String classpath = (String) props.get("java.class.path");
String[] cpElements = getClasspath(classpath);
return contains(cpElements, "spring-boot");
return (isSpringBootAppClasspath() || isSpringBootAppSysprops());
}
private boolean isSpringBootAppSysprops() {
try {
Properties sysprops = this.vm.getSystemProperties();
return sysprops.getProperty("sts4.languageserver.name") == null
&& sysprops.getProperty("java.protocol.handler.pkgs").equals("org.springframework.boot.loader");
} catch (Exception e) {
Log.log(e);
}
return false;
}
private boolean isSpringBootAppClasspath() {
try {
Properties props = this.vm.getSystemProperties();
String classpath = (String) props.get("java.class.path");
String[] cpElements = getClasspath(classpath);
return contains(cpElements, "spring-boot");
} catch (Exception e) {
Log.log(e);
}
return false;
}
public boolean containsSystemProperty(Object key) {
try {
Properties props = this.vm.getSystemProperties();

View File

@@ -31,17 +31,17 @@ import org.springframework.ide.vscode.commons.util.StringUtil;
import org.springframework.ide.vscode.commons.util.test.ACondition;
public class SpringBootAppTest {
// private static final String appName = "actuator-client-15-test-subject"; // Boot 1.5 test app
private static final String appName = "actuator-client-20-test-subject"; //Boot 2.0 test app
// private static final String appName = "actuator-client-20-thin-test-subject"; //Boot 2.0 test app with THIN launcher
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 AsyncProcess testAppRunner;
private static SpringBootApp testApp;
@BeforeClass
public static void setupClass() throws Exception {
testAppRunner = startTestApplication(SpringBootAppTest.class.getResource("/"+appName+"-0.0.1-SNAPSHOT.jar"));
@@ -52,11 +52,11 @@ public class SpringBootAppTest {
private static AsyncProcess startTestApplication(URL jarUrl) throws Exception {
File jarFile = new File(jarUrl.toURI());
return new AsyncProcess(
new File("."),
new File("."),
new ExternalCommand(
"java",
"-Dserver.port=0", //let spring boot pick randomized free port
"-jar",
"java",
"-Dserver.port=0", //let spring boot pick randomized free port
"-jar",
jarFile.getAbsolutePath()
),
false
@@ -66,7 +66,7 @@ public class SpringBootAppTest {
private static SpringBootApp getAppContaining(String nameFragment) throws Exception {
return SpringBootApp.getAllRunningJavaApps().values().stream().filter(app -> app.getProcessName().contains(nameFragment)).findAny().get();
}
@AfterClass
public static void tearDownClass() throws Exception {
testAppRunner.kill();
@@ -78,27 +78,25 @@ public class SpringBootAppTest {
Optional<SpringBootApp> myProcess = allApps.values().stream().filter(app -> app.getProcessName().contains(appName)).findAny();
assertTrue(myProcess.isPresent());
}
@Test
public void dumpJvmInfo() throws Exception {
ACondition.waitFor(TIMEOUT, this::getRequestMappings);
testApp.dumpJvmInfo();
// SpringBootApp app = getAppContaining("language-server.jar");
// app.dumpJvmInfo();
@Test public void dumpJvmInfo() throws Exception {
// ACondition.waitFor(TIMEOUT, this::getRequestMappings);
// testApp.dumpJvmInfo();
SpringBootApp app = getAppContaining("language-server.jar");
app.dumpJvmInfo();
}
@Ignore //Failing... not sure how to fix.
@Test public void getAllBootApps() throws Exception {
Map<String, SpringBootApp> allApps = SpringBootApp.getAllRunningSpringApps();
Optional<SpringBootApp> myProcess = allApps.values().stream().filter(app -> app.getProcessName().contains(appName)).findAny();
assertTrue(myProcess.isPresent());
}
@Test
public void getPort() throws Exception {
ACondition.waitFor(TIMEOUT, () -> {
int port = Integer.parseInt(testApp.getPort());
assertTrue(port > 0);
assertTrue(port > 0);
System.out.println("port = "+port);
});
}
@@ -106,7 +104,7 @@ public class SpringBootAppTest {
@Test
public void getHost() throws Exception {
ACondition.waitFor(TIMEOUT, () -> {
String host = testApp.getHost();
String host = testApp.getHost();
assertTrue(StringUtil.hasText(host));
System.out.println("host = "+host);
});
@@ -115,7 +113,7 @@ public class SpringBootAppTest {
@Test
public void getEnvironment() throws Exception {
ACondition.waitFor(TIMEOUT, () -> {
String env = testApp.getEnvironment();
String env = testApp.getEnvironment();
assertNonEmptyJsonObject(env);
System.out.println("env = "+env);
});
@@ -124,7 +122,7 @@ public class SpringBootAppTest {
@Test
public void getBeans() throws Exception {
ACondition.waitFor(TIMEOUT, () -> {
String beans = testApp.getBeans();
String beans = testApp.getBeans();
assertNonEmptyJsonObject(beans);
System.out.println("beans = "+beans);
});
@@ -133,7 +131,7 @@ public class SpringBootAppTest {
@Test
public void getRequestMappings() throws Exception {
ACondition.waitFor(TIMEOUT, () -> {
String result = testApp.getRequestMappings();
String result = testApp.getRequestMappings();
assertNonEmptyJsonObject(result);
System.out.println("requestMappings = "+result);
});
@@ -142,7 +140,7 @@ public class SpringBootAppTest {
@Test
public void getAutoConfigReport() throws Exception {
ACondition.waitFor(TIMEOUT, () -> {
String result = testApp.getAutoConfigReport();
String result = testApp.getAutoConfigReport();
assertNonEmptyJsonObject(result);
System.out.println("autoconfreport = "+result);
});

View File

@@ -56,11 +56,12 @@ import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguage
*/
public abstract class LaunguageServerApp {
public static final String STS4_LANGUAGESERVER_NAME = "sts4.languageserver.name";
private static final String STANDALONE_STARTUP = "standalone-startup";
private static final int SERVER_STANDALONE_PORT = 5007;
public static void start(String name, Provider<SimpleLanguageServer> languageServerFactory) throws IOException, InterruptedException {
System.setProperty("sts4.languageserver.name", name); //makes it easy to recognize language server processes.
System.setProperty(STS4_LANGUAGESERVER_NAME, name); //makes it easy to recognize language server processes.
LaunguageServerApp app = new LaunguageServerApp() {
@Override
protected SimpleLanguageServer createServer() {