Skip to content

Commit ca6d257

Browse files
committed
Cleaned up swagger documentation, made pythonLocation externally configurable, fixed some tests to also work under Windows, updated README.md
1 parent 9c24d6b commit ca6d257

19 files changed

+252
-192
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,45 @@ Dependencies that are needed to build and are not being downloaded via gradle:
2121

2222
- OpenJDK 17
2323
- Python 3
24+
- pip
2425

2526
`./gradlew -Pclean-release build`
2627

27-
## How to start
28+
### Python Location
2829

29-
`./gradlew bootRun`
30+
Currently, mapping-service requires Python to be installed in order to build and to run. By default, the Python location is set to `/usr/bin/python3`. In case
31+
your Python installation is located elsewhere or you build the mapping-service under Windows, you can provide the Python location externally, i.e.:
32+
33+
```
34+
`./gradlew -Pclean-release build -DpythonLocation=file:///C:/Python310/python.EXE`
35+
```
3036

31-
### Prerequisites
32-
Please make sure the application.properties file is configured correctly.
33-
Espacially the following properties (at the end of the file) are important:
34-
- `mapping-service.pythonLocation=file:///opt/homebrew/bin/python3` \
35-
Enter the loacation of your python3 installation. You can determine it by typing `which python3` in your terminal.
37+
## How to start
38+
39+
Before you can start the mapping-service, you first have to create an `application.properties` file in the source folder. As an example you may use `config/application.default.properties`
40+
and modify it according to your needs. Espacially the following properties (at the end of the file) are important:
41+
- `spring.datasource.url=jdbc:h2:file:e:/tmp/mapping-service/database`
42+
The path points to the location of the database in which your configured mappings are stored.
43+
- `mapping-service.pythonLocation=${pythonLocation:'file:///usr/bin/python3'}` \
44+
If no pythonLocation is provided externally (see above) the default `/usr/bin/python3` is used.
3645
- `mapping-service.mappingsLocation:file:///tmp/mapping-service/` \
3746
Enter the location where you want to store your mappings. This folder will be created if it does not exist yet.
3847

