- Fixed issue where some build artifacts are being bundled with package builds such as output_path and static

where they should not be included in the package.
 - Added the ability to pull static versions of packages from repositories where package names ending with `-static.ncc`
   or `_static.ncc` can be pulled if you use the `--prefer-static` or `--static` option when using the `package install`
   command. Otherwise, the normal package will be installed, avoiding static versions.
 - Added support for importing static packages from the system, allowing you to install static packages onto your
   system and import them without importing additional dependencies that isn't already included in the package.
This commit is contained in:
Netkas 2023-10-12 15:55:10 -04:00
parent e4a3dc2f99
commit 4ef923b83c
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
14 changed files with 194 additions and 77 deletions

View file

@ -7,10 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.0.2] - Unreleased
### Added
- Added support for importing static packages from the system, allowing you to install static packages onto your
system and import them without importing additional dependencies that isn't already included in the package.
- Added the ability to pull static versions of packages from repositories where package names ending with `-static.ncc`
or `_static.ncc` can be pulled if you use the `--prefer-static` or `--static` option when using the `package install`
command. Otherwise, the normal package will be installed, avoiding static versions.
### Changed
- Updated fetchPackage method to include authentication
- Update dependencies import in \ncc\Classes > Runtime > importFromPackage()
### Fixed
- Fixed issue where some build artifacts are being bundled with package builds such as `output_path` and `static`
where they should not be included in the package.
## [2.0.1] - 2023-10-11

View file

