3838# SOFTWARE.
3939
4040import os
41- import subprocess
4241import tempfile
4342import unittest
4443import urllib .parse
@@ -217,7 +216,7 @@ def generate_app(self, target_dir):
217216
218217 @unittest .skipUnless (is_gradle_enabled , "ENABLE_GRADLE_STANDALONE_UNITTESTS is not true" )
219218 def test_gradle_generated_app (self ):
220- with tempfile .TemporaryDirectory () as tmpdir :
219+ with tempfile .TemporaryDirectory () as tmpdir :
221220 target_dir = os .path .join (str (tmpdir ), "generated_app_gradle" + self .target_dir_name_sufix ())
222221 self .generate_app (target_dir )
223222 build_file = os .path .join (target_dir , self .build_file_name )
@@ -231,7 +230,7 @@ def test_gradle_generated_app(self):
231230 util .check_ouput ("BUILD SUCCESS" , out )
232231
233232 cmd = gradlew_cmd + ["nativeCompile" ]
234- # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
233+ # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
235234 # which is fine, because we need to build the native binary with a graalvm build
236235 # and the one we have set in JAVA_HOME is at least jdk24
237236 # => run without gradle = True
@@ -267,6 +266,22 @@ def test_gradle_generated_app(self):
267266 #GR-51132 - NoClassDefFoundError when running polyglot app in java mode
268267 util .check_ouput ("java.lang.NoClassDefFoundError" , out , False )
269268
269+ # move app to another folder
270+ # this will break launcher symlinks, but should be able to recover from that
271+ target_dir2 = os .path .join (str (tmpdir ), "generated_app_gradle.2" + self .target_dir_name_sufix ())
272+ os .rename (target_dir , target_dir2 )
273+ # adding new dep triggers launcher without venv regen
274+ self .copy_build_files (target_dir2 )
275+ build_file2 = os .path .join (target_dir2 , self .build_file_name )
276+ append (build_file2 , self .packages_termcolor_ujson ())
277+
278+ gradlew_cmd2 = util .get_gradle_wrapper (target_dir2 , self .env )
279+ cmd = gradlew_cmd2 + ["build" , "run" ]
280+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir2 , gradle = True )
281+ util .check_ouput ("BUILD SUCCESS" , out )
282+ util .check_ouput ("Deleting GraalPy venv due to broken launcher symlinks" , out )
283+ util .check_ouput ("hello java" , out )
284+
270285 @unittest .skipUnless (is_gradle_enabled , "ENABLE_GRADLE_STANDALONE_UNITTESTS is not true" )
271286 def test_gradle_generated_app_external_resources (self ):
272287 with tempfile .TemporaryDirectory () as tmpdir :
@@ -300,7 +315,7 @@ def test_gradle_generated_app_external_resources(self):
300315 out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
301316 util .check_ouput ("BUILD SUCCESS" , out )
302317
303- # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
318+ # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
304319 # which is fine, because we need to build the native binary with a graalvm build
305320 # and the one we have set in JAVA_HOME is at least jdk24
306321 # => run without gradle = True
@@ -704,6 +719,19 @@ def test_generated_app(self):
704719 #GR-51132 - NoClassDefFoundError when running polyglot app in java mode
705720 util .check_ouput ("java.lang.NoClassDefFoundError" , out , False )
706721
722+ # move app to another folder
723+ # this will break launcher symlinks, but should be able to recover from that
724+ target_dir2 = os .path .join (str (tmpdir ), target_name + ".2" )
725+ os .rename (target_dir , target_dir2 )
726+ mvnw_cmd2 = util .get_mvn_wrapper (target_dir2 , self .env )
727+ # adding new dep triggers launcher without venv regen
728+ util .replace_in_file (os .path .join (target_dir2 , "pom.xml" ), "<packages>" , "<packages>\n <package>ujson</package>" )
729+ cmd = mvnw_cmd2 + ["package" , "exec:java" , "-Dexec.mainClass=it.pkg.GraalPy" ]
730+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir2 )
731+ util .check_ouput ("BUILD SUCCESS" , out )
732+ util .check_ouput ("Deleting GraalPy venv due to changed launcher path" , out )
733+ util .check_ouput ("hello java" , out )
734+
707735 @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
708736 def test_generated_app_external_resources (self ):
709737 with tempfile .TemporaryDirectory () as tmpdir :
0 commit comments