Skip to content

Commit

Permalink
Merge pull request #71 from kumaS-nu/develop
Browse files Browse the repository at this point in the history
Update for version 4
  • Loading branch information
kumaS-nu authored May 30, 2023
2 parents 7c1a7dd + 0146061 commit 9223ba6
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 159 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CITest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
projectPath:
- CITest
unityVersion:
- 2020.3.40f1
- 2021.3.11f1
- 2022.1.19f1
- 2020.3.48f1
- 2021.3.25f1
- 2022.2.20f1
testMode:
- editmode
steps:
Expand All @@ -36,7 +36,7 @@ jobs:
Library-
- name: setup
run: cp -rf "NuGetImporterForUnity/Packages/NuGet Importer" "CITest/Packages/NuGet Importer" && rm -rf "CITest/Packages/NuGet Importer/Tests" && rm -f "CITest/Packages/NuGet Importer/Tests.meta"
- uses: webbertakken/unity-test-runner@v2.1.1
- uses: game-ci/unity-test-runner@v2
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
id: tests
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
projectPath:
- NuGetImporterForUnity
unityVersion:
- 2020.3.40f1
- 2021.3.11f1
- 2022.1.19f1
- 2020.3.48f1
- 2021.3.25f1
- 2022.2.20f1
testMode:
- editmode
steps:
Expand All @@ -34,7 +34,7 @@ jobs:
key: Library-${{ matrix.projectPath }}
restore-keys: |
Library-
- uses: webbertakken/unity-test-runner@v2.1.1
- uses: game-ci/unity-test-runner@v2
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
id: tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ Therefore, if you want to use CI/CD with the packages out of git's tracking, you

NuGet-importer-for-Unity install files not required at runtime (e.g., rulesets, documentation, etc.) are installed to `(your project)/NuGet`. If you want to reference them, add them reference manually.

This package works with Unity2020.3 or later, but compile errors occur once with Unity2020.3 due to Unity's compile pipline issues.
To use this, you restart Unity and open with ignore the compile error. If you are using an earlier version of Unity, use version 3.3.2.

