Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cf081b242f5e9c30e59865e1a8b163bba0d23d49 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*******************************************************************************
 * Copyright (c) 2005, 2007 Symbian Ltd 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:
 * Symbian Ltd - Initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.managedbuilder.core;

import java.util.Arrays;
import java.util.List;


/**
 * This class implements the default managed option value handler for MBS.
 * It is also be intended to be used as a base class for other value handlers.
 */
public class ManagedOptionValueHandler implements
		IManagedOptionValueHandler {

	/*
	 *  E N A B L E   U S E   A S   B A S E   C L A S S   A N D
	 *  D E F A U L T   I M P L E M E N T A T I O N
	 */

	private static ManagedOptionValueHandler mbsValueHandler;

	protected ManagedOptionValueHandler() {
		mbsValueHandler = null;
	}

	public static ManagedOptionValueHandler getManagedOptionValueHandler() {
		if( mbsValueHandler == null ) {
			mbsValueHandler = new ManagedOptionValueHandler();
		}
		return mbsValueHandler;
	}

	/*
	 *  D E F A U L T   I M P L E M E N T A T I O N S   O F   I N T E R F A C E
	 */

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler#handleValue(IConfiguration,IToolChain,IOption,String,int)
	 */
	@Override
	public boolean handleValue(IBuildObject configuration,
                   IHoldsOptions holder,
                   IOption option,
                   String extraArgument, int event)
	{
		/*
		// The following is for debug purposes and thus normally commented out
		String configLabel = "???"; //$NON-NLS-1$
		String holderLabel = "???"; //$NON-NLS-1$
		String eventLabel  = "???"; //$NON-NLS-1$

		if (configuration instanceof IConfiguration) {
			configLabel = "IConfiguration"; //$NON-NLS-1$
		} else if (configuration instanceof IResourceConfiguration) {
			configLabel = "IResourceConfiguration"; //$NON-NLS-1$
		}

		if (holder instanceof IToolChain) {
			holderLabel = "IToolChain"; //$NON-NLS-1$
		} else if (holder instanceof ITool) {
			holderLabel = "ITool"; //$NON-NLS-1$
		}

		switch (event) {
		case EVENT_OPEN:       eventLabel = "EVENT_OPEN"; break;       //$NON-NLS-1$
		case EVENT_APPLY:      eventLabel = "EVENT_APPLY"; break;      //$NON-NLS-1$
		case EVENT_SETDEFAULT: eventLabel = "EVENT_SETDEFAULT"; break; //$NON-NLS-1$
		case EVENT_CLOSE:      eventLabel = "EVENT_CLOSE"; break;      //$NON-NLS-1$
		}

		// Print the event
		System.out.println(eventLabel + "(" +              //$NON-NLS-1$
				           configLabel + " = " +           //$NON-NLS-1$
				           configuration.getId() + ", " +  //$NON-NLS-1$
				           holderLabel + " = " +           //$NON-NLS-1$
						   holder.getId() + ", " +         //$NON-NLS-1$
						   "IOption = " +                  //$NON-NLS-1$
						   option.getId() + ", " +         //$NON-NLS-1$
						   "String = " +                   //$NON-NLS-1$
						   extraArgument + ")");           //$NON-NLS-1$
        */
		// The event was not handled, thus return false
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler#isDefaultValue(IConfiguration,IToolChain,IOption,String)
	 */
	@Override
	public boolean isDefaultValue(IBuildObject configuration, IHoldsOptions holder, IOption option, String extraArgument) {
		// Get the default Value
		Object defaultValue = option.getDefaultValue();
		if (defaultValue instanceof List) {
			@SuppressWarnings("unchecked")
			List<String> list = (List<String>) defaultValue;
			defaultValue = list.toArray(new String[list.size()]);
		}

		try {
			// Figure out which type the option is and implement default behaviour for it.
			switch (option.getValueType()) {
				case IOption.STRING:
					if (option.getStringValue().equals(defaultValue)) {
						return true;
					}
					break;
				case IOption.BOOLEAN:
					if (option.getBooleanValue() == ((Boolean)defaultValue).booleanValue()) {
						return true;
					}
					break;
				case IOption.ENUMERATED:
					if (option.getValue().toString().equals(defaultValue.toString())) {
						return true;
					}
					break;
				case IOption.INCLUDE_PATH:
				case IOption.UNDEF_INCLUDE_PATH:
					if (Arrays.equals(option.getBasicStringListValue(), (String[])defaultValue)) {
						return true;
					}
					break;
				case IOption.STRING_LIST:
					if (Arrays.equals(option.getStringListValue(), (String[])defaultValue)) {
						return true;
					}
					break;
				case IOption.PREPROCESSOR_SYMBOLS:
				case IOption.UNDEF_PREPROCESSOR_SYMBOLS:
					if (Arrays.equals(option.getBasicStringListValue(), (String[])defaultValue)) {
						return true;
					}
					break;
				case IOption.LIBRARIES:
					if (Arrays.equals(option.getLibraries(), (String[])defaultValue)) {
						return true;
					}
					break;
				case IOption.OBJECTS:
					if (Arrays.equals(option.getUserObjects(), (String[])defaultValue)) {
						return true;
					}
					break;
				case IOption.INCLUDE_FILES:
				case IOption.LIBRARY_PATHS:
				case IOption.LIBRARY_FILES:
				case IOption.MACRO_FILES:
				case IOption.UNDEF_INCLUDE_FILES:
				case IOption.UNDEF_LIBRARY_PATHS:
				case IOption.UNDEF_LIBRARY_FILES:
				case IOption.UNDEF_MACRO_FILES:
				default:
					if (Arrays.equals(option.getBasicStringListValue(), (String[])defaultValue)) {
						return true;
					}
					break;
				}
		} catch (BuildException e) {
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler#isEnumValueAppropriate(IConfiguration,IToolChain,IOption,String,String)
	 */
	@Override
	public boolean isEnumValueAppropriate(IBuildObject configuration,
                              IHoldsOptions holder,
                              IOption option,
                              String extraArgument, String enumValue)
	{
		// By default return true for all the enum values.
		return true;
	}
}

Back to the top