[JEDI.NET-commits] tools/JediDoc/source JediDoc.System.Console.pas,1.1,1.2 JediDoc.System.Project.pa
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2005-03-30 14:08:45
|
Update of /cvsroot/jedidotnet/tools/JediDoc/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4527/tools/JediDoc/source Modified Files: JediDoc.System.Console.pas JediDoc.System.Project.pas Log Message: Added project file support. Index: JediDoc.System.Console.pas =================================================================== RCS file: /cvsroot/jedidotnet/tools/JediDoc/source/JediDoc.System.Console.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JediDoc.System.Console.pas 28 Mar 2005 12:26:16 -0000 1.1 --- JediDoc.System.Console.pas 30 Mar 2005 14:08:16 -0000 1.2 *************** *** 44,48 **** public type ! ExecutionTypes = (SaveProject = 0, Analyse = 1, UnitGeneration = 2, AssemblyGeneration = 4); {$ENDREGION} {$REGION 'Data'} --- 44,48 ---- public type ! ExecutionTypes = (None = 0, SaveProject = 1, Analyse = 2, UnitGeneration = 4, AssemblyGeneration = 8); {$ENDREGION} {$REGION 'Data'} *************** *** 51,56 **** class var FExecutionType: ExecutionTypes; class var FHelpShown: Boolean; - class var FProjectFile: string; class var FProjectContents: Project; class var FQuiet: Boolean; {$ENDREGION} --- 51,57 ---- class var FExecutionType: ExecutionTypes; class var FHelpShown: Boolean; class var FProjectContents: Project; + class var FSaveAsFileList: Boolean; + class var FSaveAsProject: string; class var FQuiet: Boolean; {$ENDREGION} *************** *** 86,94 **** class procedure ShowHelp; static; {$ENDREGION} {$REGION 'Properties'} public class property ExecutionType: ExecutionTypes read FExecutionType; class property ProjectContents: Project read FProjectContents; ! class property ProjectFile: string read FProjectFile; [CommandLineArgument(CaseSensitive = False, Prefix = '-', Name = 'q')] class property Quiet: Boolean read FQuiet write FQuiet; --- 87,109 ---- class procedure ShowHelp; static; {$ENDREGION} + {$REGION 'Property accessors'} + public + class procedure set_LoadedProject(value: string); static; + class procedure set_MergedProject(value: string); static; + class procedure set_SaveAsFileList(value: Boolean); static; + class procedure set_SaveAsProject(value: string); static; + {$ENDREGION} {$REGION 'Properties'} public class property ExecutionType: ExecutionTypes read FExecutionType; class property ProjectContents: Project read FProjectContents; ! [CommandLineArgument(CaseSensitive = False, Prefix = '-', Name = 'l', Name = 'load', ValueSeparator = ':')] ! class property LoadedProject: string write set_LoadedProject; ! [CommandLineArgument(CaseSensitive = False, Prefix = '-', Name = 'm', Name = 'merge', ValueSeparator = ':')] ! class property MergedProject: string write set_MergedProject; ! [CommandLineArgument(CaseSensitive = False, Prefix = '--', Name = 's', Name = 'save', ValueSeparator = ':')] ! class property SaveAsProject: string read FSaveAsProject write set_SaveAsProject; ! [CommandLineArgument(CaseSensitive = False, Prefix = '-', Name = 'sf', Name = 'saveas-filelist')] ! class property SaveAsFileList: Boolean read FSaveAsFileList write set_SaveAsFileList; [CommandLineArgument(CaseSensitive = False, Prefix = '-', Name = 'q')] class property Quiet: Boolean read FQuiet write FQuiet; *************** *** 148,151 **** --- 163,189 ---- end; + class procedure Settings.set_LoadedProject(value: string); + begin + ProjectContents.Load(value); + end; + + class procedure Settings.set_MergedProject(value: string); + begin + ProjectContents.Merge(value); + end; + + class procedure Settings.set_SaveAsFileList(value: Boolean); + begin + FArgumentDetected := True; + FSaveAsFileList := value; + end; + + class procedure Settings.set_SaveAsProject(value: string); + begin + FArgumentDetected := True; + FSaveAsProject := value; + FExecutionType := FExecutionType or ExecutionTypes.SaveProject; + end; + class procedure Settings.set_UnitGeneration(value: Boolean); begin *************** *** 172,190 **** try notSwitches := CommandLine.Parse([TypeOf(Settings), FProjectContents.Assemblies, FProjectContents.XmlFiles], '@'); ! if &Array(notSwitches).Length > 1 then begin Console.WriteLine('ERROR: Commandline parsing error:'); ! Console.WriteLine('More than project filename specified.'); Halt(100); end; ! if &Array(notSwitches).Length = 1 then ! FProjectFile := notSwitches[0]; ! if ArgumentDetected and not HelpShown and (ExecutionType = ExecutionTypes.SaveProject) and (ProjectFile = '') then begin Console.WriteLine('ERROR: Commandline parsing error:'); ! Console.WriteLine('No project filename specified to save to.'); Halt(100); end; ! //TODO: loading project file if one was specified. except on e: CommandLineException do --- 210,227 ---- try notSwitches := CommandLine.Parse([TypeOf(Settings), FProjectContents.Assemblies, FProjectContents.XmlFiles], '@'); ! if &Array(notSwitches).Length > 0 then begin Console.WriteLine('ERROR: Commandline parsing error:'); ! Console.WriteLine('Non switches provided.'); Halt(100); end; ! if not HelpShown and ArgumentDetected and (ExecutionType = ExecutionTypes.None) then begin Console.WriteLine('ERROR: Commandline parsing error:'); ! Console.WriteLine('No command specified.'); Halt(100); end; ! ProjectContents.Assemblies.Normalize; ! ProjectContents.XmlFiles.Normalize; except on e: CommandLineException do *************** *** 201,207 **** class procedure Settings.ShowHelp; begin ! Console.Write('Usage: '); Console.Write(Path.GetFileNameWithoutExtension(Process.GetCurrentProcess.MainModule.ModuleName)); ! Console.WriteLine(' [options] project'); Console.WriteLine; Console.WriteLine('Valid options:'); --- 238,249 ---- class procedure Settings.ShowHelp; begin ! Console.WriteLine('Usage: '); ! Console.Write(' '); Console.Write(Path.GetFileNameWithoutExtension(Process.GetCurrentProcess.MainModule.ModuleName)); ! Console.WriteLine(' [options] <command>'); ! Console.WriteLine('or:'); ! Console.Write(' '); ! Console.Write(Path.GetFileNameWithoutExtension(Process.GetCurrentProcess.MainModule.ModuleName)); ! Console.WriteLine(' @<path of file containing command line arguments>'); Console.WriteLine; Console.WriteLine('Valid options:'); *************** *** 209,242 **** Console.WriteLine(' -a[ssemblypath]:<path of assembly/assemblies>'); Console.WriteLine(' Adds the specified assembly or assemblies to the project. You can use'); ! Console.WriteLine(' wild-cards in the file name.'); Console.WriteLine(' -x[mlpath]:<path of xml file/files>'); Console.WriteLine(' Adds the specified xml file or files to the project. You can use wild-'); ! Console.WriteLine(' cards in the file name.'); ! Console.WriteLine(' -q'); ! Console.WriteLine(' Use quiet mode (no output other than errors and warnings).'); Console.WriteLine(' /? or --help'); Console.WriteLine(' Show this help page (also shown when no arguments were specified).'); Console.WriteLine(' --analyse'); Console.WriteLine(' Analyses the project for mismatches in documentation/assemblies.'); Console.WriteLine(' Will always result in output, regardless of -q option.'); - Console.WriteLine(' --generate:unitdocs'); - Console.WriteLine(' Generates/updates unit based XML files from the parsed assemblies.'); Console.WriteLine(' --generate:assemblydocs'); Console.WriteLine(' Generates/updates assembly based XML files from the parsed assemblies and'); Console.WriteLine(' xml files. <include> tags will be processed.'); Console.WriteLine; Console.WriteLine('Notes:'); - Console.WriteLine(' The -a and -x options affect the default project. When a project file name is'); - Console.WriteLine(' specified, those settings will be ignored.'); - Console.WriteLine; - Console.WriteLine(' If neither the analyse nor either of the generate options were specified, the'); - Console.WriteLine(' default project as build through the -a and -x options will be saved as the'); - Console.WriteLine(' specified project file (if no file name is specied an error message is'); - Console.WriteLine(' displayed).'); - Console.WriteLine; Console.WriteLine(' Instead of specifying everything on the command line, you can put all'); Console.WriteLine(' arguments in a file and use that file through the @<file> option. You can'); Console.WriteLine(' freely mix the usage of response files and arguments.'); Console.WriteLine; end; {$ENDREGION} --- 251,298 ---- Console.WriteLine(' -a[ssemblypath]:<path of assembly/assemblies>'); Console.WriteLine(' Adds the specified assembly or assemblies to the project. You can use'); ! Console.WriteLine(' wild-cards in the file name. Multiple occurances are allowed.'); ! Console.WriteLine(' -l[oad]:<path of JediDoc project file>'); ! Console.WriteLine(' Loads the specified project file. Existing project information is cleared'); ! Console.WriteLine(' prior to loading the file. Multiple occurances are allowed.'); ! Console.WriteLine(' -m[erge]:<path of JediDoc project file>'); ! Console.WriteLine(' Loads the specified project file. Existing project information is'); ! Console.WriteLine(' preserved. Multiple occurances are allowed.'); ! Console.WriteLine(' -q[+|-]'); ! Console.WriteLine(' Use quiet mode (no output other than errors and warnings). Without'); ! Console.WriteLine(' specifying a + or -, the switch toggles the current setting; + activates'); ! Console.WriteLine(' it regardless of current setting. Likewise, - deactivates the setting.'); ! Console.WriteLine(' -sf[+|-] or -saveas-filelist[+|-]'); ! Console.WriteLine(' Specifies the project is saved using actual files found, not the specified'); ! Console.WriteLine(' search masks. Only used in combination with the --save command. Without'); ! Console.WriteLine(' specifying a + or -, the switch toggles the current setting; + activates'); ! Console.WriteLine(' it regardless of current setting. Likewise, - deactivates the setting.'); Console.WriteLine(' -x[mlpath]:<path of xml file/files>'); Console.WriteLine(' Adds the specified xml file or files to the project. You can use wild-'); ! Console.WriteLine(' cards in the file name. Multiple occurances are allowed.'); Console.WriteLine(' /? or --help'); Console.WriteLine(' Show this help page (also shown when no arguments were specified).'); + Console.WriteLine; + Console.WriteLine('Valid commands:'); + Console.WriteLine; Console.WriteLine(' --analyse'); Console.WriteLine(' Analyses the project for mismatches in documentation/assemblies.'); Console.WriteLine(' Will always result in output, regardless of -q option.'); Console.WriteLine(' --generate:assemblydocs'); Console.WriteLine(' Generates/updates assembly based XML files from the parsed assemblies and'); Console.WriteLine(' xml files. <include> tags will be processed.'); + Console.WriteLine(' --generate:unitdocs'); + Console.WriteLine(' Generates/updates unit based XML files from the parsed assemblies.'); + Console.WriteLine(' --s[ave]:<path for new JediDoc project file>'); + Console.WriteLine(' Saves the current project to the specified file. If the file exists, it'); + Console.WriteLine(' will be overwritten without warning.'); Console.WriteLine; Console.WriteLine('Notes:'); Console.WriteLine(' Instead of specifying everything on the command line, you can put all'); Console.WriteLine(' arguments in a file and use that file through the @<file> option. You can'); Console.WriteLine(' freely mix the usage of response files and arguments.'); Console.WriteLine; + Console.WriteLine(' You should specify at least 1 command. A project needs at least one assembly'); + Console.WriteLine(' and one xml file to work.'); + Console.WriteLine; end; {$ENDREGION} Index: JediDoc.System.Project.pas =================================================================== RCS file: /cvsroot/jedidotnet/tools/JediDoc/source/JediDoc.System.Project.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JediDoc.System.Project.pas 28 Mar 2005 12:26:16 -0000 1.1 --- JediDoc.System.Project.pas 30 Mar 2005 14:08:16 -0000 1.2 *************** *** 30,35 **** Jedi.System.CommandLine, Jedi.Collections.InlineEditable, System.Collections, ! System.IO; {$ENDREGION} --- 30,42 ---- Jedi.System.CommandLine, Jedi.Collections.InlineEditable, + Jedi.IO.Paths, System.Collections, ! System.IO, ! System.Xml; ! {$ENDREGION} ! ! {$REGION 'Helper types'} ! type ! StringArray = array of string; {$ENDREGION} *************** *** 47,54 **** {$REGION 'Constructor'} strict protected ! constructor Create; {$ENDREGION} {$REGION 'Property accessors'} public function get_Items(index: Integer): string; procedure set_Items(index: Integer; value: string); --- 54,66 ---- {$REGION 'Constructor'} strict protected ! constructor Create(project: Project); ! {$ENDREGION} ! {$REGION 'Data'} ! strict private ! FProject: Project; {$ENDREGION} {$REGION 'Property accessors'} public + function get_Files: ICollection; function get_Items(index: Integer): string; procedure set_Items(index: Integer; value: string); *************** *** 57,65 **** public property Count: Integer read get_Count; property Items[&index: Integer]: string read get_Items write set_Items; default; {$ENDREGION} {$REGION 'Public methods'} public ! function GetFileEnumerator: IEnumerator; {$ENDREGION} end; --- 69,81 ---- public property Count: Integer read get_Count; + property Files: ICollection read get_Files; property Items[&index: Integer]: string read get_Items write set_Items; default; {$ENDREGION} + strict private + function ProcessFileSpecs: IDictionary; {$REGION 'Public methods'} public ! procedure Add(filename: string); ! procedure Normalize; {$ENDREGION} end; *************** *** 71,75 **** {$REGION 'Constructor'} private ! constructor Create; {$ENDREGION} {$REGION 'Property accessors'} --- 87,91 ---- {$REGION 'Constructor'} private ! constructor Create(project: Project); {$ENDREGION} {$REGION 'Property accessors'} *************** *** 94,98 **** {$REGION 'Constructor'} private ! constructor Create; {$ENDREGION} {$REGION 'Property accessors'} --- 110,114 ---- {$REGION 'Constructor'} private ! constructor Create(project: Project); {$ENDREGION} {$REGION 'Property accessors'} *************** *** 113,123 **** --- 129,161 ---- strict private FAssemblies: AssemblyCollection; + FBasePath: string; FXmlFiles: XmlCollection; {$ENDREGION} + {$REGION 'Property accessors'} + public + function get_BasePath: string; + {$ENDREGION} {$REGION 'Properties'} published property Assemblies: AssemblyCollection read FAssemblies; + property BasePath: string read get_BasePath; property XmlFiles: XmlCollection read FXmlFiles; {$ENDREGION} + {$REGION 'Private methods'} + strict private + procedure AssertValidProjectFile(projectFile: XmlDocument); + function GetFileList(node: XmlNode; readPath: string): StringArray; + procedure LoadImpl(filename: string; clear: Boolean); + procedure ProcessAssembly(node: XmlNode; readPath: string); + procedure ProcessSlashDoc(node: XmlNode; readPath: string); + procedure SaveFileList(files: FileCollection; filesElement: XmlElement; elementName, savePath: string; + actualFiles: Boolean); + {$ENDREGION} + {$REGION 'Public methods'} + public + procedure Load(filename: string); + procedure Merge(filename: string); + procedure Save(filename: string; actualFiles: Boolean); + {$ENDREGION} end; {$ENDREGION} *************** *** 129,141 **** begin inherited Create; ! FAssemblies := Project.AssemblyCollection.Create; ! FXmlFiles := Project.XmlCollection.Create; end; {$ENDREGION} {$REGION 'Project.AssemblyCollection'} ! constructor Project.AssemblyCollection.Create; begin ! inherited Create; end; --- 167,322 ---- begin inherited Create; ! FAssemblies := Project.AssemblyCollection.Create(Self); ! FXmlFiles := Project.XmlCollection.Create(Self); ! end; ! ! procedure Project.AssertValidProjectFile(projectFile: XmlDocument); ! var ! versionAttribute: XmlAttribute; ! begin ! // TODO: checks to make sure it's a valid file ! if projectFile.DocumentElement.Name <> 'jedidoc' then ! raise Exception.Create('Invalid JediDoc project file: no <jedidoc> element.'); ! versionAttribute := projectFile.DocumentElement.Attributes['version']; ! if versionAttribute = nil then ! raise Exception.Create('Invalid JediDoc project file: missing ''version'' attribute.'); ! if versionAttribute.Value <> '1.0' then ! raise Exception.Create(System.String.Format('Invalid JediDoc project file: invalid version "{0}".', ! versionAttribute.Value)); ! end; ! ! function Project.GetFileList(node: XmlNode; readPath: string): StringArray; ! var ! fileList: ArrayList; ! attrNode: XmlAttribute; ! begin ! fileList := ArrayList.Create; ! attrNode := node.Attributes['path']; ! if attrNode <> nil then ! fileList.Add(Jedi.IO.Paths.Path.Combine(readPath, attrNode.Value)); ! Result := StringArray(fileList.ToArray(TypeOf(string))); ! end; ! ! function Project.get_BasePath: string; ! begin ! if FBasePath = '' then ! FBasePath := Environment.CurrentDirectory; ! Result := FBasePath; ! end; ! ! procedure Project.Load(filename: string); ! begin ! LoadImpl(filename, True); ! end; ! ! procedure Project.LoadImpl(filename: string; clear: Boolean); ! var ! basePath: string; ! projectFile: XmlDocument; ! filesNode: XmlNode; ! assemblyNode: XmlNode; ! slashDocNode: XmlNode; ! begin ! filename := Path.GetFullPath(filename); ! projectFile := XmlDocument.Create; ! projectFile.PreserveWhitespace := False; ! projectFile.Load(filename); ! AssertValidProjectFile(projectFile); ! if clear then ! begin ! Assemblies.Clear; ! XmlFiles.Clear; ! FBasePath := ''; ! end; ! basePath := Path.GetDirectoryName(filename); ! if FBasePath = '' then ! FBasePath := basePath; ! for filesNode in projectFile.DocumentElement.SelectNodes('files') do ! begin ! for assemblyNode in filesNode.SelectNodes('assembly') do ! ProcessAssembly(assemblyNode, basePath); ! for slashDocNode in filesNode.SelectNodes('slashdoc') do ! ProcessSlashDoc(slashDocNode, basePath); ! end; ! end; ! ! procedure Project.Merge(filename: string); ! begin ! LoadImpl(filename, False); ! end; ! ! procedure Project.ProcessAssembly(node: XmlNode; readPath: string); ! var ! filename: string; ! begin ! for filename in GetFileList(node, readPath) do ! Assemblies.Add(Jedi.IO.Paths.Path.MakeRelativeFrom(filename, BasePath)); ! end; ! ! procedure Project.ProcessSlashDoc(node: XmlNode; readPath: string); ! var ! filename: string; ! begin ! for filename in GetFileList(node, readPath) do ! XmlFiles.Add(Jedi.IO.Paths.Path.MakeRelativeFrom(filename, BasePath)); ! end; ! ! procedure Project.Save(filename: string; actualFiles: Boolean); ! var ! xmlDoc: XmlDocument; ! projectElement: XmlElement; ! projVerAttribute: XmlAttribute; ! filesElement: XmlElement; ! xmlFile: XmlWriter; ! begin ! filename := Path.GetFullPath(filename); ! xmlDoc := XmlDocument.Create; ! xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration('1.0', '', '')); ! projectElement := xmlDoc.CreateElement('jedidoc'); ! projVerAttribute := xmlDoc.CreateAttribute('version'); ! projVerAttribute.Value := '1.0'; ! projectElement.Attributes.Append(projVerAttribute); ! filesElement := XmlDoc.CreateElement('files'); ! SaveFileList(Assemblies, filesElement, 'assembly', Path.GetDirectoryName(filename), actualFiles); ! SaveFileList(XmlFiles, filesElement, 'slashdoc', Path.GetDirectoryName(filename), actualFiles); ! projectElement.AppendChild(filesElement); ! xmlDoc.AppendChild(projectElement); ! xmlFile := XmlTextWriter.Create(StreamWriter.Create(filename)); ! try ! XmlTextWriter(xmlFile).Formatting := Formatting.Indented; ! xmlDoc.WriteTo(xmlFile); ! finally ! xmlFile.Close; ! end; ! end; ! ! procedure Project.SaveFileList(files: FileCollection; filesElement: XmlElement; elementName, savePath: string; ! actualFiles: Boolean); ! var ! col: ICollection; ! fileSpec: string; ! fileElement: XmlElement; ! pathAttribute: XmlAttribute; ! begin ! files.Normalize; ! if actualFiles then ! col := files.Files ! else ! col := files; ! for fileSpec in col do ! begin ! fileElement := filesElement.OwnerDocument.CreateElement(elementName); ! pathAttribute := filesElement.OwnerDocument.CreateAttribute('path'); ! pathAttribute.Value := Jedi.IO.Paths.Path.MakeRelativeFrom(fileSpec, savePath); ! fileElement.Attributes.Append(pathAttribute); ! filesElement.AppendChild(fileElement); ! end; end; {$ENDREGION} {$REGION 'Project.AssemblyCollection'} ! constructor Project.AssemblyCollection.Create(project: Project); begin ! inherited Create(project); end; *************** *** 147,174 **** procedure Project.AssemblyCollection.set_AssemblyPath(value: string); begin ! List.Add(&Object(value)); end; {$ENDREGION} {$REGION 'Project.FileCollection'} ! constructor Project.FileCollection.Create; begin inherited Create; end; ! function Project.FileCollection.GetFileEnumerator: IEnumerator; ! var ! files: SortedList; ! objDef: string; ! objSrc: string; begin ! files := SortedList.Create(CaseInsensitiveComparer.DefaultInvariant); ! for objDef in List do ! begin ! for objSrc in &Directory.GetFiles(&Path.GetDirectoryName(objDef), &Path.GetFileName(objDef)) do ! if not files.Contains(objSrc) then ! files.Add(objSrc, objDef); ! end; ! Result := files.Keys.GetEnumerator; end; --- 328,350 ---- procedure Project.AssemblyCollection.set_AssemblyPath(value: string); begin ! Add(value); end; {$ENDREGION} {$REGION 'Project.FileCollection'} ! constructor Project.FileCollection.Create(project: Project); begin inherited Create; + FProject := project; end; ! procedure Project.FileCollection.Add(filename: string); begin ! List.Add(Jedi.IO.Paths.Path.Combine(FProject.BasePath, filename)); ! end; ! ! function Project.FileCollection.get_Files: ICollection; ! begin ! Result := ProcessFileSpecs.Keys; end; *************** *** 182,191 **** List[index] := &Object(value); end; {$ENDREGION} {$REGION 'Project.XmlCollection'} ! constructor Project.XmlCollection.Create; begin ! inherited Create; end; --- 358,398 ---- List[index] := &Object(value); end; + + procedure Project.FileCollection.Normalize; + var + files: IList; + specs: IDictionary; + objSpec: &Object; + begin + files := IList(ProcessFileSpecs.Values); + specs := SortedList.Create(CaseInsensitiveComparer.DefaultInvariant); + for objSpec in files do + if not specs.Contains(objSpec) then + specs.Add(objSpec, nil); + List.Clear; + ArrayList.Adapter(List).AddRange(specs.Keys); + end; + + function Project.FileCollection.ProcessFileSpecs: IDictionary; + var + objSpec: &Object; + filespec: string; + filename: string; + begin + Result := SortedList.Create(CaseInsensitiveComparer.DefaultInvariant); + for objSpec in List do + begin + filespec := string(objSpec); + for filename in Directory.GetFiles(Path.GetDirectoryName(filespec), Path.GetFileName(filespec)) do + if not Result.Contains(&Object(filename)) then + Result.Add(&Object(filename), &Object(filespec)); + end; + end; {$ENDREGION} {$REGION 'Project.XmlCollection'} ! constructor Project.XmlCollection.Create(project: Project); begin ! inherited Create(project); end; *************** *** 197,201 **** procedure Project.XmlCollection.set_XmlPath(value: string); begin ! List.Add(&Object(value)); end; {$ENDREGION} --- 404,408 ---- procedure Project.XmlCollection.set_XmlPath(value: string); begin ! Add(value); end; {$ENDREGION} |