Commit 439246cb authored by Piotr Gawron's avatar Piotr Gawron
Browse files

version parsing is done on pom.xml

parent 4b5f11e0
...@@ -3,6 +3,7 @@ package lcsb.mapviewer.common; ...@@ -3,6 +3,7 @@ package lcsb.mapviewer.common;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.jar.Manifest;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -215,25 +216,17 @@ public final class Configuration { ...@@ -215,25 +216,17 @@ public final class Configuration {
systemBuildVersion = "Unknown"; systemBuildVersion = "Unknown";
systemBuildTime = "Unknown"; systemBuildTime = "Unknown";
systemVersion = "Unknown"; systemVersion = "Unknown";
File buildVersionFile = null; File manifestFile = null;
File changelogFile = null;
if (baseDir == null) { if (baseDir == null) {
buildVersionFile = new File("version.txt"); manifestFile = new File("META-INF/MANIFEST.MF");
changelogFile = new File("CHANGELOG");
} else { } else {
buildVersionFile = new File(baseDir + "version.txt"); manifestFile = new File(baseDir + "MANIFEST.MF");
changelogFile = new File(baseDir + "CHANGELOG");
} }
if (buildVersionFile.exists()) { if (manifestFile.exists()) {
loadSystemBuildVersion(buildVersionFile); loadSystemBuildVersion(manifestFile);
} else { } else {
logger.error(buildVersionFile.getAbsoluteFile() + " doesn't exist.");
} logger.error(manifestFile.getAbsoluteFile() + " doesn't exist.", new Exception());
if (changelogFile.exists()) {
loadSystemVersion(changelogFile);
} else {
logger.error(changelogFile.getAbsoluteFile() + " doesn't exist.");
} }
} }
...@@ -245,35 +238,27 @@ public final class Configuration { ...@@ -245,35 +238,27 @@ public final class Configuration {
*/ */
protected static void loadSystemBuildVersion(File file) { protected static void loadSystemBuildVersion(File file) {
try { try {
BufferedReader reader = new BufferedReader(new FileReader(file)); boolean problem = false;
systemBuildVersion = reader.readLine().trim(); Manifest manifest = new Manifest(new FileInputStream(file));
systemBuildTime = reader.readLine().trim(); systemBuildTime = manifest.getMainAttributes().getValue("git-timestamp");
reader.close(); if (systemBuildTime == null) {
} catch (IOException e) { systemBuildTime = "Unknown";
logger.error(e); problem = true;
} }
} systemBuildVersion = manifest.getMainAttributes().getValue("git-version");
if (systemBuildVersion == null) {
/** systemBuildVersion = "Unknown";
* Loads system version from debian changelog file. problem = true;
* }
* @param file systemVersion = manifest.getMainAttributes().getValue("version");
* debian changelog file if (systemVersion == null) {
*/ systemVersion = "Unknown";
protected static void loadSystemVersion(File file) { problem = true;
try { }
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine(); if (problem) {
logger.warn("MANIFEST.MF file does not contain required information.");
int startIndex = line.indexOf("(");
int endIndex = line.indexOf(")");
if (startIndex >= 0 && endIndex >= 0) {
systemVersion = line.substring(startIndex + 1, endIndex);
} else {
logger.error("Invalid CHANGELOG file. Cannot find system version in line: " + line);
} }
reader.close();
} catch (IOException e) { } catch (IOException e) {
logger.error(e); logger.error(e);
} }
......
...@@ -42,7 +42,7 @@ public class ConfigurationTest extends CommonTestFunctions { ...@@ -42,7 +42,7 @@ public class ConfigurationTest extends CommonTestFunctions {
@Test @Test
public void testLoadSystemBuildVersion2() { public void testLoadSystemBuildVersion2() {
Configuration.loadSystemVersion((String) null); Configuration.loadSystemVersion((String) null);
Configuration.loadSystemVersion(new File("unknown.xxx")); Configuration.loadSystemVersion("/tmp");
assertEquals("Unknown", Configuration.getSystemBuildVersion(null)); assertEquals("Unknown", Configuration.getSystemBuildVersion(null));
assertEquals("Unknown", Configuration.getSystemBuild(null)); assertEquals("Unknown", Configuration.getSystemBuild(null));
assertEquals("Unknown", Configuration.getSystemVersion(null)); assertEquals("Unknown", Configuration.getSystemVersion(null));
...@@ -50,15 +50,15 @@ public class ConfigurationTest extends CommonTestFunctions { ...@@ -50,15 +50,15 @@ public class ConfigurationTest extends CommonTestFunctions {
@Test @Test
public void testGetSystemBuildVersion() { public void testGetSystemBuildVersion() {
assertEquals("100", Configuration.getSystemBuildVersion("testFiles/version/", true)); assertEquals("78606521500fd349b603a77e9f64cfe57517c1a6", Configuration.getSystemBuildVersion("testFiles/version/", true));
assertEquals("100", Configuration.getSystemBuildVersion(null, false)); assertEquals("78606521500fd349b603a77e9f64cfe57517c1a6", Configuration.getSystemBuildVersion(null, false));
assertEquals("101", Configuration.getSystemVersion("testFiles/version/", true)); assertEquals("16.0.0~alpha.2", Configuration.getSystemVersion("testFiles/version/", true));
} }
@Test @Test
public void testGetSystemBuild() { public void testGetSystemBuild() {
assertEquals("102", Configuration.getSystemBuild("testFiles/version/", true)); assertEquals("2021-03-29T08:44:16+0200", Configuration.getSystemBuild("testFiles/version/", true));
assertEquals("102", Configuration.getSystemBuild(null, false)); assertEquals("2021-03-29T08:44:16+0200", Configuration.getSystemBuild(null, false));
} }
@Test @Test
...@@ -83,9 +83,12 @@ public class ConfigurationTest extends CommonTestFunctions { ...@@ -83,9 +83,12 @@ public class ConfigurationTest extends CommonTestFunctions {
} }
@Test @Test
public void testLoadInvalidSystemVersion() { public void testLoadMissingSystemVersion() {
Configuration.loadSystemVersion(new File("testFiles/version/INVALID_CHANGELOG")); FrameworkVersion version = Configuration.getFrameworkVersion("testFiles/invalid_version/");
assertEquals(1, super.getErrors().size()); assertEquals("Unknown", version.getGitVersion());
assertEquals("Unknown", version.getTime());
assertEquals("Unknown", version.getVersion());
assertEquals(1, super.getWarnings().size());
} }
@Test @Test
......
Manifest-Version: 1.0
Created-By: Apache Maven 3.6.3
Built-By: gawi
Build-Jdk: 11.0.10
minerva (101) stable; urgency=medium
* Initial release
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 4 Dec 2013 22:00:00 +0200
\ No newline at end of file
blablabla
\ No newline at end of file
Manifest-Version: 1.0
Created-By: Apache Maven 3.6.3
Built-By: gawi
Build-Jdk: 11.0.10
git-timestamp: 2021-03-29T08:44:16+0200
git-version: 78606521500fd349b603a77e9f64cfe57517c1a6
version: 16.0.0~alpha.2
100
102
\ No newline at end of file
...@@ -56,9 +56,9 @@ public class ConfigurationController extends BaseController { ...@@ -56,9 +56,9 @@ public class ConfigurationController extends BaseController {
result.put("unitTypes", configurationRestImpl.getUnitTypes()); result.put("unitTypes", configurationRestImpl.getUnitTypes());
result.put("modificationStateTypes", configurationRestImpl.getModificationStateTypes()); result.put("modificationStateTypes", configurationRestImpl.getModificationStateTypes());
result.put("privilegeTypes", configurationRestImpl.getPrivilegeTypes()); result.put("privilegeTypes", configurationRestImpl.getPrivilegeTypes());
result.put("version", configurationService.getSystemSvnVersion(context.getRealPath("/"))); result.put("version", configurationService.getSystemSvnVersion(context.getRealPath("/") + "META-INF/"));
result.put("buildDate", configurationService.getSystemBuild(context.getRealPath("/"))); result.put("buildDate", configurationService.getSystemBuild(context.getRealPath("/") + "META-INF/"));
result.put("gitHash", configurationService.getSystemGitVersion(context.getRealPath("/"))); result.put("gitHash", configurationService.getSystemGitVersion(context.getRealPath("/") + "META-INF/"));
result.put("annotators", configurationRestImpl.getAnnotators()); result.put("annotators", configurationRestImpl.getAnnotators());
result.put("bioEntityFields", configurationRestImpl.getBioEntityFields()); result.put("bioEntityFields", configurationRestImpl.getBioEntityFields());
return result; return result;
......
...@@ -41,7 +41,7 @@ public class MinervaNetController extends BaseController { ...@@ -41,7 +41,7 @@ public class MinervaNetController extends BaseController {
@PostMapping(value = "/submitError") @PostMapping(value = "/submitError")
public void submitError(@RequestBody ErrorReport report) throws IOException { public void submitError(@RequestBody ErrorReport report) throws IOException {
String version = configurationService.getSystemSvnVersion(context.getRealPath("/")); String version = configurationService.getSystemSvnVersion(context.getRealPath("/") + "META-INF/");
report.setVersion(version); report.setVersion(version);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
......
...@@ -152,11 +152,6 @@ public class ConfigurationService implements IConfigurationService { ...@@ -152,11 +152,6 @@ public class ConfigurationService implements IConfigurationService {
return runtime.maxMemory() / MEGABYTE_SIZE; return runtime.maxMemory() / MEGABYTE_SIZE;
} }
@Override
public FrameworkVersion getSystemVersion(String baseDir) {
return lcsb.mapviewer.common.Configuration.getFrameworkVersion(baseDir);
}
@Override @Override
public String getSystemBuild(String baseDir) { public String getSystemBuild(String baseDir) {
return lcsb.mapviewer.common.Configuration.getSystemBuild(baseDir); return lcsb.mapviewer.common.Configuration.getSystemBuild(baseDir);
......
...@@ -81,17 +81,6 @@ public interface IConfigurationService { ...@@ -81,17 +81,6 @@ public interface IConfigurationService {
*/ */
Long getMaxMemory(); Long getMaxMemory();
/**
* Returns currently build framework version.
*
* @param baseDir
* directory where the system is placed
* @return currently build {@link FrameworkVersion framework version}
* @throws InvalidSvnVersionException
* thrown when the git version of the build system is invalid
*/
FrameworkVersion getSystemVersion(String baseDir);
/** /**
* Returns system {@link lcsb.mapviewer.common.Configuration#systemBuild build * Returns system {@link lcsb.mapviewer.common.Configuration#systemBuild build
* date}. * date}.
......
...@@ -52,28 +52,6 @@ public class ConfigurationServiceTest extends ServiceTestFunctions { ...@@ -52,28 +52,6 @@ public class ConfigurationServiceTest extends ServiceTestFunctions {
assertEquals(ConfigurationElementType.values().length, list.size()); assertEquals(ConfigurationElementType.values().length, list.size());
} }
@Test
public void testGetSystemVersion() throws Exception {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testNormal/");
assertNotNull(view);
assertEquals("100", view.getGitVersion());
assertEquals("202", view.getVersion());
}
@Test
public void testGetSystemVersion2() throws Exception {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testModified/");
assertNotNull(view);
assertEquals("100:105", view.getGitVersion());
}
@Test
public void testGetSystemVersion3() throws Exception {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testCorrectSvn/");
assertNotNull(view);
assertEquals("117", view.getGitVersion());
}
@Test @Test
public void testGetConfiguratioElemntForPrivilege() throws Exception { public void testGetConfiguratioElemntForPrivilege() throws Exception {
for (PrivilegeType type : PrivilegeType.values()) { for (PrivilegeType type : PrivilegeType.values()) {
......
117
23/03/2015 10:58
\ No newline at end of file
100:105
23/03/2015 10:58
\ No newline at end of file
minerva (202) stable; urgency=medium
* Initial release
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 4 Dec 2013 22:00:00 +0200
\ No newline at end of file
100
23/03/2015 10:58
\ No newline at end of file
...@@ -103,7 +103,7 @@ public class VersionResourceHandler extends ResourceHandlerWrapper { ...@@ -103,7 +103,7 @@ public class VersionResourceHandler extends ResourceHandlerWrapper {
private String getVersion() { private String getVersion() {
if (version == null) { if (version == null) {
try { try {
version = new ConfigurationService(null, null).getSystemGitVersion(getPath()); version = new ConfigurationService(null, null).getSystemGitVersion(getPath() + "META-INF/");
} catch (Exception e) { } catch (Exception e) {
logger.error(e, e); logger.error(e, e);
version = "UNKNOWN"; version = "UNKNOWN";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment