Skip to content

Commit

Permalink
support custom maven repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
kojo12228 committed Aug 29, 2023
1 parent 64abad4 commit c666f20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class DefaultPostgresBinaryDownloader
private readonly Platform _platform;
private readonly Architecture? _architecture;
private readonly string _destDir;
private readonly string _mavenRepo;

/// <summary>
/// The default Postgres binary downloader uses https://github.com/zonkyio/embedded-postgres-binaries
Expand All @@ -22,12 +23,14 @@ internal class DefaultPostgresBinaryDownloader
/// <param name="pgVersion"></param>
/// <param name="platform"></param>
/// <param name="architecture"></param>
public DefaultPostgresBinaryDownloader(string pgVersion, string destDir, Platform platform, Architecture? architecture)
/// <param name="mavenRepo"></param>
public DefaultPostgresBinaryDownloader(string pgVersion, string destDir, Platform platform, Architecture? architecture, string mavenRepo)
{
_destDir = destDir;
_pgVersion = pgVersion;
_platform = platform;
_architecture = architecture;
_mavenRepo = mavenRepo;
}

public string Download()
Expand All @@ -45,7 +48,7 @@ public string Download()
architecture = "alpine-lite";
}

var downloadUrl = $"https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-{platform}-{architecture}/{_pgVersion}/embedded-postgres-binaries-{platform}-{architecture}-{_pgVersion}.jar";
var downloadUrl = $"{_mavenRepo}/io/zonky/test/postgres/embedded-postgres-binaries-{platform}-{architecture}/{_pgVersion}/embedded-postgres-binaries-{platform}-{architecture}-{_pgVersion}.jar";
var fileName = Path.GetFileName(downloadUrl);
var destFile = Path.Join(_destDir, fileName);
var zipFile = Path.Join(_destDir, Path.GetFileNameWithoutExtension(fileName) + ".txz");
Expand Down
8 changes: 6 additions & 2 deletions src/MysticMind.PostgresEmbed/PgServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class PgServer : IDisposable

private readonly Platform _platform;
private readonly Architecture _architecture;
private readonly string _mavenRepo;

public PgServer(
string pgVersion,
Expand All @@ -58,7 +59,8 @@ public PgServer(
int deleteFolderInitialTimeout =16,
int deleteFolderTimeoutFactor =2,
string locale = "",
Platform? platform = null)
Platform? platform = null,
string mavenRepo = "https://repo1.maven.org/maven2")
{

_pgCtlBin = "pg_ctl";
Expand All @@ -84,6 +86,8 @@ public PgServer(

_architecture = Utils.GetArchitecture(_platform);

_mavenRepo = mavenRepo;

PgUser = String.IsNullOrEmpty(pgUser) ? PgSuperuser : pgUser;

DbDir = Path.Combine(string.IsNullOrEmpty(dbDir) ? "." : dbDir, "pg_embed");
Expand Down Expand Up @@ -157,7 +161,7 @@ public PgServer(

private void DownloadPgBinary()
{
var downloader = new DefaultPostgresBinaryDownloader(PgVersion, BinariesDir, _platform, _architecture);
var downloader = new DefaultPostgresBinaryDownloader(PgVersion, BinariesDir, _platform, _architecture, _mavenRepo);

try
{
Expand Down

0 comments on commit c666f20

Please sign in to comment.