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

Set user directory for openoffice processes #125

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
YARG-34 Log information from LibreOffice output using slf4j-api
(cherry picked from commit bce6a82)
  • Loading branch information
Andrey Subbotin authored and IlyaChekashkin committed Feb 6, 2020
commit bdee7e7819f0b0ef46e872c0607bc5820f68a9b2
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* http:https://udk.openoffice.org/source/browse/udk/javaunohelper/com/sun/star/comp/helper/Bootstrap.java?view=markup
*/
public class OOServer {
protected static final Logger log = LoggerFactory.getLogger(JavaProcessManager.class);
protected static final Logger log = LoggerFactory.getLogger(OOServer.class);
/**
* The OOo server process.
*/
Expand Down Expand Up @@ -99,7 +99,7 @@ public OOServer(String oooExecFolder, List<String> oooOptions, String host, int
* the pipe name "oooPipe" the accept option looks like this:
* - accept option : -accept=pipe,name=oooPipe;urp;
*/
public void start() throws BootstrapException, IOException {
public synchronized void start() throws BootstrapException, IOException {
// find office executable relative to this class's class loader
String sOffice = System.getProperty("os.name").startsWith("Windows") ? "soffice.exe" : "soffice";
//accept option !Note! we are using old version notation (- instead of --) to support old version of office
Expand Down Expand Up @@ -127,8 +127,8 @@ public void start() throws BootstrapException, IOException {
// start office process
oooProcess = Runtime.getRuntime().exec(argumentsList.toArray(new String[0]));

pipe(oooProcess.getInputStream(), System.out, "CO> ");
pipe(oooProcess.getErrorStream(), System.err, "CE> ");
pipe(oooProcess.getInputStream(), "OUT");
pipe(oooProcess.getErrorStream(), "ERR");
}

public String toUrl(File file) {
Expand All @@ -143,18 +143,18 @@ public String toUrl(File file) {
* nothing.
* If there has been a previous start, kill destroys the process.
*/
public void kill() {
public synchronized void kill() {
if (oooProcess != null) {
log.info("OOServer is killing office instance with port " + port);
log.info("OOServer is killing office instance with port {}", port);
List<Long> pids = processManager.findPid(host, port);
processManager.kill(oooProcess, pids);
oooProcess = null;
deleteProfileDir();
}
}

private static void pipe(final InputStream in, final PrintStream out, final String prefix) {
new Thread("Pipe: " + prefix) {
protected void pipe(final InputStream in, final String prefix) {
new Thread(String.format("OOServer: %s", prefix)) {
@Override
public void run() {
BufferedReader r = new BufferedReader(new InputStreamReader(in));
Expand All @@ -164,10 +164,10 @@ public void run() {
if (s == null) {
break;
}
out.println(prefix + s);
log.debug("{}: {}", prefix, s);
}
} catch (IOException e) {
e.printStackTrace(System.err);
log.debug("OOServer error:", e);
}
}
}.start();
Expand Down