blob: 5697954958d0bd55dc400eedd65d47cf2c545a02 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.help.internal;
import java.io.*;
import java.util.*;
import org.eclipse.core.boot.IPlatformRunnable;
import org.eclipse.core.runtime.*;
import org.eclipse.help.internal.*;
import org.eclipse.help.internal.appserver.WebappManager;
/**
* Help application.
* Starts webserver and help web application for use
* by infocenter and stand-alone help.
* Application takes a parameter "mode", that can take values:
* "infocenter" - when help system should run as infocenter,
* "standalone" - when help system should run as standalone.
*/
public class HelpApplication
implements IPlatformRunnable, IExecutableExtension {
private static final int STATUS_EXITTING = 0;
private static final int STATUS_RESTARTING = 2;
private static final int STATUS_RUNNING = 1;
private static int status = STATUS_RUNNING;
/**
* Causes help service to stop and exit
*/
public static void stop() {
status = STATUS_EXITTING;
}
/**
* Causes help service to exit and start again
*/
public static void restart() {
if (status != STATUS_EXITTING) {
status = STATUS_RESTARTING;
}
}
/**
* Runs help service application.
*/
public Object run(Object args) throws Exception {
if (!HelpSystem.ensureWebappRunning()) {
System.out.println(
"Help web application could not start. Check log file for details.");
return EXIT_OK;
}
writeHostAndPort();
// main program loop
while (status == STATUS_RUNNING) {
try {
Thread.sleep(250);
} catch (InterruptedException ie) {
break;
}
}
if (status == STATUS_RESTARTING) {
return EXIT_RESTART;
} else {
return EXIT_OK;
}
}
/**
* @see IExecutableExtension
*/
public void setInitializationData(
IConfigurationElement configElement,
String propertyName,
Object data) {
String value = (String) ((Map) data).get("mode");
if ("infocenter".equalsIgnoreCase(value)) {
HelpSystem.setMode(HelpSystem.MODE_INFOCENTER);
} else if ("standalone".equalsIgnoreCase(value)) {
HelpSystem.setMode(HelpSystem.MODE_STANDALONE);
}
}
private void writeHostAndPort() throws IOException {
Properties p = new Properties();
p.put("host", WebappManager.getHost());
p.put("port", "" + WebappManager.getPort());
File workspace = Platform.getLocation().toFile();
File hostPortFile = new File(workspace, ".metadata/.connection");
hostPortFile.deleteOnExit();
FileOutputStream out = null;
try {
out = new FileOutputStream(hostPortFile);
p.store(out, null);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException ioe2) {
}
}
}
}
}
|