Skip to content

Commit

Permalink
Add polaris-version artifact (#591)
Browse files Browse the repository at this point in the history
Utility artifact that provides static resources containing the version and NOTICE + LICENSE* files, which can be directly served by Quarkus as static web resources, for example `http://127.0.0.1:19120/apache-polaris/NOTICE.txt`.

Utility class that provides above mentioned resources programmatically, plus information for release-builds like the Git tag, Git commit ID, build system.

Fixes #557
  • Loading branch information
snazy authored Dec 26, 2024
1 parent 1698e5c commit 5faadbd
Show file tree
Hide file tree
Showing 7 changed files with 497 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ tasks.named<RatTask>("rat").configure {
excludes.add("LICENSE")
excludes.add("NOTICE")

// Manifest files do not allow comments
excludes.add("tools/version/src/jarTest/resources/META-INF/FAKE_MANIFEST.MF")

excludes.add("ide-name.txt")
excludes.add("version.txt")
excludes.add(".git")
Expand Down
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ polaris-dropwizard-service=dropwizard/service
polaris-eclipselink=extension/persistence/eclipselink
polaris-jpa-model=extension/persistence/jpa-model
aggregated-license-report=aggregated-license-report
polaris-version=tools/version
104 changes: 104 additions & 0 deletions tools/version/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.
*/

import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id("polaris-client")
`java-library`
`java-test-fixtures`
`jvm-test-suite`
}

dependencies { testFixturesApi(libs.assertj.core) }

description =
"Provides Polaris version information programmatically, includes the NOTICE/LICENSE* files"

val syncNoticeAndLicense by
tasks.registering(Sync::class) {
// Have to manually declare the inputs of this task here on top of the from/include below
inputs.files(rootProject.layout.files("NOTICE*", "LICENSE*", "version.txt"))
inputs.property("version", project.version)
destinationDir = project.layout.buildDirectory.dir("notice-licenses").get().asFile
from(rootProject.rootDir) {
include("NOTICE*", "LICENSE*")
// Put NOTICE/LICENSE* files under META-INF/resources/ so those files can be directly
// accessed as static web resources in Quarkus.
eachFile { path = "META-INF/resources/apache-polaris/${file.name}.txt" }
}
from(rootProject.rootDir) {
include("version.txt")
// Put NOTICE/LICENSE* files under META-INF/resources/ so those files can be directly
// accessed as static web resources in Quarkus.
eachFile { path = "META-INF/resources/apache-polaris/${file.name}" }
}
}

val versionProperties by
tasks.registering(Sync::class) {
destinationDir = project.layout.buildDirectory.dir("version").get().asFile
from(project.layout.files("src/main/version"))
eachFile { path = "org/apache/polaris/version/$path" }
inputs.property("projectVersion", project.version)
filter(ReplaceTokens::class, mapOf("tokens" to mapOf("projectVersion" to project.version)))
}

sourceSets.main.configure {
resources {
srcDir(syncNoticeAndLicense)
srcDir(versionProperties)
}
}

// Build a jar for `jarTest` having both the production and test sources including the "fake
// manifest" - the production implementation expects all resources to be in the jar containing
// the `polaris-version.properties` file.
val jarTestJar by
tasks.registering(Jar::class) {
archiveClassifier.set("jarTest")
from(sourceSets.main.get().output)
from(sourceSets.getByName("jarTest").output)
}

// Add a test-suite to run against the built polaris-version*.jar, not the classes/, because we
// need to test the `jar:` scheme/protocol resolution.
testing {
suites {
withType<JvmTestSuite> { useJUnitJupiter(libs.junit.bom.map { it.version!! }) }

register<JvmTestSuite>("jarTest") {
dependencies {
compileOnly(project())
runtimeOnly(files(jarTestJar.get().archiveFile.get().asFile))
implementation(libs.assertj.core)
}

targets.all {
testTask.configure {
dependsOn("jar", jarTestJar)
systemProperty("rootProjectDir", rootProject.rootDir.relativeTo(project.projectDir))
systemProperty("polarisVersion", project.version)
}
}
}
}
}

tasks.named("test") { dependsOn("jarTest") }
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.polaris.version;

import static java.lang.String.format;
import static org.apache.polaris.version.PolarisVersion.getBuildGitTag;
import static org.apache.polaris.version.PolarisVersion.getBuildGitHead;
import static org.apache.polaris.version.PolarisVersion.getBuildJavaVersion;
import static org.apache.polaris.version.PolarisVersion.getBuildReleasedVersion;
import static org.apache.polaris.version.PolarisVersion.getBuildSystem;
import static org.apache.polaris.version.PolarisVersion.getBuildTimestamp;
import static org.apache.polaris.version.PolarisVersion.isReleaseBuild;
import static org.apache.polaris.version.PolarisVersion.polarisVersionString;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@ExtendWith(SoftAssertionsExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestPolarisVersion {
@InjectSoftAssertions private SoftAssertions soft;

/**
* Test runs using a "non release" build, so the MANIFEST.MF file has no release version
* information.
*/
@Test
@Order(1)
public void versionAvailable() {
soft.assertThat(polarisVersionString()).isEqualTo(System.getProperty("polarisVersion"));
soft.assertThat(isReleaseBuild()).isFalse();
soft.assertThat(getBuildReleasedVersion()).isEmpty();
soft.assertThat(getBuildTimestamp()).isEmpty();
soft.assertThat(getBuildGitHead()).isEmpty();
soft.assertThat(getBuildGitTag()).isEmpty();
soft.assertThat(getBuildSystem()).isEmpty();
soft.assertThat(getBuildJavaVersion()).isEmpty();
}

/**
* Test runs using a static "release" build manifest, {@link
* org.apache.polaris.version.PolarisVersion.PolarisVersionJarInfo#loadManifest(String)}
* overwrites the already loaded build-info, so this test has to run <em>after</em> {@link
* #versionAvailable()}.
*/
@Test
@Order(2)
public void fakeReleaseManifest() {
PolarisVersion.PolarisVersionJarInfo.loadManifest("FAKE_MANIFEST.MF");

soft.assertThat(polarisVersionString()).isEqualTo(System.getProperty("polarisVersion"));
soft.assertThat(isReleaseBuild()).isTrue();
soft.assertThat(getBuildReleasedVersion()).contains("0.1.2-incubating-SNAPSHOT");
soft.assertThat(getBuildTimestamp()).contains("2024-12-26-10:31:19+01:00");
soft.assertThat(getBuildGitHead()).contains("27cf81929cbb08e545c8fcb1ed27a53d7ef1af79");
soft.assertThat(getBuildGitTag()).contains("foo-tag-bar");
soft.assertThat(getBuildSystem())
.contains(
"Linux myawesomehost 6.12.6 #81 SMP PREEMPT_DYNAMIC Fri Dec 20 09:22:38 CET 2024 x86_64 x86_64 x86_64 GNU/Linux");
soft.assertThat(getBuildJavaVersion()).contains("21.0.5");
}

@Test
public void versionTxtResource() {
soft.assertThat(PolarisVersion.readResource("version").trim())
.isEqualTo(System.getProperty("polarisVersion"));
}

@ParameterizedTest
@MethodSource
public void noticeLicense(String name, Supplier<String> supplier) throws Exception {
var supplied = supplier.get();
var expected =
Files.readString(Paths.get(format("%s/%s", System.getProperty("rootProjectDir"), name)));
soft.assertThat(supplied).isEqualTo(expected);
}

static Stream<Arguments> noticeLicense() {
return Stream.of(
Arguments.arguments("NOTICE", (Supplier<String>) PolarisVersion::readNoticeFile),
Arguments.arguments("LICENSE", (Supplier<String>) PolarisVersion::readSourceLicenseFile),
Arguments.arguments(
"LICENSE-BINARY-DIST", (Supplier<String>) PolarisVersion::readBinaryLicenseFile));
}
}
9 changes: 9 additions & 0 deletions tools/version/src/jarTest/resources/META-INF/FAKE_MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Apache-Polaris-Version: 0.1.2-incubating-SNAPSHOT
Apache-Polaris-Is-Release: true
Apache-Polaris-Build-Git-Head: 27cf81929cbb08e545c8fcb1ed27a53d7ef1af79
Apache-Polaris-Build-Git-Describe: foo-tag-bar
Apache-Polaris-Build-Timestamp: 2024-12-26-10:31:19+01:00
Apache-Polaris-Build-System: Linux myawesomehost 6.12.6 #81 SMP PREEMPT_DY
NAMIC Fri Dec 20 09:22:38 CET 2024 x86_64 x86_64 x86_64 GNU/Linux
Apache-Polaris-Build-Java-Version: 21.0.5
Loading

0 comments on commit 5faadbd

Please sign in to comment.