Skip to content

Commit 05fbaec

Browse files
committed
Added new mapping-plugin-core dependency, upgraded plugin code to AbstractPythonMappingPlugin, removed unneeded stuff from build.gradle including spring-boot, added standalone toml dependency to build.gradle
1 parent 9951a8d commit 05fbaec

File tree

2 files changed

+41
-103
lines changed

2 files changed

+41
-103
lines changed

mappingservice-plugin/build.gradle

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
import org.tomlj.Toml
1+
buildscript {
2+
// Buildscript repositories
3+
repositories {
4+
mavenLocal()
5+
mavenCentral()
6+
}
7+
8+
dependencies {
9+
classpath("org.tomlj:tomlj:1.1.1")
10+
}
11+
}
212

313
plugins {
4-
id 'io.spring.dependency-management' version "1.1.7"
5-
id 'org.springframework.boot' version "3.4.4"
614
id 'java'
715
}
816

9-
group 'edu.kit.datamanager'
17+
import org.tomlj.Toml
1018

19+
// Project repositories
1120
repositories {
1221
mavenLocal()
1322
mavenCentral()
1423
}
1524

1625
dependencies {
17-
implementation 'org.springframework:spring-core:6.2.5'
18-
implementation 'org.slf4j:slf4j-api:2.0.17'
19-
implementation files("src/main/lib/mapping-service-plain.jar")
26+
implementation 'edu.kit.datamanager:mapping-plugin-core:2.0.0'
2027
}
2128

