[ls] extracted ServerLauncer.launch method

Signed-off-by: Anton Kosiakov <anton.kosyakov@typefox.io>
This commit is contained in:
Anton Kosiakov 2017-06-06 10:21:33 +05:00
parent 179b1c50b0
commit 2232228372
2 changed files with 36 additions and 23 deletions

View file

@ -10,6 +10,7 @@ package org.eclipse.xtext.ide.server
import com.google.common.io.ByteStreams
import com.google.inject.Guice
import com.google.inject.Inject
import com.google.inject.Module
import java.io.ByteArrayInputStream
import java.io.FileOutputStream
import java.io.InputStream
@ -32,14 +33,13 @@ class ServerLauncher {
public static val NO_VALIDATE = OPTION_PREFIX + 'noValidate'
def static void main(String[] args) {
val launchArgs = new LaunchArgs
launchArgs.in = System.in
launchArgs.out = System.out
redirectStandardStreams(args)
launchArgs.trace = args.trace
launchArgs.validate = args.shouldValidate
launch(ServerLauncher.name, args, new ServerModule)
}
val launcher = Guice.createInjector(new ServerModule).getInstance(ServerLauncher)
def static void launch(String prefix, String[] args, Module... modules) {
val launchArgs = createLaunchArgs(prefix, args)
val launcher = Guice.createInjector(modules).getInstance(ServerLauncher)
launcher.start(launchArgs)
}
@ -56,6 +56,16 @@ class ServerLauncher {
}
}
def static LaunchArgs createLaunchArgs(String prefix, String[] args) {
val launchArgs = new LaunchArgs
launchArgs.in = System.in
launchArgs.out = System.out
redirectStandardStreams(prefix, args)
launchArgs.trace = args.trace
launchArgs.validate = args.shouldValidate
return launchArgs
}
def static PrintWriter getTrace(String[] args) {
if (shouldTrace(args))
return createTrace
@ -65,10 +75,6 @@ class ServerLauncher {
return new PrintWriter(System.out)
}
def static redirectStandardStreams(String[] args) {
redirectStandardStreams(ServerLauncher.name, args)
}
def static redirectStandardStreams(String prefix, String[] args) {
if (shouldLogStandardStreams(args)) {
logStandardStreams(prefix)
@ -76,7 +82,7 @@ class ServerLauncher {
silentStandardStreams
}
}
def static boolean shouldValidate(String[] args) {
return !args.testArg(NO_VALIDATE)
}

View file

@ -10,6 +10,7 @@ package org.eclipse.xtext.ide.server;
import com.google.common.io.ByteStreams;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Module;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
@ -43,14 +44,14 @@ public class ServerLauncher {
public final static String NO_VALIDATE = (ServerLauncher.OPTION_PREFIX + "noValidate");
public static void main(final String[] args) {
final LaunchArgs launchArgs = new LaunchArgs();
launchArgs.setIn(System.in);
launchArgs.setOut(System.out);
ServerLauncher.redirectStandardStreams(args);
launchArgs.setTrace(ServerLauncher.getTrace(args));
launchArgs.setValidate(ServerLauncher.shouldValidate(args));
String _name = ServerLauncher.class.getName();
ServerModule _serverModule = new ServerModule();
final ServerLauncher launcher = Guice.createInjector(_serverModule).<ServerLauncher>getInstance(ServerLauncher.class);
ServerLauncher.launch(_name, args, _serverModule);
}
public static void launch(final String prefix, final String[] args, final Module... modules) {
final LaunchArgs launchArgs = ServerLauncher.createLaunchArgs(prefix, args);
final ServerLauncher launcher = Guice.createInjector(modules).<ServerLauncher>getInstance(ServerLauncher.class);
launcher.start(launchArgs);
}
@ -72,6 +73,16 @@ public class ServerLauncher {
}
}
public static LaunchArgs createLaunchArgs(final String prefix, final String[] args) {
final LaunchArgs launchArgs = new LaunchArgs();
launchArgs.setIn(System.in);
launchArgs.setOut(System.out);
ServerLauncher.redirectStandardStreams(prefix, args);
launchArgs.setTrace(ServerLauncher.getTrace(args));
launchArgs.setValidate(ServerLauncher.shouldValidate(args));
return launchArgs;
}
public static PrintWriter getTrace(final String[] args) {
boolean _shouldTrace = ServerLauncher.shouldTrace(args);
if (_shouldTrace) {
@ -84,10 +95,6 @@ public class ServerLauncher {
return new PrintWriter(System.out);
}
public static void redirectStandardStreams(final String[] args) {
ServerLauncher.redirectStandardStreams(ServerLauncher.class.getName(), args);
}
public static void redirectStandardStreams(final String prefix, final String[] args) {
boolean _shouldLogStandardStreams = ServerLauncher.shouldLogStandardStreams(args);
if (_shouldLogStandardStreams) {