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

add suport for cyclonedx/cyclonedx-library:^3 #398

Merged
merged 5 commits into from
Aug 27, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ All notable changes to this project will be documented in this file.

## unreleased

## 4.1.1 - 2023-08-28

* Dependencies
* Requires `cyclonedx/cyclonedx-library:^2.3||^3.0`, was `:^2.3` (via [#398])
* Style
* Applied latest PHP Coding Standards (via [#395])

[#395]: https://github.com/CycloneDX/cyclonedx-php-composer/pull/395
[#398]: https://github.com/CycloneDX/cyclonedx-php-composer/pull/398

## 4.1.0 - 2023-07-04

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"require": {
"php": "^8.1",
"composer-plugin-api": "^2.3",
"cyclonedx/cyclonedx-library": "^2.3",
"cyclonedx/cyclonedx-library": "^2.3 || ^3.0",
"package-url/packageurl-php": "^1.0"
},
"require-dev": {
Expand Down
37 changes: 31 additions & 6 deletions src/MakeBom/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Composer\IO\IOInterface;
use CycloneDX\Core\Serialization;
use CycloneDX\Core\Spec\Format;
use CycloneDX\Core\Spec\Spec;
use CycloneDX\Core\Spec\SpecFactory;
use CycloneDX\Core\Utils\BomUtility;
use CycloneDX\Core\Validation\Validator;
Expand All @@ -45,6 +44,8 @@
/**
* @internal
*
* @template TSpec
*
* @author jkowalleck
*/
class Command extends BaseCommand
Expand Down Expand Up @@ -87,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->writeErrorRaw(__METHOD__.' Options: '.var_export($this->options, true), verbosity: IOInterface::DEBUG);

try {
$spec = SpecFactory::makeForVersion($this->options->specVersion);
$spec = $this->makeSpec();
$bom = $this->generateBom($io, $spec);
$this->validateBom($bom, $spec, $io);
$this->writeBom($bom, $io);
Expand All @@ -113,9 +114,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/**
* @throws Throwable on error
*
* @return TSpec
*
* @psalm-suppress InvalidReturnType,InvalidReturnStatement -- psalm has issues with template TSpec
*/
private function makeSpec()
{
return SpecFactory::makeForVersion($this->options->specVersion);
}

/**
* @param TSpec $spec
*
* @throws Throwable on error
*/
private function generateBom(IOInterface $io, Spec $spec): string
private function generateBom(IOInterface $io, $spec): string
{
$io->writeError('<info>generate BOM...</info>', verbosity: IOInterface::VERBOSE);

Expand Down Expand Up @@ -157,7 +172,11 @@ private function generateBom(IOInterface $io, Spec $spec): string
));

$io->writeError('<info>serialize BOM...</info>', verbosity: IOInterface::VERBOSE);
/** @var Serialization\Serializer */
/**
* @var Serialization\Serializer $serializer
*
* @psalm-suppress MixedArgumentTypeCoercion -- psalm has issues wth template TSpec for $spec
*/
$serializer = match ($this->options->outputFormat) {
Format::JSON => new Serialization\JsonSerializer(new Serialization\JSON\NormalizerFactory($spec)),
Format::XML => new Serialization\XmlSerializer(new Serialization\DOM\NormalizerFactory($spec)),
Expand All @@ -169,18 +188,24 @@ private function generateBom(IOInterface $io, Spec $spec): string
}

/**
* @param TSpec $spec
*
* @throws Errors\ValidationError on validation errors
* @throws Throwable on error
*/
private function validateBom(string $bom, Spec $spec, IOInterface $io): void
private function validateBom(string $bom, $spec, IOInterface $io): void
{
if (false === $this->options->validate) {
$io->writeError('<info>skipped BOM validation.</info>', verbosity: IOInterface::VERBOSE);

return;
}
$io->writeError('<info>validate BOM...</info>', verbosity: IOInterface::VERBOSE);
/** @var Validator */
/**
* @var Validator $validator
*
* @psalm-suppress MixedArgumentTypeCoercion -- psalm has issues wth template TSpec for $spec
**/
$validator = match ($this->options->outputFormat) {
Format::JSON => new Validators\JsonStrictValidator($spec),
Format::XML => new Validators\XmlValidator($spec),
Expand Down