blob: bc1983e86fc33be689f2f1769ee29426fe13dd76 [file]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.solr.mcp.server;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* Test utility class for reading build information from
* {@code META-INF/build-info.properties}.
*
* <p>
* This utility provides access to build artifact name and version that are
* generated by Spring Boot during the build process. It's primarily used by
* Docker integration tests to construct Docker image names dynamically.
*
* <p>
* <strong>Prerequisites:</strong> The build-info.properties file must be
* present in the test classpath. This is typically generated by running:
*
* <pre>{@code
* ./gradlew build
* }</pre>
*/
public class BuildInfoReader {
private static final String BUILD_INFO_PROPERTIES_PATH = "/META-INF/build-info.properties";
private static final Properties buildInfo = loadBuildInfo();
// Private constructor to prevent instantiation
private BuildInfoReader() {
throw new UnsupportedOperationException("Utility class");
}
/**
* Loads build information from the properties file.
*
* @return Properties object containing build information
* @throws IllegalStateException
* if the properties file cannot be found or loaded
*/
private static Properties loadBuildInfo() {
Properties properties = new Properties();
try (InputStream input = BuildInfoReader.class.getResourceAsStream(BUILD_INFO_PROPERTIES_PATH)) {
if (input == null) {
throw new IllegalStateException("build-info.properties not found at " + BUILD_INFO_PROPERTIES_PATH
+ ". Run './gradlew build' first.");
}
properties.load(input);
} catch (IOException e) {
throw new IllegalStateException("Failed to load build-info.properties", e);
}
return properties;
}
/**
* Gets the build artifact name from build-info.properties.
*
* @return the artifact name (e.g., "solr-mcp")
*/
public static String getArtifact() {
return buildInfo.getProperty("build.artifact");
}
/**
* Gets the build version from build-info.properties.
*
* @return the version string (e.g., "1.0.0-SNAPSHOT")
*/
public static String getVersion() {
return buildInfo.getProperty("build.version");
}
/**
* Gets the Docker image name in the format "artifact:version".
*
* @return Docker image name (e.g., "solr-mcp:1.0.0-SNAPSHOT")
*/
public static String getDockerImageName() {
return String.format("%s:%s", getArtifact(), getVersion());
}
/**
* Gets the JAR file name in the format "artifact-version.jar".
*
* @return JAR file name (e.g., "solr-mcp-1.0.0-SNAPSHOT.jar")
*/
public static String getJarFileName() {
return String.format("%s-%s.jar", getArtifact(), getVersion());
}
}