@@ -107,6 +107,8 @@ TEvaluator = class(TObject)
107107 FVersionExpRegEx : TRegExpr;
108108 function ParseVersionExpression (VersionExpr : VString) : TVersionCondition;
109109 procedure Exclude ();
110+ procedure Sort ();
111+ procedure Report ();
110112 public
111113 procedure Process ();
112114 constructor Create(
@@ -118,6 +120,7 @@ TEvaluator = class(TObject)
118120 end ;
119121
120122function GetJavawInfo (Path : VString) : TJavaInstallation;
123+ function ConditionTrue (const Condition : TVersionCondition; const Installation : TJavaInstallation) : Boolean;
121124{
122125 TFGObjectList "helper" methods
123126 Since TFGObjectLIst isn't made to be subclassed, these methods are a "quick and dirty" way to ensure item uniqueness.
@@ -842,10 +845,87 @@ procedure TEvaluator.Exclude;
842845 end ;
843846end ;
844847
848+ function CompareInstallations (const inst1, inst2 : TJavaInstallation) : Integer;
849+
850+ begin
851+ Result := 0 ;
852+ if (inst1 = Nil ) and (inst2 = Nil ) then Exit;
853+ if inst1 = Nil then Result := 1
854+ else if inst2 = Nil then Result := -1
855+ else begin
856+ if inst1.Optimal <> inst2.Optimal then begin
857+ if inst1.Optimal then Result := -1
858+ else Result := 1 ;
859+ end
860+ else if inst1.Architecture <> inst2.Architecture then Result := Ord(inst2.Architecture) - Ord(inst1.Architecture)
861+ else if inst1.Version <> inst2.Version then Result := inst2.Version - inst1.Version
862+ else if inst1.Build <> inst2.Build then Result := inst2.Build - inst1.Build;
863+ end ;
864+ end ;
865+
866+ procedure TEvaluator.Sort ();
867+
868+ var
869+ opt : TVersionCondition;
870+ i : Integer;
871+
872+ begin
873+ // Tag the "optimal" installations
874+ opt := ParseVersionExpression(FSettings.GetOptimalVersion());
875+ if opt.Valid then begin
876+ for i := 0 to FInstallations.Count - 1 do FInstallations[i].Optimal := ConditionTrue(opt, FInstallations[i]);
877+ end
878+ else if (FLogger <> Nil ) and (FSettings.GetOptimalVersion() <> ' ' ) then
879+ FLogger.Log(' Ignoring invalid optimum version expression: ' + FSettings.GetOptimalVersion(), TLogLevel.WARN);
880+
881+ // Sort
882+ if FInstallations.Count < 2 then Exit;
883+ FInstallations.Sort(@CompareInstallations);
884+ end ;
885+
886+ procedure TEvaluator.Report ();
887+
888+ var
889+ i : Integer;
890+
891+ begin
892+ if (FLogger = Nil ) or (not FLogger.IsDebug()) then Exit;
893+
894+ if FInstallations.Count > 1 then begin
895+ for i := 0 to FInstallations.Count - 1 do begin
896+ FLogger.Log(
897+ ' Suitability-sorted Java installation ' + IntToVStr(i + 1 ) +
898+ ' : Version=' + IntToVStr(FInstallations[i].Version) + ' :' + IntToVStr(FInstallations[i].Build) +
899+ ' , Type=' + InstallationTypeToStr(FInstallations[i].InstallationType) +
900+ ' , Arch=' + ArchitectureToStr(FInstallations[i].Architecture, False) +
901+ ' , Optimal=' + BoolToVStr(FInstallations[i].Optimal) +
902+ ' , Path=' + FInstallations[i].Path,
903+ TLogLevel.DEBUG
904+ );
905+ end ;
906+ end
907+ else if FInstallations.Count = 1 then begin
908+ for i := 0 to FInstallations.Count - 1 do begin
909+ FLogger.Log(
910+ ' Mathing Java installation: ' +
911+ ' Version=' + IntToVStr(FInstallations[i].Version) + ' :' + IntToVStr(FInstallations[i].Build) +
912+ ' , Type=' + InstallationTypeToStr(FInstallations[i].InstallationType) +
913+ ' , Arch=' + ArchitectureToStr(FInstallations[i].Architecture, False) +
914+ ' , Optimal=' + BoolToVStr(FInstallations[i].Optimal) +
915+ ' , Path=' + FInstallations[i].Path,
916+ TLogLevel.DEBUG
917+ );
918+ end ;
919+ end
920+ else FLogger.Log(' No matching Java installation found' , TLogLevel.DEBUG);
921+ end ;
922+
845923procedure TEvaluator.Process ();
846924
847925begin
848926 Exclude();
927+ Sort();
928+ Report();
849929end ;
850930
851931constructor TEvaluator.Create(
@@ -893,6 +973,57 @@ function GetJavawInfo(Path : VString) : TJavaInstallation;
893973 end ;
894974end ;
895975
976+ function ConditionTrue (const Condition : TVersionCondition; const Installation : TJavaInstallation) : Boolean;
977+
978+ begin
979+ Result := False;
980+ if not Condition.Valid then Exit;
981+ case Condition.CompareType of
982+ TCompareType.less: begin
983+ Result := (Installation.Version > 0 ) and (
984+ (Installation.Version < Condition.Version) or (
985+ (Condition.Build > -1 ) and (Installation.Build > -1 ) and
986+ (Installation.Version = Condition.Version) and (Installation.Build < Condition.Build)
987+ )
988+ );
989+ end ;
990+ TCompareType.lessOrEqual: begin
991+ Result := (Installation.Version > 0 ) and (
992+ (Installation.Version < Condition.Version) or
993+ (
994+ (Installation.Version = Condition.Version) and (Condition.Build < 0 )
995+ ) or (
996+ (Condition.Build > -1 ) and (Installation.Build > -1 ) and
997+ (Installation.Version = Condition.Version) and (Installation.Build <= Condition.Build)
998+ )
999+ );
1000+ end ;
1001+ TCompareType.more: begin
1002+ Result := (Installation.Version > 0 ) and (
1003+ (Installation.Version > Condition.Version) or (
1004+ (Condition.Build > -1 ) and (Installation.Build > -1 ) and
1005+ (Installation.Version = Condition.Version) and (Installation.Build > Condition.Build)
1006+ )
1007+ );
1008+ end ;
1009+ TCompareType.moreOrEqual: begin
1010+ Result := (Installation.Version > 0 ) and (
1011+ (Installation.Version > Condition.Version) or
1012+ (
1013+ (Installation.Version = Condition.Version) and (Condition.Build < 0 )
1014+ ) or (
1015+ (Condition.Build > -1 ) and (Installation.Build > -1 ) and
1016+ (Installation.Version = Condition.Version) and (Installation.Build >= Condition.Build)
1017+ )
1018+ );
1019+ end ;
1020+ else
1021+ Result := (Installation.Version > 0 ) and (Installation.Version = Condition.Version) and (
1022+ (Condition.Build < 0 ) or (Installation.Build = Condition.Build)
1023+ );
1024+ end ;
1025+ end ;
1026+
8961027{
8971028 TFGObjectList "helper" methods
8981029 Since TFGObjectLIst isn't made to be subclassed, these methods are a "quick and dirty" way to ensure item uniqueness.
0 commit comments