Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#95 Cleanup GLSPServerLauncher & add CLI parsing #69

Merged
merged 2 commits into from
Aug 14, 2020

Conversation

tortmayr
Copy link
Contributor

  • Cleanup GLSPServerLauncher (refactor methods & add support to inject additional modules)
  • Add a CLIParser helper class and configure default options for configuring
    • Server port
    • consoleLog flag
    • logging directory
    • logLevel
    • help

Fixes eclipse-glsp/glsp/issues/95

- Cleanup GLSPServerLauncher (refactor methods & add support to inject additional modules)
- Add a CLIParser helper class and configure default options for configuring
-- Server port
-- consoleLog flag
-- logging directory
-- logLevel
-- help

Fixes eclipse-glsp/glsp/issues/95
tortmayr added a commit to eclipse-glsp/glsp-examples that referenced this pull request Aug 12, 2020
tortmayr added a commit to eclipse-glsp/glsp-examples that referenced this pull request Aug 12, 2020
Copy link
Contributor

@martin-fleck-at martin-fleck-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tobi, thank you for that great change, I really love the idea of having that cleaned up and all a bit more useful than before :D I have a few questions and found some minor issues, could you please have a look at this again? Thank you!

@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.glsp.api;bundle-version="0.7.0";visibility:=reexport
com.google.gson;bundle-version="2.8.2",
org.eclipse.lsp4j;bundle-version="0.7.0",
org.eclipse.lsp4j.jsonrpc,
com.google.guava;bundle-version="21.0.0"
com.google.guava;bundle-version="21.0.0",
org.apache.commons.cli;bundle-version="1.4.0";visibility:=reexport
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure about the re-export here? I just want to raise it to make sure we do not cause any troubles down the road with different versions in peoples applications. But I guess apache commons is quite stable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we should be on the save side. The latest release of commons.cli is from 2017 😉. However, I doublechecked and we are also reexporting some dependencies (guice, javax.websocket, ecore etc.). Maybe we should reconsider this.

}

public Level parseLogLevel() {
String levelArg = cmd.getOptionValue("ll");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this or the help is incorrect, the parameter in the help shows a single 'l'. Just to avoid that I suggest extracting those options into constants, Maybe even public ones as in the example the user had to set specify 'h' for evaluating help as risky string ;-)

public static void configureLogger(
final CLIParser parser) throws ParseException, IOException {
if (parser.isConsoleLog()) {
configureConsoleLogger();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the console logger the log level is not considered. Is that on purpose? For me it is just unexpected, especially since in the example launch config both parameters are specified.

Also it seems that is an either-or situation. Should it be possible to have both a file logger and a console logger at the same time? Cause that might be useful as well. It is the same when the File-Logger is configured, it removes all other appenders it seems. Is this necessary?

Copy link
Contributor Author

@tortmayr tortmayr Aug 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it sometimes might be useful to have both loggers configured. However, we also need the possibility to disable console logging (if the client-server connection is handled via sys in/out streams).

I suggest the following:

  • Console logging is enabled per default
  • File logging can be enabled/disabled via option
  • Console logging can be enabled/disabled via option
  • Print warning if file logging is disabled but an argument for the logDir is present
  • LogLevel is considered for all loggers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, great suggestion, that sounds good!

}

public boolean isConsoleLog() { return optionExists("c"); }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have utility methods for almost all parameters I suggest also adding one for 'isHelp' that evaluates the 'h'-option.

this.processName = processName;
}

public boolean optionExists(final String identifier) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity: Is there a reason you chose 'optionExists' over 'hasOption'? In my opinion 'hasOption' is both shorter and more common.

printHelp(this.processName, options);
}

public static void printHelp(final String processName, final Options options) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit-picky: It seems to me that this method would be better located at the LaunchUtil class as it has no connection to the CLIParser whatsoever besides that it takes options.

}

public static void configureLogger(
final CLIParser parser) throws ParseException, IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary linebreak.

@tortmayr
Copy link
Contributor Author

Thanks for the fast review. I simply mostly reused the CLIParser class from https://github.com/eclipse-emfcloud/emfcloud-modelserver. So we should probably incorporate the mentioned improvements there as well.

- Use constants for CLI options and default values
- Extract abstract CLI parser base class
- Improve logging configuration
@tortmayr
Copy link
Contributor Author

I addressed the mentioned issues and refactored the CLIParser class as well.

Copy link
Contributor

@martin-fleck-at martin-fleck-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks very clean now and works well, thank you very much Tobi for a great change!

@martin-fleck-at martin-fleck-at merged commit 07f68d5 into master Aug 14, 2020
@martin-fleck-at martin-fleck-at deleted the tortmayr/issues/95 branch August 14, 2020 13:53
martin-fleck-at pushed a commit to eclipse-glsp/glsp-examples that referenced this pull request Aug 14, 2020
* #95 Adapt example to conform to GLSPServerLauncher refactoring

Add launch configs for Eclipse
Requires: eclipse-glsp/glsp-server/pull/69
Part of: eclipse-glsp/glsp#95
MatthiasHofstaetter pushed a commit to MatthiasHofstaetter/glsp-server that referenced this pull request Dec 21, 2024
…-glsp#69)

* eclipse-glsp#95 Cleanup GLSPServerLauncher & add CLI parsing

- Cleanup GLSPServerLauncher (refactor methods & add support to inject additional modules)
- Add a CLIParser helper class and configure default options for configuring
-- Server port
-- consoleLog flag
-- logging directory
-- logLevel
-- help

Fixes eclipse-glsp/glsp/issues/95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup GlspServerLauncher & add CLI parsing
2 participants