|
@@ -54,7 +54,9 @@ Type
|
|
|
|
|
|
TGoogleAPIConverter = CLass(TCustomApplication)
|
|
TGoogleAPIConverter = CLass(TCustomApplication)
|
|
private
|
|
private
|
|
|
|
+ FDownloadOnly: Boolean;
|
|
FKeepJSON: Boolean;
|
|
FKeepJSON: Boolean;
|
|
|
|
+ FUnitPrefix: String;
|
|
FVerbose: Boolean;
|
|
FVerbose: Boolean;
|
|
procedure ConversionLog(Sender: TObject; LogType: TCodegenLogType; const Msg: String);
|
|
procedure ConversionLog(Sender: TObject; LogType: TCodegenLogType; const Msg: String);
|
|
procedure CreateFPMake(FileName: String; L: TAPIEntries);
|
|
procedure CreateFPMake(FileName: String; L: TAPIEntries);
|
|
@@ -71,6 +73,8 @@ Type
|
|
Procedure DoRun; override;
|
|
Procedure DoRun; override;
|
|
Property KeepJSON : Boolean Read FKeepJSON Write FKeepJSON;
|
|
Property KeepJSON : Boolean Read FKeepJSON Write FKeepJSON;
|
|
Property Verbose : Boolean Read FVerbose Write FVerbose;
|
|
Property Verbose : Boolean Read FVerbose Write FVerbose;
|
|
|
|
+ Property DownloadOnly : Boolean Read FDownloadOnly Write FDownloadOnly;
|
|
|
|
+ Property UnitPrefix : String Read FUnitPrefix Write FUnitPrefix;
|
|
end;
|
|
end;
|
|
|
|
|
|
{ TAPIEntries }
|
|
{ TAPIEntries }
|
|
@@ -85,19 +89,21 @@ begin
|
|
Result:=Add as TAPIEntry;
|
|
Result:=Add as TAPIEntry;
|
|
end;
|
|
end;
|
|
|
|
|
|
-constructor TGoogleAPIConverter.Create(AOwner: TComponent);
|
|
|
|
|
|
+Constructor TGoogleAPIConverter.Create(AOwner: TComponent);
|
|
begin
|
|
begin
|
|
inherited Create(AOwner);
|
|
inherited Create(AOwner);
|
|
StopOnException:=True;
|
|
StopOnException:=True;
|
|
TDiscoveryJSONToPas.RegisterAllObjects;
|
|
TDiscoveryJSONToPas.RegisterAllObjects;
|
|
|
|
+ UnitPrefix:='google';
|
|
end;
|
|
end;
|
|
|
|
|
|
-destructor TGoogleAPIConverter.Destroy;
|
|
|
|
|
|
+Destructor TGoogleAPIConverter.Destroy;
|
|
begin
|
|
begin
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TGoogleAPIConverter.HttpGetJSON(const URL: String; Response: TStream): Boolean;
|
|
|
|
|
|
+Function TGoogleAPIConverter.HttpGetJSON(Const URL: String; Response: TStream
|
|
|
|
+ ): Boolean;
|
|
|
|
|
|
Var
|
|
Var
|
|
Webclient : TAbstractWebClient;
|
|
Webclient : TAbstractWebClient;
|
|
@@ -116,6 +122,7 @@ begin
|
|
try
|
|
try
|
|
Req:=WebClient.CreateRequest;
|
|
Req:=WebClient.CreateRequest;
|
|
Req.ResponseContent:=Response;
|
|
Req.ResponseContent:=Response;
|
|
|
|
+ ConversionLog(Self,cltInfo,'Downloading: '+URL);
|
|
Resp:=WebClient.ExecuteRequest('GET',URL,Req);
|
|
Resp:=WebClient.ExecuteRequest('GET',URL,Req);
|
|
Result:=(Resp<>Nil);
|
|
Result:=(Resp<>Nil);
|
|
finally
|
|
finally
|
|
@@ -155,6 +162,10 @@ begin
|
|
Writeln('-u --url=URL URL to download the REST description from.');
|
|
Writeln('-u --url=URL URL to download the REST description from.');
|
|
Writeln('-v --serviceversion=v Service version to download the REST description for.');
|
|
Writeln('-v --serviceversion=v Service version to download the REST description for.');
|
|
Writeln('-V --verbose Write some diagnostic messages');
|
|
Writeln('-V --verbose Write some diagnostic messages');
|
|
|
|
+ Writeln('-k --keepjson Keep the downloaded JSON files');
|
|
|
|
+ Writeln('-d --onlydownload Just download the files, do not actually convert.');
|
|
|
|
+ Writeln(' Only effective if -k or --keepjson is also specified.');
|
|
|
|
+ Writeln('-f --unitprefix Prefix for generated unit names. Default is "google"');
|
|
Writeln('If the outputfilename is empty and cannot be determined, an error is returned');
|
|
Writeln('If the outputfilename is empty and cannot be determined, an error is returned');
|
|
Halt(Ord(Msg<>''));
|
|
Halt(Ord(Msg<>''));
|
|
end;
|
|
end;
|
|
@@ -355,7 +366,7 @@ begin
|
|
if AllVersions or O.Get('preferred',false) then
|
|
if AllVersions or O.Get('preferred',false) then
|
|
begin
|
|
begin
|
|
RU:=O.get('discoveryRestUrl');
|
|
RU:=O.get('discoveryRestUrl');
|
|
- LFN:=O.get('name');
|
|
|
|
|
|
+ LFN:=UnitPrefix+O.get('name');
|
|
if AllVersions then
|
|
if AllVersions then
|
|
LFN:=LFN+'_'+StringReplace(O.get('version'),'.','',[rfReplaceAll]);
|
|
LFN:=LFN+'_'+StringReplace(O.get('version'),'.','',[rfReplaceAll]);
|
|
if (OFN='') then
|
|
if (OFN='') then
|
|
@@ -377,33 +388,37 @@ begin
|
|
RS.Position:=0;
|
|
RS.Position:=0;
|
|
U:=UL.AddEntry;
|
|
U:=UL.AddEntry;
|
|
U.FileName:=LFN;
|
|
U.FileName:=LFN;
|
|
- DoConversion(RS,U);
|
|
|
|
|
|
+ if not DownloadOnly then
|
|
|
|
+ DoConversion(RS,U);
|
|
finally
|
|
finally
|
|
RS.Free;
|
|
RS.Free;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
- if HasOption('R','register') then
|
|
|
|
- RegisterUnit(GetOptionValue('R','register'),UL);
|
|
|
|
- if HasOption('m','fpmake') then
|
|
|
|
- CreateFpMake(GetOptionValue('m','fpmake'),UL);
|
|
|
|
|
|
+ if not DownloadOnly then
|
|
|
|
+ begin
|
|
|
|
+ if HasOption('R','register') then
|
|
|
|
+ RegisterUnit(GetOptionValue('R','register'),UL);
|
|
|
|
+ if HasOption('m','fpmake') then
|
|
|
|
+ CreateFpMake(GetOptionValue('m','fpmake'),UL);
|
|
|
|
+ end;
|
|
if HasOption('I','icon') then
|
|
if HasOption('I','icon') then
|
|
For I:=0 to UL.Count-1 do
|
|
For I:=0 to UL.Count-1 do
|
|
DownloadIcon(UL[i]);
|
|
DownloadIcon(UL[i]);
|
|
-
|
|
|
|
finally
|
|
finally
|
|
UL.Free;
|
|
UL.Free;
|
|
D.Free;
|
|
D.Free;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TGoogleAPIConverter.DoRun;
|
|
|
|
|
|
+Procedure TGoogleAPIConverter.DoRun;
|
|
|
|
|
|
Const
|
|
Const
|
|
- MyO : Array[1..19] of ansistring
|
|
|
|
|
|
+ MyO : Array[1..21] of ansistring
|
|
= ('help','input:','output:','extraunits:','baseclass:','classprefix:',
|
|
= ('help','input:','output:','extraunits:','baseclass:','classprefix:',
|
|
'url:','service:','serviceversion:','resourcesuffix:','license:',
|
|
'url:','service:','serviceversion:','resourcesuffix:','license:',
|
|
- 'All','all','register','icon','fpmake:','timestamp','verbose','keepjson');
|
|
|
|
|
|
+ 'All','all','register','icon','fpmake:','timestamp','verbose','keepjson',
|
|
|
|
+ 'onlydownload','unitprefix');
|
|
|
|
|
|
Var
|
|
Var
|
|
O,NonOpts : TStrings;
|
|
O,NonOpts : TStrings;
|
|
@@ -419,7 +434,7 @@ begin
|
|
try
|
|
try
|
|
O:=TStringList.Create;
|
|
O:=TStringList.Create;
|
|
For S in MyO do O.Add(S);
|
|
For S in MyO do O.Add(S);
|
|
- S:=Checkoptions('hi:o:e:b:p:u:s:v:r:L:aAR:Im:tVk',O,TStrings(Nil),NonOpts,True);
|
|
|
|
|
|
+ S:=Checkoptions('hi:o:e:b:p:u:s:v:r:L:aAR:Im:tVkdf',O,TStrings(Nil),NonOpts,True);
|
|
if NonOpts.Count>0 then
|
|
if NonOpts.Count>0 then
|
|
IFN:=NonOpts[0];
|
|
IFN:=NonOpts[0];
|
|
if NonOpts.Count>1 then
|
|
if NonOpts.Count>1 then
|
|
@@ -430,6 +445,10 @@ begin
|
|
end;
|
|
end;
|
|
FVerbose:=HasOption('V','verbose');
|
|
FVerbose:=HasOption('V','verbose');
|
|
FKeepJSON:=HasOption('k','keepjson');
|
|
FKeepJSON:=HasOption('k','keepjson');
|
|
|
|
+ if HasOption('f','unitprefix') then
|
|
|
|
+ UnitPrefix:=GetOptionValue('f','unitprefix');
|
|
|
|
+ If FKeepJSON Then
|
|
|
|
+ FDownLoadOnly:=HasOption('d','onlydownload');
|
|
if (S<>'') or HasOption('h','help') then
|
|
if (S<>'') or HasOption('h','help') then
|
|
Usage(S);
|
|
Usage(S);
|
|
DoAllServices:=HasOption('a','all') or HasOption('A','All');
|
|
DoAllServices:=HasOption('a','all') or HasOption('A','All');
|
|
@@ -455,7 +474,7 @@ begin
|
|
if (IFN<>'') then
|
|
if (IFN<>'') then
|
|
OFN:=ChangeFileExt(IFN,'.pp')
|
|
OFN:=ChangeFileExt(IFN,'.pp')
|
|
else if getOptionValue('s','service')<>'' then
|
|
else if getOptionValue('s','service')<>'' then
|
|
- OFN:='google'+getOptionValue('s','service')+'.pp';
|
|
|
|
|
|
+ OFN:=UnitPrefix+getOptionValue('s','service')+'.pp';
|
|
if (OFN='') and Not DoAllServices then
|
|
if (OFN='') and Not DoAllServices then
|
|
Usage('Need an output filename');
|
|
Usage('Need an output filename');
|
|
if DoAllServices then
|
|
if DoAllServices then
|
|
@@ -480,15 +499,16 @@ begin
|
|
else
|
|
else
|
|
JS:=TFileStream.Create(IFN,fmOpenRead or fmShareDenyWrite);
|
|
JS:=TFileStream.Create(IFN,fmOpenRead or fmShareDenyWrite);
|
|
try
|
|
try
|
|
- APIEntry:=TAPIEntry.Create(Nil);
|
|
|
|
- try
|
|
|
|
- APIEntry.FileName:=OFN;
|
|
|
|
- DoConversion(JS,APIEntry);
|
|
|
|
- if HasOption('I','icon') then
|
|
|
|
- DownloadIcon(APIEntry);
|
|
|
|
- finally
|
|
|
|
- APIEntry.Free;
|
|
|
|
- end;
|
|
|
|
|
|
+ if not DownLoadOnly then
|
|
|
|
+ APIEntry:=TAPIEntry.Create(Nil);
|
|
|
|
+ try
|
|
|
|
+ APIEntry.FileName:=OFN;
|
|
|
|
+ DoConversion(JS,APIEntry);
|
|
|
|
+ if HasOption('I','icon') then
|
|
|
|
+ DownloadIcon(APIEntry);
|
|
|
|
+ finally
|
|
|
|
+ APIEntry.Free;
|
|
|
|
+ end;
|
|
finally
|
|
finally
|
|
JS.Free;
|
|
JS.Free;
|
|
end;
|
|
end;
|
|
@@ -517,7 +537,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TGoogleAPIConverter.DoConversion(JS: TStream; AEntry: TAPIEntry);
|
|
|
|
|
|
+Procedure TGoogleAPIConverter.DoConversion(JS: TStream; AEntry: TAPIEntry);
|
|
|
|
|
|
Var
|
|
Var
|
|
L: String;
|
|
L: String;
|