Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUnit plugin #23

Merged
merged 10 commits into from
Sep 16, 2012
48 changes: 48 additions & 0 deletions RemObjects.Train/API/FTP.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace RemObjects.Train.API;

interface

uses
RemObjects.Train,
RemObjects.Script.EcmaScript,
RemObjects.Script.EcmaScript.Internal,
System.Text,
System.Net,
System.IO;

type

[PluginRegistration]
FTPPlugIn = public class(IPluginRegistration)
private
protected
public
method &Register(aServices: IApiRegistrationServices);
[WrapAs('ftp.upload', SkipDryRun := true)]
class method FtpUpload(aServices: IApiRegistrationServices;ec: RemObjects.Script.EcmaScript.ExecutionContext; aServer, aUsername, aPassword, aFileName, aRemote: String);
end;

implementation

method FTPPlugIn.&Register(aServices: IApiRegistrationServices);
begin
var rov := aServices.RegisterObjectValue('ftp');
rov.AddValue('upload', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(FTPPlugIn), 'FtpUpload'));
end;

class method FTPPlugIn.FtpUpload(aServices: IApiRegistrationServices; ec: RemObjects.Script.EcmaScript.ExecutionContext; aServer, aUsername, aPassword, aFileName, aRemote: String);
begin
aFileName := aServices.ResolveWithBase(ec, aFileName);
using client := new WebClient() do
begin
client.Credentials := new NetworkCredential(aUsername, aPassword);
using sr := new System.IO.FileStream(aFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read) do
begin
var ba := new Byte[sr.Length];
sr.Read(ba, 0, ba.Length - 1);
client.UploadData(aServer + '/' + aRemote, ba);
end;
end;
end;

end.
2 changes: 1 addition & 1 deletion RemObjects.Train/API/Innosetup.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ implementation
var lPath := String(aServices.Environment['InnoSetup']);
if String.IsNullOrEmpty(lPath) then
lPath := String(Microsoft.Win32.Registry.GetValue('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1', 'InstallLocation', ''));
if String.IsNullOrEmpty(lPath) then raise new Exception('"InnoSetup" env var is set');
if String.IsNullOrEmpty(lPath) then raise new Exception('"InnoSetup" env var is not set');
lPath := System.IO.Path.Combine(lPath, 'ISCC.exe');
if not System.IO.File.Exists(lPath) then raise new Exception(lPath+' could not be found');
if aServices.Engine.DryRun then exit;
Expand Down
48 changes: 48 additions & 0 deletions RemObjects.Train/API/MD5.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace RemObjects.Train.API;

interface

uses
RemObjects.Train,
System.Threading,
System.Text,
System.IO,
System.Security.Cryptography,
RemObjects.Script.EcmaScript;

type

[PluginRegistration]
MD5PlugIn = public class(IPluginRegistration)
private
protected
public
method &Register(aServices: IApiRegistrationServices);
[WrapAs('md5.createFromFile')]
class method GetMd5HashFromFile(aServices: IApiRegistrationServices; ec: ExecutionContext; aFilename: String): String;
end;

implementation

method MD5PlugIn.&Register(aServices: IApiRegistrationServices);
begin
aServices.RegisterObjectValue('md5').AddValue('createFromFile', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(MD5PlugIn), 'GetMd5HashFromFile'));
end;

class method MD5PlugIn.GetMd5HashFromFile(aServices: IApiRegistrationServices; ec: ExecutionContext; aFilename: String): String;
begin
aFilename := aServices.ResolveWithBase(ec, aFilename);
using file := new FileStream(aFilename, FileMode.Open) do
begin
var md5: MD5 := new MD5CryptoServiceProvider();
var retVal := md5.ComputeHash(file);
var sb := new StringBuilder();
for i: Int32 := 0 to retVal.Length - 1 do
begin
sb.Append(retVal[i].ToString('x2'))
end;
exit sb.ToString();
end;
end;

end.
48 changes: 48 additions & 0 deletions RemObjects.Train/API/NUnit.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace RemObjects.Train.API;

interface

uses
RemObjects.Train,
System.Threading,
System.Text,
RemObjects.Script.EcmaScript;
type

[PluginRegistration]
NUnitPlugin = public class(IPluginRegistration)
private
protected
public
method &Register(aServices: IApiRegistrationServices);
[WrapAs('nunit.run')]
class method NUnitRun(aServices: IApiRegistrationServices; ec: ExecutionContext; aFilename: String);
end;


implementation

uses
System.IO;

