Skip to content

Commit

Permalink
Store the Maven build infos in a new build.properties file and emit a…
Browse files Browse the repository at this point in the history
… log showing the build date and commit hash for better information during the runtime execution.

PiperOrigin-RevId: 580610982
Change-Id: Icb4a0664f41cc9afbf4980c1def6abdcbd53c4bf
  • Loading branch information
ludoch authored and gae-java-bot committed Nov 8, 2023
1 parent 5575291 commit dee15d4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 15 deletions.
55 changes: 42 additions & 13 deletions appengine_init/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,48 @@
<packaging>jar</packaging>
<name>AppEngine :: appengine-init</name>

<dependencies>
<dependencies>

<!-- Test dependencies. -->
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Test dependencies. -->
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>create-buildnumber</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>${nonCanonicalRevision}</revisionOnScmFailure>
<timestampFormat>{0,date,yyyy-MM-dd'T'HH:mm:ssXXX}</timestampFormat>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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});
}
}
}
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit dee15d4

Please sign in to comment.