Skip to content

Commit

Permalink
continue work on replacing local gcd.sh with a remote version
Browse files Browse the repository at this point in the history
  • Loading branch information
aozarov committed May 27, 2015
1 parent 7385fb5 commit 7093b4b
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

Expand Down Expand Up @@ -117,7 +118,7 @@ public LocalGcdHelper(String projectId) {

public void start() throws IOException, InterruptedException {
sendQuitRequest();
gcdPath = Files.createTempDirectory(GCD_VERSION);
gcdPath = Files.createTempDirectory("gcd");
File gcdFolder = gcdPath.toFile();
gcdFolder.deleteOnExit();

Expand All @@ -126,6 +127,7 @@ public void start() throws IOException, InterruptedException {
ReadableByteChannel rbc = Channels.newChannel(GCD_URL.openStream());
FileOutputStream fos = new FileOutputStream(gcdZipFile);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
}
try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(gcdZipFile))) {
ZipEntry entry = zipIn.getNextEntry();
Expand All @@ -140,27 +142,41 @@ public void start() throws IOException, InterruptedException {
entry = zipIn.getNextEntry();
}
}

File datasetFolder = new File(gcdFolder, GCD_VERSION + '/' + projectId);
deleteRecurse(datasetFolder.toPath());

// TODO: if System.getProperty("os.name").startsWith("Windows") use cmd.exe /c and gcd.cmd
Process temp = new ProcessBuilder()
ProcessBuilder processBuilder = new ProcessBuilder()
.redirectErrorStream(true)
.directory(new File(gcdFolder, GCD_VERSION))
.redirectOutput(new File("/dev/null"))
.command("bash", "gcd.sh", "create", "-d", projectId, projectId)
.start();
.directory(new File(gcdFolder, GCD_VERSION));
if (isWindows()) {
processBuilder.command("cmd", "/C", "gcd.cmd", "create", "-p", projectId, projectId);
processBuilder.redirectOutput(new File("NULL:"));
} else {
processBuilder.redirectOutput(new File("/dev/null"));
processBuilder.command("bash", "gcd.sh", "create", "-p", projectId, projectId);
}

Process temp = processBuilder.start();
temp.waitFor();

temp = new ProcessBuilder()
processBuilder = new ProcessBuilder()
.directory(new File(gcdFolder, GCD_VERSION))
.redirectErrorStream(true)
.command("bash", "gcd.sh", "start", "--testing", "--allow_remote_shutdown", projectId)
.start();
.redirectErrorStream(true);
if (isWindows()) {
processBuilder.command("cmd", "/C", "gcd.cmd", "start", "--testing",
"--allow_remote_shutdown", projectId);
} else {
processBuilder.command("bash", "gcd.sh", "start", "--testing", "--allow_remote_shutdown",
projectId);
}
temp = processBuilder.start();
processReader = ProcessStreamReader.start(temp, "Dev App Server is now running");
}

private static boolean isWindows() {
return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).indexOf("windows") > -1;
}

private static void extractFile(ZipInputStream zipIn, File filePath) throws IOException {
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) {
byte[] bytesIn = new byte[1024];
Expand Down

0 comments on commit 7093b4b

Please sign in to comment.