From a1f2c7e5ce625cdfc2b6660346330b058f52c190 Mon Sep 17 00:00:00 2001 From: Vladimir Petko Date: Mon, 9 Sep 2024 15:28:30 +1200 Subject: [PATCH] chore: split _get_java_post_build_commands 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(). --- craft_parts/plugins/base.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/craft_parts/plugins/base.py b/craft_parts/plugins/base.py index 84efff0b..88231bce 100644 --- a/craft_parts/plugins/base.py +++ b/craft_parts/plugins/base.py @@ -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):