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

chore: split _get_java_post_build_commands #837

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions craft_parts/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,39 @@ class JavaPlugin(Plugin):
symlink creation.
"""

def _get_java_post_build_commands(self) -> list[str]:
"""Get the bash commands to structure a Java build in the part's install dir.

:return: The returned list contains the bash commands to do the following:

- Create bin/ and jar/ directories in ${CRAFT_PART_INSTALL};
- Find the ``java`` executable (provided by whatever jre the part used) and
link it as ${CRAFT_PART_INSTALL}/bin/java;
- Hardlink the .jar files generated in ${CRAFT_PART_BUILD} to
${CRAFT_PART_INSTALL}/jar.
"""
def _get_java_link_commands(self) -> list[str]:
"""Get the bash commands to provide /bin/java symlink."""
# pylint: disable=line-too-long
link_java = [
return [
'# Find the "java" executable and make a link to it in CRAFT_PART_INSTALL/bin/java',
"mkdir -p ${CRAFT_PART_INSTALL}/bin",
"java_bin=$(find ${CRAFT_PART_INSTALL} -name java -type f -executable)",
"ln -s --relative $java_bin ${CRAFT_PART_INSTALL}/bin/java",
]
# pylint: enable=line-too-long

link_jars = [
def _get_jar_link_commands(self) -> list[str]:
"""Get the bash commands to provide ${CRAFT_STAGE}/jars."""
# pylint: disable=line-too-long
return [
"# Find all the generated jars and hardlink them inside CRAFT_PART_INSTALL/jar/",
"mkdir -p ${CRAFT_PART_INSTALL}/jar",
r'find ${CRAFT_PART_BUILD}/ -iname "*.jar" -exec ln {} ${CRAFT_PART_INSTALL}/jar \;',
]
# pylint: enable=line-too-long

return link_java + link_jars
def _get_java_post_build_commands(self) -> list[str]:
"""Get the bash commands to structure a Java build in the part's install dir.

:return: The returned list contains the bash commands to do the following:

- Create bin/ and jar/ directories in ${CRAFT_PART_INSTALL};
- Find the ``java`` executable (provided by whatever jre the part used) and
link it as ${CRAFT_PART_INSTALL}/bin/java;
- Hardlink the .jar files generated in ${CRAFT_PART_BUILD} to
${CRAFT_PART_INSTALL}/jar.
"""
return self._get_java_link_commands() + self._get_jar_link_commands()


class BasePythonPlugin(Plugin):
Expand Down
Loading