-
Notifications
You must be signed in to change notification settings - Fork 274
Add polaris-version
artifact
#591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably doesn't matter much, but isn't
src/main/resources
a more common name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, usually. But this should limit the replacement to that particular file - hence the separate folder.