/*
 * Copyright 2017 Google LLC
 *
 * 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;

import com.google.api.core.InternalApi;

@InternalApi("This class should only be used within google-cloud-java")
public final class PlatformInformation {
  public static final String SPECIFICATION_VERSION =
      System.getProperty("java.specification.version");
  public static final String GAE_RUNTIME_VERSION =
      System.getProperty("com.google.appengine.runtime.version");
  public static final String RUNTIME_JETTY_LOGGER =
      System.getProperty("org.eclipse.jetty.util.log.class");
  public static final String JETTY_LOGGER_ON_GAE8_PROD =
      "com.google.apphosting.runtime.jetty9.JettyLogger";
  public static final String JETTY_LOGGER_ON_GAE8_DEVSERVER =
      " com.google.appengine.development.jetty9.JettyLogger"; //note the leading space

  private PlatformInformation() {}

  public static boolean isOnGAE() {
    return GAE_RUNTIME_VERSION != null;
  }

  public static boolean isOnGAEStandard7() {
    //edge case: when a Java 7 GAE app is deployed to DevServer running on J8, SPECIFICATION_VERSION will be "1.8",
    //but RUNTIME_JETTY_LOGGER is unset
    return isOnGAE() && SPECIFICATION_VERSION.equals("1.7")
        || isOnGAE() && RUNTIME_JETTY_LOGGER == null;
  }

  public static boolean isOnGAEStandard8() {
    return isOnGAE()
        && !SPECIFICATION_VERSION.equals("1.7")
        && RUNTIME_JETTY_LOGGER != null
        && (RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_DEVSERVER)
            || RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_PROD));
  }
}

@@ -804,1316 +804,261 @@
 ing 
-SPECIFICATION_VERSION =%0A      System.getProperty(%22java.specification.version%22);%0A  public static final String GAE_RUNTIME_VERSION =%0A      System.getProperty(%22com.google.appengine.runtime.version%22);%0A  public static final String RUNTIME_JETTY_LOGGER =%0A      System.getProperty(%22org.eclipse.jetty.util.log.class%22);%0A  public static final String JETTY_LOGGER_ON_GAE8_PROD =%0A      %22com.google.apphosting.runtime.jetty9.JettyLogger%22;%0A  public static final String JETTY_LOGGER_ON_GAE8_DEVSERVER =%0A      %22 com.google.appengine.development.jetty9.JettyLogger%22; //note the leading space%0A%0A  private PlatformInformation() %7B%7D%0A%0A  public static boolean isOnGAE() %7B%0A    return GAE_RUNTIME_VERSION != null;%0A  %7D%0A%0A  public static boolean isOnGAEStandard7() %7B%0A    //edge case: when a Java 7 GAE app is deployed to DevServer running on J8, SPECIFICATION_VERSION will be %221.8%22,%0A    //but RUNTIME_JETTY_LOGGER is unset%0A    return isOnGAE() && SPECIFICATION_VERSION.equals(%221.7%22)%0A        %7C%7C isOnGAE() && RUNTIME_JETTY_LOGGER == null;%0A  %7D%0A%0A  public static boolean isOnGAEStandard8() %7B%0A    return isOnGAE()%0A        && !SPECIFICATION_VERSION.equals(%221.7%22)%0A        && RUNTIME_JETTY_LOGGER != null%0A        && (RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_DEVSERVER)%0A            %7C%7C RUNTIME_JETTY_LOGGER.equals(JETTY_LOGGER_ON_GAE8_PROD)
+GAE_RUNTIME = System.getenv(%22GAE_RUNTIME%22);%0A%0A  private PlatformInformation() %7B%7D%0A%0A  public static boolean isOnGAEStandard7() %7B%0A    return %22java7%22.equals(GAE_RUNTIME);%0A  %7D%0A%0A  public static boolean isOnGAEStandard8() %7B%0A    return %22java8%22.equals(GAE_RUNTIME
 );%0A 

use GAE_RUNTIME to detect java version (#2837)