diff --git a/appengine_init/pom.xml b/appengine_init/pom.xml index cde8f690c..158efb76f 100644 --- a/appengine_init/pom.xml +++ b/appengine_init/pom.xml @@ -29,19 +29,48 @@ jar AppEngine :: appengine-init - + - - - com.google.truth - truth - test - - - junit - junit - test - - + + + com.google.truth + truth + test + + + junit + junit + test + + + + + + src/main/resources + true + + + + + org.codehaus.mojo + buildnumber-maven-plugin + 3.2.0 + + + create-buildnumber + + create + + + false + false + ${nonCanonicalRevision} + {0,date,yyyy-MM-dd'T'HH:mm:ssXXX} + + + + + + diff --git a/appengine_init/src/main/java/com/google/appengine/init/AppEngineWebXmlInitialParse.java b/appengine_init/src/main/java/com/google/appengine/init/AppEngineWebXmlInitialParse.java index efb875acb..b625e93c0 100644 --- a/appengine_init/src/main/java/com/google/appengine/init/AppEngineWebXmlInitialParse.java +++ b/appengine_init/src/main/java/com/google/appengine/init/AppEngineWebXmlInitialParse.java @@ -18,6 +18,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.namespace.QName; @@ -40,6 +41,26 @@ public final class AppEngineWebXmlInitialParse { private static final String PROPERTY = "property"; private static final String RUNTIME = "runtime"; + /** git commit number if the build is done via Maven */ + public static final String GIT_HASH; + + /** a formatted build timestamp with pattern yyyy-MM-dd'T'HH:mm:ssXXX */ + public static final String BUILD_TIMESTAMP; + + private static final Properties BUILD_PROPERTIES = new Properties(); + + static { + try (InputStream inputStream = + AppEngineWebXmlInitialParse.class.getResourceAsStream( + "/com/google/appengine/init/build.properties")) { + BUILD_PROPERTIES.load(inputStream); + } catch (Exception ignored) { + } + GIT_HASH = BUILD_PROPERTIES.getProperty("buildNumber", "unknown"); + System.setProperty("appengine.git.hash", GIT_HASH); + BUILD_TIMESTAMP = BUILD_PROPERTIES.getProperty("timestamp", "unknown"); + } + public void handleRuntimeProperties() { try (final InputStream stream = new FileInputStream(file)) { final XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(stream); @@ -104,5 +125,9 @@ private void setAppEngineUseProperties(final XMLEventReader reader) throws XMLSt public AppEngineWebXmlInitialParse(String file) { this.file = file; + if (!GIT_HASH.equals("unknown")) { + logger.log( + Level.INFO, "built on {0} from commit {1}", new Object[] {BUILD_TIMESTAMP, GIT_HASH}); + } } } diff --git a/appengine_init/src/main/resources/com/google/appengine/init/build.properties b/appengine_init/src/main/resources/com/google/appengine/init/build.properties new file mode 100644 index 000000000..e4d6e3ab2 --- /dev/null +++ b/appengine_init/src/main/resources/com/google/appengine/init/build.properties @@ -0,0 +1,20 @@ +/* + * Copyright 2021 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 + * + * https://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. + */ + +buildNumber=${buildNumber} +timestamp=${timestamp} +version=${project.version} +scmUrl=${project.scm.connection} \ No newline at end of file diff --git a/runtime/runtime_impl_jetty12/src/main/java/com/google/apphosting/runtime/jetty/ee10/AppEngineWebAppContext.java b/runtime/runtime_impl_jetty12/src/main/java/com/google/apphosting/runtime/jetty/ee10/AppEngineWebAppContext.java index 22778f19b..ed78169f3 100644 --- a/runtime/runtime_impl_jetty12/src/main/java/com/google/apphosting/runtime/jetty/ee10/AppEngineWebAppContext.java +++ b/runtime/runtime_impl_jetty12/src/main/java/com/google/apphosting/runtime/jetty/ee10/AppEngineWebAppContext.java @@ -160,8 +160,7 @@ public AppEngineWebAppContext(File appDir, String serverInfo, boolean extractWar // Configure the Jetty SecurityHandler to understand our method of // authentication (via the UserService). - EE10AppEngineAuthentication.configureSecurityHandler( - (ConstraintSecurityHandler) getSecurityHandler()); + setSecurityHandler(EE10AppEngineAuthentication.newSecurityHandler()); setMaxFormContentSize(MAX_RESPONSE_SIZE);