Skip to content

Commit

Permalink
refactor: split _get_java_post_build_commands (#837)
Browse files Browse the repository at this point in the history
JavaPlugin provides _get_java_post_build_commands() that is
called from derived classes.

/bin/java link is broken for rockcraft projects.
Split _get_java_link_commands() into _get_java_link_commands()
and _get_jar_link_commands() to allow rockcraft plugins
override _get_java_link_commands().

Co-authored-by: Tiago Nobrega <[email protected]>
  • Loading branch information
vpa1977 and tigarmo authored Sep 20, 2024
1 parent bf01f52 commit a327fca
Showing 1 changed file with 20 additions and 14 deletions.
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

0 comments on commit a327fca

Please sign in to comment.