Skip to content
Permalink
Browse files
web launcher
  • Loading branch information
dspavlov committed Aug 4, 2017
1 parent 8943be3 commit 49e19f16d25147edc7228b6eb7fcdf46968a3f2a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
@@ -1,16 +1,27 @@
apply plugin: 'java'
apply plugin: 'war'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
compile group: 'com.google.guava', name: 'guava', version: '22.0'

compile group: 'org.apache.ignite', name: 'ignite-core', version: '2.1.0'

def jettyVer = '9.4.6.v20170531'
compile group: 'org.eclipse.jetty', name: 'jetty-util', version: jettyVer
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: jettyVer
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: jettyVer

def jerseyVer = '2.25.1'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet-core', version: jerseyVer


testCompile group: 'junit', name: 'junit', version: '4.+'
}
@@ -0,0 +1,79 @@
package org.apache.ignite.ci.web;

import com.google.common.base.Preconditions;
import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.webapp.WebAppContext;

/**
* Created by Дмитрий on 04.08.2017
*/
public class Launcher {

public static void main(String[] args) throws Exception {
Server server = new Server();

ServerConnector connector = new ServerConnector(server);
int port = 8080;
connector.setPort(port);
server.addConnector(connector);

//working directory is expected to be module dir
String webApp = "./src/main/resources";
File webResDir = new File(webApp);
Preconditions.checkState(webResDir.exists(),
"Resource directory [" + webResDir.getAbsolutePath() + "] does not exist");

WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("build/libs/ignite-teamcity-helper.war");
server.setHandler(webapp);

System.out.println("Starting server at [" + port + "]");

Runnable r = () -> {
boolean stop = waitStopSignal();
if (stop) {
try {
server.stop();
}
catch (Exception e) {
e.printStackTrace();
}
}

};
new Thread(r).start();
server.start();
}

private static boolean waitStopSignal() {
Console cons = System.console();
if (cons != null) {
Reader unbuffered = cons.reader();
try {
System.out.println("Press any key to stop");
System.out.flush();
int x = unbuffered.read();
System.out.println(String.format("%08x", x));
return x>1;
} catch (IOException e) {
e.printStackTrace();
return false;
}
} else {
try {
System.out.println("Press any key and Enter to stop");
System.out.flush();
return System.in.read() > 0;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}
}

0 comments on commit 49e19f1

Please sign in to comment.