mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Minor code cleanup.
This commit is contained in:
parent
a3758a0664
commit
55b9874f5d
4 changed files with 61 additions and 28 deletions
|
@ -16,14 +16,16 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.codan.core.externaltool.AbstractOutputParser;
|
||||
import org.eclipse.cdt.codan.core.externaltool.ConfigurationSettings;
|
||||
import org.eclipse.cdt.codan.core.externaltool.IArgsSeparator;
|
||||
import org.eclipse.cdt.codan.core.externaltool.ICommandLauncher;
|
||||
import org.eclipse.cdt.codan.core.externaltool.AbstractOutputParser;
|
||||
import org.eclipse.cdt.codan.core.externaltool.InvocationFailure;
|
||||
import org.eclipse.cdt.codan.core.externaltool.InvocationParameters;
|
||||
import org.eclipse.cdt.codan.core.externaltool.SingleConfigurationSetting;
|
||||
import org.eclipse.cdt.codan.core.externaltool.SpaceDelimitedArgsSeparator;
|
||||
import org.eclipse.cdt.codan.core.param.BasicProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.test.CodanTestCase;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -67,16 +69,19 @@ public class ExternalToolInvokerTest extends CodanTestCase {
|
|||
private MapProblemPreference createPreferences(File path, String args,
|
||||
boolean shouldDisplayOutput) {
|
||||
MapProblemPreference preferences = new MapProblemPreference();
|
||||
preferences.addChildDescriptor(new BasicProblemPreference("externalToolPath", "Path"));
|
||||
preferences.addChildDescriptor(new BasicProblemPreference("externalToolArgs", "Args"));
|
||||
preferences.addChildDescriptor(new BasicProblemPreference("externalToolShouldDisplayOutput",
|
||||
"Should Display Output"));
|
||||
preferences.setChildValue("externalToolPath", path);
|
||||
preferences.setChildValue("externalToolArgs", args);
|
||||
preferences.setChildValue("externalToolShouldDisplayOutput", shouldDisplayOutput);
|
||||
preferences.addChildDescriptor(createPreference(PathSetting.KEY, path));
|
||||
preferences.addChildDescriptor(createPreference(ArgsSetting.KEY, args));
|
||||
preferences.addChildDescriptor(createPreference(ShouldDisplayOutputSetting.KEY,
|
||||
shouldDisplayOutput));
|
||||
return preferences;
|
||||
}
|
||||
|
||||
private IProblemPreference createPreference(String key, Object value) {
|
||||
BasicProblemPreference preference = new BasicProblemPreference(key, "");
|
||||
preference.setValue(value);
|
||||
return preference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCpp() {
|
||||
return true;
|
||||
|
@ -89,26 +94,24 @@ public class ExternalToolInvokerTest extends CodanTestCase {
|
|||
InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile,
|
||||
currentIFile.getLocation().toOSString(), cproject.getProject().getLocation());
|
||||
externalToolInvoker.invoke(parameters, configurationSettings, argsSeparator, parsers);
|
||||
assertSame(cproject.getProject(), commandLauncher.project);
|
||||
assertEquals(EXTERNAL_TOOL_NAME, commandLauncher.externalToolName);
|
||||
String expectedExecutablePath = configurationSettings.getPath().getValue().toString();
|
||||
assertEquals(expectedExecutablePath, commandLauncher.executablePath.toOSString());
|
||||
String[] expectedArgs = { parameters.getActualFilePath(), "--debug=true", "--include=all" };
|
||||
assertArrayEquals(expectedArgs, commandLauncher.args);
|
||||
assertEquals(parameters.getWorkingDirectory(), commandLauncher.workingDirectory);
|
||||
assertEquals(configurationSettings.getShouldDisplayOutput().getValue().booleanValue(),
|
||||
commandLauncher.shouldDisplayOutput);
|
||||
assertSame(parsers, commandLauncher.parsers);
|
||||
commandLauncher.assertThatReceivedProject(cproject.getProject());
|
||||
commandLauncher.assertThatReceivedExternalToolName(EXTERNAL_TOOL_NAME);
|
||||
commandLauncher.assertThatReceivedExecutablePath(configurationSettings.getPath());
|
||||
commandLauncher.assertThatReceivedArgs(configurationSettings.getArgs());
|
||||
commandLauncher.assertThatReceivedWorkingDirectory(parameters.getWorkingDirectory());
|
||||
commandLauncher.assertThatReceivedShouldDisplayOutput(
|
||||
configurationSettings.getShouldDisplayOutput());
|
||||
commandLauncher.assetThatReceivedOutputParsers(parsers);
|
||||
}
|
||||
|
||||
private static class CommandLauncherStub implements ICommandLauncher {
|
||||
IProject project;
|
||||
String externalToolName;
|
||||
IPath executablePath;
|
||||
String[] args;
|
||||
IPath workingDirectory;
|
||||
boolean shouldDisplayOutput;
|
||||
List<AbstractOutputParser> parsers;
|
||||
private IProject project;
|
||||
private String externalToolName;
|
||||
private IPath executablePath;
|
||||
private String[] args;
|
||||
private IPath workingDirectory;
|
||||
private boolean shouldDisplayOutput;
|
||||
private List<AbstractOutputParser> parsers;
|
||||
|
||||
@Override
|
||||
public void buildAndLaunchCommand(IProject project, String externalToolName,
|
||||
|
@ -123,5 +126,35 @@ public class ExternalToolInvokerTest extends CodanTestCase {
|
|||
this.shouldDisplayOutput = shouldDisplayOutput;
|
||||
this.parsers = parsers;
|
||||
}
|
||||
|
||||
void assertThatReceivedProject(IProject expected) {
|
||||
assertEquals(expected, project);
|
||||
}
|
||||
|
||||
void assertThatReceivedExternalToolName(String expected) {
|
||||
assertEquals(expected, externalToolName);
|
||||
}
|
||||
|
||||
void assertThatReceivedExecutablePath(SingleConfigurationSetting<File> expected) {
|
||||
String expectedPath = expected.getValue().toString();
|
||||
assertEquals(expectedPath, executablePath.toOSString());
|
||||
}
|
||||
|
||||
void assertThatReceivedArgs(SingleConfigurationSetting<String> expected) {
|
||||
String[] expectedArgs = expected.getValue().split("\\s+");
|
||||
assertArrayEquals(expectedArgs, args);
|
||||
}
|
||||
|
||||
void assertThatReceivedWorkingDirectory(IPath expected) {
|
||||
assertSame(expected, workingDirectory);
|
||||
}
|
||||
|
||||
void assertThatReceivedShouldDisplayOutput(SingleConfigurationSetting<Boolean> expected) {
|
||||
assertEquals(expected.getValue().booleanValue(), shouldDisplayOutput);
|
||||
}
|
||||
|
||||
void assetThatReceivedOutputParsers(List<AbstractOutputParser> expected) {
|
||||
assertSame(expected, parsers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor;
|
|||
* @since 2.1
|
||||
*/
|
||||
public class ArgsSetting extends SingleConfigurationSetting<String> {
|
||||
private static final String KEY = "externalToolArgs"; //$NON-NLS-1$
|
||||
static final String KEY = "externalToolArgs"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor;
|
|||
* @since 2.1
|
||||
*/
|
||||
public class PathSetting extends SingleConfigurationSetting<File> {
|
||||
private static final String KEY = "externalToolPath"; //$NON-NLS-1$
|
||||
static final String KEY = "externalToolPath"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor;
|
|||
* @since 2.1
|
||||
*/
|
||||
public class ShouldDisplayOutputSetting extends SingleConfigurationSetting<Boolean> {
|
||||
private static final String KEY = "externalToolShouldDisplayOutput"; //$NON-NLS-1$
|
||||
static final String KEY = "externalToolShouldDisplayOutput"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
Loading…
Add table
Reference in a new issue