generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add reproducible central buildspec generation #1115
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a7a282a
feat: add macaron database extractor module
ed57cc4
feat: add maven and gradle cli parsers
4aa3743
feat: add jdk version finder from maven central java artifacts
dcae8e5
feat: add cli build command patcher
8909a01
feat: add jdk version normalizer
a8662f4
feat: add reproducible central buildspec generation
426e303
feat: expose macaron gen-build-spec cli command
f24d7af
test: modify the integration test script to use the compare rc build …
4c3ef2d
test: add integration tests for the gen-build-spec error
779c03b
fix: add jdk version 22 and 23 into the list of supported jdk major v…
d0c10de
chore: add a small log message at the beginning of build spec generation
0f9b0c6
fix: fix the sql statement for obtaining build check facts where the …
15efd52
chore: move the looking up of repository before the build tool lookup…
787e9b3
chore: support gen-build-spec for the Docker image
7d548bb
fix: use the correct analysis_id foreign key to map with Analaysis in…
86adc3b
chore: simplify the looking up component information by getting the I…
c14d8dc
refactor: refactor the function to get the purl-based directory path …
2bfc3b2
test: improve test_macaron_db_extractor test module
543246e
feat: generate build spec into a purl-based path in the output directory
5a89639
feat: always prioritize jdk version obtained from JAR from maven central
d339e50
chore: fix typos
95908b4
chore: remove extra comments feature and some refactoring to simplify…
1ee8a19
chore: misc fixes
benmss 5a7923b
chore: address PR feedback
behnazh-w 71b9f5a
chore: address PR feedback
behnazh-w a9be2e3
chore: address PR feedback
behnazh-w 211c23e
docs: fix the docstrings and comments
behnazh-w File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved. | ||
| # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. |
137 changes: 137 additions & 0 deletions
137
src/macaron/build_spec_generator/build_command_patcher.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved. | ||
| # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | ||
|
|
||
| """This module contains the implementation of the build command patching.""" | ||
|
|
||
| import logging | ||
| from collections.abc import Mapping, Sequence | ||
|
|
||
| from macaron.build_spec_generator.cli_command_parser import CLICommand, CLICommandParser, PatchCommandBuildTool | ||
| from macaron.build_spec_generator.cli_command_parser.gradle_cli_parser import ( | ||
| GradleCLICommandParser, | ||
| GradleOptionPatchValueType, | ||
| ) | ||
| from macaron.build_spec_generator.cli_command_parser.maven_cli_parser import ( | ||
| CommandLineParseError, | ||
| MavenCLICommandParser, | ||
| MavenOptionPatchValueType, | ||
| PatchBuildCommandError, | ||
| ) | ||
| from macaron.build_spec_generator.cli_command_parser.unparsed_cli_command import UnparsedCLICommand | ||
|
|
||
| logger: logging.Logger = logging.getLogger(__name__) | ||
|
|
||
| MVN_CLI_PARSER = MavenCLICommandParser() | ||
| GRADLE_CLI_PARSER = GradleCLICommandParser() | ||
|
|
||
| PatchValueType = GradleOptionPatchValueType | MavenOptionPatchValueType | ||
|
|
||
|
|
||
| def _patch_commands( | ||
| cmds_sequence: Sequence[list[str]], | ||
| cli_parsers: Sequence[CLICommandParser], | ||
| patches: Mapping[ | ||
| PatchCommandBuildTool, | ||
| Mapping[str, PatchValueType | None], | ||
| ], | ||
| ) -> list[CLICommand] | None: | ||
| """Patch the sequence of build commands, using the provided CLICommandParser instances. | ||
|
|
||
| For each command in `cmds_sequence`, it will be checked against all CLICommandParser instances until there is | ||
| one that can parse it, then a patch from ``patches`` is applied for this command if provided. | ||
|
|
||
| If a command doesn't have any corresponding ``CLICommandParser`` instance it will be parsed as UnparsedCLICommand, | ||
| which just holds the original command as a list of string, without any changes. | ||
| """ | ||
| result: list[CLICommand] = [] | ||
| for cmds in cmds_sequence: | ||
| effective_cli_parser = None | ||
| for cli_parser in cli_parsers: | ||
| if cli_parser.is_build_tool(cmds[0]): | ||
| effective_cli_parser = cli_parser | ||
| break | ||
|
|
||
| if not effective_cli_parser: | ||
| result.append(UnparsedCLICommand(original_cmds=cmds)) | ||
| continue | ||
|
|
||
| try: | ||
| cli_command = effective_cli_parser.parse(cmds) | ||
| except CommandLineParseError as error: | ||
| logger.error( | ||
| "Failed to patch the cli command %s. Error %s.", | ||
| " ".join(cmds), | ||
| error, | ||
| ) | ||
| return None | ||
|
|
||
| patch = patches.get(effective_cli_parser.build_tool, None) | ||
| if not patch: | ||
| result.append(cli_command) | ||
| continue | ||
|
|
||
| try: | ||
| new_cli_command = effective_cli_parser.apply_patch( | ||
| cli_command=cli_command, | ||
| patch_options=patch, | ||
| ) | ||
| except PatchBuildCommandError as error: | ||
| logger.error( | ||
| "Failed to patch the build command %s. Error %s.", | ||
| " ".join(cmds), | ||
| error, | ||
| ) | ||
| return None | ||
|
|
||
| result.append(new_cli_command) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def patch_commands( | ||
behnazh-w marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cmds_sequence: Sequence[list[str]], | ||
| patches: Mapping[ | ||
| PatchCommandBuildTool, | ||
| Mapping[str, PatchValueType | None], | ||
| ], | ||
| ) -> list[list[str]] | None: | ||
| """Patch a sequence of CLI commands. | ||
|
|
||
| For each command in this command sequence: | ||
|
|
||
| - If the command is not a build command, or it's a tool we do not support, it will be left intact. | ||
|
|
||
| - If the command is a build command we support, it will be patched, if a patch value is provided in ``patches``. | ||
| If no patch value is provided for a build command, it will be left intact. | ||
|
|
||
| `patches` is a mapping with: | ||
|
|
||
| - **Key**: an instance of the ``BuildTool`` enum | ||
|
|
||
| - **Value**: the patch value provided to ``CLICommandParser.apply_patch``. For more information on the patch value | ||
| see the concrete implementations of the ``CLICommandParser.apply_patch`` method. | ||
| For example: :class:`macaron.cli_command_parser.maven_cli_parser.MavenCLICommandParser.apply_patch`, | ||
| :class:`macaron.cli_command_parser.gradle_cli_parser.GradleCLICommandParser.apply_patch`. | ||
|
|
||
| This means that all commands that match a BuildTool will be applied by the same patch value. | ||
|
|
||
| Returns | ||
| ------- | ||
| list[list[str]] | None | ||
| The patched command sequence or None if there is an error. The errors that can happen if any command | ||
| which we support is invalid in ``cmds_sequence``, or the patch value is valid. | ||
| """ | ||
| result = [] | ||
| patch_cli_commands = _patch_commands( | ||
| cmds_sequence=cmds_sequence, | ||
| cli_parsers=[MVN_CLI_PARSER, GRADLE_CLI_PARSER], | ||
| patches=patches, | ||
| ) | ||
|
|
||
| if patch_cli_commands is None: | ||
| return None | ||
|
|
||
| for patch_cmd in patch_cli_commands: | ||
| result.append(patch_cmd.to_cmds()) | ||
|
|
||
| return result | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.