Skip to content

Commit 1be69e3

Browse files
committed
Added relative test and removed dead code
1 parent 3a8404e commit 1be69e3

File tree

6 files changed

+55
-308
lines changed

6 files changed

+55
-308
lines changed

src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public DotnetRestorer(CommandRunner commandRunner, LogFactory logFactory)
2323
public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources)
2424
{
2525
var packageSourcesArgument = CreatePackageSourcesArguments();
26+
var configFileArgument = CreateConfigFileArgument();
2627
var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier;
2728

2829
_logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier}");
29-
var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument}");
30-
//var exitcode = _commandRunner.Execute("dotnet", $"restore \"{pathToProjectFile}\" {packageSourcesArgument}");
30+
var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}");
3131
if (exitcode != 0)
3232
{
3333
// We must throw here, otherwise we may incorrectly run with the old 'project.assets.json'
@@ -41,6 +41,14 @@ string CreatePackageSourcesArguments()
4141
: packageSources.Select(s => $"-s {s}")
4242
.Aggregate((current, next) => $"{current} {next}");
4343
}
44+
45+
string CreateConfigFileArgument()
46+
{
47+
return string.IsNullOrWhiteSpace(projectFileInfo.NuGetConfigFile)
48+
? string.Empty
49+
: $"--configfile {projectFileInfo.NuGetConfigFile}";
50+
51+
}
4452
}
4553

4654
public bool CanRestore => true;
Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,14 @@
11
using NuGet.Configuration;
2-
using System.Collections.Generic;
32
using System.Linq;
43

54
namespace Dotnet.Script.DependencyModel.ProjectSystem
65
{
76
internal static class NuGetUtilities
87
{
9-
108
public static string GetNearestConfigPath(string pathToEvaluate)
119
{
1210
var settings = Settings.LoadDefaultSettings(pathToEvaluate);
1311
return settings.GetConfigFilePaths().FirstOrDefault();
1412
}
15-
16-
public static void CreateNuGetConfigFromLocation(string pathToEvaluate, string targetDirectory)
17-
{
18-
var sourceSettings = Settings.LoadDefaultSettings(pathToEvaluate);
19-
var targetSettings = new Settings(targetDirectory);
20-
21-
CopySection(sourceSettings, targetSettings, "config");
22-
CopySection(sourceSettings, targetSettings, "bindingRedirects");
23-
CopySection(sourceSettings, targetSettings, "packageRestore");
24-
CopySection(sourceSettings, targetSettings, "solution");
25-
CopySection(sourceSettings, targetSettings, "packageSources");
26-
CopySection(sourceSettings, targetSettings, "packageSourceCredentials");
27-
CopySection(sourceSettings, targetSettings, "apikeys");
28-
CopySection(sourceSettings, targetSettings, "disabledPackageSources");
29-
CopySection(sourceSettings, targetSettings, "activePackageSource");
30-
31-
targetSettings.SaveToDisk();
32-
}
33-
34-
private static void CopySection(ISettings sourceSettings, ISettings targetSettings, string sectionName)
35-
{
36-
var existingAddItems = sourceSettings.GetSection(sectionName)?.Items.Where(item => item is object && (item is SourceItem || item is AddItem) && item.ElementName.ToLowerInvariant() == "add").Cast<AddItem>();
37-
38-
if (existingAddItems == null)
39-
{
40-
return;
41-
}
42-
43-
foreach (var addItem in existingAddItems)
44-
{
45-
if (ShouldResolvePath(sectionName, addItem.Key))
46-
{
47-
targetSettings.AddOrUpdate(sectionName, new AddItem(addItem.Key, addItem.GetValueAsPath()));
48-
}
49-
else
50-
{
51-
targetSettings.AddOrUpdate(sectionName, addItem);
52-
}
53-
}
54-
}
55-
56-
private static bool ShouldResolvePath(string sectionName, string key)
57-
{
58-
if (sectionName == "packageSources")
59-
{
60-
return true;
61-
}
62-
63-
if (sectionName == "config")
64-
{
65-
return key == "globalPackagesFolder" || key == "repositoryPath";
66-
}
67-
68-
return false;
69-
}
7013
}
7114
}

src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public ProjectFileInfo CreateProjectForRepl(string code, string targetDirectory,
6161

6262
LogProjectFileInfo(pathToProjectFile);
6363

64-
EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
65-
//return ret pathToProjectFile;
66-
6764
return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory));
6865
}
6966

@@ -113,7 +110,6 @@ private ProjectFileInfo SaveProjectFileFromScriptFiles(string targetDirectory, s
113110

114111
LogProjectFileInfo(pathToProjectFile);
115112

116-
EvaluateAndGenerateNuGetConfigFile(targetDirectory, Path.GetDirectoryName(pathToProjectFile));
117113
return new ProjectFileInfo(pathToProjectFile, NuGetUtilities.GetNearestConfigPath(targetDirectory));
118114
}
119115

@@ -132,17 +128,6 @@ public ProjectFile CreateProjectFileFromScriptFiles(string defaultTargetFramewor
132128
return projectFile;
133129
}
134130

135-
private void EvaluateAndGenerateNuGetConfigFile(string targetDirectory, string pathToProjectFileFolder)
136-
{
137-
var pathToDestinationNuGetConfigFile = Path.Combine(pathToProjectFileFolder, Settings.DefaultSettingsFileName);
138-
139-
if (File.Exists(pathToDestinationNuGetConfigFile))
140-
File.Delete(pathToDestinationNuGetConfigFile);
141-
142-
_logger.Debug($"Generating NuGet config evaluated at {targetDirectory} to {pathToDestinationNuGetConfigFile}");
143-
NuGetUtilities.CreateNuGetConfigFromLocation(targetDirectory, pathToProjectFileFolder);
144-
}
145-
146131
public static string GetPathToProjectFile(string targetDirectory)
147132
{
148133
var pathToProjectDirectory = FileUtils.CreateTempFolder(targetDirectory);
@@ -153,13 +138,13 @@ public static string GetPathToProjectFile(string targetDirectory)
153138

154139
public class ProjectFileInfo
155140
{
156-
public ProjectFileInfo(string path, string configPath)
141+
public ProjectFileInfo(string path, string nugetConfigFile)
157142
{
158143
Path = path;
159-
ConfigPath = configPath;
144+
NuGetConfigFile = nugetConfigFile;
160145
}
161146

162147
public string Path { get; }
163-
public string ConfigPath { get; }
148+
public string NuGetConfigFile { get; }
164149
}
165150
}

src/Dotnet.Script.Shared.Tests/TestPathUtils.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public static string GetPathToGlobalPackagesFolder()
4242
public static void RemovePackageFromGlobalNugetCache(string packageName)
4343
{
4444
var pathToGlobalPackagesFolder = TestPathUtils.GetPathToGlobalPackagesFolder();
45-
var pathToAutoMapperPackage = Directory.GetDirectories(pathToGlobalPackagesFolder).Single(d => d.Contains(packageName, StringComparison.OrdinalIgnoreCase));
46-
FileUtils.RemoveDirectory(pathToAutoMapperPackage);
45+
var pathToPackage = Directory.GetDirectories(pathToGlobalPackagesFolder).SingleOrDefault(d => d.Contains(packageName, StringComparison.OrdinalIgnoreCase));
46+
if (pathToPackage != null)
47+
{
48+
FileUtils.RemoveDirectory(pathToPackage);
49+
}
4750
}
4851
}
4952
}

src/Dotnet.Script.Tests/NuGetUtilitiesTests.cs

Lines changed: 0 additions & 225 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy