Skip to content
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

Fix: use correct keyname to read the version from Manifest file #962

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java-version }}
- name: Set environment variables
run: |
echo "::set-env name=DEV_VERSION::$(./gradlew properties | awk '/^version:/ { print $2 }')"
echo "::set-env name=RELEASE_VERSION::$(./gradlew properties -Prelease | awk '/^version:/ { print $2 }')"
- name: Gradle build on ${{ matrix.java-version }}
if: matrix.os == 'ubuntu-latest'
run: |
./gradlew build
./gradlew runFunctionalTest
javac -cp api/build/libs/minio-${DEV_VERSION}-all.jar functional/TestUserAgent.java
java -Dversion=${DEV_VERSION} -cp api/build/libs/minio-${DEV_VERSION}-all.jar:functional TestUserAgent
./gradlew build -Prelease
javac -cp api/build/libs/minio-${RELEASE_VERSION}-all.jar functional/TestUserAgent.java
java -Dversion=${RELEASE_VERSION} -cp api/build/libs/minio-${RELEASE_VERSION}-all.jar:functional TestUserAgent
- name: Gradle build on ${{ matrix.java-version }}
if: matrix.os == 'windows-latest'
run: |
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/io/minio/MinioProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void setMinioClientJavaVersion(ClassLoader classLoader) throws IOExcepti
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
for (Object k : manifest.getMainAttributes().keySet()) {
String versionString = "MinIO-Client-Java-Version";
String versionString = "Implementation-Version";
if (k.toString().equals(versionString)) {
version.set(manifest.getMainAttributes().getValue((Attributes.Name) k));
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ project(':api') {
manifest {
attributes('Implementation-Title': archivesBaseName,
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-By': 'MinIO, inc',
'Built-JDK': System.getProperty('java.version'),
'Source-Compatibility': sourceCompatibility,
'Target-Compatibility': targetCompatibility)
Expand Down
49 changes: 49 additions & 0 deletions functional/TestUserAgent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
* (C) 2020 MinIO, Inc.
*
* 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
*
* 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 io.minio.BucketExistsArgs;
import io.minio.MinioClient;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class TestUserAgent {
public static void main(String[] args) throws Exception {
MinioClient client = new MinioClient("http://example.org");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
client.traceOn(baos);
client.bucketExists(BucketExistsArgs.builder().bucket("any-bucket-name-works").build());
client.traceOff();

String expectedVersion = System.getProperty("version");
String version = null;
try (Scanner scanner = new Scanner(new String(baos.toByteArray(), StandardCharsets.UTF_8))) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("User-Agent:")) {
version = line.split("/")[1];
break;
}
}
}

if (!expectedVersion.equals(version)) {
throw new Exception(
"version does not match; expected=" + expectedVersion + ", got=" + version);
}
}
}