public static CloneDetectiveResult FromSolutionPath(string solutionPath) { // Get path to log file. string logPath = PathHelper.GetLogPath(solutionPath); string cloneReportPath = PathHelper.GetCloneReportPath(solutionPath); // If the log file does not exist no clone detective result can be // constructed (if only the clone report is missing it can). if (!File.Exists(logPath)) { return(null); } // Construct the clone detective result. CloneDetectiveResult result = new CloneDetectiveResult(); if (File.Exists(cloneReportPath)) { try { // We have a clone report. Parse it and construct the source tree from it. result.CloneReport = CloneReport.FromFile(cloneReportPath); result.SourceTree = SourceTree.FromCloneReport(result.CloneReport, solutionPath); } catch (Exception ex) { // If we could not parse the clone report we write an error to the // log file (which we will parse below). result.CloneReport = null; result.SourceTree = null; LogHelper.WriteError(logPath, ex); LogHelper.WriteStatusInfo(logPath, CloneDetectiveResultStatus.Failed, 0, TimeSpan.Zero); } } // Parse the summary information out of the log file. CloneDetectiveResultStatus status; long usedMemory; TimeSpan usedTime; LogHelper.ParseStatusInfo(logPath, out status, out usedMemory, out usedTime); result.Status = status; result.UsedMemory = usedMemory; result.UsedTime = usedTime; return(result); }
/// <summary> /// Creates a <see cref="SourceTree"/> from the given <paramref name="cloneReport"/> and solution path. /// </summary> /// <param name="cloneReport">The clone report to create a source tree from.</param> /// <param name="solutionPath">The path to the solution of the clone report.</param> /// <returns>A hierarchical representation of the clone report.</returns> public static SourceTree FromCloneReport(CloneReport cloneReport, string solutionPath) { // Create the source and initialize path to solution. SourceTree sourceTree = new SourceTree(); sourceTree.SolutionPath = solutionPath; // Create the tree structure. sourceTree.FillSourceElements(cloneReport); // Traverse tree and calculate statistics. PropagateDetails(sourceTree.Root); // Sort tree elements so that directories come before files and both // are sorted by name. SortSourceElements(sourceTree.Root); return(sourceTree); }