public void deploy(ArtifactoryBuild task, Build build, BuildInfoLog log) 
        {
            ArtifactoryBuildInfoClient client = new ArtifactoryBuildInfoClient(task.Url, task.User, task.Password, log);
            client.setProxy(build.deployClient);
            client.setConnectionTimeout(build.deployClient);

            try
            {
                if (task.DeployEnabled != null && task.DeployEnabled.Equals("true"))
                {
                    /* Deploy every artifacts from the Map< module.name : artifact.name > => List<DeployDetails> */
                    task.deployableArtifactBuilderMap.ToList().ForEach(entry => entry.Value.ForEach(artifact => client.deployArtifact(artifact)));
                }

                if (task.BuildInfoEnabled != null && task.BuildInfoEnabled.Equals("true"))
                {
                    //Upload Build Info json file to Artifactory
                    log.Info("Uploading build info to Artifactory...");
                    /* Send Build Info  */
                    client.sendBuildInfo(build);
                }
            }
            catch (Exception e)
            {
                log.Error("Exception has append from ArtifactoryBuildInfoClient: " + e.Message, e);
                throw new Exception("Exception has append from ArtifactoryBuildInfoClient: " + e.Message, e);
            }
            finally 
            {
                client.Dispose();
            }         
        }
        //public ArtifactoryBuildInfoClient(string artifactoryUrl) {
        //    (artifactoryUrl, null, null);
        //}

        public ArtifactoryBuildInfoClient(string artifactoryUrl, string username, string password, BuildInfoLog log)
        {
            //Removing ending slash
            if ((!string.IsNullOrEmpty(artifactoryUrl)) && artifactoryUrl.EndsWith("/"))
            {
                artifactoryUrl = artifactoryUrl.Remove(artifactoryUrl.LastIndexOf('/'));
            }

            _httpClient     = new ArtifactoryHttpClient(artifactoryUrl, username, password);
            _artifactoryUrl = artifactoryUrl;
            _log            = log;
        }
        //public ArtifactoryBuildInfoClient(string artifactoryUrl) {
        //    (artifactoryUrl, null, null);
        //}
        public ArtifactoryBuildInfoClient(string artifactoryUrl, string username, string password, BuildInfoLog log)
        {
            //Removing ending slash
            if ((!string.IsNullOrEmpty(artifactoryUrl)) && artifactoryUrl.EndsWith("/"))
            {
                artifactoryUrl = artifactoryUrl.Remove(artifactoryUrl.LastIndexOf('/'));
            }

            _httpClient = new ArtifactoryHttpClient(artifactoryUrl, username, password);
            _artifactoryUrl = artifactoryUrl;
            _log = log;
        }
        public override bool Execute()
        {
            try
            {
                buildInfoLog = new BuildInfoLog(Log);

                //Incase the MSBuild process is up, and the global variable is still exist.
                deployableArtifactBuilderMap.Clear();

                
                //System.Diagnostics.Debugger.Launch();
                buildInfoLog.Info("Artifactory Post-Build task started");

                if (!string.IsNullOrWhiteSpace(TfsActive) && TfsActive.Equals("True"))
                {
                    buildInfoLog.Info("Running inside TFS...");
                }

                SolutionHandler solution = new SolutionHandler(this, buildInfoLog);
                solution.Execute();

                BuildDeploymentHelper buildDeploymentHelper = new BuildDeploymentHelper();
                buildDeploymentHelper.deploy(this, solution._buildInfo, buildInfoLog);

                return true;
            }
            catch (Exception ex)
            {
                buildInfoLog.Error("Exception from Artifactory Task: " + ex.Message, ex);
                /*By returning false in exception, the task will not fail the all build.*/
                throw new Exception("Exception from Artifactory Task: " + ex.Message);
                //return false;
            }
            finally 
            {
                deployableArtifactBuilderMap.Clear();
            } 
        }
        public static Build extractBuild(ArtifactoryBuild task, ArtifactoryConfig artifactoryConfig, BuildInfoLog log)
        {
            Build build = new Build
            {
                modules = new List<Module>(),
            };

            build.started = string.Format(Build.STARTED_FORMAT, task.StartTime);
            build.artifactoryPrincipal = task.User;
            build.buildAgent = new BuildAgent { name = "MSBuild", version = task.ToolVersion };
            build.type = "MSBuild";

            build.agent = Agent.BuildAgentFactory(task);

            //get the current use from the windows OS
            System.Security.Principal.WindowsIdentity user;
            user = System.Security.Principal.WindowsIdentity.GetCurrent();
            if (user != null) build.principal = string.Format(@"{0}", user.Name);

            //Calculate how long it took to do the build
            DateTime start = DateTime.ParseExact(task.StartTime, artifactoryDateFormat, null);
            build.startedDateMillis = GetTimeStamp();
            build.durationMillis = Convert.ToInt64((DateTime.Now - start).TotalMilliseconds);

            build.number = string.IsNullOrWhiteSpace(task.BuildNumber) ? build.startedDateMillis : task.BuildNumber;
            build.name = task.BuildName ?? task.ProjectName;
            build.url = build.agent.BuildAgentUrl();
            build.vcsRevision = task.VcsRevision;

            //Add build server properties, if exists.
            AddSystemVariables(artifactoryConfig, build);
            AddLicenseControl(artifactoryConfig, build, log);
            AddBlackDuck(artifactoryConfig, build, log);

            ConfigHttpClient(artifactoryConfig, build);

            return build;
        }
        private static void AddBlackDuck(ArtifactoryConfig artifactoryConfig, Build build, BuildInfoLog log)
        {
            if (artifactoryConfig.PropertyGroup.BlackDuckCheck == null)
            {
                return;
            }

            BlackDuckGovernance blackDuckControl = new BlackDuckGovernance();

            blackDuckControl.runChecks                          = artifactoryConfig.PropertyGroup.BlackDuckCheck.EnabledBlackDuckCheck;
            blackDuckControl.appName                            = artifactoryConfig.PropertyGroup.BlackDuckCheck.CodeCenterApplicationName;
            blackDuckControl.appVersion                         = artifactoryConfig.PropertyGroup.BlackDuckCheck.CodeCenterApplicationVersion;
            blackDuckControl.reportRecipients                   = new List <string>();
            blackDuckControl.scopes                             = new List <string>();
            blackDuckControl.includePublishedArtifacts          = artifactoryConfig.PropertyGroup.BlackDuckCheck.IncludePublishedArtifacts;
            blackDuckControl.autoCreateMissingComponentRequests = artifactoryConfig.PropertyGroup.BlackDuckCheck.AutoCreateMissingComponent;
            blackDuckControl.autoDiscardStaleComponentRequests  = artifactoryConfig.PropertyGroup.BlackDuckCheck.AutoDiscardStaleComponent;

            foreach (Recipient recip in artifactoryConfig.PropertyGroup.BlackDuckCheck.ComplianceReportRecipients.Recipient)
            {
                if (validateEmail(recip))
                {
                    blackDuckControl.reportRecipients.Add(recip.email);
                }
                else
                {
                    log.Warning("Invalid email address, under License Control violation recipients.");
                }
            }

            foreach (Scope scope in artifactoryConfig.PropertyGroup.BlackDuckCheck.ScopesForLicenseAnalysis.Scope)
            {
                blackDuckControl.scopes.Add(scope.value);
            }

            build.blackDuckGovernance = blackDuckControl;
        }
        private static void AddLicenseControl(ArtifactoryConfig artifactoryConfig, Build build, BuildInfoLog log)
        {
            if (artifactoryConfig.PropertyGroup.LicenseControlCheck == null)
            {
                return;
            }

            LicenseControl licenseControl = new LicenseControl();

            licenseControl.runChecks    = artifactoryConfig.PropertyGroup.LicenseControlCheck.EnabledLicenseControl;
            licenseControl.autoDiscover = artifactoryConfig.PropertyGroup.LicenseControlCheck.AutomaticLicenseDiscovery;
            licenseControl.includePublishedArtifacts   = artifactoryConfig.PropertyGroup.LicenseControlCheck.IncludePublishedArtifacts;
            licenseControl.licenseViolationsRecipients = new List <string>();
            licenseControl.scopes = new List <string>();

            foreach (Recipient recip in artifactoryConfig.PropertyGroup.LicenseControlCheck.LicenseViolationRecipients.Recipient)
            {
                if (validateEmail(recip))
                {
                    licenseControl.licenseViolationsRecipients.Add(recip.email);
                }
                else
                {
                    log.Warning("Invalid email address, under License Control violation recipients.");
                }
            }

            foreach (Scope scope in artifactoryConfig.PropertyGroup.LicenseControlCheck.ScopesForLicenseAnalysis.Scope)
            {
                licenseControl.scopes.Add(scope.value);
            }

            build.licenseControl = licenseControl;
        }
        public static Build extractBuild(ArtifactoryBuild task, ArtifactoryConfig artifactoryConfig, BuildInfoLog log)
        {
            Build build = new Build
            {
                modules = new List <Module>(),
            };

            build.started = string.Format(Build.STARTED_FORMAT, task.StartTime);
            build.artifactoryPrincipal = task.User;
            build.buildAgent           = new BuildAgent {
                name = "MSBuild", version = task.ToolVersion
            };
            build.type = "MSBuild";

            build.agent = Agent.BuildAgentFactory(task);

            //get the current use from the windows OS
            System.Security.Principal.WindowsIdentity user;
            user = System.Security.Principal.WindowsIdentity.GetCurrent();
            if (user != null)
            {
                build.principal = string.Format(@"{0}", user.Name);
            }

            //Calculate how long it took to do the build
            DateTime start = DateTime.ParseExact(task.StartTime, artifactoryDateFormat, null);

            build.startedDateMillis = GetTimeStamp();
            build.durationMillis    = Convert.ToInt64((DateTime.Now - start).TotalMilliseconds);

            build.number      = string.IsNullOrWhiteSpace(task.BuildNumber) ? build.startedDateMillis : task.BuildNumber;
            build.name        = task.BuildName ?? task.ProjectName;
            build.url         = build.agent.BuildAgentUrl();
            build.vcsRevision = task.VcsRevision;

            //Add build server properties, if exists.
            AddSystemVariables(artifactoryConfig, build);
            AddLicenseControl(artifactoryConfig, build, log);
            AddBlackDuck(artifactoryConfig, build, log);

            ConfigHttpClient(artifactoryConfig, build);

            return(build);
        }
        private static void AddBlackDuck(ArtifactoryConfig artifactoryConfig, Build build, BuildInfoLog log)
        {
            if (artifactoryConfig.PropertyGroup.BlackDuckCheck == null)
                return;

            BlackDuckGovernance blackDuckControl = new BlackDuckGovernance();
            blackDuckControl.runChecks = artifactoryConfig.PropertyGroup.BlackDuckCheck.EnabledBlackDuckCheck;
            blackDuckControl.appName = artifactoryConfig.PropertyGroup.BlackDuckCheck.CodeCenterApplicationName;
            blackDuckControl.appVersion = artifactoryConfig.PropertyGroup.BlackDuckCheck.CodeCenterApplicationVersion;
            blackDuckControl.reportRecipients = new List<string>();
            blackDuckControl.scopes = new List<string>();
            blackDuckControl.includePublishedArtifacts = artifactoryConfig.PropertyGroup.BlackDuckCheck.IncludePublishedArtifacts;
            blackDuckControl.autoCreateMissingComponentRequests = artifactoryConfig.PropertyGroup.BlackDuckCheck.AutoCreateMissingComponent;
            blackDuckControl.autoDiscardStaleComponentRequests = artifactoryConfig.PropertyGroup.BlackDuckCheck.AutoDiscardStaleComponent;

            foreach (Recipient recip in artifactoryConfig.PropertyGroup.BlackDuckCheck.ComplianceReportRecipients.Recipient)
            {
                if (validateEmail(recip))
                {
                    blackDuckControl.reportRecipients.Add(recip.email);
                }
                else
                {
                    log.Warning("Invalid email address, under License Control violation recipients.");
                }
            }

            foreach (Scope scope in artifactoryConfig.PropertyGroup.BlackDuckCheck.ScopesForLicenseAnalysis.Scope)
            {
                blackDuckControl.scopes.Add(scope.value);
            }

            build.blackDuckGovernance = blackDuckControl;
        }
        private static void AddLicenseControl(ArtifactoryConfig artifactoryConfig, Build build, BuildInfoLog log)
        {
            if (artifactoryConfig.PropertyGroup.LicenseControlCheck == null)
                return;

            LicenseControl licenseControl = new LicenseControl();
            licenseControl.runChecks = artifactoryConfig.PropertyGroup.LicenseControlCheck.EnabledLicenseControl;
            licenseControl.autoDiscover = artifactoryConfig.PropertyGroup.LicenseControlCheck.AutomaticLicenseDiscovery;
            licenseControl.includePublishedArtifacts = artifactoryConfig.PropertyGroup.LicenseControlCheck.IncludePublishedArtifacts;
            licenseControl.licenseViolationsRecipients = new List<string>();
            licenseControl.scopes = new List<string>();
           
            foreach (Recipient recip in artifactoryConfig.PropertyGroup.LicenseControlCheck.LicenseViolationRecipients.Recipient)
            {
                if (validateEmail(recip))
                {
                    licenseControl.licenseViolationsRecipients.Add(recip.email);
                }
                else 
                {
                    log.Warning("Invalid email address, under License Control violation recipients.");
                }                            
            }

            foreach (Scope scope in artifactoryConfig.PropertyGroup.LicenseControlCheck.ScopesForLicenseAnalysis.Scope)
            {
                licenseControl.scopes.Add(scope.value);
            }

            build.licenseControl = licenseControl;
        }
 public SolutionHandler(ArtifactoryBuild task, BuildInfoLog log) 
 {
     _task = task;
     _log = log;
     GetMainConfiguration();
 }
 public SolutionHandler(ArtifactoryBuild task, BuildInfoLog log)
 {
     _task = task;
     _log  = log;
     GetMainConfiguration();
 }