Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deprecated functions #1578

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2018 Lablicate GmbH.
* Copyright (c) 2014, 2023 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -13,6 +13,7 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

import org.eclipse.chemclipse.support.runtime.AbstractLinuxWineSupport;

Expand All @@ -21,6 +22,7 @@ public class LinuxWineSupport extends AbstractLinuxWineSupport implements IExten
private IAmdisSupport amdisSupport;

public LinuxWineSupport(String application, String parameter) throws FileNotFoundException {

super(application, parameter);
amdisSupport = new AmdisSupport(this);
}
Expand All @@ -29,7 +31,7 @@ public LinuxWineSupport(String application, String parameter) throws FileNotFoun
public int getSleepMillisecondsBeforeExecuteRunCommand() {

/*
* I've recognized that the e.g. NIST-DB sometimes don't start.
* Sometimes NIST-DB doesn't start.
* Does a sleep time preventing this?
*/
return 4000;
Expand All @@ -50,50 +52,29 @@ public IAmdisSupport getAmdisSupport() {
@Override
public Process executeKillCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(getKillCommand());
return process;
return getKillCommand().start();
}

@Override
public Process executeOpenCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(getOpenCommand());
return process;
return getOpenCommand().start();
}

private String getKillCommand() {
private ProcessBuilder getKillCommand() {

/*
* "pkill -f AMDIS"
*/
String command = "";
if(isValidApplicationExecutable()) {
StringBuilder builder = new StringBuilder();
builder.append("pkill -f");
builder.append(" ");
builder.append("AMDIS");
command = builder.toString();
}
return command;
return new ProcessBuilder("pkill", "-f", "AMDIS");
}

private String getOpenCommand() {
private ProcessBuilder getOpenCommand() {

/*
* "env WINEPREFIX=/home/eselmeister/.wine wine start C:\\programme\\nist\\AMDIS32-271\\AMDIS32$.exe"
*/
StringBuilder builder = new StringBuilder();
/*
* LINUX, UNIX
* "env WINEPREFIX=/home/chemclipse/.wine wine start C:\\programme\\nist\\AMDIS32-271\\AMDIS32$.exe"
*/
builder.append("env WINEPREFIX=");
builder.append(getWineEnvironment());
builder.append(" ");
builder.append("wine start");
builder.append(" ");
builder.append(getWineApplication().replace("AMDIS32$.exe", "AMDIS_32.exe")); // run the GUI version
return builder.toString();
String amdis = getWineApplication().replace("AMDIS32$.exe", "AMDIS_32.exe"); // run the GUI version
ProcessBuilder processBuilder = new ProcessBuilder("wine", "start", amdis);
Map<String, String> environment = processBuilder.environment();
environment.put("WINEPREFIX", getWineEnvironment());
return processBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2018 Lablicate GmbH.
* Copyright (c) 2014, 2023 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -21,6 +21,7 @@ public class WindowsSupport extends AbstractWindowsSupport implements IExtendedR
private IAmdisSupport amdisSupport;

public WindowsSupport(String application, String parameter) throws FileNotFoundException {

super(application, parameter);
amdisSupport = new AmdisSupport(this);
}
Expand All @@ -40,36 +41,32 @@ public IAmdisSupport getAmdisSupport() {
@Override
public Process executeOpenCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
return runtime.exec(getOpenCommand());
return getOpenCommand().start();
}

@Override
public Process executeKillCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
return runtime.exec(getKillCommand());
return getKillCommand().start();
}

private String getOpenCommand() {
private ProcessBuilder getOpenCommand() {

/*
* Returns e.g.: "C:\Programs\NIST\AMDIS32\AMDIS32$.exe
*/
StringBuilder builder = new StringBuilder();
builder.append(getApplication().replace("AMDIS32$.exe", "AMDIS_32.exe")); // run the GUI version
return builder.toString();
String amdis = getApplication().replace("AMDIS32$.exe", "AMDIS_32.exe"); // run the GUI version
return new ProcessBuilder(amdis);
}

private String getKillCommand() {
private ProcessBuilder getKillCommand() {

String command = "";
if(isValidApplicationExecutable()) {
/*
* taskkill kills the e.g. AMDIS application.
*/
command = "taskkill /f /IM AMDIS_32.exe";
return new ProcessBuilder("taskkill", "/f", "/IM", "AMDIS_32.exe");
}
return command;
return new ProcessBuilder();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2019 Lablicate GmbH.
* Copyright (c) 2008, 2023 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -15,6 +15,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

import org.eclipse.chemclipse.msd.identifier.supplier.nist.preferences.PreferenceSupplier;
import org.eclipse.chemclipse.support.runtime.AbstractLinuxWineSupport;
Expand All @@ -24,6 +25,7 @@ public class LinuxWineSupport extends AbstractLinuxWineSupport implements IExten
private final INistSupport nistSupport;

public LinuxWineSupport(File applicationFolder, String parameter) throws FileNotFoundException {

super(PreferenceSupplier.getNistExecutable(applicationFolder).getAbsolutePath(), parameter);
nistSupport = new NistSupport(this);
}
Expand Down Expand Up @@ -53,50 +55,35 @@ public INistSupport getNistSupport() {
@Override
public Process executeKillCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(getKillCommand());
return process;
return getKillCommand().start();
}

@Override
public Process executeOpenCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(getOpenCommand());
return process;
return getOpenCommand().start();
}

private String getKillCommand() {
private ProcessBuilder getKillCommand() {

/*
* "pkill -f nist"
*/
String command = "";
if(isValidApplicationExecutable()) {
StringBuilder builder = new StringBuilder();
builder.append("pkill -f");
builder.append(" ");
builder.append("nist");
command = builder.toString();
/*
* "pkill -f nist"
*/
return new ProcessBuilder("pkill", "-f", "nist");
}
return command;
return new ProcessBuilder();
}

private String getOpenCommand() {
private ProcessBuilder getOpenCommand() {

/*
* "env WINEPREFIX=/home/eselmeister/.wine wine start C:\\programme\\nist\\MSSEARCH\\nistms.exe"
*/
StringBuilder builder = new StringBuilder();
/*
* LINUX, UNIX
*/
builder.append("env WINEPREFIX=");
builder.append(getWineEnvironment());
builder.append(" ");
builder.append("wine start");
builder.append(" ");
builder.append(getWineApplication().replace("$.exe", ".exe")); // run the GUI version
return builder.toString();
String nistms = getWineApplication().replace("$.exe", ".exe"); // run the GUI version
ProcessBuilder processBuilder = new ProcessBuilder("wine", "start", nistms);
Map<String, String> environment = processBuilder.environment();
environment.put("WINEPREFIX", getWineEnvironment());
return processBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2019 Lablicate GmbH.
* Copyright (c) 2008, 2023 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -24,6 +24,7 @@ public class WindowsSupport extends AbstractWindowsSupport implements IExtendedR
private final INistSupport nistSupport;

public WindowsSupport(File applicationFolder, String parameter) throws FileNotFoundException {

super(PreferenceSupplier.getNistExecutable(applicationFolder).getAbsolutePath(), parameter);
nistSupport = new NistSupport(this);
}
Expand All @@ -43,26 +44,23 @@ public INistSupport getNistSupport() {
@Override
public Process executeOpenCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
return runtime.exec(getApplication());
return new ProcessBuilder(getApplication()).start();
}

@Override
public Process executeKillCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
return runtime.exec(getKillCommand());
return getKillCommand().start();
}

private String getKillCommand() {
private ProcessBuilder getKillCommand() {

String command = "";
if(isValidApplicationExecutable()) {
/*
* taskkill only kills the NIST-DB application.
*/
command = "taskkill /IM nistms.exe";
return new ProcessBuilder("taskkill", "/IM", "nistms.exe");
}
return command;
return new ProcessBuilder();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2020 Lablicate GmbH.
* Copyright (c) 2014, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -13,6 +13,7 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

public abstract class AbstractLinuxWineSupport extends AbstractWineRuntimeSupport implements IWineRuntimeSupport {

Expand All @@ -23,35 +24,25 @@ public abstract class AbstractLinuxWineSupport extends AbstractWineRuntimeSuppor
* @param application
* @param parameter
*/
public AbstractLinuxWineSupport(String application, String parameter) throws FileNotFoundException {
protected AbstractLinuxWineSupport(String application, String parameter) throws FileNotFoundException {

super(application, parameter);
}

@Override
public Process executeRunCommand() throws IOException {

Runtime runtime = Runtime.getRuntime();
return runtime.exec(getRunCommand());
return getRunCommand().start();
}

private String getRunCommand() {
private ProcessBuilder getRunCommand() {

/*
* "env WINEPREFIX=/home/eselmeister/.wine wine start C:\\programme\\nist\\MSSEARCH\\nistms$.exe /INSTRUMENT /PAR=2"
* "env WINEPREFIX=/home/chemclipse/.wine wine start C:\\programme\\nist\\MSSEARCH\\nistms$.exe /INSTRUMENT /PAR=2"
*/
StringBuilder builder = new StringBuilder();
/*
* LINUX, UNIX
*/
builder.append("env WINEPREFIX=");
builder.append(getWineEnvironment());
builder.append(" ");
builder.append("wine start");
builder.append(" ");
builder.append(getWineApplication());
builder.append(" ");
builder.append(getParameter());
return builder.toString();
ProcessBuilder processBuilder = new ProcessBuilder("wine", "start", getWineApplication(), getParameter());
Map<String, String> environment = processBuilder.environment();
environment.put("WINEPREFIX", getWineEnvironment());
return processBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2018 Lablicate GmbH.
* Copyright (c) 2014, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -27,7 +27,8 @@ public abstract class AbstractMacWineSupport extends AbstractWineRuntimeSupport
* @param macWineBinary
* (e.g. "/Applications/Wine.app")
*/
public AbstractMacWineSupport(String application, String parameter, String macWineBinary) throws FileNotFoundException {
protected AbstractMacWineSupport(String application, String parameter, String macWineBinary) throws FileNotFoundException {

super(application, parameter);
this.macWineBinary = macWineBinary;
}
Expand Down
Loading