implemented publish package

git-svn-id: trunk@3009 -
This commit is contained in:
mattias 2002-08-18 08:56:59 +00:00
parent 4d0a0d5c66
commit 0f1d76a734
3 changed files with 470 additions and 83 deletions

1
.gitattributes vendored
View File

@ -227,6 +227,7 @@ ide/projectdefs.pas svneol=native#text/pascal
ide/projectinspector.pas svneol=native#text/pascal
ide/projectopts.lrs svneol=native#text/pascal
ide/projectopts.pp svneol=native#text/pascal
ide/publishmodule.pas svneol=native#text/pascal
ide/publishprojectdlg.pas svneol=native#text/pascal
ide/runparamsopts.pas svneol=native#text/pascal
ide/sortselectiondlg.pas svneol=native#text/pascal

View File

@ -79,9 +79,9 @@ uses
UnitEditor, EditDefineTree, CodeToolsOptions, IDEOptionDefs, CodeToolsDefines,
DiffDialog, DiskDiffsDialog, UnitInfoDlg, EditorOptions, ViewUnit_dlg,
// rest of the ide
IDEDefs, LazarusIDEStrConsts, LazConf, MsgView, EnvironmentOpts,
TransferMacros, KeyMapping, IDEProcs, ExtToolDialog, ExtToolEditDlg,
MacroPromptDlg, OutputFilter, BuildLazDialog, MiscOptions,
IDEDefs, LazarusIDEStrConsts, LazConf, MsgView, PublishModule,
EnvironmentOpts, TransferMacros, KeyMapping, IDEProcs, ExtToolDialog,
ExtToolEditDlg, MacroPromptDlg, OutputFilter, BuildLazDialog, MiscOptions,
InputHistory, UnitDependencies, ClipBoardHistory, ProcessList,
InitialSetupDlgs, NewDialog, MakeResStrDlg, ToDoList, AboutFrm,
FindReplaceDialog, FindInFilesDlg,
@ -532,6 +532,9 @@ type
function DoBackupFile(const Filename:string;
IsPartOfProject:boolean): TModalResult; override;
function DoCheckFilesOnDisk: TModalResult; override;
function DoPublishModul(Options: TPublishModuleOptions;
const SrcDirectory, DestDirectory: string
): TModalResult; override;
// useful frontend methods
procedure DoSwitchToFormSrc(var ActiveSourceEditor:TSourceEditor;
@ -3844,8 +3847,8 @@ procedure TMainIDE.OnCopyFile(const Filename: string; var Copy: boolean;
Data: TObject);
begin
if Data=nil then exit;
if Data is TPublishProjectOptions then begin
Copy:=TPublishProjectOptions(Data).FileCanBePublished(Filename);
if Data is TPublishModuleOptions then begin
Copy:=TPublishModuleOptions(Data).FileCanBePublished(Filename);
//writeln('TMainIDE.OnCopyFile "',Filename,'" ',Copy);
end;
end;
@ -5167,23 +5170,11 @@ end;
function TMainIDE.DoPublishProject(Flags: TSaveFlags;
ShowDialog: boolean): TModalResult;
var
SrcDir, DestDir: string;
NewProjectFilename: string;
Tool: TExternalToolOptions;
CommandAfter, CmdAfterExe, CmdAfterParams: string;
procedure ShowErrorForCommandAfter;
begin
MessageDlg(lisInvalidCommand,
Format(lisTheCommandAfterIsNotExecutable, ['"', CmdAfterExe, '"']),
mtError,[mbCancel],0);
end;
begin
// show the publish project dialog
if ShowDialog then begin
Result:=ShowPublishProjectDialog(Project1.PublishOptions);
Project1.Modified:=Project1.PublishOptions.Modified;
if Result<>mrOk then exit;
IncreaseCompilerParseStamp;
end;
@ -5192,71 +5183,9 @@ begin
Result:=DoSaveProject(Flags);
if Result<>mrOk then exit;
// check command after
CommandAfter:=Project1.PublishOptions.CommandAfter;
if not MacroList.SubstituteStr(CommandAfter) then begin
Result:=mrCancel;
exit;
end;
SplitCmdLine(CommandAfter,CmdAfterExe,CmdAfterParams);
if (CmdAfterExe<>'') and not FileIsExecutable(CmdAfterExe) then begin
ShowErrorForCommandAfter;
Result:=mrCancel;
exit;
end;
// clear destination directory
DestDir:=GetProjPublishDir;
if (DestDir='') then begin
MessageDlg(lisInvalidDestinationDirectory,
Format(lisDestinationDirectoryIsInvalidPleaseChooseAComplete, ['"',
DestDir, '"', #13]),
mtError,[mbOk],0);
Result:=mrCancel;
exit;
end;
if DirectoryExists(DestDir) and (not DeleteDirectory(DestDir,true)) then
begin
MessageDlg(lisUnableToCleanUpDestinationDirectory,
Format(lisUnableToCleanUpPleaseCheckPermissions, ['"', DestDir, '"', #13]
),
mtError,[mbOk],0);
Result:=mrCancel;
exit;
end;
// copy the project directory
SrcDir:=AppendPathDelim(Project1.ProjectDirectory);
if not CopyDirectoryWithMethods(SrcDir,DestDir,
@OnCopyFile,@OnCopyError,Project1.PublishOptions) then
begin
Result:=mrCancel;
exit;
end;
// write a filtered .lpi file
NewProjectFilename:=DestDir+ExtractFilename(Project1.ProjectInfoFile);
DeleteFile(NewProjectFilename);
Result:=Project1.WriteProject(Project1.PublishOptions.WriteFlags,
NewProjectFilename);
if Result<>mrOk then exit;
// execute 'CommandAfter'
if (CmdAfterExe<>'') then begin
if FileIsExecutable(CmdAfterExe) then begin
Tool:=TExternalToolOptions.Create;
Tool.Filename:=CmdAfterExe;
Tool.Title:=lisCommandAfterPublishingProject;
Tool.WorkingDirectory:=DestDir;
Tool.CmdLineParams:=CmdAfterParams;
Result:=EnvironmentOptions.ExternalTools.Run(Tool,MacroList);
if Result<>mrOk then exit;
end else begin
ShowErrorForCommandAfter;
Result:=mrCancel;
exit;
end;
end;
// publish project
Result:=DoPublishModul(Project1.PublishOptions,Project1.ProjectDirectory,
GetProjPublishDir);
end;
function TMainIDE.DoShowProjectInspector: TModalResult;
@ -6214,6 +6143,89 @@ begin
AnUnitList.Free;
end;
function TMainIDE.DoPublishModul(Options: TPublishModuleOptions;
const SrcDirectory, DestDirectory: string): TModalResult;
var
SrcDir, DestDir: string;
NewProjectFilename: string;
Tool: TExternalToolOptions;
CommandAfter, CmdAfterExe, CmdAfterParams: string;
CurProject: TProject;
procedure ShowErrorForCommandAfter;
begin
MessageDlg(lisInvalidCommand,
Format(lisTheCommandAfterIsNotExecutable, ['"', CmdAfterExe, '"']),
mtError,[mbCancel],0);
end;
begin
// check command after
CommandAfter:=Options.CommandAfter;
if not MacroList.SubstituteStr(CommandAfter) then begin
Result:=mrCancel;
exit;
end;
SplitCmdLine(CommandAfter,CmdAfterExe,CmdAfterParams);
if (CmdAfterExe<>'') and not FileIsExecutable(CmdAfterExe) then begin
Result:=mrCancel;
exit;
end;
// clear destination directory
DestDir:=TrimFilename(DestDirectory);
if (DestDir='') then begin
ShowErrorForCommandAfter;
Result:=mrCancel;
exit;
end;
if DirectoryExists(DestDir) and (not DeleteDirectory(DestDir,true)) then
begin
MessageDlg(lisUnableToCleanUpDestinationDirectory,
Format(lisUnableToCleanUpPleaseCheckPermissions, ['"', DestDir, '"', #13]
),
mtError,[mbOk],0);
Result:=mrCancel;
exit;
end;
// copy the directory
SrcDir:=TrimFilename(AppendPathDelim(SrcDirectory));
if not CopyDirectoryWithMethods(SrcDir,DestDir,
@OnCopyFile,@OnCopyError,Options) then
begin
Result:=mrCancel;
exit;
end;
// write a filtered .lpi file
if Options is TPublishProjectOptions then begin
CurProject:=TProject(TPublishProjectOptions(Options).Owner);
NewProjectFilename:=DestDir+ExtractFilename(CurProject.ProjectInfoFile);
DeleteFile(NewProjectFilename);
Result:=CurProject.WriteProject(CurProject.PublishOptions.WriteFlags,
NewProjectFilename);
if Result<>mrOk then exit;
end;
// execute 'CommandAfter'
if (CmdAfterExe<>'') then begin
if FileIsExecutable(CmdAfterExe) then begin
Tool:=TExternalToolOptions.Create;
Tool.Filename:=CmdAfterExe;
Tool.Title:=lisCommandAfterPublishingModule;
Tool.WorkingDirectory:=DestDir;
Tool.CmdLineParams:=CmdAfterParams;
Result:=EnvironmentOptions.ExternalTools.Run(Tool,MacroList);
if Result<>mrOk then exit;
end else begin
ShowErrorForCommandAfter;
Result:=mrCancel;
exit;
end;
end;
end;
procedure TMainIDE.UpdateCaption;
var NewCaption:string;
begin
@ -8627,6 +8639,9 @@ end.
{ =============================================================================
$Log$
Revision 1.564 2003/05/12 13:11:34 mattias
implemented publish package
Revision 1.563 2003/05/12 08:06:32 mattias
small fixes for gtkopengl

371
ide/publishmodule.pas Normal file
View File

@ -0,0 +1,371 @@
{
/***************************************************************************
publishmodule.pas
-----------------
***************************************************************************/
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************
Author: Mattias Gaertner
}
unit PublishModule;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Laz_XMLCfg, IDEProcs, SynRegExpr, FileCtrl;
type
{ TPublishModuleOptions }
TPublishModuleOptions = class
private
FCommandAfter: string;
FDestinationDirectory: string;
FExcludeFileFilter: string;
FExcludeFilterRegExpr: TRegExpr;
FExcludeFilterSimpleSyntax: boolean;
FExcludeFilterValid: boolean;
FIgnoreBinaries: boolean;
FIncludeFileFilter: string;
FIncludeFilterRegExpr: TRegExpr;
FIncludeFilterSimpleSyntax: boolean;
FIncludeFilterValid: boolean;
FModified: boolean;
FModifiedLock: integer;
FOwner: TObject;
FUseExcludeFileFilter: boolean;
FUseIncludeFileFilter: boolean;
procedure SetCommandAfter(const AValue: string);
procedure SetDestinationDirectory(const AValue: string);
procedure SetExcludeFileFilter(const AValue: string);
procedure SetExcludeFilterSimpleSyntax(const AValue: boolean);
procedure SetIgnoreBinaries(const AValue: boolean);
procedure SetIncludeFileFilter(const AValue: string);
procedure SetIncludeFilterSimpleSyntax(const AValue: boolean);
procedure SetModified(const AValue: boolean);
procedure SetUseExcludeFileFilter(const AValue: boolean);
procedure SetUseIncludeFileFilter(const AValue: boolean);
procedure UpdateIncludeFilter;
procedure UpdateExcludeFilter;
protected
procedure DoOnModifyChange; virtual;
public
constructor Create(TheOwner: TObject);
destructor Destroy; override;
procedure Clear; virtual;
procedure LoadDefaults; virtual;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const APath: string); virtual;
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const APath: string); virtual;
function FileCanBePublished(const AFilename: string): boolean; virtual;
procedure LockModified;
procedure UnlockModified;
function GetDefaultDestinationDir: string; virtual;
public
property Owner: TObject read FOwner;
property Modified: boolean read FModified write SetModified;
// destination
property DestinationDirectory: string
read FDestinationDirectory write SetDestinationDirectory;
property CommandAfter: string read FCommandAfter write SetCommandAfter;
// file filter
property IgnoreBinaries: boolean read FIgnoreBinaries write SetIgnoreBinaries;
property UseIncludeFileFilter: boolean
read FUseIncludeFileFilter write SetUseIncludeFileFilter;
property IncludeFilterSimpleSyntax: boolean
read FIncludeFilterSimpleSyntax write SetIncludeFilterSimpleSyntax;
property IncludeFileFilter: string
read FIncludeFileFilter write SetIncludeFileFilter;
property IncludeFilterValid: boolean read FIncludeFilterValid;
property UseExcludeFileFilter: boolean
read FUseExcludeFileFilter write SetUseExcludeFileFilter;
property ExcludeFilterSimpleSyntax: boolean
read FExcludeFilterSimpleSyntax write SetExcludeFilterSimpleSyntax;
property ExcludeFileFilter: string
read FExcludeFileFilter write SetExcludeFileFilter;
property ExcludeFilterValid: boolean read FExcludeFilterValid;
end;
const
PublishModulOptsVersion = 2;
DefPublModIncFilter = '*.(pas|pp|inc|lpr|lfm|lrs|lpi|lpk|xml|fpc|sh)';
DefPublModExcFilter = '*.(bak|ppu|ppw|ppl|a|o|so);*~;backup';
DefPublishDirectory = '$(TestDir)/publishedproject/';
implementation
{ TPublishModuleOptions }
procedure TPublishModuleOptions.SetCommandAfter(const AValue: string);
begin
if FCommandAfter=AValue then exit;
FCommandAfter:=AValue;
Modified:=true;
end;
procedure TPublishModuleOptions.SetDestinationDirectory(const AValue: string);
begin
if FDestinationDirectory=AValue then exit;
FDestinationDirectory:=AValue;
Modified:=true;
end;
procedure TPublishModuleOptions.SetExcludeFileFilter(const AValue: string);
begin
if FExcludeFileFilter=AValue then exit;
FExcludeFileFilter:=AValue;
UpdateExcludeFilter;
Modified:=true;
end;
procedure TPublishModuleOptions.SetExcludeFilterSimpleSyntax(
const AValue: boolean);
begin
if FExcludeFilterSimpleSyntax=AValue then exit;
FExcludeFilterSimpleSyntax:=AValue;
UpdateExcludeFilter;
Modified:=true;
end;
procedure TPublishModuleOptions.SetIgnoreBinaries(const AValue: boolean);
begin
if FIgnoreBinaries=AValue then exit;
FIgnoreBinaries:=AValue;
Modified:=true;
end;
procedure TPublishModuleOptions.SetIncludeFileFilter(const AValue: string);
begin
if FIncludeFileFilter=AValue then exit;
FIncludeFileFilter:=AValue;
UpdateIncludeFilter;
Modified:=true;
end;
procedure TPublishModuleOptions.SetIncludeFilterSimpleSyntax(
const AValue: boolean);
begin
if FIncludeFilterSimpleSyntax=AValue then exit;
FIncludeFilterSimpleSyntax:=AValue;
UpdateIncludeFilter;
Modified:=true;
end;
procedure TPublishModuleOptions.SetModified(const AValue: boolean);
begin
if AValue and (FModifiedLock>0) then exit;
if FModified=AValue then exit;
FModified:=AValue;
DoOnModifyChange;
end;
procedure TPublishModuleOptions.SetUseExcludeFileFilter(const AValue: boolean
);
begin
if FUseExcludeFileFilter=AValue then exit;
FUseExcludeFileFilter:=AValue;
Modified:=true;
end;
procedure TPublishModuleOptions.SetUseIncludeFileFilter(const AValue: boolean
);
begin
if FUseIncludeFileFilter=AValue then exit;
FUseIncludeFileFilter:=AValue;
Modified:=true;
end;
procedure TPublishModuleOptions.UpdateIncludeFilter;
var
Expr: string;
begin
if FIncludeFilterRegExpr=nil then
FIncludeFilterRegExpr:=TRegExpr.Create;
if IncludeFilterSimpleSyntax then
Expr:=SimpleSyntaxToRegExpr(FIncludeFileFilter)
else
Expr:=FIncludeFileFilter;
try
FIncludeFilterRegExpr.Expression:=Expr;
FIncludeFilterValid:=true;
except
on E: Exception do begin
writeln('Invalid Include File Expression ',Expr,' ',E.Message);
FIncludeFilterValid:=false;
end;
end;
end;
procedure TPublishModuleOptions.UpdateExcludeFilter;
var
Expr: string;
begin
if FExcludeFilterRegExpr=nil then
FExcludeFilterRegExpr:=TRegExpr.Create;
if ExcludeFilterSimpleSyntax then
Expr:=SimpleSyntaxToRegExpr(FExcludeFileFilter)
else
Expr:=FExcludeFileFilter;
try
FExcludeFilterRegExpr.Expression:=Expr;
FExcludeFilterValid:=true;
except
on E: Exception do begin
writeln('Invalid Exclude File Expression ',Expr,' ',E.Message);
FExcludeFilterValid:=false;
end;
end;
end;
procedure TPublishModuleOptions.DoOnModifyChange;
begin
end;
constructor TPublishModuleOptions.Create(TheOwner: TObject);
begin
FOwner:=TheOwner;
LoadDefaults;
end;
destructor TPublishModuleOptions.Destroy;
begin
Clear;
FIncludeFilterRegExpr.Free;
FExcludeFilterRegExpr.Free;
inherited Destroy;
end;
procedure TPublishModuleOptions.Clear;
begin
LoadDefaults;
end;
procedure TPublishModuleOptions.LoadDefaults;
begin
DestinationDirectory:=GetDefaultDestinationDir;
CommandAfter:='';
UseIncludeFileFilter:=true;
IncludeFilterSimpleSyntax:=true;
IncludeFileFilter:=DefPublModIncFilter;
UseExcludeFileFilter:=false;
ExcludeFilterSimpleSyntax:=true;
ExcludeFileFilter:=DefPublModExcFilter;
end;
procedure TPublishModuleOptions.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const APath: string);
var
XMLVersion: integer;
begin
XMLVersion:=XMLConfig.GetValue(APath+'Version/Value',0);
FDestinationDirectory:=XMLConfig.GetValue(APath+'DestinationDirectory/Value',
GetDefaultDestinationDir);
FCommandAfter:=XMLConfig.GetValue(APath+'CommandAfter/Value','');
IgnoreBinaries:=XMLConfig.GetValue(APath+'IgnoreBinaries/Value',true);
UseIncludeFileFilter:=XMLConfig.GetValue(APath+'UseIncludeFileFilter/Value',
true);
IncludeFilterSimpleSyntax:=
XMLConfig.GetValue(APath+'IncludeFilterSimpleSyntax/Value',true);
if XMLVersion>=2 then
IncludeFileFilter:=XMLConfig.GetValue(APath+'IncludeFileFilter/Value',
DefPublModIncFilter);
UseExcludeFileFilter:=XMLConfig.GetValue(APath+'UseExcludeFileFilter/Value',
false);
ExcludeFilterSimpleSyntax:=
XMLConfig.GetValue(APath+'ExcludeFilterSimpleSyntax/Value',
true);
if XMLVersion>=2 then
ExcludeFileFilter:=XMLConfig.GetValue(APath+'ExcludeFileFilter/Value',
DefPublModExcFilter);
end;
procedure TPublishModuleOptions.SaveToXMLConfig(XMLConfig: TXMLConfig;
const APath: string);
begin
XMLConfig.SetValue(APath+'Version/Value',PublishModulOptsVersion);
XMLConfig.SetValue(APath+'DestinationDirectory/Value',GetDefaultDestinationDir);
XMLConfig.SetDeleteValue(APath+'CommandAfter/Value',CommandAfter,'');
XMLConfig.SetDeleteValue(APath+'IgnoreBinaries/Value',IgnoreBinaries,true);
XMLConfig.SetDeleteValue(APath+'UseIncludeFileFilter/Value',
UseIncludeFileFilter,true);
XMLConfig.SetDeleteValue(APath+'IncludeFilterSimpleSyntax/Value',
IncludeFilterSimpleSyntax,true);
XMLConfig.SetDeleteValue(APath+'IncludeFileFilter/Value',
IncludeFileFilter,DefPublModIncFilter);
XMLConfig.SetDeleteValue(APath+'UseExcludeFileFilter/Value',
UseExcludeFileFilter,false);
XMLConfig.SetDeleteValue(APath+'ExcludeFilterSimpleSyntax/Value',
ExcludeFilterSimpleSyntax,true);
XMLConfig.SetDeleteValue(APath+'ExcludeFileFilter/Value',
ExcludeFileFilter,DefPublModExcFilter);
end;
function TPublishModuleOptions.FileCanBePublished(
const AFilename: string): boolean;
begin
Result:=false;
// check include filter
if UseIncludeFileFilter
and (FIncludeFilterRegExpr<>nil)
and (not FIncludeFilterRegExpr.Exec(ExtractFilename(AFilename))) then
exit;
// check exclude filter
if UseExcludeFileFilter
and (FExcludeFilterRegExpr<>nil)
and (FExcludeFilterRegExpr.Exec(ExtractFilename(AFilename))) then
exit;
// check binaries
if IgnoreBinaries and (not DirectoryExists(AFilename))
and (not FileIsText(AFilename)) then exit;
Result:=true;
end;
procedure TPublishModuleOptions.LockModified;
begin
inc(FModifiedLock);
end;
procedure TPublishModuleOptions.UnlockModified;
begin
if FModifiedLock<=0 then
RaiseException('TPublishModuleOptions.UnlockModified');
dec(FModifiedLock);
end;
function TPublishModuleOptions.GetDefaultDestinationDir: string;
begin
Result:=DefPublishDirectory;
end;
end.