@ -152,6 +152,11 @@
$options[InstallPackageOptions::REINSTALL] = true;
}
if(isset($args['prefer-static']) || isset($args['static']))
{
$options[InstallPackageOptions::PREFER_STATIC] = true;
}
if(isset($args['skip-dependencies']))
{
$options[InstallPackageOptions::SKIP_DEPENDENCIES] = true;
@ -548,6 +553,7 @@
new CliHelpSection(['install', '--package', '-p', '--version', '-v'], 'Installs a specified ncc package version'),
new CliHelpSection(['install', '-p', '--skip-dependencies'], 'Installs a specified ncc package but skips the installation of dependencies'),
new CliHelpSection(['install', '-p', '--reinstall'], 'Installs a specified ncc package, reinstall if already installed'),
new CliHelpSection(['install', '--prefer-static', '--static'], 'Installs a static version of the package from the remote repository if available'),
new CliHelpSection(['uninstall', '--package', '-p'], 'Uninstalls a specified ncc package'),
new CliHelpSection(['uninstall', '--package', '-p', '--version', '-v'], 'Uninstalls a specified ncc package version'),
new CliHelpSection(['uninstall-all'], 'Uninstalls all packages'),

View file

@ -25,6 +25,7 @@
use CurlHandle;
use Exception;
use JsonException;
use ncc\Enums\Options\InstallPackageOptions;
use ncc\Enums\Types\AuthenticationType;
use ncc\Enums\Types\HttpRequestType;
use ncc\Enums\Types\RepositoryResultType;
@ -46,7 +47,7 @@
/**
* @inheritDoc
*/
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
{
try
{
@ -63,9 +64,9 @@
/**
* @inheritDoc
*/
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
{
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication);
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
}
/**
@ -298,11 +299,12 @@
* @param string $project The project to get the release for (eg; "ncc" or "libs/config")
* @param string $release The release to get the release for (eg; "v1.0.0")
* @param AuthenticationInterface|null $authentication Optional. The authentication to use. If null, No authentication will be used.
* @param array $options Optional. An array of options to use when fetching the package
* @return RepositoryResult The URL to the archive
* @throws AuthenticationException
* @throws NetworkException
*/
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
{
/** @noinspection DuplicatedCode */
if($release === Versions::LATEST)
@ -310,7 +312,13 @@
$release = self::getLatestRelease($repository, $group, $project, $authentication);
}
$endpoint = sprintf('%s://%s/api/v1/repos/%s/%s/releases/tags/%s', ($repository->isSsl() ? 'https' : 'http'), $repository->getHost(), rawurlencode($group), rawurlencode($project), rawurlencode($release));
$endpoint = sprintf('%s://%s/api/v1/repos/%s/%s/releases/tags/%s',
$repository->isSsl() ? 'https' : 'http',
$repository->getHost(),
rawurlencode($group),
rawurlencode($project),
rawurlencode($release)
);
if(RuntimeCache::exists($endpoint))
{
@ -336,23 +344,48 @@
CURLOPT_HTTPHEADER => $headers
]);
Console::outDebug(sprintf('Fetching release package for %s/%s/%s from %s', $group, $project, $release, $endpoint));
Console::outDebug(sprintf('Fetching release package for %s/%s/%s from %s',
$group, $project, $release, $endpoint));
$response = self::processHttpResponse($curl, $group, $project);
if(!isset($response['assets']))
{
throw new NetworkException(sprintf('Failed to get release %s package url for %s/%s', $release, $group, $project));
throw new NetworkException(sprintf('Failed to get release %s package url for %s/%s',
$release, $group, $project));
}
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC]);
$preferred_asset = null;
$fallback_asset = null;
foreach($response['assets'] as $asset)
{
if(isset($asset['name'], $asset['browser_download_url']) && preg_match('/\.ncc$/', $asset['name']))
if($static_preferred && preg_match('/(_static|-static)\.ncc$/', $asset['name']))
{
$result = new RepositoryResult($asset['browser_download_url'], RepositoryResultType::PACKAGE, $release);
$preferred_asset = $asset;
}
elseif(preg_match('/\.ncc$/', $asset['name']))
{
$fallback_asset = $asset;
}
}
$target_asset = $preferred_asset ?: $fallback_asset;
if($target_asset)
{
$asset_url = $target_asset['browser_download_url'] ?? null;
if($asset_url)
{
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE, $release);
RuntimeCache::set($endpoint, $result);
return $result;
}
throw new NetworkException(sprintf('No direct asset URL found for %s/%s/%s', $group, $project, $release));
}
throw new NetworkException(sprintf('No ncc package found for %s/%s/%s', $group, $project, $release));
@ -368,6 +401,7 @@
* @param string $project The project to get the release for (eg; "ncc" or "libs/config")
* @param string $release The release to get the release for (eg; "v1.0.0")
* @param AuthenticationInterface|null $authentication Optional. The authentication to use. If null, No authentication will be used.
* @param array $options Optional. An array of options to use when fetching the archive
* @return RepositoryResult The URL to the archive
* @throws AuthenticationException
* @throws NetworkException
@ -483,14 +517,14 @@
if($response === false)
{
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $vendor, $project, curl_error($curl), $retry_count + 1));
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $group, $project, curl_error($curl), $retry_count + 1));
$retry_count++;
}
}
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $vendor, $project, curl_error($curl)));
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
}
switch(curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -25,6 +25,7 @@
use CurlHandle;
use Exception;
use JsonException;
use ncc\Enums\Options\InstallPackageOptions;
use ncc\Enums\Types\AuthenticationType;
use ncc\Enums\Types\HttpRequestType;
use ncc\Enums\Types\RepositoryResultType;
@ -46,7 +47,7 @@
/**
* @inheritDoc
*/
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
{
try
{
@ -63,9 +64,9 @@
/**
* @inheritDoc
*/
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null): RepositoryResult
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult
{
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication);
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
}
/**
@ -298,11 +299,12 @@
* @param string $project The project to get the release for (eg; "ncc" or "libs/config")
* @param string $release The release to get the release for (eg; "v1.0.0")
* @param AuthenticationInterface|null $authentication Optional. The authentication to use. If null, No authentication will be used.
* @param array $options Optional. An array of options to use when fetching the package
* @return RepositoryResult The URL to the archive
* @throws AuthenticationException
* @throws NetworkException
*/
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
{
/** @noinspection DuplicatedCode */
if($release === Versions::LATEST)
@ -310,7 +312,7 @@
$release = self::getLatestRelease($repository, $group, $project, $authentication);
}
$endpoint = sprintf('%s://%s/repos/%s/%s/releases/tags/%s', ($repository->isSsl() ? 'https' : 'http'), $repository->getHost(), $group, $project, $release);
$endpoint = sprintf('%s://%s/repos/%s/%s/releases/tags/%s', $repository->isSsl() ? 'https' : 'http', $repository->getHost(), $group, $project, $release);
if(RuntimeCache::exists($endpoint))
{
@ -329,11 +331,7 @@
$headers = self::injectAuthentication($authentication, $curl, $headers);
}
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
CURLOPT_HTTPHEADER => $headers
]);
curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => HttpRequestType::GET, CURLOPT_HTTPHEADER => $headers]);
Console::outDebug(sprintf('Fetching release package for %s/%s/%s from %s', $group, $project, $release, $endpoint));
$response = self::processHttpResponse($curl, $group, $project);
@ -343,15 +341,32 @@
throw new NetworkException(sprintf('Failed to get release package for %s/%s/%s: No assets found', $group, $project, $release));
}
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC]);
$preferred_asset = null;
$fallback_asset = null;
foreach($response['assets'] as $asset)
{
if(preg_match('/\.ncc$/', $asset['name']) === 1)
if($static_preferred && preg_match('/(_static|-static)\.ncc$/', $asset['name']))
{
$result = new RepositoryResult($asset['browser_download_url'], RepositoryResultType::PACKAGE, $release);
RuntimeCache::set($endpoint, $result);
return $result;
$preferred_asset = $asset;
}
elseif(preg_match('/\.ncc$/', $asset['name']))
{
$fallback_asset = $asset;
}
}
$target_asset = $preferred_asset ?: $fallback_asset;
if($target_asset)
{
$asset_url = $target_asset['browser_download_url'];
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE, $release);
RuntimeCache::set($endpoint, $result);
return $result;
}
throw new NetworkException(sprintf('Failed to get release package for %s/%s/%s: No assets found', $group, $project, $release));
@ -481,14 +496,14 @@
if($response === false)
{
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $vendor, $project, curl_error($curl), $retry_count + 1));
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $group, $project, curl_error($curl), $retry_count + 1));
$retry_count++;
}
}
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $vendor, $project, curl_error($curl)));
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
}
switch (curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -25,6 +25,7 @@
use CurlHandle;
use Exception;
use JsonException;
use ncc\Enums\Options\InstallPackageOptions;
use ncc\Enums\Types\AuthenticationType;
use ncc\Enums\Types\HttpRequestType;
use ncc\Enums\Types\RepositoryResultType;
@ -46,7 +47,7 @@
/**
* @inheritDoc
*/
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
{
try
{
@ -63,9 +64,9 @@
/**
* @inheritDoc
*/
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
{
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication);
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
}
/**
@ -300,19 +301,19 @@
* @param string $project The project to get the release for (eg; "ncc" or "libs/config")
* @param string $release The release to get the release for (eg; "v1.0.0")
* @param AuthenticationInterface|null $authentication Optional. The authentication to use. If null, No authentication will be used.
* @param array $options Optional. The options to use for the request
* @return RepositoryResult The URL to the archive
* @throws AuthenticationException
* @throws NetworkException
*/
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
{
/** @noinspection DuplicatedCode */
if($release === Versions::LATEST)
{
$release = self::getLatestRelease($repository, $group, $project, $authentication);
}
$project = str_replace('.', '/', $project); // Gitlab doesn't like dots in project names (eg; "libs/config" becomes "libs%2Fconfig")
$project = str_replace('.', '/', $project);
$endpoint = sprintf('%s://%s/api/v4/projects/%s%%2F%s/releases/%s', $repository->isSsl() ? 'https' : 'http', $repository->getHost(), $group, rawurlencode($project), rawurlencode($release));
if(RuntimeCache::exists($endpoint))
@ -339,27 +340,37 @@
]);
$response = self::processHttpResponse($curl, $group, $project);
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC]);
$preferred_asset = null;
$fallback_asset = null;
foreach($response['assets']['links'] as $asset)
{
if(preg_match('/\.ncc$/', $asset['name']) === 1)
if($static_preferred && preg_match('/(_static|-static)\.ncc$/', $asset['name']) === 1)
{
if(isset($asset['direct_asset_url']))
{
$result = new RepositoryResult($asset['direct_asset_url'], RepositoryResultType::PACKAGE, $release);
}
elseif(isset($asset['url']))
{
$result = new RepositoryResult($asset['url'], RepositoryResultType::PACKAGE, $release);
}
else
{
throw new NetworkException(sprintf('No direct asset URL found for %s/%s/%s', $group, $project, $release));
}
$preferred_asset = $asset;
}
elseif(preg_match('/\.ncc$/', $asset['name']) === 1)
{
$fallback_asset = $asset;
}
}
$target_asset = $preferred_asset ?: $fallback_asset;
if ($target_asset)
{
$asset_url = $target_asset['direct_asset_url'] ?? $target_asset['url'] ?? null;
if ($asset_url)
{
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE, $release);
RuntimeCache::set($endpoint, $result);
return $result;
}
throw new NetworkException(sprintf('No direct asset URL found for %s/%s/%s', $group, $project, $release));
}
throw new NetworkException(sprintf('No ncc package found for %s/%s/%s', $group, $project, $release));
@ -504,14 +515,14 @@
if($response === false)
{
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $vendor, $project, curl_error($curl), $retry_count + 1));
Console::outWarning(sprintf('HTTP request failed for %s/%s: %s, retrying (%s/3)', $group, $project, curl_error($curl), $retry_count + 1));
$retry_count++;
}
}
if($response === false)
{
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $vendor, $project, curl_error($curl)));
throw new NetworkException(sprintf('HTTP request failed for %s/%s: %s', $group, $project, curl_error($curl)));
}
switch (curl_getinfo($curl, CURLINFO_HTTP_CODE))

