Example #1
0
        public void Pass_Process_AllProperties_ExplicitProjectPathNoRoot()
        {
            // Setup
            var filePath = $"{Fakes.RandomString()}.dtproj";
            var protectionLevelString = new[] { "EncryptAllWithPassword", "EncryptSensitiveWithPassword" }[Fakes.RandomInt(0, 199) / 200];
            var args = new[]
            {
                Path.GetFileName(filePath),
                $"-{nameof(BuildArguments.Configuration)}",
                Fakes.RandomString(),
                $"-{nameof(BuildArguments.ProtectionLevel)}",
                protectionLevelString,
                $"-{nameof(BuildArguments.NewPassword)}",
                Fakes.RandomString(),
                $"-{nameof(BuildArguments.Password)}",
                Fakes.RandomString(),
                $"-{nameof(BuildArguments.OutputFolder)}",
                $".\\{Fakes.RandomString()}",
                $"-{nameof(BuildArguments.ReleaseNotes)}",
                $".\\{Fakes.RandomString()}",
                $"-Parameter:{Fakes.RandomString()}::{Fakes.RandomString()}",
                Fakes.RandomString(),
                $"-Parameter:{Fakes.RandomString()}::{Fakes.RandomString()}",
                Fakes.RandomString(),
            };

            IBuildArguments buildArguments = null;

            _builderMock.Setup(b => b.Build(It.IsAny<IBuildArguments>())).Callback((IBuildArguments ba) => buildArguments = ba);

            // Execute
            Program.MainInternal(_builderMock.Object, args);

            // Assert
            Assert.NotNull(buildArguments);
            Assert.Equal(filePath, buildArguments.ProjectPath);
            Assert.Equal(args[2], buildArguments.Configuration);
            Assert.Equal(args[4], buildArguments.ProtectionLevel);
            Assert.Equal(args[6], buildArguments.NewPassword);
            Assert.Equal(args[8], buildArguments.Password);
            Assert.Equal(args[10], buildArguments.OutputFolder);
            Assert.Equal(args[12], buildArguments.ReleaseNotes);

            Assert.NotNull(buildArguments.Parameters);
            Assert.True(buildArguments.Parameters.Count == 2);
            Assert.Equal(args[14], buildArguments.Parameters[args[13].Split(new[] { ':' }, 2)[1]]);
            Assert.Equal(args[16], buildArguments.Parameters[args[15].Split(new[] { ':' }, 2)[1]]);
        }
Example #2
0
        private void EchoBuildArguments(IBuildArguments buildArguments)
        {
            _logger.LogMessage("SSIS Build Engine");
            _logger.LogMessage("Copyright (c) 2017 Roman Tumaykin");
            _logger.LogMessage("");
            _logger.LogMessage("Executing SSIS Build with the following arguments:");
            if (!string.IsNullOrWhiteSpace(buildArguments.ProjectPath))
            {
                _logger.LogMessage($"Project File: {buildArguments.ProjectPath}");
            }
            if (!string.IsNullOrWhiteSpace(buildArguments.ProtectionLevel))
            {
                _logger.LogMessage($"-ProtectionLevel: {buildArguments.ProtectionLevel}");
            }

            if (!string.IsNullOrWhiteSpace(buildArguments.Password))
            {
                _logger.LogMessage("-Password: (hidden)");
            }

            if (!string.IsNullOrWhiteSpace(buildArguments.NewPassword))
            {
                _logger.LogMessage("-NewPassword: (hidden)");
            }

            if (!string.IsNullOrWhiteSpace(buildArguments.OutputFolder))
            {
                _logger.LogMessage($"-OutputFolder: {buildArguments.OutputFolder}");
            }

            if (!string.IsNullOrWhiteSpace(buildArguments.Configuration))
            {
                _logger.LogMessage($"-Configuration: {buildArguments.Configuration}");
            }
            if (!string.IsNullOrWhiteSpace(buildArguments.ReleaseNotes))
            {
                _logger.LogMessage($"-ReleaseNotes: {buildArguments.ReleaseNotes}");
            }
            _logger.LogMessage("");
            _logger.LogMessage("Project parameters:");
            foreach (var parameter in buildArguments.Parameters)
            {
                _logger.LogMessage(
                    $"  {parameter.Key}: {parameter.Value}");
            }
        }
