-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
7 changed files
with
497 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") } |
114 changes: 114 additions & 0 deletions
114
tools/version/src/jarTest/java/org/apache/polaris/version/TestPolarisVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
9
tools/version/src/jarTest/resources/META-INF/FAKE_MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.