Skip to content

Commit

Permalink
moved port and pid file to more general location. make these dirs inv…
Browse files Browse the repository at this point in the history
…isible on windows.
  • Loading branch information
mfleisch committed Jul 12, 2024
1 parent 21a7f75 commit a85041a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Map;

public class Workspace {
//this
public static final Path GLOBAL_SIRIUS_WORKSPACE;
public static final Path WORKSPACE;

public static final Path loggingPropFile;
Expand All @@ -45,15 +47,25 @@ public class Workspace {
final String version = PropertyManager.getProperty("de.unijena.bioinf.siriusFrontend.version");
final String[] versionParts = version.split("[.]");
//#################### start init workspace ################################
final String home = System.getProperty("user.home");
final Path home = Paths.get(System.getProperty("user.home"));
String defaultFolderName = PropertyManager.getProperty("de.unijena.bioinf.sirius.ws.default.name", null, ".sirius");
if (versionParts != null && versionParts.length > 1)
defaultFolderName = defaultFolderName + "-" + versionParts[0] + "." + versionParts[1];

final Path DEFAULT_WORKSPACE = Paths.get(home).resolve(defaultFolderName);
GLOBAL_SIRIUS_WORKSPACE = home.resolve(".sirius");
if(Files.notExists(GLOBAL_SIRIUS_WORKSPACE)){
Files.createDirectories(GLOBAL_SIRIUS_WORKSPACE);
try {
Files.setAttribute(GLOBAL_SIRIUS_WORKSPACE, "dos:hidden", true); //make hidden on windows
} catch (IOException e) {
System.err.println("WARNING: Could NOT set invisible property on SIRIUS global workspace directory.");
}
}

final Path DEFAULT_WORKSPACE = home.resolve(defaultFolderName);
final Map<String, String> env = System.getenv();

String ws = System.getProperty("de.unijena.bioinf.sirius.ws.location"); //todo dirty hack make cli parsing work correclty
String ws = System.getProperty("de.unijena.bioinf.sirius.ws.location"); //hack make cli parsing work correctly because PropertyManager might not be available at this time
if (ws == null)
ws = PropertyManager.getProperty("de.unijena.bioinf.sirius.ws.location");
if (ws == null)
Expand All @@ -65,8 +77,13 @@ public class Workspace {
} else if (Files.notExists(wsDir)) {
try {
Files.createDirectories(wsDir);
try {
Files.setAttribute(wsDir, "dos:hidden", true); //make hidden on windows
} catch (IOException e) {
System.err.println("WARNING: Could NOT set invisible property on SIRIUS workspace directory.");
}
} catch (IOException e) {
System.err.println("Could not create Workspace set in environment variable! Falling back to default Workspace - " + DEFAULT_WORKSPACE.toString());
System.err.println("Could not create Workspace set in environment variable! Falling back to default Workspace - " + DEFAULT_WORKSPACE);
e.printStackTrace();
wsDir = DEFAULT_WORKSPACE;
} finally {
Expand All @@ -83,6 +100,11 @@ public class Workspace {
if (Files.notExists(WORKSPACE)) {
try {
Files.createDirectories(WORKSPACE);
try {
Files.setAttribute(WORKSPACE, "dos:hidden", true); //make hidden on windows
} catch (IOException e) {
System.err.println("WARNING: Could NOT set invisible property on SIRIUS workspace directory.");
}
} catch (IOException e) {
System.err.println("Could NOT create Workspace");
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ public static void main(String[] args) {
System.err.println("SIRIUS Service is running on port: " + event.getWebServer().getPort());
System.err.println("SIRIUS Service started successfully!");
});
app.addListeners(new ApplicationPidFileWriter(Workspace.WORKSPACE.resolve("sirius.pid").toFile()));
app.addListeners(new WebServerPortFileWriter(Workspace.WORKSPACE.resolve("sirius.port").toFile()));
app.addListeners(new ApplicationPidFileWriter(Workspace.GLOBAL_SIRIUS_WORKSPACE
.resolve("sirius-" + ApplicationCore.VERSION_OBJ().getMajorVersion() + ".pid").toFile()));
app.addListeners(new WebServerPortFileWriter(Workspace.GLOBAL_SIRIUS_WORKSPACE
.resolve("sirius-" + ApplicationCore.VERSION_OBJ().getMajorVersion() + ".port").toFile()));


app.run(args);
} catch (IOException e) {
Expand Down

0 comments on commit a85041a

Please sign in to comment.