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;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Manifest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -215,25 +216,17 @@ public final class Configuration {
systemBuildVersion = "Unknown";
systemBuildTime = "Unknown";
systemVersion = "Unknown";
File buildVersionFile = null;
File changelogFile = null;
File manifestFile = null;
if (baseDir == null) {
buildVersionFile = new File("version.txt");
changelogFile = new File("CHANGELOG");
manifestFile = new File("META-INF/MANIFEST.MF");
} else {
buildVersionFile = new File(baseDir + "version.txt");
changelogFile = new File(baseDir + "CHANGELOG");
manifestFile = new File(baseDir + "MANIFEST.MF");
}
if (buildVersionFile.exists()) {
loadSystemBuildVersion(buildVersionFile);
if (manifestFile.exists()) {
loadSystemBuildVersion(manifestFile);
} else {
logger.error(buildVersionFile.getAbsoluteFile() + " doesn't exist.");
}
if (changelogFile.exists()) {
loadSystemVersion(changelogFile);
} else {
logger.error(changelogFile.getAbsoluteFile() + " doesn't exist.");
logger.error(manifestFile.getAbsoluteFile() + " doesn't exist.", new Exception());
}
}
......@@ -245,35 +238,27 @@ public final class Configuration {
*/
protected static void loadSystemBuildVersion(File file) {
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
systemBuildVersion = reader.readLine().trim();
systemBuildTime = reader.readLine().trim();
reader.close();
} catch (IOException e) {
logger.error(e);
boolean problem = false;
Manifest manifest = new Manifest(new FileInputStream(file));
systemBuildTime = manifest.getMainAttributes().getValue("git-timestamp");
if (systemBuildTime == null) {
systemBuildTime = "Unknown";
problem = true;
}
systemBuildVersion = manifest.getMainAttributes().getValue("git-version");
if (systemBuildVersion == null) {
systemBuildVersion = "Unknown";
problem = true;
}
systemVersion = manifest.getMainAttributes().getValue("version");
if (systemVersion == null) {
systemVersion = "Unknown";
problem = true;
}
/**
* Loads system version from debian changelog file.
*
* @param file
* debian changelog file
*/
protected static void loadSystemVersion(File file) {
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
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);
if (problem) {
logger.warn("MANIFEST.MF file does not contain required information.");
}
reader.close();
} catch (IOException e) {
logger.error(e);
}
......
......@@ -42,7 +42,7 @@ public class ConfigurationTest extends CommonTestFunctions {
@Test
public void testLoadSystemBuildVersion2() {
Configuration.loadSystemVersion((String) null);
Configuration.loadSystemVersion(new File("unknown.xxx"));
Configuration.loadSystemVersion("/tmp");
assertEquals("Unknown", Configuration.getSystemBuildVersion(null));
assertEquals("Unknown", Configuration.getSystemBuild(null));
assertEquals("Unknown", Configuration.getSystemVersion(null));
......@@ -50,15 +50,15 @@ public class ConfigurationTest extends CommonTestFunctions {
@Test
public void testGetSystemBuildVersion() {
assertEquals("100", Configuration.getSystemBuildVersion("testFiles/version/", true));
assertEquals("100", Configuration.getSystemBuildVersion(null, false));
assertEquals("101", Configuration.getSystemVersion("testFiles/version/", true));
assertEquals("78606521500fd349b603a77e9f64cfe57517c1a6", Configuration.getSystemBuildVersion("testFiles/version/", true));
assertEquals("78606521500fd349b603a77e9f64cfe57517c1a6", Configuration.getSystemBuildVersion(null, false));
assertEquals("16.0.0~alpha.2", Configuration.getSystemVersion("testFiles/version/", true));
}
@Test
public void testGetSystemBuild() {
assertEquals("102", Configuration.getSystemBuild("testFiles/version/", true));
assertEquals("102", Configuration.getSystemBuild(null, false));
assertEquals("2021-03-29T08:44:16+0200", Configuration.getSystemBuild("testFiles/version/", true));
assertEquals("2021-03-29T08:44:16+0200", Configuration.getSystemBuild(null, false));
}
@Test
......@@ -83,9 +83,12 @@ public class ConfigurationTest extends CommonTestFunctions {
}
@Test
public void testLoadInvalidSystemVersion() {
Configuration.loadSystemVersion(new File("testFiles/version/INVALID_CHANGELOG"));
assertEquals(1, super.getErrors().size());
public void testLoadMissingSystemVersion() {
FrameworkVersion version = Configuration.getFrameworkVersion("testFiles/invalid_version/");
assertEquals("Unknown", version.getGitVersion());
assertEquals("Unknown", version.getTime());
assertEquals("Unknown", version.getVersion());
assertEquals(1, super.getWarnings().size());
}
@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 {
result.put("unitTypes", configurationRestImpl.getUnitTypes());
result.put("modificationStateTypes", configurationRestImpl.getModificationStateTypes());
result.put("privilegeTypes", configurationRestImpl.getPrivilegeTypes());
result.put("version", configurationService.getSystemSvnVersion(context.getRealPath("/")));
result.put("buildDate", configurationService.getSystemBuild(context.getRealPath("/")));
result.put("gitHash", configurationService.getSystemGitVersion(context.getRealPath("/")));
result.put("version", configurationService.getSystemSvnVersion(context.getRealPath("/") + "META-INF/"));
result.put("buildDate", configurationService.getSystemBuild(context.getRealPath("/") + "META-INF/"));
result.put("gitHash", configurationService.getSystemGitVersion(context.getRealPath("/") + "META-INF/"));
result.put("annotators", configurationRestImpl.getAnnotators());
result.put("bioEntityFields", configurationRestImpl.getBioEntityFields());
return result;
......
......@@ -41,7 +41,7 @@ public class MinervaNetController extends BaseController {
@PostMapping(value = "/submitError")
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);
ObjectMapper mapper = new ObjectMapper();
......
......@@ -152,11 +152,6 @@ public class ConfigurationService implements IConfigurationService {
return runtime.maxMemory() / MEGABYTE_SIZE;
}
@Override
public FrameworkVersion getSystemVersion(String baseDir) {
return lcsb.mapviewer.common.Configuration.getFrameworkVersion(baseDir);
}
@Override
public String getSystemBuild(String baseDir) {
return lcsb.mapviewer.common.Configuration.getSystemBuild(baseDir);
......
......@@ -81,17 +81,6 @@ public interface IConfigurationService {
*/
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
* date}.
......
......@@ -52,28 +52,6 @@ public class ConfigurationServiceTest extends ServiceTestFunctions {
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
public void testGetConfiguratioElemntForPrivilege() throws Exception {
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 {
private String getVersion() {
if (version == null) {
try {
version = new ConfigurationService(null, null).getSystemGitVersion(getPath());
version = new ConfigurationService(null, null).getSystemGitVersion(getPath() + "META-INF/");
} catch (Exception e) {
logger.error(e, e);
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