public void ExtractHeaderDefinitions_FilePathIsNull_ReturnsNull() { string filePath = null; var extractor = new LicenseHeaderExtractor(); var actual = extractor.ExtractHeaderDefinitions(filePath); Assert.That(actual, Is.Null); }
public void ExtractHeaderDefinitions_ValidFilePathTextDoesNotStartWithExtension_ReturnsOneHeader() { var filePath = CreateLicenseHeaderDefinitionFile(false); var extractor = new LicenseHeaderExtractor(); var actual = extractor.ExtractHeaderDefinitions(filePath); Assert.That(actual.Count, Is.EqualTo(1)); }
public void ExtractHeaderDefinitions_ValidFilePathTextStartsWithExtension_ReturnsTwoHeaders() { var filePath = CreateLicenseHeaderDefinitionFile(); var extractor = new LicenseHeaderExtractor(); var actual = extractor.ExtractHeaderDefinitions(filePath); Assert.That(actual.Count, Is.EqualTo(2)); }
public void ExtractHeaderDefinitions_ValidFilePathTextStartsWithExtension_ReturnsCorrectItems() { var filePath = CreateLicenseHeaderDefinitionFile(); var extractor = new LicenseHeaderExtractor(); const string expectedCs = "/* Copyright (c) rubicon IT GmbH\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"),\r\n * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\r\n * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \r\n */\r\n"; const string expectedXaml = "<!--\r\nCopyright (c) rubicon IT GmbH\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"),\r\nto deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\r\nand/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n-->\r\n"; var actual = extractor.ExtractHeaderDefinitions(filePath); Assert.That(actual.Count, Is.EqualTo(2)); Assert.That(actual[".cs"].JoinWithNewLine(), Is.EqualTo(expectedCs)); Assert.That(actual[".xaml"].JoinWithNewLine(), Is.EqualTo(expectedXaml)); }
private static void RunProgram(Options options) { if (!options.IsValid(out var errorMessage)) { WriteLineColor("The command-line invocation was syntactically correct, but the following semantic errors were detected:", c_colorError); WriteLineColor(errorMessage, c_colorError); Exit(false); } if (options.Configuration != null) { System.Console.WriteLine($"Loading configuration from \"{options.Configuration.FullName}\""); s_defaultCoreSettings = JsonOptionsManager.DeserializeAsync <CoreOptions> (options.Configuration.FullName).Result; } else { System.Console.WriteLine("No configuration file specified, using default configuration."); s_defaultCoreSettings = new CoreOptions(true); } s_headerExtractor = new LicenseHeaderExtractor(); s_replacer = new LicenseHeaderReplacer(s_defaultCoreSettings.Languages, CoreOptions.RequiredKeywordsAsEnumerable(s_defaultCoreSettings.RequiredKeywords)); UpdateLicenseHeaders(options); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the /// place where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_OnAssemblyResolve; JoinableTaskFactory = ThreadHelper.JoinableTaskFactory; LicenseHeaderExtractor = new LicenseHeaderExtractor(); await base.InitializeAsync(cancellationToken, progress); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); Dte2 = await GetServiceAsync(typeof(DTE)) as DTE2; Assumes.Present(Dte2); CreateAndConfigureFileAppender(Path.GetFileNameWithoutExtension(Dte2?.Solution.FullName)); await CreateAndConfigureOutputPaneAppenderAsync(); s_log.Info("Logger has been initialized"); _addedItems = new Stack <ProjectItem>(); await AddHeaderToProjectItemCommand.InitializeAsync(this); await RemoveHeaderFromProjectItemCommand.InitializeAsync(this); await AddLicenseHeaderToAllFilesInSolutionCommand.InitializeAsync(this); await RemoveLicenseHeaderFromAllFilesInSolutionCommand.InitializeAsync(this); await AddNewSolutionLicenseHeaderDefinitionFileCommand.InitializeAsync(this, Dte2?.Solution, () => DefaultLicenseHeaderPageModel.LicenseHeaderFileText); await OpenSolutionLicenseHeaderDefinitionFileCommand.InitializeAsync(this); await RemoveSolutionLicenseHeaderDefinitionFileCommand.InitializeAsync(this); await AddLicenseHeaderToAllFilesInProjectCommand.InitializeAsync(this); await RemoveLicenseHeaderFromAllFilesInProjectCommand.InitializeAsync(this); await AddNewLicenseHeaderDefinitionFileToProjectCommand.InitializeAsync(this); await AddExistingLicenseHeaderDefinitionFileToProjectCommand.InitializeAsync(this); await LicenseHeaderOptionsCommand.InitializeAsync(this); await AddLicenseHeaderToAllFilesInFolderCommand.InitializeAsync(this); await RemoveLicenseHeaderFromAllFilesInFolderCommand.InitializeAsync(this); await AddExistingLicenseHeaderDefinitionFileToFolderCommand.InitializeAsync(this); await AddNewLicenseHeaderDefinitionFileToFolderCommand.InitializeAsync(this); await AddLicenseHeaderEditorAdvancedMenuCommand.InitializeAsync(this); await RemoveLicenseHeaderEditorAdvancedMenuCommand.InitializeAsync(this); //register ItemAdded event handler if (Dte2?.Events is Events2 events) { _projectItemEvents = events.ProjectItemsEvents; //we need to keep a reference, otherwise the object is garbage collected and the event won't be fired _projectItemEvents.ItemAdded += ItemAdded; //Register to WebsiteItemEvents for Website Projects to work //Reference: https://social.msdn.microsoft.com/Forums/en-US/dde7d858-2440-43f9-bbdc-3e1b815d4d1e/itemadded-itemremoved-and-itemrenamed-events-not-firing-in-web-projects?forum=vsx //Concerns, that the ItemAdded Event gets called on unrelated events, like closing the solution or opening folder, could not be reproduced try { _websiteItemEvents = events.GetObject("WebSiteItemsEvents") as ProjectItemsEvents; } catch (Exception ex) { //This probably only throws an exception if no WebSite component is installed on the machine. //If no WebSite component is installed, they are probably not using a WebSite Project and therefore don't need that feature. s_log.Error("No WebSite component is installed on the machine: ", ex); } if (_websiteItemEvents != null) { _websiteItemEvents.ItemAdded += ItemAdded; } } // migrate options from registry to config file await MigrateOptionsAsync(); //register event handlers for linked commands var page = GeneralOptionsPageModel; if (page != null) { foreach (var command in page.LinkedCommands) { command.Events = Dte2.Events.CommandEvents[command.Guid, command.Id]; switch (command.ExecutionTime) { case ExecutionTime.Before: command.Events.BeforeExecute += BeforeLinkedCommandExecuted; break; case ExecutionTime.After: command.Events.AfterExecute += AfterLinkedCommandExecuted; break; default: throw new ArgumentOutOfRangeException(); } } page.LinkedCommandsChanged += CommandsChanged; //register global event handler for ItemAdded _commandEvents = Dte2.Events.CommandEvents; _commandEvents.BeforeExecute += BeforeAnyCommandExecuted; } }