1 // Copyright 2012 Google Inc. All Rights Reserved.
3 package com
.google
.apphosting
.utils
.config
;
6 import java
.io
.FileNotFoundException
;
7 import java
.io
.FileReader
;
8 import java
.io
.FileWriter
;
9 import java
.io
.IOException
;
12 * A utility to convert an app.yaml file into a web.xml and an appengine-web.xml file
15 public final class AppYamlProcessor
{
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()) {
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()) {
40 appYaml
= AppYaml
.parse(new FileReader(appYamlFile
));
41 } catch (FileNotFoundException ex
) {
42 throw new AppEngineConfigException("Unable to parse " + appYamlFile
, ex
);
46 FileWriter aewebWriter
= new FileWriter(aeweb
);
47 appYaml
.generateAppEngineWebXml(aewebWriter
);
49 aeweb
.setLastModified(appYamlFile
.lastModified());
50 } catch (IOException ex
) {
51 throw new AppEngineConfigException("Unable to generate " + aeweb
, ex
);
54 FileWriter webXmlWriter
= new FileWriter(webXml
);
55 appYaml
.generateWebXml(webXmlWriter
);
57 webXml
.setLastModified(appYamlFile
.lastModified());
58 } catch (IOException ex
) {
59 throw new AppEngineConfigException("Unable to generate " + webXml
, ex
);