1
0
Fork 0
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:
Alex Ruiz 2012-02-23 13:19:06 -08:00 committed by Sergey Prigogin
parent a3758a0664
commit 55b9874f5d
4 changed files with 61 additions and 28 deletions

View file

@ -16,14 +16,16 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.ConfigurationSettings;
import org.eclipse.cdt.codan.core.externaltool.IArgsSeparator; import org.eclipse.cdt.codan.core.externaltool.IArgsSeparator;
import org.eclipse.cdt.codan.core.externaltool.ICommandLauncher; 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.InvocationFailure;
import org.eclipse.cdt.codan.core.externaltool.InvocationParameters; 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.externaltool.SpaceDelimitedArgsSeparator;
import org.eclipse.cdt.codan.core.param.BasicProblemPreference; 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.param.MapProblemPreference;
import org.eclipse.cdt.codan.core.test.CodanTestCase; import org.eclipse.cdt.codan.core.test.CodanTestCase;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -67,16 +69,19 @@ public class ExternalToolInvokerTest extends CodanTestCase {
private MapProblemPreference createPreferences(File path, String args, private MapProblemPreference createPreferences(File path, String args,
boolean shouldDisplayOutput) { boolean shouldDisplayOutput) {
MapProblemPreference preferences = new MapProblemPreference(); MapProblemPreference preferences = new MapProblemPreference();
preferences.addChildDescriptor(new BasicProblemPreference("externalToolPath", "Path")); preferences.addChildDescriptor(createPreference(PathSetting.KEY, path));
preferences.addChildDescriptor(new BasicProblemPreference("externalToolArgs", "Args")); preferences.addChildDescriptor(createPreference(ArgsSetting.KEY, args));
preferences.addChildDescriptor(new BasicProblemPreference("externalToolShouldDisplayOutput", preferences.addChildDescriptor(createPreference(ShouldDisplayOutputSetting.KEY,
"Should Display Output")); shouldDisplayOutput));
preferences.setChildValue("externalToolPath", path);
preferences.setChildValue("externalToolArgs", args);
preferences.setChildValue("externalToolShouldDisplayOutput", shouldDisplayOutput);
return preferences; return preferences;
} }
private IProblemPreference createPreference(String key, Object value) {
BasicProblemPreference preference = new BasicProblemPreference(key, "");
preference.setValue(value);
return preference;
}
@Override @Override
public boolean isCpp() { public boolean isCpp() {
return true; return true;
@ -89,26 +94,24 @@ public class ExternalToolInvokerTest extends CodanTestCase {
InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile, InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile,
currentIFile.getLocation().toOSString(), cproject.getProject().getLocation()); currentIFile.getLocation().toOSString(), cproject.getProject().getLocation());
externalToolInvoker.invoke(parameters, configurationSettings, argsSeparator, parsers); externalToolInvoker.invoke(parameters, configurationSettings, argsSeparator, parsers);
assertSame(cproject.getProject(), commandLauncher.project); commandLauncher.assertThatReceivedProject(cproject.getProject());
assertEquals(EXTERNAL_TOOL_NAME, commandLauncher.externalToolName); commandLauncher.assertThatReceivedExternalToolName(EXTERNAL_TOOL_NAME);
String expectedExecutablePath = configurationSettings.getPath().getValue().toString(); commandLauncher.assertThatReceivedExecutablePath(configurationSettings.getPath());
assertEquals(expectedExecutablePath, commandLauncher.executablePath.toOSString()); commandLauncher.assertThatReceivedArgs(configurationSettings.getArgs());
String[] expectedArgs = { parameters.getActualFilePath(), "--debug=true", "--include=all" }; commandLauncher.assertThatReceivedWorkingDirectory(parameters.getWorkingDirectory());
assertArrayEquals(expectedArgs, commandLauncher.args); commandLauncher.assertThatReceivedShouldDisplayOutput(
assertEquals(parameters.getWorkingDirectory(), commandLauncher.workingDirectory); configurationSettings.getShouldDisplayOutput());
assertEquals(configurationSettings.getShouldDisplayOutput().getValue().booleanValue(), commandLauncher.assetThatReceivedOutputParsers(parsers);
commandLauncher.shouldDisplayOutput);
assertSame(parsers, commandLauncher.parsers);
} }
private static class CommandLauncherStub implements ICommandLauncher { private static class CommandLauncherStub implements ICommandLauncher {
IProject project; private IProject project;
String externalToolName; private String externalToolName;
IPath executablePath; private IPath executablePath;
String[] args; private String[] args;
IPath workingDirectory; private IPath workingDirectory;
boolean shouldDisplayOutput; private boolean shouldDisplayOutput;
List<AbstractOutputParser> parsers; private List<AbstractOutputParser> parsers;
@Override @Override
public void buildAndLaunchCommand(IProject project, String externalToolName, public void buildAndLaunchCommand(IProject project, String externalToolName,
@ -123,5 +126,35 @@ public class ExternalToolInvokerTest extends CodanTestCase {
this.shouldDisplayOutput = shouldDisplayOutput; this.shouldDisplayOutput = shouldDisplayOutput;
this.parsers = parsers; 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);
}
} }
} }

View file

@ -26,7 +26,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor;
* @since 2.1 * @since 2.1
*/ */
public class ArgsSetting extends SingleConfigurationSetting<String> { public class ArgsSetting extends SingleConfigurationSetting<String> {
private static final String KEY = "externalToolArgs"; //$NON-NLS-1$ static final String KEY = "externalToolArgs"; //$NON-NLS-1$
/** /**
* Constructor. * Constructor.

View file

@ -27,7 +27,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor;
* @since 2.1 * @since 2.1
*/ */
public class PathSetting extends SingleConfigurationSetting<File> { public class PathSetting extends SingleConfigurationSetting<File> {
private static final String KEY = "externalToolPath"; //$NON-NLS-1$ static final String KEY = "externalToolPath"; //$NON-NLS-1$
/** /**
* Constructor. * Constructor.

View file

@ -26,7 +26,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor;
* @since 2.1 * @since 2.1
*/ */
public class ShouldDisplayOutputSetting extends SingleConfigurationSetting<Boolean> { public class ShouldDisplayOutputSetting extends SingleConfigurationSetting<Boolean> {
private static final String KEY = "externalToolShouldDisplayOutput"; //$NON-NLS-1$ static final String KEY = "externalToolShouldDisplayOutput"; //$NON-NLS-1$
/** /**
* Constructor. * Constructor.