Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 5f20ce9

Browse files
Added functionality to parse the MAINIFEST files to get the version of the protocols
* extend MsgService, add functionality to read protocol versions * Added functionality to parse the MAINIFEST files to get the version of the protocols * Added constant variable for string * Fix: Added constant variable for string
1 parent 0d9bd28 commit 5f20ce9

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ gradlew.bat
77

88
build/
99
.gradle/
10+
/bin/
11+
12+
.classpath
13+
.project
14+
.settings/

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ plugins{
1515
id 'eclipse'
1616
}
1717

18+
apply plugin: 'java'
19+
apply plugin: 'eclipse'
20+
1821
jar {
1922
baseName = 'remrem-shared'
2023
version = '0.2.0'
@@ -24,12 +27,13 @@ group 'com.ericsson.eiffel.remrem'
2427
version '1.0-SNAPSHOT'
2528

2629
task wrapper(type: Wrapper) {
27-
gradleVersion = '2.12'
30+
gradleVersion = '3.1'
2831
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
2932
}
3033

3134
repositories {
3235
mavenCentral()
36+
jcenter()
3337
}
3438

3539
dependencies {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.ericsson.eiffel.remrem.shared;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.net.URL;
6+
import java.util.Enumeration;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
import java.util.jar.Attributes;
10+
import java.util.jar.JarFile;
11+
import java.util.jar.Manifest;
12+
13+
/**
14+
* This class will search in all registered jars and their manifest file for
15+
* attribute Remrem-Version-Key. It will return a list with all versions found.
16+
*
17+
* @author evasiba
18+
*
19+
*/
20+
public class VersionService {
21+
22+
private static final String REMREM_VERSION_KEY = "remremVersionKey";
23+
private static final String IS_ENDPOINT_VERSION = "isEndpointVersion";
24+
private static final String ENDPOINT_VERSION = "endpointVersions";
25+
private static final String SERVICE_VERSION = "serviceVersion";
26+
27+
/**
28+
* This method will load and parse the MINIFEST files to get the version of
29+
* the loaded messaging protocols. It is required to define the versions as
30+
* mainifest attributes in the build.gradle or pom.xml files using
31+
* attributes "remremVersionKey" and "isEndpointVersion" to specify the type
32+
* of the protocol or service and if it is endpoint or not respectively.
33+
* Example for build.gradle: manifest { attributes('remremVersionKey':
34+
* 'semanticsVersion') attributes('semanticsVersion': version)
35+
* attributes('isEndpointVersion': 'true') }
36+
*
37+
* @return a map containing the protocol and service types with their
38+
* versions {"endpointVersions" : {"semanticsVersion" : "1.1.1"},
39+
* "serviceVersion": {"remremGenerateVersion": "0.1.1"}}
40+
*/
41+
public static Map<String, Map<String, String>> getMessagingVersions() {
42+
Enumeration<?> resEnum;
43+
Map<String, Map<String, String>> versions = new HashMap<>();
44+
Map<String, String> endpointVersions = new HashMap<String, String>();
45+
Map<String, String> serviceVersion = new HashMap<String, String>();
46+
47+
try {
48+
resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
49+
while (resEnum.hasMoreElements()) {
50+
try {
51+
URL url = (URL) resEnum.nextElement();
52+
InputStream is = url.openStream();
53+
if (is != null) {
54+
Manifest manifest = new Manifest(is);
55+
Attributes mainAttribs = manifest.getMainAttributes();
56+
String versionKey = mainAttribs.getValue(REMREM_VERSION_KEY);
57+
58+
if (versionKey != null) {
59+
String version = mainAttribs.getValue(versionKey);
60+
if (version != null) {
61+
if (mainAttribs.getValue(IS_ENDPOINT_VERSION) != null) {
62+
endpointVersions.put(versionKey, version);
63+
} else {
64+
serviceVersion.put(versionKey, version);
65+
}
66+
}
67+
}
68+
}
69+
} catch (Exception e) {
70+
// Silently ignore wrong manifests on classpath?
71+
}
72+
}
73+
versions.put(ENDPOINT_VERSION, endpointVersions);
74+
versions.put(SERVICE_VERSION, serviceVersion);
75+
} catch (IOException e1) {
76+
// Silently ignore wrong manifests on classpath?
77+
}
78+
return versions;
79+
}
80+
}

0 commit comments

Comments
 (0)