View file

@ -323,6 +323,19 @@
$metadata->setMainExecutionPolicy($this->project_manager->getProjectConfiguration()->getBuild()->getMain());
$metadata->setInstaller($this->project_manager->getProjectConfiguration()->getInstaller());
// Strip out 'output_file' build artifact.
if(isset($metadata->getOptions()[BuildConfigurationOptions::OUTPUT_FILE]))
{
$metadata->removeOption(BuildConfigurationOptions::OUTPUT_FILE);
}
// Strip out 'static' build artifact, PackageFlags::STATIC_DEPENDENCIES is used instead
// Making this option redundant.
if(isset($metadata->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES]))
{
$metadata->removeOption(BuildConfigurationOptions::STATIC_DEPENDENCIES);
}
/** @noinspection UnusedFunctionResultInspection */
$package_writer->setMetadata($metadata);
}

View file

@ -30,6 +30,7 @@
use ncc\Enums\PackageDirectory;
use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\NotSupportedException;
use ncc\Objects\Package\Component;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\Package\Metadata;
@ -341,6 +342,7 @@
*
* @return Metadata
* @throws ConfigurationException
* @throws NotSupportedException
*/
public function getMetadata(): Metadata
{
@ -357,6 +359,11 @@
}
$metadata = Metadata::fromArray(ZiProto::decode($this->get($directory)));
foreach($this->getFlags() as $flag)
{
$metadata->setOption($flag, true);
}
$this->cache[$directory] = $metadata;
return $metadata;
}

