public void AddDependency(Dependency dep)
        {
            if (dep is null)
            {
                throw new ArgumentNullException(nameof(dep), Resources.DependencyNull);
            }
            if (dep.Id is null)
            {
                throw new ArgumentException(Resources.DependencyIdNull);
            }
            // This should be faily straightforward:
            // The given dependency should be added to the config, the config should be committed
            // Then we should perform (automatically or manually) restore in order to ensure we can obtain this dependency.
            // If we are adding a dependency that already exists (by id) we update the version to match this.
            var conf = configProvider.GetConfig();

            if (conf is null)
            {
                throw new ConfigException(Resources.ConfigNotFound);
            }
            if (conf.Info is null)
            {
                throw new ConfigException(Resources.ConfigInfoIsNull);
            }
            if (conf.Info.Id.Equals(dep.Id, StringComparison.OrdinalIgnoreCase))
            {
                throw new DependencyException($"Recursive dependency! Tried to add dependency: {dep.Id}, but package ID matches!");
            }
            // Ids are not case sensitive
            var existing = conf.Dependencies.Find(d => dep.Id.Equals(d.Id, StringComparison.OrdinalIgnoreCase));

            if (existing is null)
            {
                conf.Dependencies.Add(dep);
            }
            else
            {
                existing.VersionRange = dep.VersionRange;
                existing.AdditionalData.Clear();
                foreach (var p in dep.AdditionalData)
                {
                    existing.AdditionalData.Add(p.Key, p.Value);
                }
            }
            var shared = configProvider.GetSharedConfig();

            if (shared != null)
            {
                shared.Config = conf;
            }
            OnConfigDependencyAdded?.Invoke(this, conf, dep, existing != null);
            configProvider.Commit();
            // Perform additional modification
            OnDependencyAdded?.Invoke(this, dep, existing != null);
        }
        public void Publish()
        {
            // Ensure the config is valid
            var sharedConfig = configProvider.GetSharedConfig();

            if (sharedConfig is null)
            {
                throw new ConfigException("Config does not exist!");
            }

            // All ids in config.Dependencies must be covered in localConfig.IncludedDependencies
            if (sharedConfig.Config.Dependencies.Any())
            {
                foreach (var d in sharedConfig.Config.Dependencies)
                {
                    if (!sharedConfig.RestoredDependencies.Exists(p => p.Dependency !.Id.Equals(d.Id !, StringComparison.OrdinalIgnoreCase) && d.VersionRange.IsSatisfied(p.Version)))
                    {
                        throw new DependencyException($"Not all dependencies are restored or of correct versions! Restore before attempting to publish! Missing or mismatch dependency: {d.Id} with range: {d.VersionRange}");
                    }
                }
            }
            // My shared folder should have includes that don't use ..
            // My config should have both a Url and a soUrl
            if (sharedConfig.Config.Info.Url is null)
            {
                throw new DependencyException("Config url does not exist!");
            }
            if (!sharedConfig.Config.Info.AdditionalData.ContainsKey(SupportedPropertiesCommand.ReleaseSoLink) && (!sharedConfig.Config.Info.AdditionalData.TryGetValue(SupportedPropertiesCommand.HeadersOnly, out var header) || !header.GetBoolean()))
            {
                throw new DependencyException($"Config {SupportedPropertiesCommand.ReleaseSoLink} does not exist! Try using {SupportedPropertiesCommand.HeadersOnly} if you do not need a .so file. See 'properties-list' for more info");
            }

            // Push it to the server
            api.Push(sharedConfig);
        }
Beispiel #3
0
        public void CreatePackage(PackageInfo info)
        {
            if (info is null)
            {
                throw new ArgumentNullException(Resources.Info);
            }
            var conf = configProvider.GetConfig(true);

            if (conf is null)
            {
                throw new ConfigException(Resources.ConfigNotCreated);
            }
            var shared = configProvider.GetSharedConfig();
            var tmp    = conf.Info;

            conf.Info = info;
            if (shared != null && shared.Config != null)
            {
                shared.Config.Info = info;
            }
            // Call extra modification as necessary
            try
            {
                OnPackageConfigured?.Invoke(this, conf, info);
            }
            catch
            {
                conf.Info = tmp;
                if (shared != null && shared.Config != null)
                {
                    shared.Config.Info = tmp;
                }
                throw;
            }
            configProvider.Commit();
            // Perform extra modification
            OnPackageCreated?.Invoke(this, info);
            // Ex: Android.mk modification
            // Grab the config (or create it if it doesn't exist) and put the package info into it
            // Package info should contain the ID, version of this, along with a package URL (what repo this exists at) optionally empty.
            // Creating a package also ensures your Android.mk has the correct MOD_ID and VERSION set, which SHOULD be used in your main.cpp setup function.
        }