Skip to content

Commit

Permalink
Fix: use correct keyname to read the version from Manifest file
Browse files Browse the repository at this point in the history
  • Loading branch information
kannappanr committed Jun 3, 2020
1 parent ad41b8f commit 53d0bb9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ jobs:
run: |
./gradlew build
./gradlew runFunctionalTest
echo ::set-env name=VERSION::$(./gradlew properties | awk '/^version:/ { print $2 }')
javac -cp api/build/libs/minio-${VERSION}-all.jar functional/TestUserAgent.java
java -Dversion=${VERSION} -cp api/build/libs/minio-${VERSION}-all.jar:functional TestUserAgent
./gradlew build -Prelease
echo ::set-env name=VERSION::$(./gradlew properties -Prelease | awk '/^version:/ { print $2 }')
javac -cp api/build/libs/minio-${VERSION}-all.jar functional/TestUserAgent.java
java -Dversion=${VERSION} -cp api/build/libs/minio-${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);
}
}
}

0 comments on commit 53d0bb9

Please sign in to comment.