Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
blob: c4c59d420128f6db3863cca8d4467ef07ceceec7 (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
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.core.connection.strategy;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.te.core.activator.CoreBundleActivator;
import org.eclipse.tcf.te.core.nls.Messages;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.stepper.extensions.AbstractContextStepExecutor;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IContext;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IContextStep;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId;

/**
 * Connect strategy step executor implementation.
 */
public class ConnectStrategyStepExecutor extends AbstractContextStepExecutor {

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.stepper.extensions.AbstractContextStepExecutor#formatMessage(java.lang.String, int, org.eclipse.tcf.te.runtime.stepper.interfaces.IContextStep, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.tcf.te.runtime.stepper.interfaces.IContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer)
	 */
	@Override
	protected String formatMessage(String message, int severity, IContextStep step, IFullQualifiedId id, IContext context, IPropertiesContainer data) {
		String template = null;

		switch (severity) {
			case IStatus.INFO:
				template = Messages.ConnectStrategyStepExecutor_info_stepFailed;
				break;
			case IStatus.WARNING:
				template = Messages.ConnectStrategyStepExecutor_warning_stepFailed;
				break;
			case IStatus.ERROR:
				template = Messages.ConnectStrategyStepExecutor_error_stepFailed;
				break;
		}

		// If we cannot determine the formatted message template, just return the message as is
		if (template == null) {
			return message;
		}

		// Split the message. The first sentence is shown more prominent on the top,
		// the rest as additional information below the step information.
		String[] splittedMsg = message != null ? message.split("[\t\n\r\f]+", 2) : new String[] { null, null }; //$NON-NLS-1$

		// Format the core message
		String formattedMessage = NLS.bind(template, new String[] { splittedMsg[0],
										   context.getContextName(),
										   ConnectStrategyStepper.getConnectStrategy(data).getLabel(),
										   step.getLabel()
									});

		// Get the context information
		String contextInfo = formatContextInfo(context);
		if (contextInfo != null) {
			formattedMessage += "\n\n" + contextInfo; //$NON-NLS-1$
		}

		// If we have more information available, append them
		if (splittedMsg.length > 1 && splittedMsg[1] != null && !"".equals(splittedMsg[1])) { //$NON-NLS-1$
			formattedMessage += "\n\n" + splittedMsg[1]; //$NON-NLS-1$
		}

		// In debug mode, there is even more information to add
		if (CoreBundleActivator.getTraceHandler().isSlotEnabled(1, null)) {
			formattedMessage += "\n\n" + NLS.bind(Messages.ConnectStrategyStepExecutor_stepFailed_debugInfo, id.toString()); //$NON-NLS-1$
		}

		return formattedMessage;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.stepper.AbstractContextStepExecutor#isExceptionMessageFormatted(java.lang.String)
	 */
	@Override
	protected boolean isExceptionMessageFormatted(String message) {
		Assert.isNotNull(message);
		return message.startsWith(Messages.ConnectStrategyStepExecutor_checkPoint_normalizationNeeded);
	}

	/**
	 * Determines additional context information to show in the failure message.
	 *
	 * @param context The context. Must not be <code>null</code>.
	 * @return The additional context information string or <code>null</code>.
	 */
	protected String formatContextInfo(IContext context) {
		Assert.isNotNull(context);
		return context.getContextInfo();
	}
}

Back to the top