in app-gradle-plugin/src/integTest/java/com/google/cloud/tools/gradle/appengine/sourcecontext/SourceContextPluginIntegrationTest.java [45:89]
public void setUpTestProject() throws IOException {
Path buildFile = testProjectDir.getRoot().toPath().resolve("build.gradle");
Files.createDirectory(testProjectDir.getRoot().toPath().resolve("src"));
InputStream buildFileContent =
getClass()
.getClassLoader()
.getResourceAsStream("projects/sourcecontext-project/build.gradle");
Files.copy(buildFileContent, buildFile);
Path gitContext = testProjectDir.getRoot().toPath().resolve("gitContext.zip");
InputStream gitContextContent =
getClass()
.getClassLoader()
.getResourceAsStream("projects/sourcecontext-project/gitContext.zip");
Files.copy(gitContextContent, gitContext);
try (ZipFile zipFile = new ZipFile(gitContext.toFile())) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File entryDestination = new File(testProjectDir.getRoot(), entry.getName());
if (!entryDestination.toPath().normalize().startsWith(testProjectDir.getRoot().toPath())) {
throw new RuntimeException("Bad zip entry");
}
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
InputStream in = zipFile.getInputStream(entry);
OutputStream out = new FileOutputStream(entryDestination);
IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
out.close();
}
}
}
FileUtils.delete(gitContext.toFile());
Path webInf = testProjectDir.getRoot().toPath().resolve("src/main/webapp/WEB-INF");
Files.createDirectories(webInf);
File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));
}