Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EclipseCon Europe 2018: Spring Tools 4 - A Look Behind the Scenes

EclipseCon Europe 2018: Spring Tools 4 - A Look Behind the Scenes

D65e990ab4df0d0a75c3b0ae5d036bc5?s=128

Martin Lippert

October 23, 2018
Tweet

Transcript

  1. Spring Tools 4 A Look Behind the Scenes Martin Lippert

    - Pivotal @martinlippert
  2. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Our Mission Support Spring developers around the globe writing modern Spring applications 2
  3. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Our Journey Spring IDE was invented • back in 2005 • in a time where everybody used Spring with XML • where Eclipse was THE best and market-dominating IDE on the planet Spring IDE (and the Spring Tool Suite) were enhanced and improved a lot over time • but it is time to take a fresh look 3
  4. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Tools 4 - now GA 4 https://spring.io/tools Spring Tools 4 for Eclipse Spring Tools 4 for Visual Studio Code Spring Tools 4 for Atom IDE
  5. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Behind the Scenes
  6. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Overall design decisions • focus on Spring Boot (focus on key pieces, don’t start with everything at once) • re-imagine developer tooling for Spring (what do we really need?) • start from scratch • do not focus on one specific IDE • performance is key • lightweight beats heavyweight • forget about validations 6
  7. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What is our focus? • developers choose a variety of developer tools nowadays • focus on the key elements (Spring Boot), not specific IDE internals • implement the tooling in an IDE-agnostic way • => Language Server Protocol • implement as much as possible within the language server • avoid changes to the protocol wherever possible 7
  8. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Developer tooling for Spring Boot • Spring Boot application development is mostly based on • regular (Java) source code • (Java) annotations • Java IDEs already provide great tooling for that • What else do you need? 8
  9. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Looking at your app from the Spring PoV • what are the key elements of your application? • all request mappings? • all bean definitions? • specific bean definitions? • How does the application behave at runtime? • what is being wired and why? • what about conditions? • what about available request mappings? 9
  10. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring-specific overview • generate Spring-specific symbols for everything • analyze source code • be as smart as possible • LSP: • provide symbols via LSP symbol infrastructure • super easy navigation • super easy overviews 10
  11. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo
  12. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Internals • Use JDTs ASTParser to parse all the source code • Resolve type bindings where necessary • Visit all generated AST nodes • analyze the code • find Spring elements • extract the symbols • forget the AST 12
  13. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Parsing Java private void scanFiles(IJavaProject project, ASTParser parser, String[] javaFiles, String[] classpathEntries) throws Exception { Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_10, options); ASTParser parser = ASTParser.newParser(AST.JLS10); parser.setCompilerOptions(options); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setStatementsRecovery(true); parser.setBindingsRecovery(true); parser.setResolveBindings(true); parser.setIgnoreMethodBodies(false); String[] sourceEntries = new String[0]; parser.setEnvironment(classpathEntries, sourceEntries, null, false); FileASTRequestor requestor = new FileASTRequestor() { @Override public void acceptAST(String sourceFilePath, CompilationUnit cu) { ... } }; parser.createASTs(javaFiles, null, new String[0], requestor, null); } 13
  14. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Runtime information • show what happens in a running Spring boot application • what beans are being created? • how are they wired together? • what happens at runtime and why? • show live information directly in the source code at the right position • LSP: • use hover to show all the details • use code lenses to show quick links and summaries 14
  15. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo
  16. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Internals • Lookup all running Spring Boot apps on your machine (com.sun.tools.attach.*) • Extract Spring actuator data via JMX • Parse source code for open editors (cached ASTs) • Match actuator data against AST • For remote apps: • no automatic discovery (manual JMX connection config necessary) • everything else works just fine • good for identifying performance bottlenecks 16
  17. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Forget about validations • Spring applications are more and more dynamic (e.g. @Conditional…) • you can’t predict exactly what happens at runtime from looking at the source • false warnings are super annoying for developers • => no validations at source-code level anymore • Instead: clear distinction between source code and runtime information • symbol navigation based on source code analysis • live wiring info (e.g.) based on running application 17
  18. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Performance is key • do not block the UI -> great LSP benefit • source code analysis is done in the background (in the language server) • respond to LSP requests as fast as possible (even with partial results) • optimize performance all along the way 18
  19. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Understanding Java projects • Spring Boot applications are (usually) Java projects • to analyze source code, you need to understand the project context (classpath resolution) • first attempt: • understand the project structure on our own (use Gradle, Maven, etc.) • => slow, error-prone, could result in mismatches with Java language tooling • second attempt: • ask the Java tooling (Java language server) for resolved projects and updates 19
  20. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Internals • classpath lookup mechanism • extension for jdt.ls (as regular OSGi bundle to handle commands) • specific commands (to register and receive notifications) • client-side work needed to forward commands • => hard to debug • => depends on existence of jdt.ls in your install • => but saves a lot of resources (again, focus on the key elements) 20
  21. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outlook
  22. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outlook • live hovers - just the beginning • providing more and more runtime information directly in the source code • eat your own dog food • language servers implemented as Spring Boot apps • keeping it small is a challenge • performance improvements • ship updates of language servers independent of the surrounding IDE 22
  23. > Thanks. Martin Lippert mlippert@pivotal.io #springone @s1p