Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 16d6e7e0abaf6236270c43eacf9906da0a8e7555 (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
/*******************************************************************************
 * Copyright (c) 2012 Google, Inc.
 * 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:
 *    Alex Ruiz  - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.codan.core.externaltool;

import java.io.File;

import org.eclipse.cdt.codan.core.param.MapProblemPreference;
import org.eclipse.cdt.codan.internal.core.externaltool.ArgsSetting;
import org.eclipse.cdt.codan.internal.core.externaltool.PathSetting;
import org.eclipse.cdt.codan.internal.core.externaltool.ShouldDisplayOutputSetting;

/**
 * User-configurable external tool settings.
 *
 * @author alruiz@google.com (Alex Ruiz)
 *
 * @since 2.1
 */
public final class ConfigurationSettings {
	private final PathSetting path;
	private final ArgsSetting args;
	private final ShouldDisplayOutputSetting shouldDisplayOutput;
	private final String externalToolName;

	/**
	 * Constructor.
	 * @param externalToolName the name of the external tool, to be displayed to the user.
	 * @param defaultPath the default path of the external tool.
	 * @param defaultArgs the default arguments to pass when invoking the external tool.
	 * @param defaultShouldDisplayOutput indicates whether output of an external tool should be
	 *        displayed in an Eclipse console.
	 */
	public ConfigurationSettings(String externalToolName, File defaultPath, String defaultArgs,
			boolean defaultShouldDisplayOutput) {
		this.externalToolName = externalToolName;
		this.path = new PathSetting(externalToolName, defaultPath);
		this.args = new ArgsSetting(externalToolName, defaultArgs);
		this.shouldDisplayOutput = new ShouldDisplayOutputSetting(defaultShouldDisplayOutput);
	}

	/**
	 * Returns the name of the external tool, to be displayed to the user.
	 * @return the name of the external tool, to be displayed to the user.
	 */
	public String getExternalToolName() {
		return externalToolName;
	}

	/**
	 * Returns the setting that specifies the path and name of the external tool to invoke.
	 * @return the setting that specifies the path and name of the external tool to invoke.
	 */
	public SingleConfigurationSetting<File> getPath() {
		return path;
	}

	/**
	 * Returns the setting that specifies the arguments to pass when invoking the external tool.
	 * @return the setting that specifies the arguments to pass when invoking the external tool.
	 */
	public SingleConfigurationSetting<String> getArgs() {
		return args;
	}

	/**
	 * Returns the setting that specifies whether the output of the external tools should be
	 * displayed in an Eclipse console.
	 * @return the shouldDisplayOutput the setting that specifies whether the output of the external
	 *         tools should be displayed in an Eclipse console.
	 */
	public SingleConfigurationSetting<Boolean> getShouldDisplayOutput() {
		return shouldDisplayOutput;
	}

	/**
	 * Updates the values of the configuration settings value with the ones stored in the given
	 * preference map.
	 * @param preferences the given preference map that may contain the values to set.
	 * @throws ClassCastException if any of the values to set is not of the same type as the one
	 *         supported by a setting.
	 */
	public void updateValuesFrom(MapProblemPreference preferences) {
		path.updateValue(preferences);
		args.updateValue(preferences);
		shouldDisplayOutput.updateValue(preferences);
	}
}

Back to the top