// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/AppYaml.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class AppYaml {
// 
//   private RuntimeConfig runtimeConfig = new RuntimeConfig();
//   private BetaSettings betaSettings = new BetaSettings();
// 
//   /**
//    * Checks environment variables and overwrites any existing settings in this object.
//    * @param overrideSettings A map of the settings.
//    */
//   public void applyOverrideSettings(Map<String, Object> overrideSettings) throws IOException {
//     runtimeConfig.applyOverrideSettings(overrideSettings);
//     betaSettings.applyOverrideSettings(overrideSettings);
//   }
// 
//   @JsonProperty("runtime_config")
//   public RuntimeConfig getRuntimeConfig() {
//     return runtimeConfig;
//   }
// 
//   public void setRuntimeConfig(RuntimeConfig runtimeConfig) {
//     this.runtimeConfig = runtimeConfig;
//   }
// 
//   @JsonProperty("beta_settings")
//   public BetaSettings getBetaSettings() {
//     return betaSettings;
//   }
// 
//   public void setBetaSettings(BetaSettings betaSettings) {
//     this.betaSettings = betaSettings;
//   }
// }
// 
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/BetaSettings.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public final class BetaSettings extends OverrideableSetting {
// 
//   private static final String ENABLE_APP_ENGINE_APIS_SETTING_NAME = "enable_app_engine_apis";
// 
//   @OverrideSetting(ENABLE_APP_ENGINE_APIS_SETTING_NAME)
//   private boolean enableAppEngineApis = false;
// 
//   public boolean isEnableAppEngineApis() {
//     return enableAppEngineApis;
//   }
// 
//   @JsonProperty(ENABLE_APP_ENGINE_APIS_SETTING_NAME)
//   public void setEnableAppEngineApis(boolean enableAppEngineApis) {
//     this.enableAppEngineApis = enableAppEngineApis;
//   }
// }
// 
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/RuntimeConfig.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public final class RuntimeConfig extends OverrideableSetting {
// 
//   private static final String BUILD_SCRIPT_SETTING_NAME = "build_script";
//   private static final String JETTY_QUICKSTART_SETTING_NAME = "jetty_quickstart";
// 
//   @OverrideSetting
//   private String jdk;
// 
//   @OverrideSetting
//   private String server;
// 
//   @OverrideSetting(BUILD_SCRIPT_SETTING_NAME)
//   private String buildScript;
// 
//   @OverrideSetting
//   private String artifact;
// 
//   @OverrideSetting(JETTY_QUICKSTART_SETTING_NAME)
//   private boolean jettyQuickstart;
// 
//   public String getJdk() {
//     return jdk;
//   }
// 
//   public void setJdk(String jdk) {
//     this.jdk = jdk;
//   }
// 
//   public String getArtifact() {
//     return artifact;
//   }
// 
//   public void setArtifact(String artifact) {
//     this.artifact = artifact;
//   }
// 
//   public String getServer() {
//     return server;
//   }
// 
//   public void setServer(String server) {
//     this.server = server;
//   }
// 
//   public String getBuildScript() {
//     return buildScript;
//   }
// 
//   @JsonProperty(BUILD_SCRIPT_SETTING_NAME)
//   public void setBuildScript(String buildScript) {
//     this.buildScript = buildScript;
//   }
// 
//   public boolean getJettyQuickstart() {
//     return jettyQuickstart;
//   }
// 
//   @JsonProperty(JETTY_QUICKSTART_SETTING_NAME)
//   public void setJettyQuickstart(boolean jettyQuickstart) {
//     this.jettyQuickstart = jettyQuickstart;
//   }
// }


import com.google.cloud.runtimes.builder.config.domain.AppYaml;
import com.google.cloud.runtimes.builder.config.domain.BetaSettings;
import com.google.cloud.runtimes.builder.config.domain.RuntimeConfig;
import com.google.inject.Inject;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.IOException;
import java.nio.file.Path;
/*
 * Copyright 2017 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.cloud.runtimes.builder.config;




/**
 * YamlParser implementation that handles parsing of files in the {@link AppYaml} format.
 */
public class AppYamlParser implements YamlParser<AppYaml> {

  private final ObjectMapper objectMapper;

  /**
   * Constructs a new {@link AppYamlParser}.
   */
  @Inject
  public AppYamlParser() {
    this.objectMapper = new ObjectMapper(new YAMLFactory());
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  }

  @Override
  public AppYaml parse(Path yamlFilePath) throws IOException {
    AppYaml appYaml = objectMapper.readValue(yamlFilePath.toFile(), AppYaml.class);
    if (appYaml.getBetaSettings() == null) {
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/AppYaml.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class AppYaml {
// 
//   private RuntimeConfig runtimeConfig = new RuntimeConfig();
//   private BetaSettings betaSettings = new BetaSettings();
// 
//   /**
//    * Checks environment variables and overwrites any existing settings in this object.
//    * @param overrideSettings A map of the settings.
//    */
//   public void applyOverrideSettings(Map<String, Object> overrideSettings) throws IOException {
//     runtimeConfig.applyOverrideSettings(overrideSettings);
//     betaSettings.applyOverrideSettings(overrideSettings);
//   }
// 
//   @JsonProperty("runtime_config")
//   public RuntimeConfig getRuntimeConfig() {
//     return runtimeConfig;
//   }
// 
//   public void setRuntimeConfig(RuntimeConfig runtimeConfig) {
//     this.runtimeConfig = runtimeConfig;
//   }
// 
//   @JsonProperty("beta_settings")
//   public BetaSettings getBetaSettings() {
//     return betaSettings;
//   }
// 
//   public void setBetaSettings(BetaSettings betaSettings) {
//     this.betaSettings = betaSettings;
//   }
// }
// 
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/BetaSettings.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public final class BetaSettings extends OverrideableSetting {
// 
//   private static final String ENABLE_APP_ENGINE_APIS_SETTING_NAME = "enable_app_engine_apis";
// 
//   @OverrideSetting(ENABLE_APP_ENGINE_APIS_SETTING_NAME)
//   private boolean enableAppEngineApis = false;
// 
//   public boolean isEnableAppEngineApis() {
//     return enableAppEngineApis;
//   }
// 
//   @JsonProperty(ENABLE_APP_ENGINE_APIS_SETTING_NAME)
//   public void setEnableAppEngineApis(boolean enableAppEngineApis) {
//     this.enableAppEngineApis = enableAppEngineApis;
//   }
// }
// 
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/RuntimeConfig.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public final class RuntimeConfig extends OverrideableSetting {
// 
//   private static final String BUILD_SCRIPT_SETTING_NAME = "build_script";
//   private static final String JETTY_QUICKSTART_SETTING_NAME = "jetty_quickstart";
// 
//   @OverrideSetting
//   private String jdk;
// 
//   @OverrideSetting
//   private String server;
// 
//   @OverrideSetting(BUILD_SCRIPT_SETTING_NAME)
//   private String buildScript;
// 
//   @OverrideSetting
//   private String artifact;
// 
//   @OverrideSetting(JETTY_QUICKSTART_SETTING_NAME)
//   private boolean jettyQuickstart;
// 
//   public String getJdk() {
//     return jdk;
//   }
// 
//   public void setJdk(String jdk) {
//     this.jdk = jdk;
//   }
// 
//   public String getArtifact() {
//     return artifact;
//   }
// 
//   public void setArtifact(String artifact) {
//     this.artifact = artifact;
//   }
// 
//   public String getServer() {
//     return server;
//   }
// 
//   public void setServer(String server) {
//     this.server = server;
//   }
// 
//   public String getBuildScript() {
//     return buildScript;
//   }
// 
//   @JsonProperty(BUILD_SCRIPT_SETTING_NAME)
//   public void setBuildScript(String buildScript) {
//     this.buildScript = buildScript;
//   }
// 
//   public boolean getJettyQuickstart() {
//     return jettyQuickstart;
//   }
// 
//   @JsonProperty(JETTY_QUICKSTART_SETTING_NAME)
//   public void setJettyQuickstart(boolean jettyQuickstart) {
//     this.jettyQuickstart = jettyQuickstart;
//   }
// }


// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/AppYamlParser.java
import com.google.cloud.runtimes.builder.config.domain.AppYaml;
import com.google.cloud.runtimes.builder.config.domain.BetaSettings;
import com.google.cloud.runtimes.builder.config.domain.RuntimeConfig;
import com.google.inject.Inject;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.IOException;
import java.nio.file.Path;

/*
 * Copyright 2017 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.cloud.runtimes.builder.config;




/**
 * YamlParser implementation that handles parsing of files in the {@link AppYaml} format.
 */
public class AppYamlParser implements YamlParser<AppYaml> {

  private final ObjectMapper objectMapper;

  /**
   * Constructs a new {@link AppYamlParser}.
   */
  @Inject
  public AppYamlParser() {
    this.objectMapper = new ObjectMapper(new YAMLFactory());
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  }

  @Override
  public AppYaml parse(Path yamlFilePath) throws IOException {
    AppYaml appYaml = objectMapper.readValue(yamlFilePath.toFile(), AppYaml.class);
    if (appYaml.getBetaSettings() == null) {
      appYaml.setBetaSettings(new BetaSettings());