Skip to content

Commit f047173

Browse files
committed
Added a helper method to return the version
1 parent 2bdda74 commit f047173

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

org.bridgedb/src/main/java/org/bridgedb/BridgeDb.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
//
1717
package org.bridgedb;
1818

19+
import java.io.IOException;
20+
import java.io.InputStream;
1921
import java.util.HashMap;
2022
import java.util.Map;
23+
import java.util.Properties;
2124

2225
/**
2326
* Central access point for connecting to IDMappers.
@@ -69,4 +72,23 @@ public static void register(String protocol, Driver driver)
6972
{
7073
drivers.put(protocol, driver);
7174
}
75+
76+
private static volatile String version;
77+
78+
/**
79+
* Returns the version of BridgeDb.
80+
*/
81+
public static String getVersion() {
82+
if (version != null) return version;
83+
try (InputStream stream = BridgeDb.class.getResourceAsStream("/version.props")) {
84+
Properties props = new Properties();
85+
props.load(stream);
86+
version = props.getProperty("bridgedb.version");
87+
return version;
88+
} catch (IOException exception) {
89+
exception.printStackTrace();
90+
}
91+
return null;
92+
}
93+
7294
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright (c) 2025 Egon Willighagen <egonw@users.sf.net>
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
8+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
* See the License for the specific language governing permissions and limitations under the License.
10+
*/
11+
package org.bridgedb;
12+
13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
import org.junit.jupiter.api.Test;
17+
18+
public class BridgeDbTest {
19+
20+
@Test
21+
public void testVersion() {
22+
String version = BridgeDb.getVersion();
23+
assertNotNull(version);
24+
assertTrue(version.startsWith("3."));
25+
}
26+
}

0 commit comments

Comments
 (0)