3948
You might want to add a plugin to make the service working. Normally, there should be a gemma-plugin-x.x.x.jar in the plugins folder.
4049
If not, you can find its source code [here](https://github.com/maximilianiKIT/gemma-plugin).
4150

51+
After doing this, the mapping-service is ready for the first start. This can be achieved by executing:
52+
53+
`./gradlew bootRun`
54+
55+
### Python Location
56+
57+
Similar to configuring the Python location for the build process, you may also do the same for running the mapping-service via:
58+
59+
```
60+
.\gradlew -DpythonLocation=file:///C:/Python310/python.EXE bootRun
61+
```
62+
4263
## License
4364

4465
See [LICENSE file in this repository](LICENSE).

build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ repositories {
3232

3333
ext {
3434
set('snippetsDir', file('build/generated-snippets'))
35-
applicationProperties = System.getProperty('applicationProperties', 'src/main/resources/application.properties')
35+
applicationProperties = System.getProperty('applicationProperties', './src/test/resources/test-config/application-test.properties')
36+
pythonLocation = System.getProperty('pythonLocation', 'file:///usr/bin/python3')
3637
}
3738

3839
dependencies {
@@ -85,6 +86,7 @@ test {
8586
finalizedBy jacocoTestReport
8687
print("Running tests with configuration: ${applicationProperties}")
8788
environment 'spring.config.location', applicationProperties
89+
environment 'pythonLocation', pythonLocation
8890
// environment 'spring.config.location', 'classpath:/test-config/'
8991
useJUnitPlatform()
9092
}
@@ -117,6 +119,11 @@ springBoot {
117119
buildInfo()
118120
}
119121

122+
bootRun {
123+
systemProperty "spring.config.location", "file:$projectDir/"
124+
systemProperty "pythonLocation", pythonLocation
125+
}
126+
120127
bootJar {
121128
dependsOn asciidoctor
122129
from ("${asciidoctor.outputDir}/html5") {

src/main/resources/application.properties renamed to config/application.default.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ management.endpoints.web.exposure.include=*
2424
# Database
2525
##################################################
2626
spring.datasource.driver-class-name=org.h2.Driver
27-
spring.datasource.url=jdbc:h2:file:///tmp/mapping-service/database
27+
spring.datasource.url=jdbc:h2:file:e:/tmp/mapping-service/database
2828
spring.datasource.username=user
2929
spring.datasource.password=password
3030
spring.jpa.hibernate.ddl-auto=update
@@ -33,7 +33,7 @@ spring.jpa.hibernate.ddl-auto=update
3333
# Mapping-Service specific settings
3434
##################################################
3535
# Absolute path to the local python interpreter
36-
mapping-service.pythonLocation=file:///usr/bin/python3
36+
mapping-service.pythonLocation=${pythonLocation:'file:///usr/bin/python3'}
3737

3838
# Absolute path to the local gemma mappings folder
3939
mapping-service.mappingSchemasLocation=file:///tmp/mapping-service/mappingSchemas

echo.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo @1

output

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/java/edu/kit/datamanager/mappingservice/plugins/JARFileFilter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
public class JARFileFilter implements FileFilter {
2727

28+
@Override
2829
public boolean accept(File f) {
2930
return f.getName().toLowerCase().endsWith(".jar");
3031
}

src/main/java/edu/kit/datamanager/mappingservice/plugins/PluginLoader.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
1615
package edu.kit.datamanager.mappingservice.plugins;
1716

1817
import org.slf4j.Logger;
@@ -44,21 +43,31 @@ public class PluginLoader {
4443
*/
4544
static Logger LOG = LoggerFactory.getLogger(PluginLoader.class);
4645

46+
static ClassLoader cl = null;
47+
48+
public static void unload() {
49+
cl = null;
50+
System.gc();
51+
}
52+
4753
/**
4854
* Load plugins from a given directory.
4955
*
5056
* @param plugDir Directory containing plugins.
5157
* @return Map of plugins.
52-
* @throws IOException If there is an error with the file system.
53-
* @throws MappingPluginException If there is an error with the plugin or the input.
58+
* @throws IOException If there is an error with the file system.
59+
* @throws MappingPluginException If there is an error with the plugin or
60+
* the input.
5461
*/
5562
public static Map<String, IMappingPlugin> loadPlugins(File plugDir) throws IOException, MappingPluginException {
56-
if (plugDir == null || plugDir.getAbsolutePath().isBlank())
63+
if (plugDir == null || plugDir.getAbsolutePath().isBlank()) {
5764
throw new MappingPluginException(MappingPluginState.INVALID_INPUT, "Empty input!");
65+
}
5866
File[] plugJars = plugDir.listFiles(new JARFileFilter());
59-
if (plugJars == null || plugJars.length < 1)
67+
if (plugJars == null || plugJars.length < 1) {
6068
throw new MappingPluginException(MappingPluginState.NOT_FOUND, "No plugins found.");
61-
ClassLoader cl = new URLClassLoader(PluginLoader.fileArrayToURLArray(plugJars));
69+
}
70+
cl = new URLClassLoader(PluginLoader.fileArrayToURLArray(plugJars));
6271
List<Class<IMappingPlugin>> plugClasses = PluginLoader.extractClassesFromJARs(plugJars, cl);
6372

6473
List<IMappingPlugin> IMappingPluginList = PluginLoader.createPluggableObjects(plugClasses);
@@ -71,7 +80,6 @@ public static Map<String, IMappingPlugin> loadPlugins(File plugDir) throws IOExc
7180
return result;
7281
}
7382

74-
7583
private static URL[] fileArrayToURLArray(File[] files) throws MalformedURLException {
7684

7785
URL[] urls = new URL[files.length];
@@ -93,22 +101,22 @@ private static List<Class<IMappingPlugin>> extractClassesFromJARs(File[] jars, C
93101
private static List<Class<IMappingPlugin>> extractClassesFromJAR(File jar, ClassLoader cl) throws IOException, MappingPluginException {
94102

95103
List<Class<IMappingPlugin>> classes = new ArrayList<>();
96-
JarInputStream jaris = new JarInputStream(new FileInputStream(jar));
97-
JarEntry ent;
98-
while ((ent = jaris.getNextJarEntry()) != null) {
99-
if (ent.getName().toLowerCase().endsWith(".class")) {
100-
try {
101-
Class<?> cls = cl.loadClass(ent.getName().substring(0, ent.getName().length() - 6).replace('/', '.'));
102-
if (PluginLoader.isPluggableClass(cls)) {
103-
classes.add((Class<IMappingPlugin>) cls);
104+
try (JarInputStream jaris = new JarInputStream(new FileInputStream(jar))) {
105+
JarEntry ent;
106+
while ((ent = jaris.getNextJarEntry()) != null) {
107+
if (ent.getName().toLowerCase().endsWith(".class")) {
108+
try {
109+
Class<?> cls = cl.loadClass(ent.getName().substring(0, ent.getName().length() - 6).replace('/', '.'));
110+
if (PluginLoader.isPluggableClass(cls)) {
111+
classes.add((Class<IMappingPlugin>) cls);
112+
}
113+
} catch (ClassNotFoundException e) {
114+
LOG.info("Can't load Class " + ent.getName());
115+
throw new MappingPluginException(MappingPluginState.UNKNOWN_ERROR, "Can't load Class " + ent.getName(), e);
104116
}
105-
} catch (ClassNotFoundException e) {
106-
LOG.info("Can't load Class " + ent.getName());
107-
throw new MappingPluginException(MappingPluginState.UNKNOWN_ERROR, "Can't load Class " + ent.getName(), e);
108117
}
109118
}
110119
}
111-
jaris.close();
112120
return classes;
113121
}
114122

src/main/java/edu/kit/datamanager/mappingservice/plugins/PluginManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public static PluginManager soleInstance() {
6666
return soleInstance;
6767
}
6868

69+
public void unload(){
70+
PluginLoader.unload();
71+
plugins.clear();
72+
}
6973
/**
7074
* Reloads the plugins from the 'plugins' directory.
7175
*/

0 commit comments

Comments
 (0)