Пример #1
0
        private List <MavenCoordinates> Verify(MavenCoordinates coordinates, OverwriteOption overwrite)
        {
            if (overwrite == OverwriteOption.Replace)
            {
                return(new List <MavenCoordinates> {
                    coordinates
                });
            }

            var artifact = new Model.Artifact(coordinates);
            var search   = Artifactory.Search()
                           .ArtifactsByGavc()
                           .GroupId(coordinates.GroupId)
                           .ArtifactId(coordinates.ArtifactId)
                           .Version(coordinates.Version);
            var run = search.Run();

            if (run.Artifacts != null && run.Artifacts.Count > 0)
            {
                if (overwrite == OverwriteOption.Abort)
                {
                    throw new ArgumentException(artifact + " already exists");
                }
                else if (overwrite == OverwriteOption.AddNew)
                {
                    Logger.Info(coordinates + " already exist. Skipping upload.");
                    return(new List <MavenCoordinates>());
                }
            }

            return(new List <MavenCoordinates> {
                coordinates
            });;
        }
Пример #2
0
        public Model.Artifact ResolveLatestVariable(Model.Project coordinates)
        {
            var artifact = new Model.Artifact(coordinates.GroupId, coordinates.ArtifactId, coordinates.Version);

            if (artifact.Version != "latest")
            {
                return(artifact);
            }

            var search = Artifactory.Search()
                         .ArtifactsByGavc()
                         .GroupId(coordinates.GroupId)
                         .ArtifactId(coordinates.ArtifactId);

            var run        = search.Run();
            var maxVersion = run.Artifacts
                             .Select(a => Model.Artifact.ParseArtifactoryPath(a.Uri.ToString()))
                             .Select(a => new Version(a.Version))
                             .Max();

            if (maxVersion == null)
            {
                throw new ArgumentException("There is no project matching " + coordinates);
            }

            return(new Model.Artifact(coordinates.GroupId, coordinates.ArtifactId, maxVersion.ToString()));
        }
Пример #3
0
        public async Task <HookResponse> Hook([FromBody] HookRequest request)
        {
            var words = request.Text.Trim().Split(' ');

            if (words.Length != 2)
            {
                return(new HookResponse
                {
                    Text = $"You must specify packages version. Example: \"{request.TriggerWord} 2.6.4\""
                });
            }

            var packageVersion = words.Last();

            var options = _configuration.GetSection("artifactory").Get <ArtifactoryOptions>();

            var artifactory = new Artifactory(options.Host, options.User, options.Password);

            var searchQueryBuilds = options.Packages.Select(p =>
            {
                Action <ISearchQueryBuilder> action = (ISearchQueryBuilder q) =>
                                                      q.WhereName().Match($"{p}*{packageVersion}*");

                return(action);
            }).ToArray();

            var artifactsList = await artifactory.Search()
                                .Or(searchQueryBuilds)
                                .Build()
                                .Execute();

            var artifacts = artifactsList.Results.Select(a =>
                                                         new ArtifactModel(a, options.PackageNamePattern, ":white_check_mark:"))
                            .GroupBy(a => a.Name)
                            .Select(gr => gr.OrderByDescending(it => it.Version).First())
                            .ToList();

            foreach (var notFoundPackage in options.Packages.Where(p => !artifacts.Any(a => a.Name == p)))
            {
                artifacts.Add(new ArtifactModel(notFoundPackage, ":x:"));
            }

            return(new HookResponse
            {
                Text = GetTable(artifacts)
            });
        }
Пример #4
0
        public List <Model.Artifact> ListProjects()
        {
            var search = Artifactory.Search()
                         .ArtifactsByGavc()
                         .GroupId("com.forcam.lib.project.*");
            var run = search.Run();

            if (run.Artifacts == null)
            {
                Logger.Error(run.Response.ErrorMessage);
                return(new List <Model.Artifact>());
            }

            return(run.Artifacts
                   .Select(a => Model.Artifact.ParseArtifactoryPath(a.Uri.ToString()))
                   .ToList());
        }
Пример #5
0
        private List <Artifact> ExecutePreBuildAdaptations(List <AdaptationUsage> usages,
                                                           ILogger logger)
        {
            var result = new List <Artifact>();

            if (usages.All(u => u.PreBuildMethod == null))
            {
                logger.Info("There is no discovered adaptations with pre build instructions");
                return(result);
            }

            logger.Info("Executing discovered adaptations with pre build instructions");

            foreach (var usage in Sort(usages))
            {
                var method = usage.PreBuildMethod;
                if (method == null)
                {
                    logger.Debug("Adaptation does not contain void PreBuild(IServiceProvider provider) method. Skipping...");
                    continue;
                }

                Attribute attribute;
                try
                {
                    attribute       = usage.AttributeData.CreateAttribute();
                    usage.Attribute = attribute;
                }
                catch (Exception e)
                {
                    logger.Warn($"Could not create adaptation attribute. Details: {e.GetBaseException().Message}.");
                    continue;
                }

                try
                {
                    logger.Info("------------");
                    logger.Info($"Adaptation: {usage.AttributeData}");

                    var artifactory     = new Artifactory();
                    var serviceProvider = new ServiceProvider();
                    serviceProvider.AddService(typeof(CSharpCompilation), _compilation);
                    serviceProvider.AddService(typeof(SyntaxNode), usage.AssociatedSyntaxNode);
                    serviceProvider.AddService(typeof(SyntaxTree), usage.SyntaxTree);
                    serviceProvider.AddService(typeof(SemanticModel), usage.SemanticModel);
                    serviceProvider.AddService(typeof(ILogger), new ScopeLogger(logger));
                    serviceProvider.AddService(typeof(IExplorer), _explorer);
                    serviceProvider.AddService(typeof(IArtifactory), artifactory);
                    serviceProvider.AddService(typeof(INugetExplorer), _nugetExplorer);
                    serviceProvider.AddService(typeof(IDynamicVault), _dynamicVault);
                    serviceProvider.AddService(typeof(IMacroResolver), _macroResolver);

                    method.Invoke(attribute, new object[] { serviceProvider });

                    result.AddRange(artifactory.Artifacts);
                }
                catch (Exception e)
                {
                    logger.Error($"Adaptation failed. Details: {e.GetBaseException().Message}.");
                }
            }
            return(result);
        }