When importing this package into your project, this package makes the following changes.
- Turn off `PlayerSettings -> assemblyVersionValidation`. (To make Unity not check the assembly version as NuGet does.)
- Add reference `System.IO.Compression.FileSystem.dll`. (NuGet importer for Unity handles Zip files.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@

実行時に必要なファイル以外(例:アナライザーやドキュメントなど)は `(your project)/NuGet` 以下に配置されます。参照する際は手動で追加してください。

Unity2021以降であれば問題なく動きますが、Unity2020.3では一度コンパイルエラーが発生します。エディターを再起動し、コンパイルエラーを無視して開いてください。
それ以前のUnityの場合はバージョン3.3.2を使用してください。

このパッケージを導入する際、以下の変更を加えます。
- `PlayerSettings -> assemblyVersionValidation` をオフに。(NuGet と同様にアセンブリ参照のバージョンの同一性をチェックしなくさせるため。)
- `System.IO.Compression.FileSystem.dll` を参照に追加。(NuGet importer for Unity が Zip ファイルを扱うため。)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AssemblyDefinitionFile

/// <summary>
/// <para>Version defines of asmdef.</para>
/// <para>asmdef偺Version defines丅</para>
/// <para>asmdefのVersion defines。</para>
/// </summary>
[Serializable]
public class VersionDefine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace kumaS.NuGetImporter.Editor.DataClasses
{
Expand Down Expand Up @@ -26,6 +28,24 @@ public class NativePlatform
{ nameof(OSType.Gentoo), nameof(ArchitectureType.X64) }
};

private static readonly List<(string, int)> PriorityTable = new List<(string, int)>()
{
(nameof(OSType.Win), -1),
(nameof(OSType.OSX), -1),
(nameof(OSType.Android), -1),
(nameof(OSType.IOS), -1),
(nameof(OSType.Linux), -1),
(nameof(OSType.Ubuntu), 1),
(nameof(OSType.Debian), 2),
(nameof(OSType.Fedora), 3),
(nameof(OSType.Centos), 4),
(nameof(OSType.Alpine), 5),
(nameof(OSType.Rhel), 6),
(nameof(OSType.Arch), 7),
(nameof(OSType.Opensuse), 8),
(nameof(OSType.Gentoo), 9)
};

public readonly string Path;
public readonly string OS;
public readonly int OSPriority;
Expand All @@ -41,81 +61,24 @@ public NativePlatform(string directoryPath)

private (string os, int priority) GetOSInfo(string directoryName)
{
if (directoryName.StartsWith(nameof(OSType.Win)))
{
return (nameof(OSType.Win), -1);
}

if (directoryName.StartsWith(nameof(OSType.OSX)))
{
return (nameof(OSType.OSX), -1);
}

if (directoryName.StartsWith(nameof(OSType.Android)))
{
return (nameof(OSType.Android), -1);
}

if (directoryName.StartsWith(nameof(OSType.IOS)))
{
return (nameof(OSType.IOS), -1);
}

if (directoryName.StartsWith(nameof(OSType.Linux)))
{
return (nameof(OSType.Linux), 0);
}

if (directoryName.StartsWith(nameof(OSType.Ubuntu)))
{
return (nameof(OSType.Ubuntu), 1);
}

if (directoryName.StartsWith(nameof(OSType.Debian)))
{
return (nameof(OSType.Debian), 2);
}

if (directoryName.StartsWith(nameof(OSType.Fedora)))
{
return (nameof(OSType.Fedora), 3);
}

if (directoryName.StartsWith(nameof(OSType.Centos)))
{
return (nameof(OSType.Centos), 4);
}

if (directoryName.StartsWith(nameof(OSType.Alpine)))
var matchedPriority = PriorityTable.Where(table => directoryName.StartsWith(table.Item1.ToLowerInvariant()));
if (matchedPriority.Any())
{
return (nameof(OSType.Alpine), 5);
return matchedPriority.First();
}

return directoryName.StartsWith(nameof(OSType.Rhel))
? ((string os, int priority))(nameof(OSType.Rhel), 6)
: directoryName.StartsWith(nameof(OSType.Arch))
? ((string os, int priority))(nameof(OSType.Arch), 7)
: directoryName.StartsWith(nameof(OSType.Opensuse))
? ((string os, int priority))(nameof(OSType.Opensuse), 8)
: directoryName.StartsWith(nameof(OSType.Gentoo))
? ((string os, int priority))(nameof(OSType.Gentoo), 9)
: ((string os, int priority))(directoryName.Split('-')[0], int.MaxValue);
return (directoryName.Split('-')[0], int.MaxValue);
}

private string GetArchInfo(string directoryName)
{
if (directoryName.EndsWith(nameof(ArchitectureType.X64)))
var matchedArch = Enum.GetNames(typeof(ArchitectureType)).Where(table => directoryName.EndsWith(table.ToLowerInvariant()));
if (matchedArch.Any())
{
return nameof(ArchitectureType.X64);
return matchedArch.First();
}

return directoryName.EndsWith(nameof(ArchitectureType.X86))
? nameof(ArchitectureType.X86)
: directoryName.EndsWith(nameof(ArchitectureType.ARM64))
? nameof(ArchitectureType.ARM64)
: directoryName.EndsWith(nameof(ArchitectureType.ARM))
? nameof(ArchitectureType.ARM)
: DefaultArch.TryGetValue(OS, out var arch)
return DefaultArch.TryGetValue(OS, out var arch)
? arch
: nameof(ArchitectureType.X64);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Datum
public string projectUrl;
public string[] tags;
public string[] authors;
public int totalDownloads;
public long totalDownloads;
public bool verified;
public Packagetype[] packageTypes;
public PackageVersionInformation[] versions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public SemVer Merge(SemVer newVersion, bool onlyStable = true)
}

var allowVer = "";
if (ret._maximumVersion == null && ret._excludeMinimum == false)
if (ret._maximumVersion == null && !ret._excludeMinimum)
{
allowVer = ret._minimumVersion == null
? ""
Expand All @@ -271,8 +271,8 @@ public SemVer Merge(SemVer newVersion, bool onlyStable = true)
&& ret._maximumVersion != null
&& ret._minimumVersion.Aggregate((now, next) => now + "." + next)
== ret._maximumVersion.Aggregate((now, next) => now + "." + next)
&& ret._excludeMinimum == false
&& ret._excludeMaximum == false)
&& !ret._excludeMinimum
&& !ret._excludeMaximum)
{
allowVer = "[" + ret._minimumVersion.Aggregate((now, next) => now + "." + next) + "]";
}
Expand Down Expand Up @@ -375,7 +375,6 @@ private string GetHighestVersion(bool onlyStable)
}
}


throw new InvalidOperationException(
$@"There is no available version. Versions: {
_existVersions.Select(it => it?.Aggregate((prev, curr) => $"{prev}.{curr}"))
Expand Down Expand Up @@ -432,7 +431,6 @@ private string GetLowestVersion(bool onlyStable)
}
}


throw new InvalidOperationException(
$@"There is no available version. Versions: {
_existVersions?.Select(it => it?.Aggregate((prev, curr) => $"{prev}.{curr}"))
Expand Down Expand Up @@ -485,7 +483,6 @@ private string GetSuitVersion(bool onlyStable)
}
}


