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);
        }
Beispiel #2
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.
        }