Skip to content

Commit 21864b7

Browse files
committed
Created return of results
1 parent 39deb74 commit 21864b7

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

NsJavaLocator.lpr

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
Utils;
3434

3535
type
36+
TReturnOption = (Version, Build, VersionString, InstallationType, Architecture, ArchitectureBits);
3637

3738
{ TParameters }
3839

@@ -49,6 +50,7 @@ TParameters = class(TObject, TSettings)
4950
FLogLevel : TLogLevel;
5051
FIsLogging : Boolean;
5152
FIsDialogDebug : Boolean;
53+
FReturnOptions : TFPGList<TReturnOption>;
5254
function ReadParams() : TVStringList;
5355
function GetLogLevel() : TLogLevel;
5456
function GetLogging() : Boolean;
@@ -62,6 +64,7 @@ TParameters = class(TObject, TSettings)
6264
function GetMinVersion() : VString;
6365
function GetMaxVersion() : VString;
6466
function GetOptimalVersion() : VString;
67+
function GetReturnOptions() : TFPGList<TReturnOption>;
6568
procedure ParseParams();
6669
constructor Create();
6770
destructor Destroy(); override;
@@ -77,6 +80,7 @@ TParameters = class(TObject, TSettings)
7780
property LogLevel : TLogLevel read GetLogLevel;
7881
property IsLogging : Boolean read GetLogging;
7982
property IsDialogDebug : Boolean read GetDialogDebug;
83+
property ReturnOptions : TFPGList<TReturnOption> read GetReturnOptions;
8084
end;
8185

8286
{ TRunner }
@@ -85,6 +89,7 @@ TRunner = class(TObject, TLogger)
8589
private
8690
FParams : TParameters;
8791
FLogLevel : TLogLevel;
92+
procedure ReturnResults(const Installations : TFPGObjectList<TJavaInstallation>);
8893
public
8994
procedure Log(const Message : VString; const LogLevel : TLogLevel);
9095
function IsWarn() : Boolean;
@@ -97,6 +102,46 @@ TRunner = class(TObject, TLogger)
97102

98103
{ TRunner }
99104

105+
procedure TRunner.ReturnResults(const Installations : TFPGObjectList<TJavaInstallation>);
106+
107+
var
108+
Installation : TJavaInstallation;
109+
i : Integer;
110+
s : VString;
111+
112+
begin
113+
if (Installations = Nil) or (Installations.Count < 1) then begin
114+
for i := 1 to FParams.ReturnOptions.Count do PushString('');
115+
PushString('');
116+
Exit;
117+
end;
118+
Installation := Installations[0];
119+
for i := FParams.ReturnOptions.Count - 1 downto 0 do begin
120+
case FParams.ReturnOptions[i] of
121+
TReturnOption.Version: begin
122+
if Installation.Version > 0 then PushString(IntToVStr(Installation.Version))
123+
else PushString('');
124+
end;
125+
TReturnOption.Build: begin
126+
if Installation.Build > -1 then PushString(IntToVStr(Installation.Build))
127+
else PushString('');
128+
end;
129+
TReturnOption.VersionString: begin
130+
if Installation.Version < 1 then PushString('')
131+
else begin
132+
s := IntToVStr(Installation.Version);
133+
if Installation.Build > -1 then s := s + '.' + IntToVStr(Installation.Build);
134+
PushString(s);
135+
end;
136+
end;
137+
TReturnOption.InstallationType: PushString(InstallationTypeToStr(Installation.InstallationType));
138+
TReturnOption.Architecture: PushString(ArchitectureToStr(Installation.Architecture, False));
139+
TReturnOption.ArchitectureBits: PushString(ArchitectureToStr(Installation.Architecture, True));
140+
end;
141+
end;
142+
PushString(Installation.Path);
143+
end;
144+
100145
procedure TRunner.Log(const Message : VString; const LogLevel : TLogLevel);
101146

102147
var
@@ -154,6 +199,7 @@ procedure TRunner.Run();
154199
finally
155200
Evaluator.Free();
156201
end;
202+
ReturnResults(Parser.Installations);
157203
finally
158204
Parser.Free();
159205
end;
@@ -211,6 +257,11 @@ function TParameters.GetOptimalVersion() : VString;
211257
Result := FOptimalVersion;
212258
end;
213259

260+
function TParameters.GetReturnOptions() : TFPGList<TReturnOption>;
261+
begin
262+
Result := FReturnOptions;
263+
end;
264+
214265
function TParameters.ReadParams() : TVStringList;
215266

216267
var
@@ -256,6 +307,12 @@ procedure TParameters.ParseParams();
256307
poLog = '/LOG';
257308
poDialogDebug = '/DIALOGDEBUG';
258309
poLogLevel = '/LOGLEVEL';
310+
poRetVersion = '/RETVERSION';
311+
poRetBuild = '/RETBUILD';
312+
poRetVersionStr = '/RETVERSIONSTR';
313+
poRetInstType = '/RETINSTTYPE';
314+
poRetArch = '/RETARCH';
315+
poRetArchBits = '/RETARCHBITS';
259316

260317
var
261318
parameterList : TVStringList;
@@ -271,6 +328,12 @@ procedure TParameters.ParseParams();
271328
if EqualStr(poLog, parameterList[i], False) then FIsLogging := True
272329
else if EqualStr(poDialogDebug, parameterList[i], False) then FIsDialogDebug := True
273330
else if EqualStr(poSkipOSPath, parameterList[i], False) then FIsSkipOSPath := True
331+
else if EqualStr(poRetVersion, parameterList[i], False) then FReturnOptions.Add(TReturnOption.Version)
332+
else if EqualStr(poRetBuild, parameterList[i], False) then FReturnOptions.Add(TReturnOption.Build)
333+
else if EqualStr(poRetVersionStr, parameterList[i], False) then FReturnOptions.Add(TReturnOption.VersionString)
334+
else if EqualStr(poRetInstType, parameterList[i], False) then FReturnOptions.Add(TReturnOption.InstallationType)
335+
else if EqualStr(poRetArch, parameterList[i], False) then FReturnOptions.Add(TReturnOption.Architecture)
336+
else if EqualStr(poRetArchBits, parameterList[i], False) then FReturnOptions.Add(TReturnOption.ArchitectureBits)
274337

275338
// All value-less options must be handled before this point
276339
else if (i + 1 >= parameterList.Count) or (parameterList[i + 1][1] = '/') then begin
@@ -487,10 +550,12 @@ constructor TParameters.Create();
487550
FLogLevel := TLogLevel.INFO;
488551
FIsLogging := False;
489552
FIsDialogDebug := False;
553+
FReturnOptions := TFPGList<TReturnOption>.Create();
490554
end;
491555

492556
destructor TParameters.Destroy();
493557
begin
558+
FReturnOptions.Free();
494559
FFilteredPaths.Free();
495560
FFilePaths.Free();
496561
FEnvironmentVariables.Free();

0 commit comments

Comments
 (0)