App Engine Java SDK version 1.9.25
[gae.git] / java / src / main / com / google / apphosting / utils / config / AppYamlProcessor.java
blob405e7c301f281402d068a859d817e837b796a4ea
1 // Copyright 2012 Google Inc. All Rights Reserved.
3 package com.google.apphosting.utils.config;
5 import java.io.File;
6 import java.io.FileNotFoundException;
7 import java.io.FileReader;
8 import java.io.FileWriter;
9 import java.io.IOException;
11 /**
12 * A utility to convert an app.yaml file into a web.xml and an appengine-web.xml file
15 public final class AppYamlProcessor {
17 /**
18 * Reads the app.yaml file from the given directory and generates
19 * a web.xml and an appengine-web.xml file in the same directory. Usually this directory
20 * will be the WEB-INF directory of a WAR directory. If the directory
21 * does not contain an app.yaml file, does nothing.
22 * @param baseDir A directory possibly containing an app.yaml file
23 * @param aewebPath The path to the appengine-web.xml file to generate.
24 * @param webXmlPath The path to the web.xml file to generate.
26 public static void convert(File baseDir, String aewebPath, String webXmlPath) {
27 File appYamlFile = new File(baseDir, "app.yaml");
28 if (!appYamlFile.exists()) {
29 return;
31 File aeweb = new File(aewebPath);
32 File webXml = new File(webXmlPath);
33 if (aeweb.exists() && webXml.exists() &&
34 aeweb.lastModified() >= appYamlFile.lastModified() &&
35 webXml.lastModified() >= appYamlFile.lastModified()) {
36 return;
38 AppYaml appYaml;
39 try {
40 appYaml = AppYaml.parse(new FileReader(appYamlFile));
41 } catch (FileNotFoundException ex) {
42 throw new AppEngineConfigException("Unable to parse " + appYamlFile, ex);
45 try {
46 FileWriter aewebWriter = new FileWriter(aeweb);
47 appYaml.generateAppEngineWebXml(aewebWriter);
48 aewebWriter.close();
49 aeweb.setLastModified(appYamlFile.lastModified());
50 } catch (IOException ex) {
51 throw new AppEngineConfigException("Unable to generate " + aeweb, ex);
53 try {
54 FileWriter webXmlWriter = new FileWriter(webXml);
55 appYaml.generateWebXml(webXmlWriter);
56 webXmlWriter.close();
57 webXml.setLastModified(appYamlFile.lastModified());
58 } catch (IOException ex) {
59 throw new AppEngineConfigException("Unable to generate " + webXml, ex);