method NUnitPlugin.&Register(aServices: IApiRegistrationServices);
begin
aServices.RegisterObjectValue('nunit')
.AddValue('run', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(NUnitPlugin), 'NUnitRun'));
end;

class method NUnitPlugin.NUnitRun(aServices: IApiRegistrationServices; ec: ExecutionContext; aFilename: String);
begin
aFilename := aServices.ResolveWithBase(ec, aFilename);
aServices.Logger.LogMessage('Running Unit Tests in this file : ' + aFilename);
var lPath := String(aServices.Environment['NUnit']);
if String.IsNullOrEmpty(lPath) then raise new Exception('"NUnit" env var is not set');
lPath := System.IO.Path.Combine(lPath, 'nunit-console.exe');
if not System.IO.File.Exists(lPath) then raise new Exception(lPath + ' could not be found');
var n:= Shell.ExecuteProcess(lPath, aFilename, nil, false,
a-> aServices.Logger.LogError(a),
a-> aServices.Logger.LogMessage(a), nil, nil);
if n <> 0 then raise new Exception('Units test(s) failed');
end;

end.
5 changes: 3 additions & 2 deletions RemObjects.Train/API/Zip.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface
public
method &Register(aServices: IApiRegistrationServices);
[WrapAs('zip.compress', SkipDryRun := true)]
class method ZipCompress(aServices: IApiRegistrationServices; ec: ExecutionContext; zip: String; aInputFolder: String; aFileMasks: String; aRecurse: Boolean := true);
class method ZipCompress(aServices: IApiRegistrationServices; ec: ExecutionContext; zip: String; aInputFolder: String; aFileMasks: String; aRecurse: Boolean := true; aPassword: String := nil);

[WrapAs('zip.list', SkipDryRun := true, Important := false)]
class method ZipList(aServices: IApiRegistrationServices; ec: ExecutionContext; zip: String): array of ZipEntryData;
Expand Down Expand Up @@ -47,7 +47,7 @@ implementation
;
end;

class method ZipRegistration.ZipCompress(aServices: IApiRegistrationServices; ec: ExecutionContext; zip: String; aInputFolder: String; aFileMasks: String; aRecurse: Boolean);
class method ZipRegistration.ZipCompress(aServices: IApiRegistrationServices; ec: ExecutionContext; zip: String; aInputFolder: String; aFileMasks: String; aRecurse: Boolean; aPassword: String := nil);
begin
zip := aServices.ResolveWithBase(ec,zip);
//if System.IO.File.Exists(zip) then System.IO.File.Delete(zip);
Expand All @@ -57,6 +57,7 @@ implementation
if not aInputFolder.EndsWith(System.IO.Path.DirectorySeparatorChar) then
aInputFolder := aInputFolder + System.IO.Path.DirectorySeparatorChar;
var lZip := new Ionic.Zip.ZipFile();
if not String.IsNullOrEmpty(aPassword) then lZip.Password := aPassword;
lZip.ParallelDeflateThreshold := -1;
for each mask in aFileMasks.Split([';'], StringSplitOptions.RemoveEmptyEntries) do
for each el in System.IO.Directory.EnumerateFiles(aInputFolder, mask, if aRecurse then System.IO.SearchOption.AllDirectories else System.IO.SearchOption.TopDirectoryOnly) do begin
Expand Down
30 changes: 6 additions & 24 deletions RemObjects.Train/RemObjects.Train.oxygene
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,21 @@
<Compile Include="API\Delphi.pas" />
<Compile Include="API\Environment.pas" />
<Compile Include="API\File.pas" />
<Compile Include="API\FTP.pas" />
<Compile Include="API\Gac.pas" />
<Compile Include="API\Images.pas" />
<Compile Include="API\Ini.pas" />
<Compile Include="API\InnoSetup.pas" />
<Compile Include="API\Interfaces.pas" />
<Compile Include="API\Logging.pas" />
<Compile Include="API\Mail.pas" />
<Compile Include="API\MD5.pas" />
<Compile Include="API\MSBuild.pas" />
<Compile Include="API\NUnit.pas" />
<Compile Include="API\Resources.pas" />
<Compile Include="API\Shell.pas" />
<Compile Include="API\SSH.pas" />
<Compile Include="API\TextFile.pas" />
<Compile Include="API\Web.pas" />
<Compile Include="API\Wrapper.pas" />
<Compile Include="API\Xcode.pas" />
Expand Down Expand Up @@ -134,29 +138,7 @@
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Oxygene\RemObjects.Oxygene.targets" />
<PropertyGroup>
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PreBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent />
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
</Project>