throw new InvalidOperationException(
$@"There is no available version. Versions: {
_existVersions.Select(it => it?.Aggregate((prev, curr) => $"{prev}.{curr}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,7 @@ private static void EnsureNoCircularReference(
targetName = node.PackageName;
}

if (log == null)
{
log = new List<string>() { targetName };
}
log ??= new List<string>() { targetName };

foreach (DependencyNode depended in node.DependedNode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public static class GUILayoutExtention
/// </param>
public static void UrlLabel(string text, string url, int fontSize = -1, GUIStyle style = null, params GUILayoutOption[] options)
{
if (style == null)
{
style = new GUIStyle(EditorStyles.linkLabel);
}
style ??= new GUIStyle(EditorStyles.linkLabel);
if (fontSize < 0)
{
fontSize = GUI.skin.label.fontSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private static string OnGeneratedCSProject(string path, string content)
XElement project = xDoc.Root;
XNamespace xNamespace = project!.Name.Namespace;

var baseDir = Path.GetDirectoryName(path);
ICollection<XElement> analyzer = project.Descendants(xNamespace + "Analyzer").ToArray();
var analyzersInCsproj = new HashSet<string>(analyzer.Select(x => x.Attribute("Include")?.Value).Where(x => x != null));
ICollection<string> addingAnalyzer = analyzersPath.Where(x => !analyzersInCsproj.Contains(x)).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,7 @@ public void OnGUI()
)
);

if (_detail != null)
{
_detail.ToDetailGUI(bold, _summary.SelectedVersion);
}
_detail?.ToDetailGUI(bold, _summary.SelectedVersion);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class PackageControllerAsAsset : PackageControllerBase

public PackageControllerAsAsset()
{
pathSolver = new AssetPathSolver();
PathSolver = new AssetPathSolver();
}

/// <inheritdoc/>
Expand Down Expand Up @@ -82,7 +82,7 @@ internal override void DeletePluginsOutOfDirectory(Package package)
Directory.CreateDirectory(topDirectory);
}

Task<string> task = pathSolver.InstallPath(package);
Task<string> task = PathSolver.InstallPath(package);
await ExtractPackageAsync(package);
var installPath = await task;
var asm = new PackageManagedPluginList { packageName = package.ID, fileNames = new List<string>() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class PackageControllerAsUPM : PackageControllerBase
{
public PackageControllerAsUPM()
{
pathSolver = new UPMPathSolver();
PathSolver = new UPMPathSolver();
}

/// <inheritdoc/>
Expand All @@ -23,7 +23,7 @@ internal override void DeletePluginsOutOfDirectory(Package package) { }
internal override async Task<(bool isSkipped, Package package, PackageManagedPluginList asm)>
InstallPackageAsync(Package package, IEnumerable<string> loadedAsmName)
{
Task<string> task = pathSolver.InstallPath(package);
Task<string> task = PathSolver.InstallPath(package);
Task<Catalog> task2 = NuGet.GetCatalog(package.ID);
await ExtractPackageAsync(package);
var installPath = await task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal abstract class PackageControllerBase
"_rels", "package", "build", "buildMultiTargeting", "buildTransitive"
};

protected internal PackagePathSolverBase pathSolver { protected set; get; }
protected internal PackagePathSolverBase PathSolver { protected set; get; }

/// <summary>
/// <para>Install the specified package.</para>
Expand Down Expand Up @@ -127,7 +127,7 @@ IEnumerable<Package> root
DeletePluginsOutOfDirectory(native);
}

IEnumerable<Task<string>> tasks = natives.Select(package => pathSolver.InstallPath(package));
IEnumerable<Task<string>> tasks = natives.Select(package => PathSolver.InstallPath(package));
IEnumerable<string> nativeDirectory = await Task.WhenAll(tasks);
IEnumerable<string> nativeNugetDirectory = natives.Select(
package => Path.Combine(
Expand Down Expand Up @@ -187,7 +187,7 @@ protected void GetLoadableAsmInPackage(string searchPath, PackageManagedPluginLi
/// </exception>
protected async Task ExtractPackageAsync(Package package)
{
var extractPath = await pathSolver.InstallPath(package);
var extractPath = await PathSolver.InstallPath(package);
var nupkgName = package.ID.ToLowerInvariant() + "." + package.Version.ToLowerInvariant() + ".nupkg";
var tempPath = PackageManager.DataPath.Replace("Assets", "Temp");
var downloadPath = Path.Combine(tempPath, nupkgName);
Expand Down Expand Up @@ -440,11 +440,11 @@ private void LocalizeDirectoryProcess(string nugetPackagePath, string extractPat

private void NativeProcess(string nativePath, string nugetPackagePath, string extractPath)
{
IEnumerable<NativePlatform> moveList = Directory.GetDirectories(nativePath)
ICollection<NativePlatform> moveList = Directory.GetDirectories(nativePath)
.Select(native => new NativePlatform(native))
.Where(native => native.OSPriority >= 0)
.OrderBy(native => native.OSPriority)
.Skip(1);
.Skip(1).ToArray();

foreach (NativePlatform move in moveList)
{
Expand Down Expand Up @@ -561,7 +561,7 @@ private List<List<string>> GroupLocalizedDirectory(string managedPath)
/// </param>
private async Task UninstallManagedPackageAsync(Package package)
{
var path = await pathSolver.InstallPath(package);
var path = await PathSolver.InstallPath(package);
var nugetPackagePath = Path.Combine(
PackageManager.DataPath.Replace("Assets", "NuGet"),
package.ID.ToLowerInvariant() + "." + package.Version.ToLowerInvariant()
Expand Down
Loading

0 comments on commit 9223ba6

Please sign in to comment.