/usr/lib/lazarus/0.9.30.4/ide/publishmodule.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | {
/***************************************************************************
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, FileUtil, LCLProc;
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;
AdjustPathDelims: boolean); virtual;
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const APath: string;
UsePathDelim: TPathDelimSwitch); 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|sh)';
DefPublModExcFilter = '*.(bak|ppu|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
DebugLn('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
DebugLn('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:='';
IgnoreBinaries:=true;
UseIncludeFileFilter:=true;
IncludeFilterSimpleSyntax:=true;
IncludeFileFilter:=DefPublModIncFilter;
UseExcludeFileFilter:=false;
ExcludeFilterSimpleSyntax:=true;
ExcludeFileFilter:=DefPublModExcFilter;
end;
procedure TPublishModuleOptions.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const APath: string; AdjustPathDelims: boolean);
function f(const Filename: string): string;
begin
Result:=SwitchPathDelims(Filename,AdjustPathDelims);
end;
var
XMLVersion: integer;
begin
XMLVersion:=XMLConfig.GetValue(APath+'Version/Value',0);
FDestinationDirectory:=f(XMLConfig.GetValue(APath+'DestinationDirectory/Value',
GetDefaultDestinationDir));
FCommandAfter:=f(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; UsePathDelim: TPathDelimSwitch);
function f(const AFilename: string): string;
begin
Result:=SwitchPathDelims(AFilename,UsePathDelim);
end;
begin
XMLConfig.SetValue(APath+'Version/Value',PublishModulOptsVersion);
XMLConfig.SetDeleteValue(APath+'DestinationDirectory/Value',
f(DestinationDirectory),
f(GetDefaultDestinationDir));
XMLConfig.SetDeleteValue(APath+'CommandAfter/Value',f(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 DirPathExists(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.
|