2229
if (System.getenv('VERSION_OVERRIDE_BY_BRANCH')) {
@@ -32,22 +39,26 @@ tasks.register('printVersion') {
3239
println project.version
3340
}
3441

42+
group 'edu.kit.datamanager'
43+
3544
//Task for creating a resource file with the version info
3645
tasks.register("generateVersionProps", WriteProperties) { t ->
3746
def generatedResourcesDir = project.layout.buildDirectory.dir(["resources", "main"].join(File.separator))
38-
def outputFile = generatedResourcesDir.map { it.file("sempluginversion.properties") }
47+
def outputFile = generatedResourcesDir.map { it.file("genericsemtojson.properties") }
3948

4049
t.destinationFile = outputFile.get().asFile
4150
t.property("version", project.version)
51+
//add if required
52+
//t.property("min.python", "3.0.0")
4253
}
4354

44-
resolveMainClassName.dependsOn("generateVersionProps")
55+
//resolveMainClassName.dependsOn("generateVersionProps")
4556

4657
jar {
4758
dependsOn(generateVersionProps)
4859
archiveFileName
4960
}
5061

51-
bootJar {
62+
/*bootJar {
5263
enabled = false
53-
}
64+
}*/
Lines changed: 19 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,15 @@
11
package edu.kit.datamanager.semplugin;
22

3-
import edu.kit.datamanager.mappingservice.exception.PluginInitializationFailedException;
4-
import edu.kit.datamanager.mappingservice.plugins.*;
5-
import edu.kit.datamanager.mappingservice.util.*;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
8-
import org.springframework.util.MimeType;
9-
import org.springframework.util.MimeTypeUtils;
10-
11-
import java.io.IOException;
12-
import java.io.InputStream;
13-
import java.net.URL;
3+
import edu.kit.datamanager.mappingservice.plugins.AbstractPythonMappingPlugin;
144
import java.nio.file.Path;
15-
import java.util.Properties;
16-
17-
public class SEMImagePlugin implements IMappingPlugin {
185

19-
private static String version;
6+
public class SEMImagePlugin extends AbstractPythonMappingPlugin {
207

21-
private final Logger LOGGER = LoggerFactory.getLogger(SEMImagePlugin.class);
22-
private final String REPOSITORY = "https://github.com/kit-data-manager/tomo_mapper";
23-
private String TAG;
24-
private Path dir;
8+
private static final String REPOSITORY = "https://github.com/kit-data-manager/tomo_mapper";
259

26-
private String pluginVenv = "venv/PluginVenv";
27-
private String venvInterpreter;
2810

2911
public SEMImagePlugin() {
30-
try {
31-
// Get the context class loader
32-
ClassLoader classLoader = this.getClass().getClassLoader();
33-
// TODO: do we need to make sure that the resource path is somehow related to the current plugin to avoid loading the wrong property file in case of identical property names?
34-
URL resource = classLoader.getResource("sempluginversion.properties");
35-
LOGGER.info("Resource file: {}", resource);
36-
if (resource != null) {
37-
// Load the properties file
38-
try (InputStream input = resource.openStream()) {
39-
Properties properties = new Properties();
40-
properties.load(input);
41-
version = properties.getProperty("version");
42-
TAG = version;
43-
}
44-
} else {
45-
System.err.println("Properties file not found!");
46-
version = "unavailable";
47-
TAG = "unavailable";
48-
}
49-
50-
if (System.getProperty("os.name").startsWith("Windows")) {
51-
venvInterpreter = pluginVenv + "/Scripts/python.exe";
52-
} else {
53-
venvInterpreter = pluginVenv + "/bin/python3";
54-
}
55-
56-
} catch (IOException e) {
57-
throw new PluginInitializationFailedException("Failed to instantiate plugin class.", e);
58-
}
12+
super("GenericSEMtoJSON", REPOSITORY);
5913
}
6014

6115
@Override
@@ -69,53 +23,26 @@ public String description() {
6923
}
7024

7125
@Override
72-
public String version() {
73-
return version;
74-
}
75-
76-
@Override
77-
public String uri() {
78-
return REPOSITORY;
79-
}
80-
81-
@Override
82-
public MimeType[] inputTypes() {
83-
return new MimeType[]{MimeTypeUtils.parseMimeType("image/tiff")}; //should currently be IMAGE/TIFF
84-
}
85-
86-
@Override
87-
public MimeType[] outputTypes() {
88-
return new MimeType[]{MimeTypeUtils.APPLICATION_JSON};
26+
public String[] inputTypes() {
27+
return new String[]{"image/tiff"};
8928
}
9029

9130
@Override
92-
public void setup() {
93-
LOGGER.trace("Setting up mapping plugin {} {}", name(), version());
94-
//TODO: test for minimal python version?
95-
try {
96-
LOGGER.info("Cloning git repository {}, Tag {}", REPOSITORY, TAG);
97-
dir = FileUtil.cloneGitRepository(REPOSITORY, TAG);
98-
// Install Python dependencies
99-
MappingPluginState venvState = PythonRunnerUtil.runPythonScript("-m", "venv", "--system-site-packages", dir + "/" + pluginVenv);
100-
if (MappingPluginState.SUCCESS().getState().equals(venvState.getState())) {
101-
LOGGER.info("Venv for plugin installed successfully. Installing packages.");
102-
ShellRunnerUtil.run(dir + "/" + venvInterpreter, "-m", "pip", "install", "-r", dir + "/" + "requirements.dist.txt");
103-
} else {
104-
throw new PluginInitializationFailedException("Venv installation was not successful. Status: " + venvState.getState());
105-
}
106-
} catch (MappingPluginException e) {
107-
throw new PluginInitializationFailedException("Unexpected error during plugin setup.", e);
108-
}
31+
public String[] outputTypes() {
32+
return new String[]{"application/json"};
10933
}
11034

11135
@Override
112-
public MappingPluginState mapFile(Path mappingFile, Path inputFile, Path outputFile) throws MappingPluginException {
113-
long startTime = System.currentTimeMillis();
114-
LOGGER.trace("Run SEM-Mapping-Tool on '{}' with mapping '{}' -> '{}'", mappingFile, inputFile, outputFile);
115-
MappingPluginState result = ShellRunnerUtil.run(dir + "/" + venvInterpreter, dir + "/plugin_wrapper.py", "sem", "-m", mappingFile.toString(), "-i", inputFile.toString(), "-o", outputFile.toString());
116-
long endTime = System.currentTimeMillis();
117-
long totalTime = endTime - startTime;
118-
LOGGER.info("Execution time of mapFile: {} milliseconds", totalTime);
119-
return result;
36+
public String[] getCommandArray(Path workingDir, Path mappingFile, Path inputFile, Path outputFile) {
37+
return new String[]{
38+
workingDir + "/plugin_wrapper.py",
39+
"sem",
40+
"-m",
41+
mappingFile.toString(),
42+
"-i",
43+
inputFile.toString(),
44+
"-o",
45+
outputFile.toString()
46+
};
12047
}
12148
}

0 commit comments

Comments
 (0)