View file

@ -46,7 +46,7 @@
/**
* @inheritDoc
*/
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null): RepositoryResult
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult
{
if($version === Versions::LATEST)
{
@ -98,7 +98,7 @@
* @inheritDoc
* @throws NotSupportedException
*/
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null): RepositoryResult
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult
{
throw new NotSupportedException('Fetching ncc packages from Packagist is not supported');
}

View file

@ -177,15 +177,6 @@
self::$class_map[strtolower($class)] = $component_path;
}
self::$imported_packages[$package] = $entry->getPath($version);
// Import dependencies recursively
foreach($entry->getVersion($version)->getDependencies() as $dependency)
{
/** @noinspection UnusedFunctionResultInspection */
self::import($dependency->getName(), $dependency->getVersion());
}
if($entry->getMetadata($version)->getOption(BuildConfigurationOptions::REQUIRE_FILES) !== null)
{
foreach($entry->getMetadata($version)->getOption(BuildConfigurationOptions::REQUIRE_FILES) as $item)
@ -206,6 +197,26 @@
}
}
self::$imported_packages[$package] = $entry->getPath($version);
if(isset($entry->getMetadata($version)->getOptions()[PackageFlags::STATIC_DEPENDENCIES]))
{
// Fake import the dependencies
foreach($entry->getVersion($version)->getDependencies() as $dependency)
{
self::$imported_packages[$dependency->getName()] = $entry->getPath($version);
}
}
else
{
// Import dependencies recursively
foreach($entry->getVersion($version)->getDependencies() as $dependency)
{
/** @noinspection UnusedFunctionResultInspection */
self::import($dependency->getName(), $dependency->getVersion());
}
}
return $package;
}
@ -215,10 +226,9 @@
* @param string $package_path
* @return string
* @throws ConfigurationException
* @throws IOException
* @throws ImportException
* @throws NotSupportedException
* @throws OperationException
* @throws PathNotFoundException
*/
private static function importFromPackage(string $package_path): string
{
@ -268,7 +278,7 @@
}
}
if(!$package_reader->getFlag(PackageFlags::STATIC_DEPENDENCIES))
if($package_reader->getFlag(PackageFlags::STATIC_DEPENDENCIES))
{
// Fake import the dependencies
foreach($package_reader->getDependencies() as $dependency_name)

View file

@ -98,6 +98,8 @@
*/
public const OPERATION_EXCEPTION = -1776;
public const IMPORT_EXCEPTION = -1777;
/**
* All the exception codes from NCC
*/
@ -115,6 +117,7 @@
self::PACKAGE_EXCEPTION,
self::NETWORK_EXCEPTION,
self::INTEGRITY_EXCEPTION,
self::OPERATION_EXCEPTION
self::OPERATION_EXCEPTION,
self::IMPORT_EXCEPTION
];
}

