Skip to content

Commit

Permalink
! lib_compiled: Add initial support for remote repositories
Browse files Browse the repository at this point in the history
TODO: handle errors, add support for multiple repositories
  • Loading branch information
MatejKafka committed Apr 1, 2024
1 parent c715cf3 commit 8d09a88
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/Pog/_scripts/build remote repo from local.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
param([Parameter(Mandatory)]$RemoteRepoDir)

$env:POG_DEBUG = "1"; Import-Module Pog

cd $RemoteRepoDir

rm -Recurse *

$Packages = [array][Pog.InternalState]::Repository.Enumerate()

$VersionMap = [ordered]@{}
$Packages | % {
$VersionMap[$_.PackageName] = @($_.EnumerateVersions() | % ToString)
}
# not really html, but whatever
$VersionMap | ConvertTo-Json -Depth 100 -Compress > index.html

$TmpPackage = New-PogImportedPackage _zip_export
try {
$Packages | % {
$null = mkdir $_.PackageName
$_.Enumerate() | % {
$_.ImportTo($TmpPackage)
Compress-Archive "$($TmpPackage.Path)\*" ".\$($_.PackageName)\$($_.Version).zip"
echo $_.Path
}
}
} finally {
rm -Force -Recurse $TmpPackage.Path
}
56 changes: 56 additions & 0 deletions app/Pog/lib_compiled/Pog.Tests/src/Utils/TimedLazy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Pog.Utils;
using Xunit;

namespace Pog.Tests.Utils;

public class TimedLazyTests {
[Fact]
public void TestCaching() {
TestClass.Reset();
var lazy = new TimedLazy<TestClass>(TimeSpan.FromMilliseconds(100), () => new TestClass());

Assert.Equal(0, lazy.Value.Index);
Assert.Equal(0, lazy.Value.Index);
Assert.Equal(0, lazy.Value.Index);

Thread.Sleep(105);

Assert.Equal(1, lazy.Value.Index);
Assert.Equal(1, lazy.Value.Index);
Assert.Equal(1, lazy.Value.Index);

lazy.Invalidate();
Assert.Equal(2, lazy.Value.Index);
}

// in case TimedLazy is ever switched to a struct, this test validates that it's not copied where it shouldn't be
[Fact]
public void TestCachingWithWrapper() {
TestClass.Reset();
var wrapper = new Wrapper();

Assert.Equal(0, wrapper.Value.Index);
Assert.Equal(0, wrapper.Value.Index);
Assert.Equal(0, wrapper.Value.Index);

Thread.Sleep(105);

Assert.Equal(1, wrapper.Value.Index);
Assert.Equal(1, wrapper.Value.Index);
Assert.Equal(1, wrapper.Value.Index);
}

private class Wrapper {
private readonly TimedLazy<TestClass> _lazy = new(TimeSpan.FromMilliseconds(100), () => new TestClass());
internal TestClass Value => _lazy.Value;
}

private class TestClass {
private static int _counter = 0;
public readonly int Index = _counter++;

internal static void Reset() {
_counter = 0;
}
}
}
1 change: 1 addition & 0 deletions app/Pog/lib_compiled/Pog/Pog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<!-- This would be better with PrivateAssets="all", but we cannot do that because it breaks ILRepack. -->
<PackageReference Include="PowerShellStandard.Library" Version="7.0.0-preview.1"/>
<PackageReference Include="System.Text.Json" Version="9.0.0-preview.2.24128.5"/>
<PackageReference Include="System.Net.Http.Json" Version="9.0.0-preview.2.24128.5"/>
<PackageReference Include="MatejKafka.XmlDoc2CmdletDoc" Version="0.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
10 changes: 10 additions & 0 deletions app/Pog/lib_compiled/Pog/src/Pog.InternalState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public static void OverrideDataRoot(string dataRootDirPath) {
_pathConfig = new PathConfig(GetRootDirPath(), dataRootDirPath);
}

/// Debug method, used for testing.
[UsedImplicitly]
public static void OverrideRepository(IRepository repository) {
if (_repository != null) {
throw new Exception("Cannot override Pog repository, as it is already set, " +
"probably due to auto-configuration on the first access.");
}
_repository = repository;
}

private static PathConfig? _pathConfig;
public static PathConfig PathConfig => _pathConfig ??= new PathConfig(GetRootDirPath());

Expand Down
Loading

0 comments on commit 8d09a88

Please sign in to comment.