Skip to content

Commit

Permalink
issue 39 - detect the file encoding if possible. Fall back to ANSI if…
Browse files Browse the repository at this point in the history
… not able to detect. issue 56 - make token replacement configurable and ignore anything that doesn't map and add token replacement switch to the command line.
  • Loading branch information
ferventcoder committed Aug 12, 2011
1 parent d1a25ec commit f4bb6d3
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 239 deletions.
7 changes: 6 additions & 1 deletion product/roundhouse.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
//force all anytime scripts
.Add("runallanytimescripts|forceanytimescripts",
"RunAllAnyTimeScripts - This instructs RH to run any time scripts every time it is run. Defaults to false.",
option => configuration.RunAllAnyTimeScripts = option != null)
option => configuration.RunAllAnyTimeScripts = option != null)
//disable token replacement
.Add("disabletokens|disabletokenreplacement",
"DisableTokenReplacement - This instructs RH to not perform token replacement {{somename}}. Defaults to false.",
option => configuration.DisableTokenReplacement = option != null)
//recorders
.Add("baseline",
"Baseline - This instructs RH to create an insert for its recording tables, but not to actually run anything against the database. Use this option if you already have scripts that have been run through other means (and BEFORE you start the new ones).",
Expand Down Expand Up @@ -293,6 +297,7 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
"/simple " +
"/debug " +
"/runallanytimescripts " +
"/disabletokenreplacement " +
"/baseline " +
"/dryrun " +
"]", Environment.NewLine);
Expand Down
1 change: 1 addition & 0 deletions product/roundhouse.tasks/DBDeploy_MSBuild.proj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
WithTransaction="false"
RecoveryModeSimple="false"
RunAllAnyTimeScripts="false"
DisableTokenReplacement="false"
/>
</Target>

Expand Down
2 changes: 2 additions & 0 deletions product/roundhouse.tasks/Roundhouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ bool ITask.Execute()

public bool RunAllAnyTimeScripts { get; set; }

public bool DisableTokenReplacement { get; set; }

#endregion

public void run_the_task()
Expand Down
1 change: 1 addition & 0 deletions product/roundhouse.tasks/samples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
WithTransaction="false"
RecoveryModeSimple="false"
RunAllAnyTimeScripts="false"
DisableTokenReplacement="false"
/>

</msbuild>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,9 @@ public void if_given_a_value_that_is_not_set_should_return_empty_string()
}

[Observation]
public void if_given_a_value_that_does_not_exist_should_error()
public void if_given_a_value_that_does_not_exist_should_return_the_value()
{
bool error_happened = false;
try
{
TokenReplacer.replace_tokens(configuration, "ALTER DATABASE {{database}}");
}
catch (Exception)
{
error_happened = true;
}

error_happened.should_be_true();

TokenReplacer.replace_tokens(configuration, "ALTER DATABASE {{database}}").should_be_equal_to("ALTER DATABASE {{database}}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.IO;

namespace roundhouse.tests.infrastructure.filesystem
{
using roundhouse.infrastructure.filesystem;
using bdddoc.core;
using developwithpassion.bdd.contexts;
using developwithpassion.bdd.mbunit;
using developwithpassion.bdd.mbunit.standard;
using developwithpassion.bdd.mbunit.standard.observations;

public class WindowsFileSystemAccessSpecs
{
public abstract class concern_for_file_system : observations_for_a_sut_with_a_contract<FileSystemAccess, WindowsFileSystemAccess>
{
protected static object result;

context c = () => { };
}

[Concern(typeof(WindowsFileSystemAccess))]
public class when_reading_files_with_different_formats : concern_for_file_system
{
protected static string utf8_file;
protected static string ansi_file;

because b = () =>
{
if (File.Exists(@".\infrastructure\filesystem\utf8encoded.txt"))
{
utf8_file = sut.read_file_text(@".\infrastructure\filesystem\utf8encoded.txt");
}
else
{
utf8_file = sut.read_file_text(@".\\build_output\RoundhousE\infrastructure\filesystem\utf8encoded.txt");
}
if (File.Exists(@".\infrastructure\filesystem\ansiencoded.txt"))
{
ansi_file = sut.read_file_text(@".\infrastructure\filesystem\ansiencoded.txt");
}
else
{
ansi_file = sut.read_file_text(@".\build_output\RoundhousE\infrastructure\filesystem\ansiencoded.txt");
}
};

[Observation]
public void utf8_encoded_file_should_read_correctly()
{
utf8_file.should_be_equal_to("INSERT INTO [dbo].[timmy]([value]) VALUES('Gã')");
}

[Observation]
public void ansi_encoded_file_should_read_correctly()
{
ansi_file.should_be_equal_to("INSERT INTO [dbo].[timmy]([value]) VALUES('Gã')");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO [dbo].[timmy]([value]) VALUES('G�')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO [dbo].[timmy]([value]) VALUES('Gã')
13 changes: 10 additions & 3 deletions product/roundhouse.tests/roundhouse.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<Compile Include="infrastructure\logging\LogSpecs.cs" />
<Compile Include="migrators\DefaultDatabaseMigratorSpecs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="infrastructure\filesystem\WindowsFileSystemAccessSpecs.cs" />
<Compile Include="sqlsplitters\SplitterContext.cs" />
<Compile Include="sqlsplitters\StatementSplitterSpecs.cs" />
<Compile Include="TestExtensions.cs" />
Expand All @@ -143,9 +144,7 @@
<Name>roundhouse</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="infrastructure\filesystem\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
Expand All @@ -166,6 +165,14 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="infrastructure\filesystem\ansiencoded.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="infrastructure\filesystem\utf8encoded.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
1 change: 1 addition & 0 deletions product/roundhouse/consoles/DefaultConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder
public bool DryRun { get; set; }
public bool Baseline { get; set; }
public bool RunAllAnyTimeScripts { get; set; }
public bool DisableTokenReplacement { get; set; }
}
}
6 changes: 5 additions & 1 deletion product/roundhouse/databases/DefaultDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public void create_database_if_it_doesnt_exist()
string create_script = create_database_script();
if (!string.IsNullOrEmpty(custom_create_database_script))
{
create_script = TokenReplacer.replace_tokens(configuration, custom_create_database_script);
create_script = custom_create_database_script;
if (!configuration.DisableTokenReplacement)
{
create_script = TokenReplacer.replace_tokens(configuration, create_script);
}
}
run_sql(create_script, ConnectionType.Admin);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ public interface ConfigurationPropertyHolder
bool DryRun { get; set; }
bool Baseline { get; set; }
bool RunAllAnyTimeScripts { get; set; }
bool DisableTokenReplacement { get; set; }
}
}
14 changes: 6 additions & 8 deletions product/roundhouse/infrastructure.app/tokens/TokenReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ public static string replace_tokens(ConfigurationPropertyHolder configuration, s
{
string key = "";
try
key = m.Groups["key"].Value.to_lower();
if (!dictionary.ContainsKey(key))
{
key = m.Groups["key"].Value.to_lower();
var value = dictionary[key];
return value;
}
catch (Exception)
{
throw;
return "{{" + key + "}}";
}
var value = dictionary[key];
return value;
});

return output;
Expand Down
Loading

0 comments on commit f4bb6d3

Please sign in to comment.