Die Migration der Bereiche "Docker Registry" und "Artifiacts" ist fast abgeschlossen. Die letzten Daten werden im Laufe des heutigen Abend (05.08.2021) noch vollständig hochgeladen. Das Anlegen neuer Images und Artifacts funktioniert bereits wieder.

Commit 06848f58 authored by Jean-Marc Ronck's avatar Jean-Marc Ronck
Browse files

Fixes new routine for Linux (5).

parent 62a8b84c
Pipeline #73332 passed with stage
in 6 minutes and 22 seconds
package de.monticore.lang.monticar.visualization.emam.resources;
import java.io.IOException;
import java.io.InputStream;
public interface ResourcesService {
boolean isPackaged();
void addResource(String id, String resource);
String getResource(String id);
InputStream getResourceAsStream(String id);
InputStream getResourceAsStream(String id) throws IOException;
}
......@@ -2,9 +2,12 @@ package de.monticore.lang.monticar.visualization.emam.resources;
import de.monticore.lang.monticar.visualization.emam.application.Application;
import de.monticore.lang.monticar.visualization.emam.application.ApplicationContribution;
import org.apache.commons.io.FileUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
......@@ -34,19 +37,14 @@ public class ResourcesServiceImpl implements ResourcesService, ApplicationContri
}
@Override
public void addResource(String id, String resource) {
if (this.resources.containsKey(id)) this.logger.warning("A resource under the id of " + id + " was already registered");
else this.resources.put(id, this.relativize(resource, 7)); //Linux
public boolean isPackaged() {
return ResourcesServiceImpl.class.getResource("ResourcesServiceImpl.class").toString().startsWith("jar:");
}
protected String relativize(String resource, int depth) {
StringBuilder relativePart = new StringBuilder();
for (int i = 0; i < depth; i++) {
relativePart.append("../");
}
return relativePart.toString() + resource;
@Override
public void addResource(String id, String resource) {
if (this.resources.containsKey(id)) this.logger.warning("A resource under the id of " + id + " was already registered");
else this.resources.put(id, resource);
}
@Override
......@@ -55,9 +53,20 @@ public class ResourcesServiceImpl implements ResourcesService, ApplicationContri
}
@Override
public InputStream getResourceAsStream(String id) {
public InputStream getResourceAsStream(String id) throws IOException {
String resource = this.resources.get(id);
return ResourcesServiceImpl.class.getResourceAsStream(resource);
if (this.isPackaged()) return this.getPackagedResourceAsStream(resource);
else return this.getUnpackagedResourceAsStream(resource);
}
protected InputStream getPackagedResourceAsStream(String resource) {
return ResourcesServiceImpl.class.getClassLoader().getResourceAsStream(resource);
}
protected InputStream getUnpackagedResourceAsStream(String resource) throws IOException {
File resourceFile = new File("src/main/resources/" + resource);
return FileUtils.openInputStream(resourceFile);
}
}
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