Skip to content

Commit

Permalink
Merge branch 'release/v1.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
monai committed May 10, 2016
2 parents 5153eb8 + 058670e commit a21f1c7
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 18 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ Request and response content types are `application/json`.

### GET /status

Returns default options with given optimizations and Closure Compiler version.
Returns Closure Compiler versions.

Response:

- `compilerVersions` String - Closure Compiler version

### GET /options

Returns default options with given optimizations.

Query parameters:

Expand All @@ -56,7 +64,6 @@ Query parameters:
Response:

- `options` Object - is of type [CompilerOptions](https://github.com/google/closure-compiler/blob/v20160208/src/com/google/javascript/jscomp/CompilerOptions.java), compiler options
- `compilerVersions` String - Closure Compiler version

### GET /externs

Expand Down
2 changes: 1 addition & 1 deletion pom-jar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.github.monai</groupId>
<artifactId>cc-web-runner-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<relativePath>pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom-war.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.github.monai</groupId>
<artifactId>cc-web-runner-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<relativePath>pom.xml</relativePath>
</parent>

Expand Down
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
<groupId>com.github.monai</groupId>
<artifactId>cc-web-runner-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.5</version>
<version>1.0.6</version>

<properties>
<java.version>1.8</java.version>
<jetty.version>9.3.7.v20160115</jetty.version>
<jetty.version>9.3.8.v20160314</jetty.version>
<jersey.version>2.22.2</jersey.version>
<genson.version>1.3</genson.version>
<closure-compiler.version>v20160208</closure-compiler.version>
<closure-compiler.version>v20160315</closure-compiler.version>
<tinylog.version>1.1</tinylog.version>
<plugin.exec.version>1.4.0</plugin.exec.version>
<plugin.compiler.version>3.5.1</plugin.compiler.version>
<main.class>com.github.monai.Application</main.class>
Expand Down Expand Up @@ -105,5 +106,10 @@
<artifactId>closure-compiler</artifactId>
<version>${closure-compiler.version}</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-binding</artifactId>
<version>${tinylog.version}</version>
</dependency>
</dependencies>
</project>
29 changes: 29 additions & 0 deletions src/main/java/com/github/monai/AccessLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.monai;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Response;
import org.pmw.tinylog.Level;
import org.pmw.tinylog.Logger;

public class AccessLog implements RequestLog {
@Override
public void log(Request request, Response response) {
Logger.info(request);

if (Logger.getLevel().compareTo(Level.DEBUG) == 1) {
Logger.info(formatResponse(response));
} else {
Logger.debug(response.toString());
}
}

private String formatResponse(Response response) {
return String.format("%s[%s %d %s]@%x",
response.getClass().getSimpleName(),
response.getHttpChannel().getRequest().getHttpVersion(),
response.getStatus(),
response.getReason(),
response.hashCode());
}
}
10 changes: 9 additions & 1 deletion src/main/java/com/github/monai/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import org.pmw.tinylog.Logger;

import javax.ws.rs.ApplicationPath;
import java.io.IOException;
Expand Down Expand Up @@ -48,10 +49,12 @@ public static void main(String[] args) throws Exception {

Server server = new Server(port);
Application app = new Application();
AccessLog accessLog = new AccessLog();

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
server.setRequestLog(accessLog);

ServletContainer servletContainer = new ServletContainer(app);
ServletHolder servlet = new ServletHolder(servletContainer);
Expand All @@ -65,7 +68,12 @@ public static void main(String[] args) throws Exception {
server.start();
server.join();
} finally {
server.destroy();
try {
server.destroy();
} catch (Throwable error) {
Logger.error(error);
System.exit(1);
}
}
}
}
8 changes: 2 additions & 6 deletions src/main/java/com/github/monai/DefaultExterns.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
public final class DefaultExterns {
public final HashMap<CompilerOptions.Environment, List<SourceFile>> externs;


public DefaultExterns() throws IOException {
DefaultExterns() throws IOException {
this.externs = new HashMap<>();

for (CompilerOptions.Environment env : CompilerOptions.Environment.values()) {
CompilerOptions options = new CompilerOptions();
options.setEnvironment(env);

List<SourceFile> externs = CommandLineRunner.getBuiltinExterns(options);
List<SourceFile> externs = CommandLineRunner.getBuiltinExterns(env);
this.externs.put(env, externs);
}
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/github/monai/resource/WebRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
public class WebRunner {
@GET
@Path("/status")
public HashMap<String, Object> status(@QueryParam("level") CompilationLevel level,
public HashMap<String, Object> status() {
HashMap<String, Object> out = new HashMap<>();

out.put("compilerVersion", Compiler.getReleaseVersion());

return out;
}

@GET
@Path("/options")
public HashMap<String, Object> options(@QueryParam("level") CompilationLevel level,
@QueryParam("debug") @DefaultValue("false") boolean debug,
@QueryParam("typeBased") @DefaultValue("false") boolean typeBased,
@QueryParam("wrappedOutput") @DefaultValue("false") boolean wrappedOutput) throws IOException {
Expand All @@ -32,7 +42,6 @@ public HashMap<String, Object> status(@QueryParam("level") CompilationLevel leve
}

out.put("options", options);
out.put("compilerVersion", Compiler.getReleaseVersion());

return out;
}
Expand All @@ -42,7 +51,8 @@ public HashMap<String, Object> status(@QueryParam("level") CompilationLevel leve
public HashMap<String, Object> externs() throws IOException {
HashMap<String, Object> out = new HashMap<>();

out.put("externs", CommandLineRunner.getBuiltinExterns(new CompilerOptions()));
CompilerOptions.Environment environment = new CompilerOptions().getEnvironment();
out.put("externs", CommandLineRunner.getBuiltinExterns(environment));

return out;
}
Expand Down Expand Up @@ -84,7 +94,7 @@ private void applyOptimizations(Optimizations optim, CompilerOptions options) {
}
}

class VoidErrorManager extends BasicErrorManager {
private class VoidErrorManager extends BasicErrorManager {
@Override
public void println(CheckLevel level, JSError error) {}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/tinylog.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tinylog.level=info
tinylog.format={level}: {date:yyyy-MM-dd HH:mm:ss} [{thread}] {message}

0 comments on commit a21f1c7

Please sign in to comment.