Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Remove XASdkProject #7869

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,8 @@ string PrepareProject (string testName)
CopyRecursively (TestProjectRootDirectory, temporaryProjectPath, ignore);
CopyRecursively (CommonSampleLibraryRootDirectory, Path.Combine (tempRoot, CommonSampleLibraryName), ignore);
CopyFile (Path.Combine (XABuildPaths.TopDirectory, "Directory.Build.props"), Path.Combine (tempRoot, "Directory.Build.props" ));
XASdkProject.SaveNuGetConfig (tempRoot);
var project = new XamarinAndroidApplicationProject ();
project.CopyNuGetConfig (Path.Combine (tempRoot, "NuGet.config"));
return temporaryProjectPath;
}

Expand Down

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class DotNetCLI
public string JavaSdkPath { get; set; } = AndroidSdkResolver.GetJavaSdkPath ();
public string ProjectDirectory { get; set; }

readonly XASdkProject project;
readonly string projectOrSolution;

public DotNetCLI (string projectOrSolution)
Expand All @@ -25,21 +24,17 @@ public DotNetCLI (string projectOrSolution)
ProjectDirectory = Path.GetDirectoryName (projectOrSolution);
}

public DotNetCLI (XASdkProject project, string projectOrSolution)
: this (projectOrSolution)
{
this.project = project;
}

/// <summary>
/// Runs the `dotnet` tool with the specified arguments.
/// </summary>
/// <param name="args">command arguments</param>
/// <returns>Whether or not the command succeeded.</returns>
protected bool Execute (params string [] args)
{
if (string.IsNullOrEmpty (ProcessLogFile))
ProcessLogFile = Path.Combine (XABuildPaths.TestOutputDirectory, $"dotnet{DateTime.Now.ToString ("yyyyMMddHHmmssff")}-process.log");
if (string.IsNullOrEmpty (ProcessLogFile)) {
Directory.CreateDirectory (ProjectDirectory);
ProcessLogFile = Path.Combine (ProjectDirectory, $"dotnet{DateTime.Now.ToString ("yyyyMMddHHmmssff")}-process.log");
}

var procOutput = new StringBuilder ();
bool succeeded;
Expand Down Expand Up @@ -162,9 +157,6 @@ List<string> GetDefaultCommandLineArgs (string verb, string target = null, strin
if (!string.IsNullOrEmpty (target)) {
arguments.Add ($"/t:{target}");
}
if (project != null) {
arguments.Add ($"/p:Configuration={project.Configuration}");
}
if (Directory.Exists (AndroidSdkPath)) {
arguments.Add ($"/p:AndroidSdkDirectory=\"{AndroidSdkPath}\"");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ public string PackageTargetFallback {
set { SetProperty ("PackageTargetFallback", value); }
}

/// <summary>
/// Projects targeting net7.0 require ref/runtime packs on NuGet.org or dotnet6/dotnet7
/// </summary>
public void AddNuGetSourcesForOlderTargetFrameworks (string targetFramework = null)
{
targetFramework ??= TargetFramework;
if (targetFramework.IndexOf ("net7.0", StringComparison.OrdinalIgnoreCase) != -1) {
ExtraNuGetConfigSources = new List<string> {
"https://api.nuget.org/v3/index.json",
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json",
};
}
}

public string Sdk { get; set; }

public IList<BuildItem> OtherBuildItems { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class XamarinProject
/// <summary>
/// If true, the ProjectDirectory will be deleted and populated on the first build
/// </summary>
public virtual bool ShouldPopulate => true;
public virtual bool ShouldPopulate { get; set; } = true;
public IList<Import> Imports { get; private set; }
PropertyGroup common, debug, release;
bool isRelease;
Expand Down Expand Up @@ -119,6 +119,11 @@ public string TargetFramework {
set { SetProperty ("TargetFramework", value); }
}

public string TargetFrameworks {
get { return GetProperty ("TargetFrameworks"); }
set { SetProperty ("TargetFrameworks", value); }
}

public string GetProperty (string name)
{
return GetProperty (CommonProperties, name);
Expand Down Expand Up @@ -418,11 +423,11 @@ public void CopyNuGetConfig (string relativeDirectory)
Directory.CreateDirectory (Path.GetDirectoryName (projNugetConfig));
File.Copy (repoNuGetConfig, projNugetConfig, overwrite: true);

var doc = XDocument.Load (projNugetConfig);
AddNuGetConfigSources (doc);
AddNuGetConfigSources (projNugetConfig);

// Set a local PackageReference installation folder if specified
if (!string.IsNullOrEmpty (GlobalPackagesFolder)) {
var doc = XDocument.Load (projNugetConfig);
XElement gpfElement = doc.Descendants ().FirstOrDefault (c => c.Name.LocalName.ToLowerInvariant () == "add"
&& c.Attributes ().Any (a => a.Name.LocalName.ToLowerInvariant () == "key" && a.Value.ToLowerInvariant () == "globalpackagesfolder"));
if (gpfElement != default (XElement)) {
Expand All @@ -440,42 +445,48 @@ public void CopyNuGetConfig (string relativeDirectory)
doc.Root.Add (configParentElement);
}
}
doc.Save (projNugetConfig);
}

doc.Save (projNugetConfig);
}
}

/// <summary>
/// Updates a NuGet.config based on sources in ExtraNuGetConfigSources
/// The dotnet7 source is required while in preview, but eventually it should not be needed by tests
/// If target framework is not the latest or default, sources are added for previous releases
/// </summary>
protected void AddNuGetConfigSources (XDocument doc)
protected void AddNuGetConfigSources (string nugetConfigPath)
{
XDocument doc;
if (File.Exists (nugetConfigPath))
doc = XDocument.Load (nugetConfigPath);
else
doc = new XDocument (new XElement ("configuration"));

const string elementName = "packageSources";
XElement pkgSourcesElement = doc.Root.Elements ().FirstOrDefault (d => string.Equals (d.Name.LocalName, elementName, StringComparison.OrdinalIgnoreCase));
XElement pkgSourcesElement = doc.Root?.Elements ().FirstOrDefault (d => string.Equals (d.Name.LocalName, elementName, StringComparison.OrdinalIgnoreCase));
if (pkgSourcesElement == null) {
doc.Root.Add (pkgSourcesElement= new XElement (elementName));
doc.Root.Add (pkgSourcesElement = new XElement (elementName));
}

foreach (XElement element in pkgSourcesElement.Elements ()) {
XAttribute value = element.Attribute ("value");
if (value != null && value.Value == "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json") {
element.Remove ();
break;
}
if (ExtraNuGetConfigSources == null) {
ExtraNuGetConfigSources = new List<string> ();
}

if (TargetFramework?.IndexOf ("net7.0", StringComparison.OrdinalIgnoreCase) != -1
|| TargetFrameworks?.IndexOf ("net7.0", StringComparison.OrdinalIgnoreCase) != -1) {
ExtraNuGetConfigSources.Add ("https://api.nuget.org/v3/index.json");
ExtraNuGetConfigSources.Add ("https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json");
}

// Add extra sources
if (ExtraNuGetConfigSources == null)
return;
int sourceIndex = 0;
foreach (var source in ExtraNuGetConfigSources) {
var sourceElement = new XElement ("add");
sourceElement.SetAttributeValue ("key", $"testsource{++sourceIndex}");
sourceElement.SetAttributeValue ("value", source);
pkgSourcesElement.Add (sourceElement);
}

doc.Save (nugetConfigPath);
}
}
}
Loading