Skip to content

Commit

Permalink
Merge pull request #1002 from RichardLake/UserProvidesSelect
Browse files Browse the repository at this point in the history
Once again allow users to select dependencies when multiple provides exist
  • Loading branch information
pjf committed Jun 5, 2015
2 parents 349810d + 2cbcdf1 commit c57dc8a
Show file tree
Hide file tree
Showing 16 changed files with 509 additions and 278 deletions.
6 changes: 5 additions & 1 deletion Cmdline/CKAN-cmdline.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
<AssemblyName>CmdLine</AssemblyName>
<StartupObject>CKAN.CmdLine.MainClass</StartupObject>
<ApplicationIcon>..\GUI\assets\ckan.ico</ApplicationIcon>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine">
Expand Down Expand Up @@ -63,6 +66,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
</Project>
</Project>
16 changes: 8 additions & 8 deletions Cmdline/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ internal class MainClass
private static readonly ILog log = LogManager.GetLogger(typeof (MainClass));

/*
* When the STAThread is applied, it changes the apartment state of the current thread to be single threaded.
* When the STAThread is applied, it changes the apartment state of the current thread to be single threaded.
* Without getting into a huge discussion about COM and threading,
* this attribute ensures the communication mechanism between the current thread an
* other threads that may want to talk to it via COM. When you're using Windows Forms,
* depending on the feature you're using, it may be using COM interop in order to communicate with
* operating system components. Good examples of this are the Clipboard and the File Dialogs.
* operating system components. Good examples of this are the Clipboard and the File Dialogs.
*/
[STAThread]
public static int Main(string[] args)
Expand Down Expand Up @@ -66,7 +66,7 @@ public static int Main(string[] args)
{
if (!options.AsRoot)
{
user.RaiseError(@"You are trying to run CKAN as root.
user.RaiseError(@"You are trying to run CKAN as root.
This is a bad idea and there is absolutely no good reason to do it. Please run CKAN from a user account (or use --asroot if you are feeling brave).");
return Exit.ERROR;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public static int Main(string[] args)

default:
break;
}
}

#endregion

Expand Down Expand Up @@ -228,16 +228,16 @@ private static void CheckMonoVersion(IUser user, int rec_major, int rec_minor, i

MethodInfo display_name = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (display_name != null)
{
{
var version_string = (string) display_name.Invoke(null, null);
var match = Regex.Match(version_string, @"^\D*(?<major>[\d]+)\.(?<minor>\d+)\.(?<revision>\d+).*$");

if (match.Success)
{
{
int major = Int32.Parse(match.Groups["major"].Value);
int minor = Int32.Parse(match.Groups["minor"].Value);
int patch = Int32.Parse(match.Groups["revision"].Value);

if (major < rec_major || (major == rec_major && minor < rec_minor))
{
user.RaiseMessage(
Expand Down
3 changes: 3 additions & 0 deletions Cmdline/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
55 changes: 43 additions & 12 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public object Clone()
// If we resolved in things breadth-first order, we're less likely to encounter surprises
// where a nth-deep recommend blocks a top-level recommend.

// TODO: Add mechanism so that clients can add mods with relationshup other than UserAdded.
// Currently only made to support the with_{} options.
// TODO: Add mechanism so that clients can add mods with relationshup other than UserAdded.
// Currently only made to support the with_{} options.
public class RelationshipResolver
{
// A list of all the mods we're going to install.
Expand Down Expand Up @@ -111,7 +111,7 @@ public RelationshipResolver(ICollection<CkanModule> modules, RelationshipResolve
{
log.DebugFormat("Preparing to resolve relationships for {0} {1}", module.identifier, module.version);

var module1 = module; //Silence a warning re. closures over foreach var.
var module1 = module; //Silence a warning re. closures over foreach var.
foreach (CkanModule listed_mod in modlist.Values.Where(listed_mod => listed_mod.ConflictsWith(module1)))
{
if (options.procede_with_inconsistencies)
Expand Down Expand Up @@ -155,7 +155,7 @@ public RelationshipResolver(ICollection<CkanModule> modules, RelationshipResolve
/// <summary>
/// Returns the default options for relationship resolution.
/// </summary>

// TODO: This should just be able to return a new RelationshipResolverOptions
// and the defaults in the class definition should do the right thing.
public static RelationshipResolverOptions DefaultOpts()
Expand Down Expand Up @@ -202,10 +202,10 @@ private void Resolve(CkanModule module, RelationshipResolverOptions options)
/// Resolve a relationship stanza (a list of relationships).
/// This will add modules to be installed, if required.
/// May recurse back to Resolve for those new modules.
///
///
/// If `soft_resolve` is true, we warn rather than throw exceptions on mods we cannot find.
/// If `soft_resolve` is false (default), we throw a ModuleNotFoundKraken if we can't find a dependency.
///
///
/// Throws a TooManyModsProvideKraken if we have too many choices and
/// options.without_toomanyprovides_kraken is not set.
///
Expand All @@ -232,7 +232,8 @@ private void ResolveStanza(IEnumerable<RelationshipDescriptor> stanza, Relations
continue;
}

List<CkanModule> candidates = registry.LatestAvailableWithProvides(dep_name, kspversion);
List<CkanModule> candidates = registry.LatestAvailableWithProvides(dep_name, kspversion)
.Where(mod=>MightBeInstallable(mod)).ToList();

if (candidates.Count == 0)
{
Expand Down Expand Up @@ -334,7 +335,37 @@ private void Add(CkanModule module, Relationship reason)
}

/// <summary>
/// Returns a list of all modules to install to satisify the changes required.
/// Tests that a module might be able to be installed via checking if dependencies
/// exist for current version.
/// </summary>
/// <param name="module">The module to consider</param>
/// <param name="compatible">For internal use</param>
/// <returns>If it has dependencies compatible for the current version</returns>
private bool MightBeInstallable(CkanModule module, List<string> compatible = null)
{
if (module.depends == null) return true;
if (compatible == null)
{
compatible = new List<string>();
}
else if (compatible.Contains(module.identifier))
{
return true;
}
//When checking the dependencies we assume that this module is installable
// in case a dependent depends on it
compatible.Add(module.identifier);

var needed = module.depends.Select(depend => registry.LatestAvailableWithProvides(depend.name, kspversion));
//We need every dependency to have at least one possible module
var installable = needed.All(need => need.Any(mod => MightBeInstallable(mod, compatible)));
compatible.Remove(module.identifier);
return installable;
}


/// <summary>
/// Returns a list of all modules to install to satisfy the changes required.
/// </summary>
public List<CkanModule> ModList()
{
Expand All @@ -344,7 +375,7 @@ public List<CkanModule> ModList()

/// <summary>
/// Returns a IList consisting of keyValuePairs containing conflicting mods.
/// Note: (a,b) in the list should imply that (b,a) is in the list.
/// Note: (a,b) in the list should imply that (b,a) is in the list.
/// </summary>
public Dictionary<Module, String> ConflictList
{
Expand Down Expand Up @@ -398,14 +429,14 @@ public string ReasonStringFor(Module mod)
}

/// <summary>
/// Used to keep track of the relationships between modules in the resolver.
/// Intended to be used for displaying messages to the user.
/// Used to keep track of the relationships between modules in the resolver.
/// Intended to be used for displaying messages to the user.
/// </summary>
internal abstract class Relationship
{
//Currently assumed to exist for any relationship other than useradded
public virtual CkanModule Parent { get; protected set; }
//Should contain a newline at the end of the string.
//Should contain a newline at the end of the string.
public abstract String Reason { get; }


Expand Down
6 changes: 3 additions & 3 deletions GUI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true" />
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
</configuration>
1 change: 1 addition & 0 deletions GUI/CKAN-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>false</Optimize>
Expand Down
6 changes: 3 additions & 3 deletions GUI/ErrorDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions GUI/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c57dc8a

Please sign in to comment.