Skip to content

Commit 25e989b

Browse files
Add project information file (#240)
* add project information file * add changelog info
1 parent 5fd71bc commit 25e989b

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This project adheres to `Semantic Versioning <https://semver.org/>`_.
1212

1313
**Added**
1414

15+
* Add ProjectInformation.java to groovy portlets
16+
1517
* speedup runtime of groovy osgi portlets
1618

1719
**Fixed**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package life.qbic.portal.portlet;
2+
3+
import java.io.IOException;
4+
import java.util.Properties;
5+
import org.osgi.framework.Bundle;
6+
import org.osgi.framework.FrameworkUtil;
7+
8+
/**
9+
* Shows the portlet information
10+
* <p>
11+
* This class can be used when the bundle description is missing
12+
*
13+
* @since: 2.6.2
14+
*/
15+
public class PortletInformation {
16+
17+
private String portletName;
18+
private String portletVersion;
19+
private String portletRepoURL;
20+
21+
public PortletInformation(){
22+
Bundle bundle = FrameworkUtil.getBundle({{ cookiecutter.main_class_prefix }}PortletUI.class);
23+
if (bundle == null) {
24+
tryToLoadProperties();
25+
} else {
26+
loadBundleProperties(bundle);
27+
}
28+
}
29+
30+
public String getPortletName() {
31+
return portletName;
32+
}
33+
34+
public String getPortletVersion() {
35+
return portletVersion;
36+
}
37+
38+
public String getPortletRepoURL() {
39+
return portletRepoURL;
40+
}
41+
42+
private void loadBundleProperties(Bundle bundle) {
43+
portletName = bundle.getHeaders().get("Bundle-Name");
44+
portletVersion = bundle.getVersion().toString();
45+
portletRepoURL = bundle.getHeaders().get("Bundle-DocURL");
46+
}
47+
48+
private void tryToLoadProperties() {
49+
try {
50+
loadProperties();
51+
} catch (IOException e){
52+
throw new RuntimeException(e);
53+
}
54+
}
55+
56+
private void loadProperties() throws IOException {
57+
final Properties properties = new Properties();
58+
properties.load(this.getClass().getClassLoader().getResourceAsStream("app.properties"));
59+
portletName = properties.getProperty("name");
60+
portletVersion = properties.getProperty("version");
61+
portletRepoURL = properties.getProperty("url");
62+
}
63+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name=${project.name}
2+
version=${project.version}
3+
symbolicName=${project.groupId}.${project.artifactId}
4+
url=${project.url}

0 commit comments

Comments
 (0)