1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Add better boot script error reporting. Externalize strings.

Change-Id: If0193ffeaf9ea03f44eb87cde3e6dd4a3e24f7f5
Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2016-12-01 22:33:07 -05:00
parent ecd433f470
commit 4206d11f69
9 changed files with 149 additions and 65 deletions

View file

@ -29,9 +29,13 @@ parent_is_not_orphan () {
do_check() {
java_vers=`java -version 2>&1`
vers=`expr "$java_vers" : "java version \"\([0-9]*\.[0-9]*\).*\""`
if test "%$vers" != "%1.8"; then
echo fail:invalid java version $vers
major=`expr "$java_vers" : "java version \"\([0-9]*\)\.[0-9]*.*\""`
minor=`expr "$java_vers" : "java version \"[0-9]*\.\([0-9]*\).*\""`
if test "$major" -ge 2 -o "$minor" -ge 8; then
:
else
echo "fail:invalid java version $major.$minor; must be >= 1.8"
return
fi
case "`uname`" in
Linux)
@ -45,7 +49,8 @@ do_check() {
proxydir=$installdir/Proxy.app;
plugins=$proxydir/Contents/Eclipse/plugins;;
*)
echo fail:system not supported;;
echo fail:system not supported;
return;;
esac
proxy=no
if test -d $proxydir; then

View file

@ -36,6 +36,7 @@ import org.eclipse.remote.internal.proxy.core.commands.ExecCommand;
import org.eclipse.remote.internal.proxy.core.commands.GetCwdCommand;
import org.eclipse.remote.internal.proxy.core.commands.GetEnvCommand;
import org.eclipse.remote.internal.proxy.core.commands.GetPropertiesCommand;
import org.eclipse.remote.internal.proxy.core.messages.Messages;
import org.eclipse.remote.proxy.protocol.core.StreamChannelManager;
import org.eclipse.remote.proxy.protocol.core.StreamChannel;
import org.eclipse.remote.proxy.protocol.core.exceptions.ProxyException;
@ -171,11 +172,11 @@ public class ProxyConnection implements IRemoteConnectionControlService,
*/
@Override
public void open(IProgressMonitor monitor) throws RemoteConnectionException {
SubMonitor subMon = SubMonitor.convert(monitor, "Opening connection...", 20);
SubMonitor subMon = SubMonitor.convert(monitor, Messages.ProxyConnection_0, 20);
if (!isOpen) {
ProxyConnectionBootstrap bootstrap = new ProxyConnectionBootstrap();
channelMux = bootstrap.run(getRemoteConnection(), subMon.newChild(10));
new Thread(channelMux, "multiplexer").start();
new Thread(channelMux, "multiplexer").start(); //$NON-NLS-1$
try {
commandChannel = channelMux.openChannel();
initialize(subMon.newChild(10));
@ -198,15 +199,15 @@ public class ProxyConnection implements IRemoteConnectionControlService,
SubMonitor subMon = SubMonitor.convert(monitor, 30);
fWorkingDir = getCwd(subMon.newChild(10));
if (subMon.isCanceled()) {
throw new RemoteConnectionException("User canceled opening connection");
throw new RemoteConnectionException(Messages.ProxyConnection_2);
}
fEnv.putAll(loadEnv(subMon.newChild(10)));
if (subMon.isCanceled()) {
throw new RemoteConnectionException("User canceled opening connection");
throw new RemoteConnectionException(Messages.ProxyConnection_2);
}
fProperties.putAll(loadProperties(subMon.newChild(10)));
if (subMon.isCanceled()) {
throw new RemoteConnectionException("User canceled opening connection");
throw new RemoteConnectionException(Messages.ProxyConnection_2);
}
}
@ -252,6 +253,7 @@ public class ProxyConnection implements IRemoteConnectionControlService,
private StringBuffer stdout = new StringBuffer();
private StringBuffer stderr = new StringBuffer();
@SuppressWarnings("unused")
private String executeSshCommand(ChannelShell shell, String command) throws RemoteConnectionException {
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
@ -276,7 +278,7 @@ public class ProxyConnection implements IRemoteConnectionControlService,
final StreamChannel chanA = channelMux.openChannel();
final StreamChannel chanB = channelMux.openChannel();
final StreamChannel chanC = channelMux.openChannel();
new Thread("cmd stdin reader") {
new Thread("cmd stdin reader") { //$NON-NLS-1$
@Override
public void run() {
byte[] buf = new byte[1024];
@ -290,7 +292,7 @@ public class ProxyConnection implements IRemoteConnectionControlService,
}
}
}.start();
new Thread("cmd stderr reader") {
new Thread("cmd stderr reader") { //$NON-NLS-1$
@Override
public void run() {
byte[] buf = new byte[1024];
@ -346,10 +348,7 @@ public class ProxyConnection implements IRemoteConnectionControlService,
@Override
public IRemoteProcess getCommandShell(int flags) throws IOException {
if (!proxyRunning) {
}
return null;
throw new IOException("Not implemented yet");
}
@Override

View file

@ -25,12 +25,14 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jsch.core.IJSchService;
import org.eclipse.osgi.util.NLS;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionHostService;
import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
import org.eclipse.remote.core.IUserAuthenticatorService;
import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.remote.internal.jsch.core.JSchUserInfo;
import org.eclipse.remote.internal.proxy.core.messages.Messages;
import org.eclipse.remote.proxy.protocol.core.StreamChannelManager;
import org.osgi.framework.Bundle;
@ -48,6 +50,7 @@ public class ProxyConnectionBootstrap {
private State state;
private String osName;
private String osArch;
private String errorMessage;
private final SubMonitor monitor;
private final BufferedReader reader;
@ -87,6 +90,14 @@ public class ProxyConnectionBootstrap {
void setOSArch(String osArch) {
this.osArch = osArch;
}
void setErrorMessage(String message) {
this.errorMessage = message;
}
String getErrorMessage() {
return errorMessage;
}
}
private interface State {
@ -100,10 +111,10 @@ public class ProxyConnectionBootstrap {
INIT {
@Override
public boolean process(Context context) throws IOException {
context.getMonitor().subTask("Initializing");
context.getMonitor().subTask(Messages.ProxyConnectionBootstrap_0);
String line = context.reader.readLine();
context.getMonitor().worked(1);
if (line.equals("running")) {
if (line.equals("running")) { //$NON-NLS-1$
context.setState(States.CHECK);
return true;
}
@ -113,33 +124,34 @@ public class ProxyConnectionBootstrap {
CHECK {
@Override
public boolean process(Context context) throws IOException {
context.getMonitor().subTask("Validating environment");
String bundleName = "org.eclipse.remote.proxy.server.core";
context.getMonitor().subTask(Messages.ProxyConnectionBootstrap_1);
String bundleName = "org.eclipse.remote.proxy.server.core"; //$NON-NLS-1$
Bundle serverBundle = Platform.getBundle(bundleName);
if (serverBundle == null) {
throw new IOException("Unable to locate server bundle " + bundleName);
throw new IOException(NLS.bind(Messages.ProxyConnectionBootstrap_2, bundleName));
}
context.writer.write("check " + serverBundle.getVersion() + "\n");
context.writer.write("check " + serverBundle.getVersion() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
context.writer.flush();
String line = context.reader.readLine();
while (line != null) {
context.getMonitor().worked(2);
String[] parts = line.split(":");
String[] parts = line.split(":"); //$NON-NLS-1$
switch (parts[0]) {
case "ok":
String[] status = parts[1].split("/");
case "ok": //$NON-NLS-1$
String[] status = parts[1].split("/"); //$NON-NLS-1$
context.setOSName(status[1]);
context.setOSArch(status[2]);
context.setState(status[0].equals("proxy") ? States.START : States.DOWNLOAD);
context.setState(status[0].equals("proxy") ? States.START : States.DOWNLOAD); //$NON-NLS-1$
return true;
case "fail":
System.out.println("fail:"+parts[1]);
case "fail": //$NON-NLS-1$
context.setErrorMessage(parts[1]);
System.out.println("fail:"+parts[1]); //$NON-NLS-1$
return false;
case "debug":
case "debug": //$NON-NLS-1$
System.err.println(line);
break;
default:
System.err.println("Invalid response from bootstrap script: " + line);
System.err.println("Invalid response from bootstrap script: " + line); //$NON-NLS-1$
return false;
}
line = context.reader.readLine();
@ -150,37 +162,38 @@ public class ProxyConnectionBootstrap {
DOWNLOAD {
@Override
public boolean process(Context context) throws IOException {
context.getMonitor().subTask("Updating server proxy");
String bundleName = "org.eclipse.remote.proxy.server." + context.getOSName() + "." + context.getOSArch();
context.getMonitor().subTask(Messages.ProxyConnectionBootstrap_3);
String bundleName = "org.eclipse.remote.proxy.server." + context.getOSName() + "." + context.getOSArch(); //$NON-NLS-1$ //$NON-NLS-2$
Bundle serverBundle = Platform.getBundle(bundleName);
if (serverBundle == null) {
throw new IOException("Unable to locate server bundle " + bundleName);
throw new IOException(NLS.bind(Messages.ProxyConnectionBootstrap_2, bundleName));
}
URL fileURL = FileLocator.find(serverBundle, new Path("proxy.server.tar.gz"), null);
URL fileURL = FileLocator.find(serverBundle, new Path("proxy.server.tar.gz"), null); //$NON-NLS-1$
if (fileURL == null) {
return false;
}
File file = new File(FileLocator.toFileURL(fileURL).getFile());
long count = file.length() / 510;
context.writer.write("download " + count + "\n");
context.writer.write("download " + count + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
context.writer.flush();
context.getMonitor().worked(2);
if (downloadFile(file, context.writer, context.getMonitor().newChild(5))) {
String line = context.reader.readLine();
while (line != null) {
String[] parts = line.split(":");
String[] parts = line.split(":"); //$NON-NLS-1$
switch (parts[0]) {
case "ok":
case "ok": //$NON-NLS-1$
context.setState(States.START);
return true;
case "fail":
System.out.println("fail:"+parts[1]);
case "fail": //$NON-NLS-1$
context.setErrorMessage(parts[1]);
System.out.println("fail:"+parts[1]); //$NON-NLS-1$
return false;
case "debug":
case "debug": //$NON-NLS-1$
System.err.println(line);
break;
default:
System.err.println("Invalid response from bootstrap script: " + line);
System.err.println("Invalid response from bootstrap script: " + line); //$NON-NLS-1$
return false;
}
line = context.reader.readLine();
@ -215,8 +228,8 @@ public class ProxyConnectionBootstrap {
START {
@Override
public boolean process(Context context) throws IOException {
context.getMonitor().subTask("Starting server");
context.writer.write("start\n");
context.getMonitor().subTask(Messages.ProxyConnectionBootstrap_4);
context.writer.write("start\n"); //$NON-NLS-1$
context.writer.flush();
return false; // Finished
}
@ -233,17 +246,17 @@ public class ProxyConnectionBootstrap {
final Channel chan = openChannel(connection, subMon.newChild(10));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(chan.getOutputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(chan.getInputStream()));
subMon.beginTask("Checking server installation", 10);
subMon.subTask("Loading bootstrap shell");
URL fileURL = FileLocator.find(Activator.getDefault().getBundle(), new Path("bootstrap.sh"), null);
subMon.beginTask(Messages.ProxyConnectionBootstrap_5, 10);
subMon.subTask(Messages.ProxyConnectionBootstrap_9);
URL fileURL = FileLocator.find(Activator.getDefault().getBundle(), new Path("bootstrap.sh"), null); //$NON-NLS-1$
if (fileURL == null) {
throw new RemoteConnectionException("Unable to locate bootstrap shell");
throw new RemoteConnectionException(Messages.ProxyConnectionBootstrap_6);
}
File file = new File(FileLocator.toFileURL(fileURL).getFile());
BufferedReader scriptReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line;
while ((line = scriptReader.readLine()) != null) {
writer.write(line + "\n");
writer.write(line + "\n"); //$NON-NLS-1$
}
scriptReader.close();
writer.flush();
@ -253,18 +266,18 @@ public class ProxyConnectionBootstrap {
// do state machine
}
if (context.getState() != States.START) {
context.writer.write("exit\n");
context.writer.write("exit\n"); //$NON-NLS-1$
context.writer.flush();
throw new RemoteConnectionException("Unable to start server");
throw new RemoteConnectionException(NLS.bind(Messages.ProxyConnectionBootstrap_7, context.getErrorMessage()));
}
new Thread("server error stream") {
new Thread("server error stream") { //$NON-NLS-1$
@Override
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(chan.getExtInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.err.println("server: "+ line);
System.err.println("server: "+ line); //$NON-NLS-1$
}
} catch (IOException e) {
// Ignore and terminate thread
@ -295,10 +308,10 @@ public class ProxyConnectionBootstrap {
}
jSchService.connect(session, hostService.getTimeout() * 1000, monitor);
if (monitor.isCanceled()) {
throw new RemoteConnectionException("User canceled connection open");
throw new RemoteConnectionException(Messages.ProxyConnectionBootstrap_8);
}
exec = (ChannelExec) session.openChannel("exec"); //$NON-NLS-1$
exec.setCommand("/bin/sh -l");
exec.setCommand("/bin/sh -l"); //$NON-NLS-1$
exec.connect();
return exec;
} catch (JSchException e) {

View file

@ -32,6 +32,7 @@ public class ProxyConnectionProviderService implements IRemoteConnectionProvider
@Override
public void init() {
// Nothing
}
@Override

View file

@ -36,6 +36,7 @@ import org.eclipse.remote.internal.proxy.core.commands.GetInputStreamCommand;
import org.eclipse.remote.internal.proxy.core.commands.GetOutputStreamCommand;
import org.eclipse.remote.internal.proxy.core.commands.MkdirCommand;
import org.eclipse.remote.internal.proxy.core.commands.PutInfoCommand;
import org.eclipse.remote.internal.proxy.core.messages.Messages;
import org.eclipse.remote.proxy.protocol.core.exceptions.ProxyException;
public class ProxyFileStore extends FileStore {
@ -71,18 +72,18 @@ public class ProxyFileStore extends FileStore {
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
IRemoteConnectionType connectionType = manager.getConnectionType(fURI);
if (connectionType == null) {
throw new RemoteConnectionException(NLS.bind("No remote services found for URI {0}", fURI));
throw new RemoteConnectionException(NLS.bind(Messages.ProxyFileStore_0, fURI));
}
try {
IRemoteConnection connection = connectionType.getConnection(fURI);
if (connection == null) {
throw new RemoteConnectionException(NLS.bind("Invalid connection for URI {0}", fURI));
throw new RemoteConnectionException(NLS.bind(Messages.ProxyFileStore_1, fURI));
}
if (!connection.isOpen()) {
connection.open(monitor);
if (!connection.isOpen()) {
throw new RemoteConnectionException("Connection is not open");
throw new RemoteConnectionException(Messages.ProxyFileStore_2);
}
}
return connection.getService(ProxyConnection.class);
@ -234,7 +235,7 @@ public class ProxyFileStore extends FileStore {
IFileStore parent = getParent();
if (parent != null && !parent.fetchInfo(EFS.NONE, subMon.newChild(5)).exists()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRITE,
NLS.bind("The parent of directory {0} does not exist", fRemotePath.toString()), null));
NLS.bind(Messages.ProxyFileStore_3, fRemotePath.toString()), null));
}
if (subMon.isCanceled()) {
return this;
@ -256,11 +257,11 @@ public class ProxyFileStore extends FileStore {
if (!subMon.isCanceled()) {
if (!info.exists()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRITE,
NLS.bind("The directory {0} could not be created", fRemotePath.toString()), null));
NLS.bind(Messages.ProxyFileStore_4, fRemotePath.toString()), null));
}
if (!info.isDirectory()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE,
NLS.bind("A file of name {0} already exists", fRemotePath.toString()), null));
NLS.bind(Messages.ProxyFileStore_5, fRemotePath.toString()), null));
}
}
}
@ -282,11 +283,11 @@ public class ProxyFileStore extends FileStore {
if (!subMon.isCanceled()) {
if (!info.exists()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_READ,
NLS.bind("File {0} does not exist", fRemotePath.toString()), null));
NLS.bind(Messages.ProxyFileStore_6, fRemotePath.toString()), null));
}
if (info.isDirectory()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE,
NLS.bind("{0} is a directory", fRemotePath.toString()), null));
NLS.bind(Messages.ProxyFileStore_7, fRemotePath.toString()), null));
}
GetInputStreamCommand command = new GetInputStreamCommand(connection, options, fRemotePath.toString());
try {
@ -312,7 +313,7 @@ public class ProxyFileStore extends FileStore {
if (!subMon.isCanceled()) {
if (info.isDirectory()) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE,
NLS.bind("{0} is a directory", fRemotePath.toString()), null));
NLS.bind(Messages.ProxyFileStore_7, fRemotePath.toString()), null));
}
GetOutputStreamCommand command = new GetOutputStreamCommand(connection, options, fRemotePath.toString());
try {

View file

@ -65,7 +65,7 @@ public class ProxyProcess extends RemoteProcess implements IRemoteProcessControl
isCompleted = false;
exitValue = 0;
cmdThread = new Thread("process " + builder.command().get(0) + " result reader") {
cmdThread = new Thread("process " + builder.command().get(0) + " result reader") { //$NON-NLS-1$ //$NON-NLS-2$
@Override
public void run() {
try {
@ -203,5 +203,6 @@ public class ProxyProcess extends RemoteProcess implements IRemoteProcessControl
@Override
public void setTerminalSize(int cols, int rows, int pwidth, int pheight) {
// Nothing?
}
}

View file

@ -22,6 +22,7 @@ import org.eclipse.remote.core.IRemoteFileService;
import org.eclipse.remote.core.IRemoteProcess;
import org.eclipse.remote.core.IRemoteProcessBuilder;
import org.eclipse.remote.internal.proxy.core.commands.ExecCommand;
import org.eclipse.remote.internal.proxy.core.messages.Messages;
import org.eclipse.remote.proxy.protocol.core.StreamChannel;
import org.eclipse.remote.proxy.protocol.core.exceptions.ProxyException;
@ -90,14 +91,14 @@ public class ProxyProcessBuilder extends AbstractRemoteProcessBuilder {
final ProxyConnection conn = getRemoteConnection().getService(ProxyConnection.class);
if (conn == null) {
throw new IOException("Unable to located connection for this process");
throw new IOException(Messages.ProxyProcessBuilder_0);
}
final StreamChannel chanStdIO = conn.openChannel();
final StreamChannel chanStdErr = conn.openChannel();
final StreamChannel chanControl = conn.openChannel();
Job job = new Job("process executor") {
Job job = new Job("process executor") { //$NON-NLS-1$
@Override
protected IStatus run(IProgressMonitor monitor) {
ExecCommand cmd = new ExecCommand(conn, cmdArgs, env, directory().toURI().getPath(), redirectErrorStream(), append,

View file

@ -56,6 +56,48 @@ public class Messages extends NLS {
public static String JschFileStore_A_file_of_name_already_exists;
public static String JschFileStore_The_parent_of_directory_does_not_exist;
public static String ProxyConnection_0;
public static String ProxyConnection_2;
public static String ProxyConnectionBootstrap_0;
public static String ProxyConnectionBootstrap_1;
public static String ProxyConnectionBootstrap_2;
public static String ProxyConnectionBootstrap_3;
public static String ProxyConnectionBootstrap_4;
public static String ProxyConnectionBootstrap_5;
public static String ProxyConnectionBootstrap_6;
public static String ProxyConnectionBootstrap_7;
public static String ProxyConnectionBootstrap_8;
public static String ProxyConnectionBootstrap_9;
public static String ProxyFileStore_0;
public static String ProxyFileStore_1;
public static String ProxyFileStore_2;
public static String ProxyFileStore_3;
public static String ProxyFileStore_4;
public static String ProxyFileStore_5;
public static String ProxyFileStore_6;
public static String ProxyFileStore_7;
public static String ProxyProcessBuilder_0;
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_ID, Messages.class);

View file

@ -43,3 +43,24 @@ JschFileStore_No_remote_services_found_for_URI=No remote services found for URI:
JschFileStore_The_directory_could_not_be_created=The directory {0} could not be created
JschFileStore_A_file_of_name_already_exists=A file of name {0} already exists
JschFileStore_The_parent_of_directory_does_not_exist=The parent of directory {0} does not exist
ProxyConnection_0=Opening connection...
ProxyConnection_2=User canceled opening connection
ProxyConnectionBootstrap_0=Initializing
ProxyConnectionBootstrap_1=Validating environment
ProxyConnectionBootstrap_2=Unable to locate server bundle {0}
ProxyConnectionBootstrap_3=Updating server proxy
ProxyConnectionBootstrap_4=Starting server
ProxyConnectionBootstrap_5=Checking server installation
ProxyConnectionBootstrap_6=Unable to locate bootstrap shell
ProxyConnectionBootstrap_7=Unable to start server: {0}
ProxyConnectionBootstrap_8=User canceled connection open
ProxyConnectionBootstrap_9=Loading bootstrap shell
ProxyFileStore_0=No remote services found for URI {0}
ProxyFileStore_1=Invalid connection for URI {0}
ProxyFileStore_2=Connection is not open
ProxyFileStore_3=The parent of directory {0} does not exist
ProxyFileStore_4=The directory {0} could not be created
ProxyFileStore_5=A file of name {0} already exists
ProxyFileStore_6=File {0} does not exist
ProxyFileStore_7={0} is a directory
ProxyProcessBuilder_0=Unable to located connection for this process