Example #3
0
        public void Build(IBuildArguments buildArguments)
        {
            if (buildArguments == null)
            {
                throw new ArgumentNullException(nameof(buildArguments));
            }
            string projectPath;

            if (string.IsNullOrWhiteSpace(buildArguments.ProjectPath))
            {
                projectPath = Directory.EnumerateFiles(buildArguments.WorkingFolder, "*.dtproj").FirstOrDefault();
                if (string.IsNullOrWhiteSpace(projectPath))
                {
                    throw new ProjectFileNotFoundException(buildArguments.WorkingFolder);
                }
            }
            else
            {
                projectPath = Path.GetFullPath(
                    Path.IsPathRooted(buildArguments.ProjectPath)
                        ? buildArguments.ProjectPath
                        : Path.Combine(buildArguments.WorkingFolder, buildArguments.ProjectPath)
                    );
            }

            EchoBuildArguments(
                new BuildArguments(
                    buildArguments.WorkingFolder,
                    projectPath,
                    buildArguments.OutputFolder,
                    buildArguments.ProtectionLevel,
                    buildArguments.Password,
                    buildArguments.NewPassword,
                    buildArguments.Configuration,
                    buildArguments.ReleaseNotes,
                    buildArguments.Parameters
                    )
                );

            _logger.LogMessage("-------------------------------------------------------------------------------");
            _logger.LogMessage($"Starting build. Loading project files from {projectPath}.");

            // Load and process project
            _project.LoadFromDtproj(projectPath, buildArguments.Configuration, buildArguments.Password);

            // replace parameter values
            foreach (var buildArgumentsParameter in buildArguments.Parameters)
            {
                _project.UpdateParameter(buildArgumentsParameter.Key, buildArgumentsParameter.Value, ParameterSource.Manual);
            }

            // parse release notes if provided
            if (!string.IsNullOrWhiteSpace(buildArguments.ReleaseNotes))
            {
                var releaseNotesPath = Path.GetFullPath(
                    Path.IsPathRooted(buildArguments.ReleaseNotes)
                        ? buildArguments.ReleaseNotes
                        : Path.Combine(buildArguments.WorkingFolder, buildArguments.ReleaseNotes)
                    );
                ApplyReleaseNotes(releaseNotesPath, _project);
            }

            EchoFinalParameterValues(_project.Parameters.Values.ToArray());

            var outputFolder = string.IsNullOrWhiteSpace(buildArguments.OutputFolder)
                    ? Path.Combine(Path.GetDirectoryName(projectPath), "bin", buildArguments.Configuration)
                    : buildArguments.OutputFolder;

            var destinationPath = Path.Combine(outputFolder, Path.ChangeExtension(Path.GetFileName(projectPath), "ispac"));

            var finalProtectionLevel = string.IsNullOrWhiteSpace(buildArguments.ProtectionLevel)
                ? _project.ProtectionLevel
                : (ProtectionLevel)Enum.Parse(typeof(ProtectionLevel), buildArguments.ProtectionLevel, true);

            if (finalProtectionLevel != _project.ProtectionLevel)
            {
                _logger.LogMessage($"Changing protection level from {_project.ProtectionLevel} to {finalProtectionLevel}.");
            }
            else
            {
                _logger.LogMessage($"Protection Level is unchanged: {finalProtectionLevel}.");
            }



            if (finalProtectionLevel == ProtectionLevel.DontSaveSensitive)
            {
                _project.Save(destinationPath);
            }
            else
            {
                var encryptionPassword = string.IsNullOrWhiteSpace(buildArguments.NewPassword) ? buildArguments.Password : buildArguments.NewPassword;
                if (string.IsNullOrWhiteSpace(encryptionPassword))
                {
                    throw new PasswordRequiredException(finalProtectionLevel.ToString());
                }

                _project.Save(destinationPath, finalProtectionLevel, encryptionPassword);
            }

            _logger.LogMessage("");
            _logger.LogMessage("Build completed successfully");
        }