Changeset 13 for trunk/Units


Ignore:
Timestamp:
May 30, 2015, 1:02:36 PM (9 years ago)
Author:
chronos
Message:
  • Added: New test form where general functionality of selected backend can be tested.
  • Added: Basic git backend implementation.
  • Added: Project group form and ability to open/save group of projects as configuration to XML file.
Location:
trunk/Units
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Units/UBackend.pas

    r10 r13  
    1010type
    1111  TWorkingCopyClass = class of TWorkingCopy;
     12  TRepositoryClass = class of TRepository;
    1213
    1314  { TBackend }
     
    1516  TBackend = class
    1617    Name: string;
     18    HomePage: string;
    1719    WorkingCopyClass: TWorkingCopyClass;
     20    RepositoryClass: TRepositoryClass;
     21    function IsRepository(Directory: string): Boolean; virtual;
    1822    function IsWorkingCopy(Directory: string): Boolean; virtual;
    1923  end;
     
    2226
    2327{ TBackend }
     28
     29function TBackend.IsRepository(Directory: string): Boolean;
     30begin
     31  Result := False;
     32end;
    2433
    2534function TBackend.IsWorkingCopy(Directory: string): Boolean;
  • trunk/Units/UProject.pas

    r9 r13  
    66
    77uses
    8   Classes, SysUtils, UVCS, UBackend;
     8  Classes, SysUtils, UVCS, UBackend, Contnrs, DOM, XMLRead, XMLWrite, UXMLUtils,
     9  FileUtil;
    910
    1011type
     
    2223  public
    2324    WorkingCopy: TWorkingCopy;
     25    Repository: TRepository;
    2426    procedure Open(Directory: string);
    2527    constructor Create;
    2628    destructor Destroy; override;
     29    procedure LoadXMLNOde(Node: TDOMNode);
     30    procedure SaveXMLNOde(Node: TDOMNode);
    2731    property Backend: TBackend read FBackend write SetBackend;
    2832    property Directory: string read GetDirectory write SetDirectory;
     
    3034  end;
    3135
     36  { TProjects }
     37
     38  TProjects = class(TObjectList)
     39    procedure LoadXMLNode(Node: TDOMNode);
     40    procedure SaveXMLNode(Node: TDOMNode);
     41  end;
     42
     43  { TProjectGroup }
     44
     45  TProjectGroup = class
     46    FileName: string;
     47    Projects: TProjects;
     48    constructor Create;
     49    destructor Destroy; override;
     50    procedure LoadFromFile(FileName: string);
     51    procedure SaveToFile(FileName: string);
     52  end;
     53
    3254
    3355implementation
    3456
    35 uses
    36   USubversion;
     57resourcestring
     58  SWrongFileFormat = 'Wrong file format';
     59
     60{ TProjects }
     61
     62procedure TProjects.LoadXMLNode(Node: TDOMNode);
     63var
     64  NewProject: TProject;
     65  Node2: TDOMNode;
     66begin
     67  Node2 := Node.FirstChild;
     68  while Assigned(Node2) and (Node2.NodeName = 'Project') do begin
     69    NewProject := TProject.Create;
     70    NewProject.LoadXMLNode(Node2);
     71    Add(NewProject);
     72    Node2 := Node2.NextSibling;
     73  end;
     74end;
     75
     76procedure TProjects.SaveXMLNode(Node: TDOMNode);
     77var
     78  I: Integer;
     79  NewNode: TDOMNode;
     80begin
     81  for I := 0 to Count - 1 do begin;
     82    NewNode := Node.OwnerDocument.CreateElement('Project');
     83    Node.AppendChild(NewNode);
     84    TProject(Items[I]).SaveXMLNode(NewNode);
     85  end;
     86end;
     87
     88
     89{ TProjectGroup }
     90
     91constructor TProjectGroup.Create;
     92begin
     93  Projects := TProjects.Create;
     94end;
     95
     96destructor TProjectGroup.Destroy;
     97begin
     98  Projects.Free;
     99  inherited Destroy;
     100end;
     101
     102procedure TProjectGroup.LoadFromFile(FileName: string);
     103var
     104  Doc: TXMLDocument;
     105  RootNode: TDOMNode;
     106  Node: TDOMNode;
     107  Node2: TDOMNode;
     108begin
     109  Self.FileName := FileName;
     110  ReadXMLFile(Doc, UTF8Decode(FileName));
     111  with Doc do try
     112    if Doc.DocumentElement.NodeName <> 'ProjectGroup' then
     113      raise Exception.Create(SWrongFileFormat);
     114    RootNode := Doc.DocumentElement;
     115    with RootNode do begin
     116      Node := FindNode('Projects');
     117      if Assigned(Node) then Projects.LoadXMLNode(Node);
     118    end;
     119  finally
     120    Doc.Free;
     121  end;
     122end;
     123
     124procedure TProjectGroup.SaveToFile(FileName: string);
     125var
     126  NewNode: TDOMNode;
     127  Doc: TXMLDocument;
     128  RootNode: TDOMNode;
     129begin
     130  if FileName = '' then Exit;
     131  Self.FileName := FileName;
     132  Doc := TXMLDocument.Create;
     133  with Doc do try
     134    RootNode := CreateElement('ProjectGroup');
     135    AppendChild(RootNode);
     136    with RootNode do begin
     137      NewNode := OwnerDocument.CreateElement('Projects');
     138      AppendChild(NewNode);
     139      Projects.SaveXMLNode(NewNode);
     140    end;
     141    ForceDirectoriesUTF8(ExtractFileDir(FileName));
     142    WriteXMLFile(Doc, UTF8Decode(FileName));
     143  finally
     144    Doc.Free;
     145  end;
     146end;
    37147
    38148{ TProject }
     
    44154  FreeAndNil(WorkingCopy);
    45155  WorkingCopy := AValue.WorkingCopyClass.Create;
     156  FreeAndNil(Repository);
     157  Repository := AValue.RepositoryClass.Create;
    46158end;
    47159
     
    64176begin
    65177  WorkingCopy.RepositoryURL := AValue;
     178  Repository.Path := AValue;
    66179end;
    67180
     
    74187begin
    75188  WorkingCopy := TWorkingCopy.Create;
     189  Repository := TRepository.Create;
    76190end;
    77191
     
    79193begin
    80194  WorkingCopy.Free;
     195  Repository.Free;
    81196  inherited Destroy;
    82197end;
    83198
     199procedure TProject.LoadXMLNOde(Node: TDOMNode);
     200begin
     201  RepositoryURL := ReadString(Node, 'RepositoryURL', '');
     202  Directory := ReadString(Node, 'Directory', '');
     203end;
     204
     205procedure TProject.SaveXMLNOde(Node: TDOMNode);
     206begin
     207  WriteString(Node, 'RepositoryURL', RepositoryURL);
     208  WriteString(Node, 'Directory', Directory);
     209end;
     210
    84211end.
    85212
  • trunk/Units/UVCS.pas

    r11 r13  
    3636    procedure SetRepositoryURL(AValue: string);
    3737  protected
     38    EnvVars: TStringList;
    3839    procedure ExecuteProcess(Command: string; Parameters: array of string); virtual;
    3940    function GetNext(var Text: string; Separator: string): string;
    4041  public
     42    UserName: string;
     43    Password: string;
     44    Email: string;
    4145    ExecutionOutput: TStringList;
    4246    procedure Checkout; virtual;
     
    4852    procedure Refresh; virtual;
    4953    procedure Add(FileName: string); virtual;
     54    procedure Remove(FileName: string); virtual;
    5055    procedure GetLog(FileName: string; Log: TLogList); virtual;
    5156    constructor Create;
     
    5560  end;
    5661
     62  { TRepository }
     63
    5764  TRepository = class
     65  protected
     66    procedure ExecuteProcess(Command: string; Parameters: array of string); virtual;
     67  public
     68    ExecutionOutput: TStringList;
    5869    Path: string;
    59   end;
    60 
    61 
     70    procedure Init; virtual;
     71    constructor Create;
     72    destructor Destroy; override;
     73  end;
     74
     75
     76function URLFromDirectory(DirName: string; Relative: Boolean): string;
    6277
    6378implementation
     
    6681  UFormConsole;
    6782
    68 { TLogItem }
    69 
    70 constructor TLogItem.Create;
    71 begin
    72   Messages := TStringList.Create;
    73   ChangedFiles := TStringList.Create;
    74 end;
    75 
    76 destructor TLogItem.Destroy;
    77 begin
    78   Messages.Free;
    79   ChangedFiles.Free;
    80   inherited Destroy;
    81 end;
    82 
    83 { TWorkingCopy }
    84 
    85 procedure TWorkingCopy.SetPath(AValue: string);
    86 begin
    87   if FPath = AValue then Exit;
    88   FPath := AValue;
    89   Refresh;
    90 end;
    91 
    92 procedure TWorkingCopy.SetRepositoryURL(AValue: string);
    93 begin
    94   if FRepositoryURL=AValue then Exit;
    95   FRepositoryURL:=AValue;
    96 end;
    97 
    98 procedure TWorkingCopy.ExecuteProcess(Command: string; Parameters: array of string);
     83function URLFromDirectory(DirName: string; Relative: Boolean): string;
     84begin
     85  Result := DirName;
     86  if Relative then Result := GetCurrentDirUTF8 + DirectorySeparator + Result;
     87  Result := 'file:///' + StringReplace(Result, DirectorySeparator, '/', [rfReplaceAll]);
     88end;
     89
     90{ TRepository }
     91
     92procedure TRepository.ExecuteProcess(Command: string;
     93  Parameters: array of string);
    9994begin
    10095  FormConsole.Executable := Command;
     
    107102end;
    108103
     104procedure TRepository.Init;
     105begin
     106
     107end;
     108
     109constructor TRepository.Create;
     110begin
     111  ExecutionOutput := TStringList.Create;
     112  Path := '';
     113end;
     114
     115destructor TRepository.Destroy;
     116begin
     117  FreeAndNil(ExecutionOutput);
     118  inherited Destroy;
     119end;
     120
     121{ TLogItem }
     122
     123constructor TLogItem.Create;
     124begin
     125  Messages := TStringList.Create;
     126  ChangedFiles := TStringList.Create;
     127end;
     128
     129destructor TLogItem.Destroy;
     130begin
     131  Messages.Free;
     132  ChangedFiles.Free;
     133  inherited Destroy;
     134end;
     135
     136{ TWorkingCopy }
     137
     138procedure TWorkingCopy.SetPath(AValue: string);
     139begin
     140  if FPath = AValue then Exit;
     141  FPath := AValue;
     142  Refresh;
     143end;
     144
     145procedure TWorkingCopy.SetRepositoryURL(AValue: string);
     146begin
     147  if FRepositoryURL=AValue then Exit;
     148  FRepositoryURL:=AValue;
     149end;
     150
     151procedure TWorkingCopy.ExecuteProcess(Command: string; Parameters: array of string);
     152begin
     153  FormConsole.Executable := Command;
     154  FormConsole.EnvironmentVariables.Assign(EnvVars);
     155  FormConsole.Parameters.Clear;
     156  FormConsole.Parameters.AddStrings(Parameters);
     157  if DirectoryExistsUTF8(Path) then FormConsole.WorkingDir := Path
     158    else FormConsole.WorkingDir := '';
     159  FormConsole.ShowModal;
     160  ExecutionOutput.Assign(FormConsole.Log);
     161end;
     162
    109163function TWorkingCopy.GetNext(var Text: string; Separator: string): string;
    110164begin
     
    158212end;
    159213
     214procedure TWorkingCopy.Remove(FileName: string);
     215begin
     216
     217end;
     218
    160219procedure TWorkingCopy.GetLog(FileName: string; Log: TLogList);
    161220begin
     
    166225begin
    167226  ExecutionOutput := TStringList.Create;
     227  EnvVars := TStringList.Create;
    168228  FPath := '';
    169229  FRepositoryURL := '';
     
    172232destructor TWorkingCopy.Destroy;
    173233begin
     234  FreeAndNil(EnvVars);
    174235  FreeAndNil(ExecutionOutput);
    175236  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.