View file

@ -37,4 +37,10 @@
* Including dependencies if they are being processed.
*/
public const REINSTALL = 'reinstall';
/**
* Installs a static version of the package if it's available
* otherwise it will install non-static version
*/
public const PREFER_STATIC = 'prefer_static';
}

View file

@ -40,11 +40,12 @@
* @param string $project The project to get the source for (eg; "ncc" or "libs/config")
* @param string $version Optional. The version to get the source for. By default, it will get the latest version
* @param AuthenticationType|null $authentication Optional. The authentication to use. If null, No authentication will be used.
* @param array $options Optional. The options to use for the request
* @return RepositoryResult The result of the request
* @throws AuthenticationException If the authentication is invalid
* @throws NetworkException If there was an error getting the source
*/
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult;
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult;
/**
* Returns the archive URL for the ncc package of the specified group and project.
@ -55,9 +56,10 @@
* @param string $project The project to get the package for (eg; "ncc" or "libs/config")
* @param string $version Optional. The version to get the package for. By default, it will get the latest version
* @param AuthenticationType|null $authentication Optional. The authentication to use. If null, No authentication will be used.
* @param array $options Optional. The options to use for the request
* @return RepositoryResult The result of the request
* @throws AuthenticationException If the authentication is invalid
* @throws NetworkException If there was an error getting the package
*/
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult;
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult;
}

View file

@ -558,7 +558,7 @@
// First try to fetch a pre-built package from the repository
$results = $this->repository_manager->getRepository($input->getRepository())->fetchPackage(
$input->getVendor(), $input->getPackage(), $input->getVersion(), $authentication
$input->getVendor(), $input->getPackage(), $input->getVersion(), $authentication, $options
);
$package_path = $this->downloadFile($results->getUrl(), PathFinder::getCachePath());
@ -592,7 +592,7 @@
));
$results = $this->repository_manager->getRepository($input->getRepository())->fetchSourceArchive(
$input->getVendor(), $input->getPackage(), $input->getVersion(), $authentication
$input->getVendor(), $input->getPackage(), $input->getVersion(), $authentication, $options
);
$archive_path = $this->downloadFile($results->getUrl(), PathFinder::getCachePath());

View file

@ -178,13 +178,13 @@
* @throws NetworkException If there was an error getting the package
* @throws NotSupportedException If the repository type does not support fetching packages
*/
public function fetchPackage(string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult
public function fetchPackage(string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
{
return match(strtolower($this->type))
{
RepositoryType::GITHUB => GithubRepository::fetchPackage($this, $vendor, $project, $version, $authentication),
RepositoryType::GITLAB => GitlabRepository::fetchPackage($this, $vendor, $project, $version, $authentication),
RepositoryType::GITEA => GiteaRepository::fetchPackage($this, $vendor, $project, $version, $authentication),
RepositoryType::GITHUB => GithubRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options),
RepositoryType::GITLAB => GitlabRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options),
RepositoryType::GITEA => GiteaRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options),
RepositoryType::PACKAGIST => throw new NotSupportedException('Fetching ncc packages from Packagist is not supported'),
default => throw new InvalidArgumentException(sprintf('Invalid repository type \'%s\'', $this->type)),
};
@ -202,14 +202,14 @@
* @throws AuthenticationException If the authentication is invalid
* @throws NetworkException If there was an error getting the source
*/
public function fetchSourceArchive(string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null): RepositoryResult
public function fetchSourceArchive(string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
{
return match(strtolower($this->type))
{
RepositoryType::GITHUB => GithubRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication),
RepositoryType::GITLAB => GitlabRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication),
RepositoryType::GITEA => GiteaRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication),
RepositoryType::PACKAGIST => PackagistRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication),
RepositoryType::GITHUB => GithubRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options),
RepositoryType::GITLAB => GitlabRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options),
RepositoryType::GITEA => GiteaRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options),
RepositoryType::PACKAGIST => PackagistRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options),
default => throw new InvalidArgumentException(sprintf('Invalid repository type \'%s\'', $this->type)),
};
}