Converted build tool to Maven.

This commit is contained in:
Winston Li
2015-01-09 07:21:13 +00:00
parent ece573c942
commit 27e0952afb
180 changed files with 608 additions and 570 deletions
@@ -21,6 +21,7 @@ public class WLGitBridgeApplication {
private String configFilePath;
private Config config;
private WLGitBridgeServer server;
/**
* Constructs an instance of the WriteLatex-Git Bridge application.
@@ -40,14 +41,8 @@ public class WLGitBridgeApplication {
System.out.println("Invalid config file. Check the file path.");
System.exit(EXIT_CODE_FAILED);
}
}
/**
* Starts the server with the port number and root directory path given in the command-line arguments.
*/
public void run() {
try {
new WLGitBridgeServer(config).start();
server = new WLGitBridgeServer(config);
} catch (ServletException e) {
e.printStackTrace();
} catch (InvalidRootDirectoryPathException e) {
@@ -56,6 +51,17 @@ public class WLGitBridgeApplication {
}
}
/**
* Starts the server with the port number and root directory path given in the command-line arguments.
*/
public void run() {
server.start();
}
public void stop() {
server.stop();
}
/* Helper methods */
private void parseArguments(String[] args) throws InvalidProgramArgumentsException {
@@ -75,9 +75,12 @@ public class WLGitBridgeServer {
} catch (Exception e) {
e.printStackTrace();
}
}
public void stop() {
try {
jettyServer.join();
} catch (InterruptedException e) {
jettyServer.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -0,0 +1,46 @@
package uk.ac.ic.wlgitbridge.test;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created by Winston on 09/01/15.
*/
public class SnapshotDummyServer {
private final Server server;
private int port;
public SnapshotDummyServer() {
server = new Server(0);
server.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.getWriter().println(target);
baseRequest.setHandled(true);
}
});
}
public void start() {
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort();
System.out.println(port);
}
public static void main(String[] args) {
new SnapshotDummyServer().start();
}
}
@@ -9,7 +9,6 @@ import com.ning.http.client.Realm;
import com.ning.http.client.Response;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -71,25 +70,21 @@ public abstract class Request<T extends Result> {
}
private void request(BoundRequestBuilder boundRequestBuilder) {
try {
future = boundRequestBuilder.setRealm(buildRequestRealm()).execute(new AsyncCompletionHandler<T>() {
future = boundRequestBuilder.setRealm(buildRequestRealm()).execute(new AsyncCompletionHandler<T>() {
@Override
public T onCompleted(Response response) throws Exception {
System.out.println("Response: " + response.getResponseBody());
return parseResponse(new Gson().fromJson(response.getResponseBody(), JsonElement.class));
}
@Override
public T onCompleted(Response response) throws Exception {
System.out.println("Response: " + response.getResponseBody());
return parseResponse(new Gson().fromJson(response.getResponseBody(), JsonElement.class));
}
@Override
public void onThrowable(Throwable t) {
t.printStackTrace();
error = true;
}
@Override
public void onThrowable(Throwable t) {
t.printStackTrace();
error = true;
}
});
} catch (IOException e) {
error = true;
}
});
}
}
@@ -9,7 +9,6 @@ import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStoreAPI;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -38,26 +37,22 @@ public class ExternalBlob extends Blob {
private void fetchContents(String url) throws FailedConnectionException {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
try {
future = asyncHttpClient.prepareGet(url).execute(new AsyncCompletionHandler<byte[]>() {
future = asyncHttpClient.prepareGet(url).execute(new AsyncCompletionHandler<byte[]>() {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
bytes.write(bodyPart.getBodyPartBytes());
return STATE.CONTINUE;
}
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
bytes.write(bodyPart.getBodyPartBytes());
return STATE.CONTINUE;
}
@Override
public byte[] onCompleted(Response response) throws Exception {
return bytes.toByteArray();
}
@Override
public byte[] onCompleted(Response response) throws Exception {
return bytes.toByteArray();
}
});
} catch (IOException e) {
throw new FailedConnectionException();
}
});
}
@Override

Some files were not shown because too many files have changed in this diff Show More