diff --git a/CHANGELOG.md b/CHANGELOG.md index de43e1cb..d8c99a98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - updated eiffel-remrem-semantics version from 2.2.1 to 2.2.2 - Introduced new (/message_protocols) Endpoint which returns the available message protocols list and their respective edition names. - Updated all curl commands in documentation +- Removed archived repo remrem-shared dependencies ## 2.1.4 - Fixed issue related to ER lookup strategy in REMReM-generate. diff --git a/cli/pom.xml b/cli/pom.xml index 4a98f5a8..a3e6bfdb 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -11,10 +11,6 @@ generate-cli jar - - com.github.eiffel-community - eiffel-remrem-shared - com.github.eiffel-community eiffel-remrem-semantics diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java index 53119b62..6c8ff4d4 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java @@ -27,7 +27,6 @@ import org.apache.commons.cli.Options; import com.ericsson.eiffel.remrem.generate.config.PropertiesConfig; -import com.ericsson.eiffel.remrem.shared.VersionService; public class CLIOptions { diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/VersionService.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/VersionService.java new file mode 100644 index 00000000..02df66ed --- /dev/null +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/VersionService.java @@ -0,0 +1,130 @@ +/* + Copyright 2017 Ericsson AB. + For a full list of individual contributors, please see the commit history. + 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. +*/ +package com.ericsson.eiffel.remrem.generate.cli; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + +import com.google.gson.JsonParser; +import ch.qos.logback.classic.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class will search in all registered jars and their manifest file for + * attribute Remrem-Version-Key. It will return a list with all versions found. + */ +public class VersionService { + + private static final String WEB_INF = "WEB-INF"; + private static final String VERSION = "version"; + private static final String META_INF_MANIFEST_MF = "META-INF/MANIFEST.MF"; + private static final String REMREM_VERSION_KEY = "remremVersionKey"; + private static final String IS_ENDPOINT_VERSION = "isEndpointVersion"; + private static final String ENDPOINT_VERSION = "endpointVersions"; + private static final String SERVICE_VERSION = "serviceVersion"; + private Logger log = (Logger) LoggerFactory.getLogger(VersionService.class); + JsonParser parser = new JsonParser(); + Map> versions = new HashMap<>(); + Map endpointVersions = new HashMap(); + Map serviceVersion = new HashMap(); + /** + * This method will load and parse the MINIFEST files to get the version of + * the loaded messaging protocols. It is required to define the versions as + * mainifest attributes in the build.gradle or pom.xml files using + * attributes "remremVersionKey" and "isEndpointVersion" to specify the type + * of the protocol or service and if it is endpoint or not respectively. + * Example for build.gradle: manifest { attributes('remremVersionKey': + * 'semanticsVersion') attributes('semanticsVersion': version) + * attributes('isEndpointVersion': 'true') } + * + * @return a map containing the protocol and service types with their + * versions {"endpointVersions" : {"semanticsVersion" : "1.1.1"}, + * "serviceVersion": {"remremGenerateVersion": "0.1.1"}} + */ + public Map> getMessagingVersions() { + Enumeration resEnum; + + try { + resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); + while (resEnum.hasMoreElements()) { + try { + URL url = (URL) resEnum.nextElement(); + InputStream is = url.openStream(); + if (is != null) { + Manifest manifest = new Manifest(is); + Attributes mainAttribs = manifest.getMainAttributes(); + String versionKey = mainAttribs.getValue(REMREM_VERSION_KEY); + if (versionKey != null) { + String version = mainAttribs.getValue(versionKey); + if (version != null) { + + if (mainAttribs.getValue(IS_ENDPOINT_VERSION) != null) { + endpointVersions.put(versionKey, version); + } else { + serviceVersion.put(versionKey, version); + } + } + } + } + } catch (Exception e) { + // Silently ignore wrong manifests on classpath? + log.debug("Ignore wrong manifests on classpath ",e.getMessage()); + } + } + if(serviceVersion.isEmpty()){ + serviceVersion=getServiceVersion(); + } + versions.put(ENDPOINT_VERSION, endpointVersions); + versions.put(SERVICE_VERSION, serviceVersion); + } catch (IOException e1) { + // Silently ignore wrong manifests on classpath? + log.debug("Ignore wrong manifests on classpath ",e1.getMessage()); + } + return versions; + } + + /** + * this method will parse manifest file of current project. + * + * @return map containing the version of current project. + */ + public Map getServiceVersion() { + String resourcesPath = this.getClass().getClassLoader().getResource("").getPath(); + String manifestPath = resourcesPath.substring(0, resourcesPath.lastIndexOf(WEB_INF)).concat(META_INF_MANIFEST_MF); + try { + Manifest manifest = new Manifest(new FileInputStream(manifestPath)); + Attributes mainAttribs = manifest.getMainAttributes(); + String versionKey = mainAttribs.getValue(REMREM_VERSION_KEY); + if (versionKey != null) { + String version = mainAttribs.getValue(versionKey); + if (version != null) { + serviceVersion.put(VERSION, version); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return serviceVersion; + } +} + diff --git a/pom.xml b/pom.xml index da62d5fa..a9360ac9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,6 @@ 2.1.5 - 2.0.5 2.2.2 eiffel-remrem-generate @@ -19,11 +18,6 @@ pom - - com.github.eiffel-community - eiffel-remrem-shared - ${eiffel-remrem-shared.version} - com.github.eiffel-community eiffel-remrem-semantics diff --git a/service/pom.xml b/service/pom.xml index 9587141a..7ea0c668 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -11,10 +11,6 @@ generate-service war - - com.github.eiffel-community - eiffel-remrem-shared - com.github.eiffel-community eiffel-remrem-semantics diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java index 416f04fa..9d5d0ba7 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java @@ -18,7 +18,6 @@ import com.ericsson.eiffel.remrem.generate.constants.RemremGenerateServiceConstants; import com.ericsson.eiffel.remrem.generate.exception.REMGenerateException; import com.ericsson.eiffel.remrem.protocol.MsgService; -import com.ericsson.eiffel.remrem.shared.VersionService; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -415,4 +414,4 @@ public static String readJasyptKeyFile(final String jasyptKeyFilePath) { } return jasyptKey; } -} \ No newline at end of file +} diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/VersionService.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/VersionService.java new file mode 100644 index 00000000..90c91677 --- /dev/null +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/VersionService.java @@ -0,0 +1,130 @@ +/* + Copyright 2017 Ericsson AB. + For a full list of individual contributors, please see the commit history. + 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. +*/ +package com.ericsson.eiffel.remrem.generate.controller; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + +import com.google.gson.JsonParser; +import ch.qos.logback.classic.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class will search in all registered jars and their manifest file for + * attribute Remrem-Version-Key. It will return a list with all versions found. + */ +public class VersionService { + + private static final String WEB_INF = "WEB-INF"; + private static final String VERSION = "version"; + private static final String META_INF_MANIFEST_MF = "META-INF/MANIFEST.MF"; + private static final String REMREM_VERSION_KEY = "remremVersionKey"; + private static final String IS_ENDPOINT_VERSION = "isEndpointVersion"; + private static final String ENDPOINT_VERSION = "endpointVersions"; + private static final String SERVICE_VERSION = "serviceVersion"; + private Logger log = (Logger) LoggerFactory.getLogger(VersionService.class); + JsonParser parser = new JsonParser(); + Map> versions = new HashMap<>(); + Map endpointVersions = new HashMap(); + Map serviceVersion = new HashMap(); + /** + * This method will load and parse the MINIFEST files to get the version of + * the loaded messaging protocols. It is required to define the versions as + * mainifest attributes in the build.gradle or pom.xml files using + * attributes "remremVersionKey" and "isEndpointVersion" to specify the type + * of the protocol or service and if it is endpoint or not respectively. + * Example for build.gradle: manifest { attributes('remremVersionKey': + * 'semanticsVersion') attributes('semanticsVersion': version) + * attributes('isEndpointVersion': 'true') } + * + * @return a map containing the protocol and service types with their + * versions {"endpointVersions" : {"semanticsVersion" : "1.1.1"}, + * "serviceVersion": {"remremGenerateVersion": "0.1.1"}} + */ + public Map> getMessagingVersions() { + Enumeration resEnum; + + try { + resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); + while (resEnum.hasMoreElements()) { + try { + URL url = (URL) resEnum.nextElement(); + InputStream is = url.openStream(); + if (is != null) { + Manifest manifest = new Manifest(is); + Attributes mainAttribs = manifest.getMainAttributes(); + String versionKey = mainAttribs.getValue(REMREM_VERSION_KEY); + if (versionKey != null) { + String version = mainAttribs.getValue(versionKey); + if (version != null) { + + if (mainAttribs.getValue(IS_ENDPOINT_VERSION) != null) { + endpointVersions.put(versionKey, version); + } else { + serviceVersion.put(versionKey, version); + } + } + } + } + } catch (Exception e) { + // Silently ignore wrong manifests on classpath? + log.debug("Ignore wrong manifests on classpath ",e.getMessage()); + } + } + if(serviceVersion.isEmpty()){ + serviceVersion=getServiceVersion(); + } + versions.put(ENDPOINT_VERSION, endpointVersions); + versions.put(SERVICE_VERSION, serviceVersion); + } catch (IOException e1) { + // Silently ignore wrong manifests on classpath? + log.debug("Ignore wrong manifests on classpath ",e1.getMessage()); + } + return versions; + } + + /** + * this method will parse manifest file of current project. + * + * @return map containing the version of current project. + */ + public Map getServiceVersion() { + String resourcesPath = this.getClass().getClassLoader().getResource("").getPath(); + String manifestPath = resourcesPath.substring(0, resourcesPath.lastIndexOf(WEB_INF)).concat(META_INF_MANIFEST_MF); + try { + Manifest manifest = new Manifest(new FileInputStream(manifestPath)); + Attributes mainAttribs = manifest.getMainAttributes(); + String versionKey = mainAttribs.getValue(REMREM_VERSION_KEY); + if (versionKey != null) { + String version = mainAttribs.getValue(versionKey); + if (version != null) { + serviceVersion.put(VERSION, version); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return serviceVersion; + } +} +